feat: add option to set collapsed by default

pull/663/head
Divyansh Singh 3 years ago
parent 1a18ca8dcb
commit c706517c0c

@ -34,7 +34,12 @@ watchPostEffect(async () => {
</span>
<div v-for="group in sidebar" :key="group.text" class="group">
<VPSidebarGroup :text="group.text" :items="group.items" :collapsible="group.collapsible" />
<VPSidebarGroup
:text="group.text"
:items="group.items"
:collapsible="group.collapsible"
:collapsed="group.collapsed"
/>
</div>
</nav>
</aside>

@ -7,6 +7,7 @@ const props = defineProps<{
text: string
items: DefaultTheme.SidebarItem[]
collapsible?: boolean
collapsed?: boolean
}>()
const collapsed = ref(false)
@ -14,16 +15,20 @@ const itemsDiv = ref<HTMLDivElement | null>(null)
const height = ref('')
const storeHeight = () => {
height.value = itemsDiv.value?.clientHeight + 'px'
if (!collapsed.value) height.value = itemsDiv.value?.clientHeight + 'px'
}
const toggle = () => {
if (!props.collapsible) return
if (!collapsed.value) storeHeight()
storeHeight()
collapsed.value = !collapsed.value
}
onMounted(storeHeight)
onMounted(() => {
if (!props.collapsible) return
storeHeight()
collapsed.value = !!props.collapsed
})
</script>
<template>
@ -84,13 +89,13 @@ onMounted(storeHeight)
}
.items {
height: v-bind('height');
transition: height 0.5s;
max-height: v-bind('height');
transition: max-height 0.5s;
overflow: hidden;
}
.items.collapsed {
height: 0;
max-height: 0;
margin-bottom: -22px;
}

@ -10,6 +10,10 @@ html {
-webkit-text-size-adjust: 100%;
}
html.dark {
color-scheme: dark;
}
body {
margin: 0;
width: 100%;

@ -82,7 +82,12 @@ export namespace DefaultTheme {
export interface SidebarGroup {
text: string
items: SidebarItem[]
// If `true`, toggle button is shown.
// Default: false
collapsible?: boolean
// If `true`, collapsible group is collapsed by default.
// Default: false
collapsed?: boolean
}
export interface SidebarItem {

Loading…
Cancel
Save