naive-ui/demo/demo.vue

557 lines
16 KiB
Vue
Raw Normal View History

<template>
2019-12-23 16:31:26 +08:00
<n-config-provider class="demo" namespace="naive-ui-doc" :theme="theme" :language="lang">
<n-nimbus-service-layout :padding-body="false" :items="items">
<template v-slot:nav>
2019-09-24 16:59:07 +08:00
<doc-header
:lang="lang"
:items="flattenedItems"
2019-09-24 16:59:07 +08:00
@lang-change="handleLangChange"
/>
2019-09-17 19:28:28 +08:00
</template>
2019-06-23 19:52:26 +08:00
<router-view />
</n-nimbus-service-layout>
</n-config-provider>
</template>
<script>
2019-09-17 19:28:28 +08:00
import DocHeader from './header.vue'
2019-09-24 16:59:07 +08:00
import { i18n } from './init'
2019-09-17 19:28:28 +08:00
export default {
2019-09-17 19:28:28 +08:00
components: {
DocHeader
},
2019-09-24 16:59:07 +08:00
beforeRouteEnter (to, from, next) {
// console.log(i18n)
2019-09-24 16:59:07 +08:00
i18n.locale = to.params.lang
next()
},
beforeRouteUpdate (to, from, next) {
this.$i18n.locale = to.params.lang
next()
},
computed: {
items () {
2019-12-31 18:26:21 +08:00
const appendCounts = item => {
if (!item.childItems) {
item.count = 1
return item
}
if (item.childItems) {
item.childItems.forEach(appendCounts)
item.count = item.childItems.reduce((sum, item) => sum + item.count, 0)
if (!item.group) {
item.title = h => {
return h('n-config-consumer', {
props: {
transparent: true
},
scopedSlots: {
default: ({ styleScheme }) => {
return h('span', {
}, [ item.name, h('span', {
style: {
color: styleScheme.tertiaryTextColor,
fontWeight: '400',
transition: `color .3s ${styleScheme.easeInOutCubicBezier}`
}
}, [ ' (', item.count, ')' ])])
}
}
})
}
} else {
item.name += ` (${item.count})`
}
return item
}
}
2019-09-24 16:59:07 +08:00
return [
2019-06-23 19:52:26 +08:00
{
2019-10-10 22:38:29 +08:00
name: 'Naive UI',
path: `/${this.lang}/${this.theme}` + '/intro'
},
{
name: 'Getting Started',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/start'
2019-06-23 19:52:26 +08:00
},
{
2019-10-10 22:38:29 +08:00
name: 'Develop Guidelines',
path: `/${this.lang}/${this.theme}` + '/dev-guildlines'
},
{
2019-12-07 00:02:31 +08:00
name: 'Create Themed Component',
path: `/${this.lang}/${this.theme}` + '/n-theme'
2019-10-10 22:38:29 +08:00
},
2019-12-31 18:26:21 +08:00
appendCounts({
name: 'Components',
2019-11-09 14:19:07 +08:00
childItems: [
{
2019-12-31 18:26:21 +08:00
name: 'Config Components',
group: true,
childItems: [
{
name: 'Config Provider',
path: `/${this.lang}/${this.theme}` + '/n-config-provider'
},
{
name: 'Config Consumer',
path: `/${this.lang}/${this.theme}` + '/n-config-consumer'
},
{
name: 'Element',
path: `/${this.lang}/${this.theme}` + '/n-element'
}
]
},
{
name: 'Layout Components',
group: true,
childItems: [
{
name: 'Layout',
path: `/${this.lang}/${this.theme}` + '/n-layout'
},
{
name: 'Grid',
path: `/${this.lang}/${this.theme}` + '/n-grid'
}
]
},
{
name: 'Common Components',
group: true,
childItems: [
{
name: 'Avatar',
path: `/${this.lang}/${this.theme}` + '/n-avatar'
},
{
name: 'Button',
path: `/${this.lang}/${this.theme}` + '/n-button'
},
{
name: 'Card',
path: `/${this.lang}/${this.theme}` + '/n-card'
},
{
name: 'Collapse',
path: `/${this.lang}/${this.theme}` + '/n-collapse'
},
{
name: 'Divider',
path: `/${this.lang}/${this.theme}` + '/n-divider'
},
{
name: 'Dropdown',
path: `/${this.lang}/${this.theme}` + '/n-dropdown'
},
{
name: 'Gradient Text',
path: `/${this.lang}/${this.theme}` + '/n-gradient-text'
},
{
name: 'Icon',
path: `/${this.lang}/${this.theme}` + '/n-icon'
},
{
name: 'Tag',
path: `/${this.lang}/${this.theme}` + '/n-tag'
},
{
name: 'Typography',
path: `/${this.lang}/${this.theme}` + '/n-typography'
}
]
},
{
name: 'Data Input Components',
group: true,
childItems: [
{
name: 'Auto Complete',
path: `/${this.lang}/${this.theme}` + '/n-auto-complete'
},
{
name: 'Cascader',
path: `/${this.lang}/${this.theme}` + '/n-cascader'
},
{
name: 'Checkbox',
path: `/${this.lang}/${this.theme}` + '/n-checkbox'
},
{
name: 'Custom Input (in progress)',
path: `/${this.lang}/${this.theme}` + '/n-custom-input'
},
{
name: 'Date Picker',
path: `/${this.lang}/${this.theme}` + '/n-date-picker'
},
{
name: 'Form',
path: `/${this.lang}/${this.theme}` + '/n-form'
},
{
name: 'Input',
path: `/${this.lang}/${this.theme}` + '/n-input'
},
{
name: 'Input Number',
path: `/${this.lang}/${this.theme}` + '/n-input-number'
},
{
name: 'Radio',
path: `/${this.lang}/${this.theme}` + '/n-radio'
},
{
name: 'Select',
path: `/${this.lang}/${this.theme}` + '/n-select'
},
{
name: 'Slider',
path: `/${this.lang}/${this.theme}` + '/n-slider'
},
{
name: 'Switch',
path: `/${this.lang}/${this.theme}` + '/n-switch'
},
{
name: 'Time Picker',
path: `/${this.lang}/${this.theme}` + '/n-time-picker'
},
{
name: 'Transfer',
path: `/${this.lang}/${this.theme}` + '/n-transfer'
}
]
},
{
name: 'Data Display Components',
group: true,
childItems: [
{
name: 'Code',
path: `/${this.lang}/${this.theme}` + '/n-code'
},
{
name: 'DataTable',
path: `/${this.lang}/${this.theme}` + '/n-data-table'
},
2019-12-31 18:26:21 +08:00
{
name: 'Descriptions',
path: `/${this.lang}/${this.theme}` + '/n-descriptions'
},
{
name: 'Empty',
path: `/${this.lang}/${this.theme}` + '/n-empty'
},
{
name: 'List',
path: `/${this.lang}/${this.theme}` + '/n-list'
},
{
name: 'Log',
path: `/${this.lang}/${this.theme}` + '/n-log'
},
{
name: 'Statistic',
path: `/${this.lang}/${this.theme}` + '/n-statistic'
},
{
name: 'Thing',
path: `/${this.lang}/${this.theme}` + '/n-thing'
},
{
name: 'Time',
path: `/${this.lang}/${this.theme}` + '/n-time'
},
{
name: 'Timeline',
path: `/${this.lang}/${this.theme}` + '/n-timeline'
},
{
name: 'Tree (in progress)',
path: `/${this.lang}/${this.theme}` + '/n-tree'
}
]
},
{
name: 'Navigation Components',
group: true,
childItems: [
{
name: 'Affix',
path: `/${this.lang}/${this.theme}` + '/n-affix'
},
{
name: 'Anchor',
path: `/${this.lang}/${this.theme}` + '/n-anchor'
},
{
name: 'BackTop',
path: `/${this.lang}/${this.theme}` + '/n-back-top'
},
{
name: 'Breadcrumb',
path: `/${this.lang}/${this.theme}` + '/n-breadcrumb'
},
{
name: 'Loading Bar',
path: `/${this.lang}/${this.theme}` + '/n-loading-bar'
},
{
name: 'Menu',
path: `/${this.lang}/${this.theme}` + '/n-menu'
},
{
name: 'Pagination',
path: `/${this.lang}/${this.theme}` + '/n-pagination'
},
{
name: 'Steps',
path: `/${this.lang}/${this.theme}` + '/n-steps'
},
{
name: 'Tabs',
path: `/${this.lang}/${this.theme}` + '/n-tabs'
}
]
},
{
name: 'Feedback Components',
group: true,
childItems: [
{
name: 'Alert',
path: `/${this.lang}/${this.theme}` + '/n-alert'
},
{
name: 'Badge',
path: `/${this.lang}/${this.theme}` + '/n-badge'
},
{
name: 'Confirm',
path: `/${this.lang}/${this.theme}` + '/n-confirm'
},
{
name: 'Drawer',
path: `/${this.lang}/${this.theme}` + '/n-drawer'
},
{
name: 'Message',
path: `/${this.lang}/${this.theme}` + '/n-message'
},
{
name: 'Modal',
path: `/${this.lang}/${this.theme}` + '/n-modal'
},
{
name: 'Notification',
path: `/${this.lang}/${this.theme}` + '/n-notification'
},
{
name: 'Popover',
path: `/${this.lang}/${this.theme}` + '/n-popover'
},
{
name: 'Popconfirm',
path: `/${this.lang}/${this.theme}` + '/n-popconfirm'
},
{
name: 'Popselect',
path: `/${this.lang}/${this.theme}` + '/n-popselect'
},
{
name: 'Progress',
path: `/${this.lang}/${this.theme}` + '/n-progress'
},
{
name: 'Result',
path: `/${this.lang}/${this.theme}` + '/n-result'
},
{
name: 'Spin',
path: `/${this.lang}/${this.theme}` + '/n-spin'
},
{
name: 'Tooltip',
path: `/${this.lang}/${this.theme}` + '/n-tooltip'
}
]
2019-11-09 14:19:07 +08:00
}
]
2019-12-31 18:26:21 +08:00
}),
2019-11-09 14:19:07 +08:00
{
2019-12-31 18:26:21 +08:00
name: 'Deprecated',
path: `/${this.lang}/${this.theme}` + '/',
2019-11-09 14:19:07 +08:00
childItems: [
{
2019-12-31 18:26:21 +08:00
name: 'Nimbus Service Layout',
path: `/${this.lang}/${this.theme}` + '/n-nimbus-service-layout'
}
]
},
{
name: 'Debug',
childItems: [
{
name: 'CancelMarkDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-cancel-mark-debug'
},
{
name: 'PopoverDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-popover-debug'
},
{
name: 'RouterDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-router-debug'
2019-07-26 16:33:01 +08:00
},
{
name: 'ModalDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-modal-debug'
},
{
name: 'ScrollbarDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-scrollbar-debug'
},
{
name: 'ScrollbarDebug2',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-scrollbar-debug2'
},
{
name: 'DatePickerDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-date-picker-debug'
},
{
name: 'BackTopDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-back-top-debug'
2019-08-27 11:19:53 +08:00
},
{
2019-09-12 11:56:49 +08:00
name: 'CascaderDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-cascader-debug'
2019-09-12 11:56:49 +08:00
},
{
name: 'VerticalAlignDebug',
2019-09-27 15:56:01 +08:00
path: `/${this.lang}/${this.theme}` + '/n-vertical-align-debug'
},
{
name: 'IconTransitionDebug',
path: `/${this.lang}/${this.theme}` + '/n-icon-transition-debug'
2019-12-27 14:25:24 +08:00
},
{
name: 'SelectDebug',
path: `/${this.lang}/${this.theme}` + '/n-select-debug'
}
]
}
]
2019-09-24 16:59:07 +08:00
},
flattenedItems () {
const flattenedItems = []
const traverse = items => {
if (items) {
items.forEach(item => {
if (item.childItems) traverse(item.childItems)
else flattenedItems.push(item)
})
}
}
traverse(this.items)
return flattenedItems
},
2019-09-24 16:59:07 +08:00
lang: {
get () {
2019-12-23 16:31:26 +08:00
return this.$route.params.lang || 'en-US'
2019-09-24 16:59:07 +08:00
},
set (lang) {
this.$router.push(changeLangInPath(this.$route.fullPath, lang))
2019-09-24 16:59:07 +08:00
}
},
theme: {
get () {
2019-09-27 15:56:01 +08:00
return this.$route.params.theme === 'light' ? 'light' : 'dark'
2019-09-24 16:59:07 +08:00
},
set (theme) {
this.$router.push(changeThemeInPath(this.$route.fullPath, theme))
2019-09-24 16:59:07 +08:00
}
}
},
methods: {
handleLangChange (lang) {
this.lang = lang
}
}
}
2019-09-24 16:59:07 +08:00
function changeLangInPath (path, lang) {
2019-12-23 16:31:26 +08:00
const langReg = /^\/(zh-CN|en-US)\//
2019-09-24 16:59:07 +08:00
return path.replace(langReg, `/${lang}/`)
}
2019-09-27 15:56:01 +08:00
function changeThemeInPath (path, theme) {
const themeReg = /(^\/[^/]+\/)([^/]+)/
return path.replace(themeReg, '$1' + theme)
}
</script>
<style lang="scss" scoped>
.demo {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
2019-06-27 16:26:23 +08:00
min-width: 1080px;
}
</style>
2019-06-18 16:53:16 +08:00
2019-06-24 01:16:38 +08:00
<style lang="scss">
body {
-webkit-text-size-adjust: 100%;
}
2019-06-24 01:16:38 +08:00
.n-doc {
2019-06-27 16:26:23 +08:00
width: 720px;
2019-06-24 01:16:38 +08:00
margin: 0 auto;
.n-doc-header {
display: flex;
2019-09-20 00:21:33 +08:00
// height: 60px;
// border-bottom: 1px solid rgba(255, 255, 255, 0.2);
margin-bottom: 16px;
// align-items: center;
2019-06-24 01:16:38 +08:00
}
.n-doc-section {
.n-doc-section__header {
font-size: 16px;
2019-12-23 16:48:49 +08:00
font-weight: 500;
2019-06-24 01:16:38 +08:00
margin-bottom: 12px;
}
.n-doc-section__view {
2019-06-26 20:16:11 +08:00
background: #5c657eff;
2019-06-24 01:16:38 +08:00
padding: 18px;
border-radius: 8px;
justify-content: center;
display: flex;
margin-bottom: 12px;
flex-wrap: wrap;
}
2019-07-15 17:41:56 +08:00
.n-doc-section__inspect {
background: #5c657eff;
padding: 18px;
border-radius: 8px;
display: flex;
margin-bottom: 12px;
flex-wrap: wrap;
}
2019-06-26 13:37:58 +08:00
.n-doc-section__text-content {
font-size: 16px;
}
2019-06-24 01:16:38 +08:00
.n-doc-section__source {
position: relative;
2019-06-24 01:16:38 +08:00
}
}
}
2019-06-18 16:53:16 +08:00
</style>