20 lines
602 B
TypeScript
20 lines
602 B
TypeScript
const SIDENAV_CONTEXT_KEY = Symbol('sidenav-context');
|
|
|
|
export interface SidenavContext {
|
|
isHovered: Readonly<Ref<boolean>>;
|
|
sidebarWidth: Readonly<Ref<number>>;
|
|
isOpen: Readonly<Ref<boolean>>;
|
|
close: () => void;
|
|
}
|
|
|
|
export const provideSidenavContext = (context: SidenavContext) => {
|
|
provide(SIDENAV_CONTEXT_KEY, context);
|
|
};
|
|
|
|
export const useSidenavContext = (): SidenavContext => {
|
|
const context = inject<SidenavContext>(SIDENAV_CONTEXT_KEY);
|
|
if (!context) {
|
|
throw new Error('useSidenavContext must be used within a Sidenav provider');
|
|
}
|
|
return context;
|
|
}; |