You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/site/components/header.vue

81 lines
2.5 KiB

7 years ago
<script>
import { isZhCN } from '../util'
import sortBy from 'lodash/sortBy'
7 years ago
export default {
props: {
7 years ago
name: String,
7 years ago
searchData: Array,
7 years ago
},
data () {
return {
7 years ago
value: null,
7 years ago
}
},
methods: {
handleClick () {
7 years ago
const name = this.name
const path = this.$route.path
const newName = isZhCN(name) ? name.replace(/-cn\/?$/, '') : `${name}-cn`
7 years ago
this.$router.push({
7 years ago
path: path.replace(name, newName),
7 years ago
})
},
7 years ago
onSelect (val) {
this.$router.push(val)
this.value = val
},
7 years ago
},
render () {
7 years ago
const name = this.name
const searchData = sortBy(this.searchData, ['title'])
7 years ago
const isCN = isZhCN(name)
return (
<header id='header'>
<a-row>
<a-col xxl={4} xl={5} lg={5} md={6} sm={24} xs={24}>
<router-link to={{ path: '/ant-design' }} id='logo'>
7 years ago
<img alt='logo' height='32' src='https://raw.githubusercontent.com/vueComponent/ant-design/master/logo.png' />
7 years ago
<span> VUE-ANTD</span>
</router-link>
</a-col>
<a-col xxl={20} xl={19} lg={19} md={18} sm={0} xs={0}>
7 years ago
<div id='search-box' style='display: block'>
<a-icon type='search' />
<a-select
ref='selectBox'
placeholder={isCN ? '搜索组件...' : 'input search text'}
style='width: 200px'
defaultActiveFirstOption={false}
showArrow={false}
showSearch
onSelect={this.onSelect}
optionFilterProp='children'
key={this.value}
>
{
searchData.map(({ title, subtitle, url }) =>
<a-select-option key={url}>
{title} {isCN && subtitle}
</a-select-option>)
}
</a-select>
7 years ago
</div>
<a-button ghost size='small' onClick={this.handleClick} class='header-lang-button' key='lang-button'>
{isCN ? 'English' : '中文'}
</a-button>
<a-menu selectedKeys={['components']} mode='horizontal' class='menu-site' id='nav'>
<a-menu-item key='components'>
{isCN ? '组件' : 'Components'}
</a-menu-item>
<a-menu-item key='github'>
<a href='https://github.com/vueComponent/ant-design'>GitHub</a>
</a-menu-item>
</a-menu>
</a-col>
</a-row>
</header>
)
},
}
</script>