fix(theme): infer collapsible from collapsed (#1865)

BREAKING CHANGE: `collapsible` is dropped from sidebar, use `collapsed` instead
pull/1871/head
Divyansh Singh 2 years ago committed by GitHub
parent 8f7d35ff8a
commit dea6cfa9cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,7 +4,7 @@ const sidebar: DefaultTheme.Config['sidebar'] = {
'/': [ '/': [
{ {
text: 'Frontmatter', text: 'Frontmatter',
collapsible: true, collapsed: false,
items: [ items: [
{ {
text: 'Multiple Levels Outline', text: 'Multiple Levels Outline',

@ -79,7 +79,7 @@ function sidebarGuide() {
return [ return [
{ {
text: 'Introduction', text: 'Introduction',
collapsible: true, collapsed: false,
items: [ items: [
{ text: 'What is VitePress?', link: '/guide/what-is-vitepress' }, { text: 'What is VitePress?', link: '/guide/what-is-vitepress' },
{ text: 'Getting Started', link: '/guide/getting-started' }, { text: 'Getting Started', link: '/guide/getting-started' },
@ -91,7 +91,7 @@ function sidebarGuide() {
}, },
{ {
text: 'Writing', text: 'Writing',
collapsible: true, collapsed: false,
items: [ items: [
{ text: 'Markdown', link: '/guide/markdown' }, { text: 'Markdown', link: '/guide/markdown' },
{ text: 'Asset Handling', link: '/guide/asset-handling' }, { text: 'Asset Handling', link: '/guide/asset-handling' },
@ -102,7 +102,7 @@ function sidebarGuide() {
}, },
{ {
text: 'Theme', text: 'Theme',
collapsible: true, collapsed: false,
items: [ items: [
{ text: 'Introduction', link: '/guide/theme-introduction' }, { text: 'Introduction', link: '/guide/theme-introduction' },
{ text: 'Nav', link: '/guide/theme-nav' }, { text: 'Nav', link: '/guide/theme-nav' },
@ -121,7 +121,7 @@ function sidebarGuide() {
}, },
{ {
text: 'Migrations', text: 'Migrations',
collapsible: true, collapsed: false,
items: [ items: [
{ {
text: 'Migration from VuePress', text: 'Migration from VuePress',

@ -147,16 +147,11 @@ export type SidebarItem = {
items?: SidebarItem[] items?: SidebarItem[]
/** /**
* If `true`, toggle button is shown. * If not specified, group is not collapsible.
* *
* @default false * If `true`, group is collapsible and collapsed by default
*/
collapsible?: boolean
/**
* If `true`, collapsible group is collapsed by default.
* *
* @default false * If `false`, group is collapsible but expanded by default
*/ */
collapsed?: boolean collapsed?: boolean
} }

@ -149,7 +149,7 @@ export default {
## Collapsible Sidebar Groups ## Collapsible Sidebar Groups
By adding `collapsible` option to the sidebar group, it shows a toggle button to hide/show each section. By adding `collapsed` option to the sidebar group, it shows a toggle button to hide/show each section.
```js ```js
export default { export default {
@ -157,12 +157,7 @@ export default {
sidebar: [ sidebar: [
{ {
text: 'Section Title A', text: 'Section Title A',
collapsible: true, collapsed: false,
items: [...]
},
{
text: 'Section Title B',
collapsible: true,
items: [...] items: [...]
} }
] ]
@ -178,7 +173,6 @@ export default {
sidebar: [ sidebar: [
{ {
text: 'Section Title A', text: 'Section Title A',
collapsible: true,
collapsed: true, collapsed: true,
items: [...] items: [...]
} }

@ -59,8 +59,8 @@ function onCaretClick() {
<component :is="textTag" class="text" v-html="item.text" /> <component :is="textTag" class="text" v-html="item.text" />
</VPLink> </VPLink>
<div class="caret" role="button" @click="onCaretClick"> <div v-if="item.collapsed != null" class="caret" role="button" @click="onCaretClick">
<VPIconChevronRight v-if="item.collapsible" class="caret-icon" /> <VPIconChevronRight class="caret-icon" />
</div> </div>
</div> </div>

@ -126,7 +126,7 @@ export function useSidebarControl(
const collapsed = ref(false) const collapsed = ref(false)
const collapsible = computed(() => { const collapsible = computed(() => {
return !!item.value.collapsible return item.value.collapsed != null
}) })
const isLink = computed(() => { const isLink = computed(() => {
@ -152,7 +152,7 @@ export function useSidebarControl(
}) })
watchEffect(() => { watchEffect(() => {
collapsed.value = !!(item.value.collapsible && item.value.collapsed) collapsed.value = !!(collapsible.value && item.value.collapsed)
}) })
watchEffect(() => { watchEffect(() => {
@ -160,7 +160,7 @@ export function useSidebarControl(
}) })
function toggle() { function toggle() {
if (item.value.collapsible) { if (collapsible.value) {
collapsed.value = !collapsed.value collapsed.value = !collapsed.value
} }
} }

@ -183,16 +183,11 @@ export namespace DefaultTheme {
items?: SidebarItem[] items?: SidebarItem[]
/** /**
* If `true`, toggle button is shown. * If not specified, group is not collapsible.
* *
* @default false * If `true`, group is collapsible and collapsed by default
*/
collapsible?: boolean
/**
* If `true`, collapsible group is collapsed by default.
* *
* @default false * If `false`, group is collapsible but expanded by default
*/ */
collapsed?: boolean collapsed?: boolean
} }

Loading…
Cancel
Save