Store sidebar state
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -10,8 +10,23 @@ import { Button } from "../Button/Button";
|
||||
|
||||
const sidebarContext = createContext({ open: true });
|
||||
|
||||
function useSidebarState() {
|
||||
const [open, setOpenState] = useState(() => {
|
||||
const stored = localStorage.getItem("sidebar-open");
|
||||
return stored !== null ? JSON.parse(stored) : true;
|
||||
});
|
||||
|
||||
const setOpen = (value: boolean) => {
|
||||
setOpenState(value);
|
||||
|
||||
localStorage.setItem("sidebar-open", JSON.stringify(value));
|
||||
};
|
||||
|
||||
return [open, setOpen] as const;
|
||||
}
|
||||
|
||||
export function Sidebar({ children }: PropsWithChildren) {
|
||||
const [open, setOpen] = useState(true);
|
||||
const [open, setOpen] = useSidebarState();
|
||||
return (
|
||||
<sidebarContext.Provider value={{ open }}>
|
||||
<aside
|
||||
|
||||
Reference in New Issue
Block a user