Skip to content

Commit 2f75815

Browse files
committed
docs: update navigation
1 parent 024e5c0 commit 2f75815

File tree

2 files changed

+90
-69
lines changed

2 files changed

+90
-69
lines changed

packages/docs/.vuepress/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ export default defineUserConfig<DefaultThemeOptions>({
287287
},
288288
],
289289
},
290+
{
291+
text: 'Migration',
292+
link: '/migration/',
293+
icon: '<path fill="var(--ci-primary-color, currentColor)" d="M464,256.25C464,370.8,370.8,464,256.25,464S48.5,370.8,48.5,256.25,141.7,48.5,256.25,48.5a208,208,0,0,1,149.963,64H328.5v32h128V16.5h-32V85.478A239.717,239.717,0,1,0,496,256.25Z" class="ci-primary"></path><polygon fill="var(--ci-primary-color, currentColor)" points="272.5 112.451 240.5 112.549 241.017 282.756 353.301 334.53 366.699 305.47 272.954 262.244 272.5 112.451" class="ci-primary"></polygon>',
294+
children: [
295+
{
296+
text: 'v4',
297+
link: '/migration/v4.html',
298+
},
299+
],
300+
},
290301
],
291302
},
292303
})
Lines changed: 79 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h } from 'vue'
1+
import { defineComponent, h, computed, onMounted, ref } from 'vue'
22
import type { VNode } from 'vue'
33
import { RouterLink, useRoute } from 'vue-router'
44
import type { RouteLocationNormalizedLoaded } from 'vue-router'
@@ -41,81 +41,91 @@ const isActiveItem = (route: RouteLocationNormalizedLoaded, item: ResolvedSideba
4141
return false
4242
}
4343

44-
const renderItem = (item: ResolvedSidebarItem): VNode => {
45-
const route = useRoute()
46-
if (item.children && !item.link.includes('.html')) {
47-
return h(
48-
CNavGroup,
49-
{
50-
active: item.children.some((child) => isActiveItem(route, child)),
51-
compact: true,
52-
},
53-
{
54-
togglerContent: () => [
55-
h(CIcon, {
56-
customClassName: 'nav-icon text-primary',
57-
icon: ['512 512', item.icon],
58-
height: 64,
59-
width: 64,
60-
}),
61-
item.text,
62-
],
63-
default: () => item.children.map((child) => renderItem(child)),
64-
},
65-
)
66-
}
67-
68-
return h(
69-
RouterLink,
70-
{
71-
to: item.link,
72-
custom: true,
44+
const SidebarNav = defineComponent({
45+
name: 'SidebarNav',
46+
props: {
47+
items: {
48+
type: Array,
49+
required: true,
7350
},
74-
{
75-
default: (props) =>
76-
h(
77-
CNavItem,
51+
},
52+
setup(props) {
53+
const route = useRoute()
54+
const firstRender = ref(true)
55+
56+
onMounted(() => {
57+
firstRender.value = false
58+
})
59+
60+
const renderItem = (item: ResolvedSidebarItem): VNode => {
61+
if (item.children && !item.link.includes('.html')) {
62+
const visible = computed(() => item.children.some((child) => isActiveItem(route, child)))
63+
64+
return h(
65+
CNavGroup,
7866
{
79-
active: props.isActive,
80-
disabled: item.disabled,
81-
href: withBase(item.link),
67+
...(firstRender.value && { visible: visible.value }),
68+
compact: true,
8269
},
8370
{
84-
default: () => [
71+
togglerContent: () => [
72+
h(CIcon, {
73+
customClassName: 'nav-icon text-primary',
74+
icon: ['512 512', item.icon],
75+
height: 64,
76+
width: 64,
77+
}),
8578
item.text,
86-
item.badge &&
87-
h(
88-
CBadge,
89-
{
90-
class: 'ms-auto',
91-
color: item.badge.color,
92-
},
93-
{
94-
default: () => item.badge.text,
95-
},
96-
),
9779
],
80+
default: () => item.children.map((child) => renderItem(child)),
9881
},
99-
),
100-
},
101-
)
102-
}
82+
)
83+
}
10384

104-
export const SidebarNav = ({ items }) => {
105-
return h(
106-
CSidebarNav,
107-
{},
108-
{
109-
default: () => items.map((item) => renderItem(item)),
110-
},
111-
)
112-
}
85+
return h(
86+
RouterLink,
87+
{
88+
to: item.link,
89+
custom: true,
90+
},
91+
{
92+
default: (props) =>
93+
h(
94+
CNavItem,
95+
{
96+
active: props.isActive,
97+
disabled: item.disabled,
98+
href: withBase(item.link),
99+
},
100+
{
101+
default: () => [
102+
item.text,
103+
item.badge &&
104+
h(
105+
CBadge,
106+
{
107+
class: 'ms-auto',
108+
color: item.badge.color,
109+
},
110+
{
111+
default: () => item.badge.text,
112+
},
113+
),
114+
],
115+
},
116+
),
117+
},
118+
)
119+
}
113120

114-
SidebarNav.displayName = 'SidebarNav'
121+
return () => h(
122+
CSidebarNav,
123+
{},
124+
{
125+
default: () => props.items.map((item: any) => renderItem(item)),
126+
}
127+
)
128+
},
129+
})
115130

116-
SidebarNav.props = {
117-
items: {
118-
type: Array,
119-
required: true,
120-
},
121-
}
131+
export { SidebarNav }

0 commit comments

Comments
 (0)