{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"settings-sidebar","type":"registry:block","title":"Settings sidebar","description":"Grouped settings with a sliding highlight and the picked section beside them; a select on phones.","dependencies":["lucide-react"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-use-indicator.json","https://dashral.com/r/avatar.json","https://dashral.com/r/badge.json","https://dashral.com/r/button.json","https://dashral.com/r/input.json","https://dashral.com/r/native-select.json","https://dashral.com/r/switch.json"],"files":[{"path":"registry/dashral/blocks/settings-sidebar.tsx","type":"registry:file","target":"components/dashral/blocks/settings-sidebar.tsx","content":"\"use client\"\n\nimport { useState } from \"react\"\nimport { Bell, Blocks, Building2, CreditCard, Shield, User, Users } from \"lucide-react\"\nimport { Avatar } from \"../avatar\"\nimport { Badge } from \"../badge\"\nimport { Button } from \"../button\"\nimport { Input } from \"../input\"\nimport { NativeSelect } from \"../native-select\"\nimport { Switch } from \"../switch\"\nimport { indicatorMotion, useIndicator } from \"../lib/use-indicator\"\nimport { cn } from \"../lib/utils\"\n\n// The products named here are real ones, as examples: their names are their owners' trademarks, no affiliation implied. Put in the tools your product really works with.\nconst brands = { chat: \"Slack\", code: \"GitHub\", payments: \"Stripe\", files: \"Dropbox\" }\n\n/** One settings section: its place in the nav and the title above its content. */\nexport type SettingsPage = { id: string; label: string; icon: React.ReactNode; description: string; badge?: React.ReactNode; count?: number }\nexport type SettingsGroup = { label: string; pages: SettingsPage[] }\n\nconst sampleGroups: SettingsGroup[] = [\n  {\n    label: \"Account\",\n    pages: [\n      { id: \"profile\", label: \"Profile\", icon: <User />, description: \"How others see you across the workspace.\" },\n      { id: \"notifications\", label: \"Notifications\", icon: <Bell />, description: \"What reaches you, and where.\" },\n      { id: \"security\", label: \"Security\", icon: <Shield />, description: \"Sign-in, two-factor and your sessions.\" },\n    ],\n  },\n  {\n    label: \"Workspace\",\n    pages: [\n      { id: \"general\", label: \"General\", icon: <Building2 />, description: \"Your workspace's name and address.\" },\n      { id: \"members\", label: \"Members\", icon: <Users />, description: \"Who's in the workspace, and their roles.\", count: 12 },\n      { id: \"billing\", label: \"Billing\", icon: <CreditCard />, description: \"Your plan, seats and invoices.\", badge: <Badge variant=\"soft\" color=\"primary\">Team</Badge> },\n      { id: \"integrations\", label: \"Integrations\", icon: <Blocks />, description: \"The tools Acme talks to.\" },\n    ],\n  },\n]\n\n/**\n * A settings page: grouped sections on the left with a highlight that slides to the one you pick, and that section\n * on the right. On phones the sections are a select above the content. Your sections come in `groups`, the one shown\n * is controllable (`onNavigate` when it changes), and `content` renders each one; the sample forms render without it.\n */\nexport function SettingsSidebar({\n  groups = sampleGroups,\n  current: currentProp,\n  onNavigate,\n  content = (page) => <Content id={page.id} />,\n}: {\n  groups?: SettingsGroup[]\n  /** The section shown, by id (the block keeps it without it). */\n  current?: string\n  onNavigate?: (id: string) => void\n  content?: (page: SettingsPage) => React.ReactNode\n}) {\n  const pages = groups.flatMap((g) => g.pages)\n  const [ownCurrent, setOwnCurrent] = useState(pages[0]?.id ?? \"\")\n  const current = currentProp ?? ownCurrent\n  const setCurrent = (id: string) => {\n    setOwnCurrent(id)\n    onNavigate?.(id)\n  }\n  const [navRef, highlight] = useIndicator<HTMLElement>(\"[aria-current=page]\")\n  const page = pages.find((p) => p.id === current) ?? pages[0]\n  if (!page) return null\n\n  return (\n    <div className=\"mx-auto grid w-full max-w-5xl gap-6 p-4 sm:p-6 md:grid-cols-[13rem_minmax(0,1fr)] md:gap-10 md:p-10\">\n      <div className=\"md:hidden\">\n        <NativeSelect\n          aria-label=\"Settings section\"\n          value={current}\n          onChange={(e) => setCurrent(e.target.value)}\n          options={groups.map((g) => ({ label: g.label, options: g.pages.map((p) => ({ value: p.id, label: p.label })) }))}\n        />\n      </div>\n\n      <nav ref={navRef} aria-label=\"Settings\" className=\"relative hidden content-start md:grid\">\n        {highlight && (\n          <span\n            aria-hidden\n            className={cn(indicatorMotion, \"rounded-md bg-accent\")}\n            style={{ translate: `${highlight.x}px ${highlight.y}px`, width: highlight.width, height: highlight.height }}\n          />\n        )}\n        {groups.map((group, g) => (\n          <div key={group.label} className={cn(g > 0 && \"mt-6\")}>\n            <p className=\"mb-1 px-3 text-xs font-medium text-muted-foreground\">{group.label}</p>\n            <ul className=\"grid gap-0.5\">\n              {group.pages.map((p) => (\n                <li key={p.id}>\n                  <button\n                    type=\"button\"\n                    aria-current={current === p.id ? \"page\" : undefined}\n                    onClick={() => setCurrent(p.id)}\n                    className=\"relative flex h-9 w-full items-center gap-3 rounded-md px-3 text-sm text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 aria-[current=page]:font-medium aria-[current=page]:text-foreground [&>svg]:size-4 [&>svg]:shrink-0\"\n                  >\n                    {p.icon}\n                    <span className=\"flex-1 text-start\">{p.label}</span>\n                    {p.count !== undefined && <span className=\"text-xs text-muted-foreground tabular-nums\">{p.count}</span>}\n                    {p.badge}\n                  </button>\n                </li>\n              ))}\n            </ul>\n          </div>\n        ))}\n      </nav>\n\n      {/* Keyed by the section, so each one fades in. */}\n      <section key={page.id} aria-labelledby=\"settings-title\" className=\"grid min-w-0 content-start gap-6 animate-in fade-in-0 duration-(--duration-standard) ease-enter\">\n        <header className=\"border-b pb-5\">\n          <h2 id=\"settings-title\" className=\"text-lg font-semibold\">\n            {page.label}\n          </h2>\n          <p className=\"mt-1 text-sm text-muted-foreground\">{page.description}</p>\n        </header>\n        {content(page)}\n      </section>\n    </div>\n  )\n}\n\nfunction Content({ id }: { id: string }) {\n  const save = (\n    <div className=\"flex justify-end\">\n      <Button>Save changes</Button>\n    </div>\n  )\n\n  switch (id) {\n    case \"profile\":\n      return (\n        <div className=\"grid gap-5\">\n          <div className=\"flex items-center gap-4\">\n            <Avatar src=\"https://randomuser.me/api/portraits/women/44.jpg\" name=\"Olivia Martin\" alt=\"\" size=\"xl\" />\n            <Button variant=\"outline\" size=\"sm\">\n              Change photo\n            </Button>\n          </div>\n          <div className=\"grid gap-4 sm:grid-cols-2\">\n            <Input label=\"Full name\" defaultValue=\"Olivia Martin\" />\n            <Input label=\"Email\" type=\"email\" defaultValue=\"olivia@acme.com\" />\n          </div>\n          {save}\n        </div>\n      )\n    case \"notifications\":\n      return (\n        <div className=\"grid gap-5\">\n          <Switch label=\"Comments and mentions\" description=\"When someone replies to you or @mentions you.\" labelPosition=\"start\" defaultChecked />\n          <Switch label=\"Weekly digest\" description=\"A summary every Monday morning.\" labelPosition=\"start\" defaultChecked />\n          <Switch label=\"Product news\" description=\"New features, once a month at most.\" labelPosition=\"start\" />\n        </div>\n      )\n    case \"security\":\n      return (\n        <div className=\"grid gap-5\">\n          <Switch label=\"Two-factor authentication\" description=\"A code from your authenticator app at every sign-in.\" labelPosition=\"start\" />\n          <div className=\"grid gap-2\">\n            <p className=\"text-sm font-medium\">Sessions</p>\n            {[\n              { device: \"MacBook Pro · Chrome\", where: \"Jakarta · now\", current: true },\n              { device: \"iPhone 15 · Safari\", where: \"Bandung · 2 days ago\" },\n            ].map((s) => (\n              <div key={s.device} className=\"flex items-center justify-between gap-3 rounded-lg border p-3 text-sm\">\n                <span className=\"grid\">\n                  <span className=\"font-medium\">{s.device}</span>\n                  <span className=\"text-xs text-muted-foreground\">{s.where}</span>\n                </span>\n                {s.current ? <Badge variant=\"soft\" color=\"success\">This device</Badge> : <Button variant=\"ghost\" size=\"sm\">Sign out</Button>}\n              </div>\n            ))}\n          </div>\n        </div>\n      )\n    case \"general\":\n      return (\n        <div className=\"grid gap-4\">\n          <Input label=\"Workspace name\" defaultValue=\"Acme Inc.\" />\n          <Input label=\"Address\" prefix=\"dashral.com/\" defaultValue=\"acme\" description=\"Letters, numbers and dashes.\" />\n          {save}\n        </div>\n      )\n    case \"members\":\n      return (\n        <ul className=\"divide-y rounded-lg border\">\n          {[\n            { name: \"Olivia Martin\", email: \"olivia@acme.com\", role: \"Owner\", src: \"https://randomuser.me/api/portraits/women/44.jpg\" },\n            { name: \"Liam Johnson\", email: \"liam@acme.com\", role: \"Admin\", src: \"https://randomuser.me/api/portraits/men/32.jpg\" },\n            { name: \"Budi Santoso\", email: \"budi@acme.com\", role: \"Member\" },\n          ].map((m) => (\n            <li key={m.email} className=\"flex items-center gap-3 p-3\">\n              <Avatar src={m.src} name={m.name} alt=\"\" />\n              <span className=\"grid min-w-0 flex-1\">\n                <span className=\"truncate text-sm font-medium\">{m.name}</span>\n                <span className=\"truncate text-xs text-muted-foreground\">{m.email}</span>\n              </span>\n              <Badge variant=\"outline\" color=\"neutral\">\n                {m.role}\n              </Badge>\n            </li>\n          ))}\n        </ul>\n      )\n    case \"billing\":\n      return (\n        <div className=\"flex flex-wrap items-center justify-between gap-4 rounded-lg border p-4\">\n          <div>\n            <p className=\"text-sm font-semibold\">Team plan · $49 a month</p>\n            <p className=\"text-sm text-muted-foreground\">12 of 15 seats · renews Nov 1, 2026</p>\n          </div>\n          <div className=\"flex gap-2\">\n            <Button variant=\"outline\" size=\"sm\">\n              Invoices\n            </Button>\n            <Button size=\"sm\">Upgrade</Button>\n          </div>\n        </div>\n      )\n    default:\n      return (\n        <ul className=\"grid gap-3 sm:grid-cols-2\">\n          {[\n            { name: brands.chat, about: \"Alerts in your channels\", on: true },\n            { name: brands.code, about: \"Link issues to pull requests\", on: true },\n            { name: brands.payments, about: \"Revenue in your dashboards\" },\n            { name: brands.files, about: `Attach files from ${brands.files}` },\n          ].map((tool) => (\n            <li key={tool.name} className=\"flex items-center justify-between gap-3 rounded-lg border p-3\">\n              <span className=\"grid\">\n                <span className=\"text-sm font-medium\">{tool.name}</span>\n                <span className=\"text-xs text-muted-foreground\">{tool.about}</span>\n              </span>\n              <Button variant={tool.on ? \"outline\" : \"solid\"} size=\"sm\">\n                {tool.on ? \"Connected\" : \"Connect\"}\n              </Button>\n            </li>\n          ))}\n        </ul>\n      )\n  }\n}\n"}],"cssVars":{"theme":{"ease-standard":"var(--ease-standard)","ease-enter":"var(--ease-enter)","ease-exit":"var(--ease-exit)","ease-spring":"var(--ease-spring)"},"light":{"duration-fast":"160ms","duration-standard":"240ms","duration-considered":"480ms","ease-standard":"cubic-bezier(0.2, 0, 0, 1)","ease-enter":"cubic-bezier(0, 0, 0, 1)","ease-exit":"cubic-bezier(0.3, 0, 1, 1)","ease-spring":"linear(0, 0.071 4%, 0.234 8%, 0.433 12%, 0.626 17%, 0.791 21%, 0.917 25%, 1.004 29%, 1.055 33%, 1.079 38%, 1.083 42%, 1.075 46%, 1.06 50%, 1.043 54%, 1.027 58%, 1.015 62%, 1.005 67%, 0.998 71%, 0.995 75%, 0.993 79%, 0.993 83%, 0.994 88%, 0.995 92%, 0.997 96%, 1)"},"dark":{}}}