blob: 43ea9b82ec4165a77057ab0c4745b1d209b0aaba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
"use client";
import { createContext, useContext, useState, ReactNode } from "react";
interface SidebarContextType {
isOpen: boolean;
toggleSidebar: () => void;
setIsOpen: (isOpen: boolean) => void;
}
const SidebarContext = createContext<SidebarContextType | undefined>(undefined);
export function SidebarProvider({ children }: { children: ReactNode }) {
const [isOpen, setIsOpen] = useState(true); // Default open on desktop
const toggleSidebar = () => setIsOpen(!isOpen);
return (
<SidebarContext.Provider value={{ isOpen, toggleSidebar, setIsOpen }}>
{children}
</SidebarContext.Provider>
);
}
export function useSidebar() {
const context = useContext(SidebarContext);
if (context === undefined) {
throw new Error("useSidebar must be used within a SidebarProvider");
}
return context;
}
|