{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"app-sidebar-with-nested-groups-and-active-item","type":"registry:component","title":"App Sidebar With Nested Groups and Active Item","description":"Free React sidebar in Tailwind with an HTML version: groups that open and close, an unread badge and a highlighted current page set with aria-current.","dependencies":[],"files":[{"path":"components/we-inc/app-sidebar-with-nested-groups-and-active-item.tsx","type":"registry:component","content":"import { useState } from \"react\";\n\n// Navigation tree. Groups with `items` open and close; `href` items are plain links.\nconst nav = [\n  { label: \"Inbox\", badge: 12 },\n  { label: \"Projects\", items: [\"Harbour Wall survey\", \"Mill Lane extension\", \"Riverside flats\"] },\n  { label: \"Team\", items: [\"People\", \"Rotas\", \"Time off\"] },\n  { label: \"Billing\", items: [\"Invoices\", \"Purchase orders\", \"Suppliers\"] },\n  { label: \"Settings\" },\n];\n\nexport default function AppSidebarWithNestedGroupsAndActiveItem() {\n  const [openGroups, setOpenGroups] = useState<string[]>([\"Projects\", \"Billing\"]);\n  const [current, setCurrent] = useState(\"Mill Lane extension\");\n\n  const toggle = (g: string) =>\n    setOpenGroups((list) => (list.includes(g) ? list.filter((x) => x !== g) : [...list, g]));\n\n  const linkBase = \"flex h-10 w-full items-center rounded-lg px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-600\";\n\n  return (\n    <div className=\"bg-emerald-50/60 px-4 py-10 sm:px-8\">\n      <div className=\"mx-auto flex h-[540px] max-w-4xl overflow-hidden rounded-2xl bg-white ring-1 ring-slate-200\">\n        <aside className=\"flex w-full shrink-0 flex-col border-slate-200 sm:w-64 sm:border-r\">\n          <div className=\"flex h-16 items-center gap-2.5 border-b border-slate-100 px-4\">\n            <svg width=\"26\" height=\"26\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M3 20L12 4l9 16z\" className=\"fill-emerald-600\" /><path d=\"M8.5 20L12 13.5 15.5 20z\" fill=\"#fff\" /></svg>\n            <span className=\"text-sm font-semibold text-slate-900\">Brockway Builders</span>\n          </div>\n          <nav aria-label=\"Main\" className=\"flex-1 overflow-y-auto p-3\">\n            <ul className=\"space-y-0.5\">\n              {nav.map((n) =>\n                n.items ? (\n                  <li key={n.label}>\n                    <button\n                      type=\"button\"\n                      aria-expanded={openGroups.includes(n.label)}\n                      aria-controls={`asg-${n.label}`}\n                      onClick={() => toggle(n.label)}\n                      className={`${linkBase} justify-between font-medium text-slate-800 hover:bg-slate-100`}\n                    >\n                      {n.label}\n                      <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" className={`text-slate-500 transition-transform duration-200 motion-reduce:transition-none ${openGroups.includes(n.label) ? \"rotate-90\" : \"\"}`} aria-hidden=\"true\"><path d=\"M9 6l6 6-6 6\" /></svg>\n                    </button>\n                    <ul id={`asg-${n.label}`} hidden={!openGroups.includes(n.label)} className=\"ml-4 mt-0.5 space-y-0.5 border-l border-slate-200 pl-2\">\n                      {n.items.map((it) => (\n                        <li key={it}>\n                          <a\n                            href=\"#\"\n                            aria-current={current === it ? \"page\" : undefined}\n                            onClick={(e) => { e.preventDefault(); setCurrent(it); }}\n                            className={`${linkBase} ${current === it ? \"bg-emerald-50 font-semibold text-emerald-800\" : \"text-slate-600 hover:bg-slate-100 hover:text-slate-900\"}`}\n                          >\n                            <span className=\"truncate\">{it}</span>\n                          </a>\n                        </li>\n                      ))}\n                    </ul>\n                  </li>\n                ) : (\n                  <li key={n.label}>\n                    <a\n                      href=\"#\"\n                      aria-current={current === n.label ? \"page\" : undefined}\n                      onClick={(e) => { e.preventDefault(); setCurrent(n.label); }}\n                      className={`${linkBase} justify-between font-medium ${current === n.label ? \"bg-emerald-50 text-emerald-800\" : \"text-slate-800 hover:bg-slate-100\"}`}\n                    >\n                      {n.label}\n                      {n.badge ? <span className=\"rounded-full bg-emerald-600 px-2 py-0.5 text-xs font-semibold text-white\">{n.badge}<span className=\"sr-only\"> unread</span></span> : null}\n                    </a>\n                  </li>\n                ),\n              )}\n            </ul>\n          </nav>\n        </aside>\n        <main className=\"hidden min-w-0 flex-1 p-6 sm:block\">\n          <p className=\"text-xs font-semibold uppercase tracking-wider text-emerald-700\">Projects</p>\n          <h2 className=\"mt-1 text-xl font-semibold text-slate-900\">{current}</h2>\n          <div className=\"mt-6 space-y-3\" aria-hidden=\"true\">\n            <div className=\"h-3 w-3/4 rounded bg-slate-100\" />\n            <div className=\"h-3 w-2/3 rounded bg-slate-100\" />\n            <div className=\"h-24 rounded-xl bg-slate-50 ring-1 ring-slate-200\" />\n          </div>\n        </main>\n      </div>\n    </div>\n  );\n}\n"}]}
