31 lines
772 B
TypeScript
31 lines
772 B
TypeScript
"use client"
|
|
|
|
import type React from "react"
|
|
import { createContext, useContext, useState } from "react"
|
|
|
|
interface SidebarContextType {
|
|
isOpen: boolean
|
|
toggleSidebar: () => void
|
|
}
|
|
|
|
const SidebarContext = createContext<SidebarContextType | undefined>(undefined)
|
|
|
|
export function SidebarProvider({ children }: { children: React.ReactNode }) {
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
const toggleSidebar = () => {
|
|
setIsOpen((prev) => !prev)
|
|
}
|
|
|
|
return <SidebarContext.Provider value={{ isOpen, toggleSidebar }}>{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
|
|
}
|
|
|