{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"mobile-off-canvas-sidebar-with-overlay","type":"registry:component","title":"Mobile Off-Canvas Sidebar With Overlay","description":"","dependencies":[],"files":[{"path":"components/we-inc/mobile-off-canvas-sidebar-with-overlay.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Links in the off-canvas sidebar.\nconst links = [\n  { label: \"Today\", count: 4 },\n  { label: \"Upcoming\", count: 11 },\n  { label: \"Recipes\" },\n  { label: \"Shopping list\", count: 7 },\n  { label: \"Pantry\" },\n];\n\nexport default function MobileOffCanvasSidebarWithOverlay() {\n  const [open, setOpen] = useState(true);\n  const [current, setCurrent] = useState(\"Upcoming\");\n  const opener = useRef<HTMLButtonElement>(null);\n  const closer = useRef<HTMLButtonElement>(null);\n\n  const close = () => {\n    setOpen(false);\n    opener.current?.focus();\n  };\n\n  useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && close();\n    document.addEventListener(\"keydown\", onKey);\n    return () => document.removeEventListener(\"keydown\", onKey);\n  }, [open]);\n\n  return (\n    <div className=\"flex justify-center bg-orange-50 px-4 py-10\">\n      <div className=\"relative h-[580px] w-full max-w-[360px] overflow-hidden rounded-[2rem] border border-orange-200 bg-white shadow-lg\">\n        <header className=\"flex h-14 items-center gap-2 border-b border-orange-100 px-3\">\n          <button\n            ref={opener}\n            type=\"button\"\n            aria-expanded={open}\n            aria-controls=\"moc-side\"\n            aria-label=\"Open sidebar\"\n            onClick={() => { setOpen(true); setTimeout(() => closer.current?.focus(), 0); }}\n            className=\"grid h-11 w-11 place-items-center rounded-xl text-stone-800 hover:bg-orange-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-orange-500\"\n          >\n            <svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\"><path d=\"M4 6h16M4 12h16M4 18h16\" /></svg>\n          </button>\n          <h2 className=\"text-base font-semibold text-stone-900\">{current}</h2>\n        </header>\n        <ul className=\"space-y-2 p-4\" aria-label=\"Meals\">\n          {[\"Miso salmon with greens\", \"Lentil and squash dal\", \"Lemon orzo with peas\"].map((m, i) => (\n            <li key={m} className=\"flex items-center gap-3 rounded-xl bg-orange-50/70 p-3\">\n              <span className=\"text-xs font-semibold text-orange-800\">{[\"Mon\", \"Tue\", \"Wed\"][i]}</span>\n              <span className=\"text-sm text-stone-800\">{m}</span>\n            </li>\n          ))}\n        </ul>\n\n        <div aria-hidden=\"true\" onClick={close} className={`absolute inset-0 bg-stone-900/50 transition-opacity duration-300 motion-reduce:transition-none ${open ? \"opacity-100\" : \"pointer-events-none opacity-0\"}`} />\n        <aside\n          id=\"moc-side\"\n          role=\"dialog\"\n          aria-modal=\"true\"\n          aria-label=\"Sidebar\"\n          className={`absolute inset-y-0 left-0 flex w-[78%] flex-col bg-stone-50 transition duration-300 ease-out motion-reduce:transition-none ${open ? \"visible translate-x-0\" : \"invisible -translate-x-full\"}`}\n        >\n          <div className=\"flex h-14 items-center justify-between px-4\">\n            <span className=\"text-base font-bold text-orange-700\">Sunday Prep</span>\n            <button ref={closer} type=\"button\" onClick={close} aria-label=\"Close sidebar\" className=\"grid h-10 w-10 place-items-center rounded-xl text-stone-600 hover:bg-stone-200/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-orange-500\">\n              <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\"><path d=\"M15 6l-6 6 6 6\" /></svg>\n            </button>\n          </div>\n          <nav aria-label=\"Main\" className=\"flex-1 px-3\">\n            <ul className=\"space-y-1\">\n              {links.map((l) => (\n                <li key={l.label}>\n                  <a\n                    href=\"#\"\n                    aria-current={current === l.label ? \"page\" : undefined}\n                    onClick={(e) => { e.preventDefault(); setCurrent(l.label); close(); }}\n                    className={`flex h-11 items-center justify-between rounded-xl px-3 text-[15px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-orange-500 ${current === l.label ? \"bg-orange-600 font-medium text-white\" : \"text-stone-800 hover:bg-stone-200/60\"}`}\n                  >\n                    {l.label}\n                    {l.count ? <span className={`text-xs tabular-nums ${current === l.label ? \"text-orange-50\" : \"text-stone-600\"}`}>{l.count}</span> : null}\n                  </a>\n                </li>\n              ))}\n            </ul>\n          </nav>\n          <p className=\"m-3 rounded-xl bg-orange-100 p-3 text-xs leading-5 text-orange-900\">Plan five dinners and the shopping list fills itself.</p>\n        </aside>\n      </div>\n    </div>\n  );\n}\n"}]}
