import * as React from "react" import { useMediaQuery } from "../hooks/use-media-query" import { cn } from "../lib/utils" import { AppSidebar, type AppSidebarProps } from "./app-sidebar" import { useShell } from "./shell-provider" /** * Каркас окна: тёмное меню слева, справа — лист с текущим разделом (`children`, обычно ``). * Окно целиком не прокручивается — только тело раздела. Свёрнутость меню помнится * (`.sidebar-collapsed`), на узком экране меню всегда свёрнуто. При печати меню скрыто. * Нужен ShellProvider выше. */ export function AppShell({ sidebar, className, children, }: { sidebar: Omit className?: string children: React.ReactNode }) { const { storageKey } = useShell() const collapsedKey = `${storageKey}.sidebar-collapsed` const [collapsed, setCollapsed] = React.useState(() => { try { return localStorage.getItem(collapsedKey) === "1" } catch { return false } }) // На узких экранах меню — всегда полоса иконок, иначе контенту не остаётся места. const narrow = useMediaQuery("(max-width: 767px)") const toggle = () => setCollapsed((v) => { try { localStorage.setItem(collapsedKey, v ? "0" : "1") } catch { // не запомнили — не страшно } return !v }) return (
{children}
) }