The sidebar state is managed using a provider/consumer pattern. To enable sidebar functionality across your application, you must call useSidebarProvider() in a high-level ancestor component (e.g., App.vue). This initializes the state and provides it to the rest of the component tree via Vue's provide API.
To access or manipulate the sidebar state in any child component, use the useSidebar() composable.
Note: Calling useSidebar() in a component that does not have an ancestor calling useSidebarProvider() will throw an error: useSidebar must be used within a component that has SidebarProvider as an ancestor.
<script setup>
// In a top-level component (e.g., App.vue)
import { useSidebarProvider } from '@/composables/useSidebar'
useSidebarProvider()
</script>
<template>
<router-view />
</template>
---
<script setup>
// In any child component
import { useSidebar } from '@/composables/useSidebar'
const { isExpanded, toggleSidebar } = useSidebar()
</script>