naive-ui/demo/header.vue

147 lines
2.8 KiB
Vue
Raw Normal View History

2019-09-23 11:32:50 +08:00
<i18n>
{
2019-12-23 16:31:26 +08:00
"zh-CN": {
2019-09-23 11:32:50 +08:00
"dark": "深色",
2020-02-05 13:46:57 +08:00
"light": "浅色",
"searchPlaceholder": "搜索组件"
2019-09-23 11:32:50 +08:00
},
2019-12-23 16:31:26 +08:00
"en-US": {
2019-09-23 11:32:50 +08:00
"dark": "Dark",
2020-02-05 13:46:57 +08:00
"light": "Light",
"searchPlaceholder": "Search Components"
2019-09-23 11:32:50 +08:00
}
}
</i18n>
2019-09-17 19:28:28 +08:00
<template>
<div class="nav">
<div class="ui-logo">
2019-10-28 12:39:56 +08:00
<img src="./assets/images/naivelogo.svg">
2019-10-10 22:38:29 +08:00
Naive UI ({{ version }})
2019-09-17 19:28:28 +08:00
</div>
<div style="width: 200px; margin-left: 48px;">
<n-auto-complete
v-model="searchInputValue"
2020-02-05 13:46:57 +08:00
:placeholder="$t('searchPlaceholder')"
:options="searchOptions"
clear-after-select
blur-after-select
@select="handleSelect"
/>
</div>
2019-09-17 19:28:28 +08:00
<div class="theme-picker">
<n-select
v-model="NConfigProvider.$parent.theme"
2019-09-17 19:28:28 +08:00
size="small"
:options="options"
/>
</div>
2019-09-21 17:03:37 +08:00
<div class="lang-picker">
<n-select
2019-09-24 16:59:07 +08:00
:value="lang"
2019-09-21 17:03:37 +08:00
size="small"
:options="langOptions"
2020-01-29 20:51:51 +08:00
@change="handleLanguageChange"
2019-09-21 17:03:37 +08:00
/>
</div>
2019-09-17 19:28:28 +08:00
</div>
</template>
<script>
2019-09-20 00:22:55 +08:00
import { version } from '../package.json'
2019-09-17 19:28:28 +08:00
import withapp from '../packages/mixins/withapp'
export default {
mixins: [withapp],
2019-09-24 16:59:07 +08:00
props: {
lang: {
type: String,
required: true
},
items: {
type: Array,
default: () => []
2019-09-24 16:59:07 +08:00
}
},
2019-09-17 19:28:28 +08:00
data () {
return {
searchInputValue: '',
2019-09-20 00:22:55 +08:00
version,
2019-09-24 16:59:07 +08:00
theme: 'dark',
2019-09-21 17:03:37 +08:00
langOptions: [
{
label: '中文',
2019-12-23 16:31:26 +08:00
value: 'zh-CN'
2019-09-21 17:03:37 +08:00
},
{
label: 'English',
2019-12-23 16:31:26 +08:00
value: 'en-US'
2019-09-21 17:03:37 +08:00
}
2019-09-17 19:28:28 +08:00
]
}
},
2019-09-23 11:32:50 +08:00
computed: {
searchOptions () {
if (!this.searchInputValue) return []
return this.items.filter(item => {
// console.log(item.name.toLowerCase(), this.searchInputValue.toLowerCase())
return ~item.name.toLowerCase().indexOf(this.searchInputValue.toLowerCase())
}).map(item => ({
label: item.name,
value: item.path
}))
},
2019-09-23 11:32:50 +08:00
options: function () {
return [
{
label: this.$t('dark'),
2019-09-24 16:59:07 +08:00
value: 'dark'
2019-09-23 11:32:50 +08:00
},
{
label: this.$t('light'),
value: 'light'
}
]
}
},
2019-09-17 19:28:28 +08:00
methods: {
handleSelect (value) {
this.$router.push(value)
document.body.focus()
},
handleThemeChange (theme) {
this.NConfigProvider.$parent.theme = theme
},
2020-01-29 20:51:51 +08:00
handleLanguageChange (lang) {
2019-09-24 16:59:07 +08:00
this.$emit('lang-change', lang)
2019-09-17 19:28:28 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.nav {
display: grid;
grid-template-columns: 272px 1fr 96px 140px;
2019-09-17 19:28:28 +08:00
grid-template-rows: 64px;
align-items: center;
}
.ui-logo {
2019-10-20 00:18:55 +08:00
display: flex;
align-items: center;
padding-left: 44px;
font-size: 18px;
}
.ui-logo > img {
margin-right: 12px;
height: 32px;
width: 32px;
2019-09-17 19:28:28 +08:00
}
.theme-picker {
2019-09-21 17:03:37 +08:00
padding-right: 16px;
}
.lang-picker {
2019-09-17 19:28:28 +08:00
padding-right: 48px;
}
</style>