{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-settings-nav",
  "type": "registry:component",
  "title": "Sidebar Settings Nav",
  "description": "A settings sidebar with a back link, grouped items and a search field that filters items live and highlights the match.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "settings",
    "search",
    "filter",
    "navigation",
    "preferences"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-settings-nav",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-settings-nav.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-settings-nav.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst ICONS = {\n  user: \"M10 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM3.8 16.5c.6-2.8 3-4.3 6.2-4.3s5.6 1.5 6.2 4.3\",\n  shield: \"M10 2.8l6 2.2v4.6c0 3.4-2.4 5.9-6 7.6-3.6-1.7-6-4.2-6-7.6V5z\",\n  bell: \"M5.5 14V9.2a4.5 4.5 0 0 1 9 0V14l1.3 1.5H4.2zM8.3 17.2h3.4\",\n  building: \"M4.5 17V4.5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1V17M12.5 8.5h2a1 1 0 0 1 1 1V17M3.5 17h13M7.5 7h2M7.5 10h2M7.5 13h2\",\n  card: \"M3.5 5.5h13a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1h-13a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1zM2.5 8.5h15M5.5 12h3\",\n  plug: \"M7.5 3v4M12.5 3v4M5.5 7h9v2.5a4.5 4.5 0 0 1-9 0zM10 14v3\",\n  palette:\n    \"M10 3a7 7 0 1 0 0 14c1 0 1.5-.7 1.2-1.5-.4-1 .3-2 1.4-2H14a3 3 0 0 0 3-3C17 5.7 13.9 3 10 3zM6.8 9.5v.01M9 6.8v.01M12 7v.01\",\n  key: \"M12.5 11.5a3.5 3.5 0 1 0-3-1.7L3.5 15.8V17h2v-1.5h1.5V14h1.5l1.7-1.8a3.5 3.5 0 0 0 2.3-.7zM13 7.5v.01\",\n} as const;\n\nexport type SidebarSettingsIconName = keyof typeof ICONS;\n\nexport function SidebarSettingsIcon({ name }: { name: SidebarSettingsIconName }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={ICONS[name]} />\n    </svg>\n  );\n}\n\nexport interface SettingsNavItem {\n  id: string;\n  label: string;\n  icon?: SidebarSettingsIconName;\n  keywords?: string[];\n  badge?: string;\n}\n\nexport interface SettingsNavGroup {\n  id: string;\n  title: string;\n  items: SettingsNavItem[];\n}\n\nexport interface SidebarSettingsNavProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  groups?: SettingsNavGroup[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  query?: string;\n  defaultQuery?: string;\n  onQueryChange?: (query: string) => void;\n  onBack?: () => void;\n  backHref?: string;\n  backLabel?: string;\n  title?: string;\n  placeholder?: string;\n  emptyText?: string;\n  accent?: string;\n}\n\nconst defaultGroups: SettingsNavGroup[] = [\n  {\n    id: \"account\",\n    title: \"Account\",\n    items: [\n      { id: \"profile\", label: \"Profile\", icon: \"user\", keywords: [\"name\", \"avatar\", \"email\"] },\n      { id: \"security\", label: \"Security\", icon: \"shield\", keywords: [\"password\", \"2fa\", \"sessions\"] },\n      { id: \"notifications\", label: \"Notifications\", icon: \"bell\", keywords: [\"email\", \"alerts\", \"digest\"] },\n      { id: \"appearance\", label: \"Appearance\", icon: \"palette\", keywords: [\"theme\", \"dark\", \"light\"] },\n    ],\n  },\n  {\n    id: \"workspace\",\n    title: \"Workspace\",\n    items: [\n      { id: \"general\", label: \"General\", icon: \"building\", keywords: [\"name\", \"logo\", \"domain\"] },\n      { id: \"billing\", label: \"Billing\", icon: \"card\", keywords: [\"plan\", \"invoice\", \"payment\"], badge: \"Pro\" },\n      { id: \"integrations\", label: \"Integrations\", icon: \"plug\", keywords: [\"apps\", \"slack\", \"webhooks\"] },\n      { id: \"keys\", label: \"API keys\", icon: \"key\", keywords: [\"token\", \"developer\", \"secret\"] },\n    ],\n  },\n];\n\nconst css = `\n.hb-yc5 {\n  --hb-yc5-a: #2f7bff;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  min-height: 0;\n  border-right: 1px solid #262626;\n  background: #0f0f0f;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 18px;\n}\n.hb-yc5 *, .hb-yc5 *::before, .hb-yc5 *::after { box-sizing: border-box; }\n.hb-yc5-top { flex: none; padding: 10px 10px 8px; }\n.hb-yc5-back {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  height: 28px;\n  margin: 0 0 6px -4px;\n  padding: 0 8px 0 4px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 500;\n  text-decoration: none;\n  cursor: pointer;\n  transition: color .15s ease, background-color .15s ease;\n}\n.hb-yc5-back svg { width: 14px; height: 14px; transition: transform .2s ease; }\n.hb-yc5-back:hover { background: #181818; color: #ededed; }\n.hb-yc5-back:hover svg { transform: translateX(-2px); }\n.hb-yc5-back:focus-visible { outline: 2px solid var(--hb-yc5-a); outline-offset: 1px; }\n.hb-yc5-ttl { margin: 0 0 8px; font-size: 16px; font-weight: 650; letter-spacing: -.015em; line-height: 22px; }\n.hb-yc5-field {\n  position: relative;\n  display: flex;\n  align-items: center;\n  height: 32px;\n  border: 1px solid #262626;\n  border-radius: 9px;\n  background: #0a0a0a;\n  transition: border-color .18s ease, box-shadow .18s ease;\n}\n.hb-yc5-field:focus-within {\n  border-color: var(--hb-yc5-a);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-yc5-a) 22%, transparent);\n}\n.hb-yc5-mag { position: absolute; left: 9px; width: 14px; height: 14px; color: #6f6f6f; pointer-events: none; }\n.hb-yc5-input {\n  width: 100%;\n  height: 100%;\n  min-width: 0;\n  padding: 0 28px 0 29px;\n  border: 0;\n  outline: none;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 13px;\n}\n.hb-yc5-input::placeholder { color: #6f6f6f; }\n.hb-yc5-clear {\n  position: absolute;\n  right: 5px;\n  display: grid;\n  place-items: center;\n  width: 20px;\n  height: 20px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 6px;\n  background: #1f1f1f;\n  color: #a1a1a1;\n  cursor: pointer;\n  animation: hb-yc5-pop .18s ease both;\n}\n.hb-yc5-clear svg { width: 10px; height: 10px; }\n.hb-yc5-clear:hover { background: #2a2a2a; color: #ffffff; }\n.hb-yc5-clear:focus-visible { outline: 2px solid var(--hb-yc5-a); outline-offset: 1px; }\n.hb-yc5-scroll { position: relative; flex: 1; min-height: 0; padding: 2px 8px 10px; overflow-y: auto; scrollbar-width: none; }\n.hb-yc5-scroll::-webkit-scrollbar { display: none; }\n.hb-yc5-head { margin: 0; padding: 10px 8px 4px; color: #6f6f6f; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; line-height: 14px; text-transform: uppercase; }\n.hb-yc5-list { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }\n.hb-yc5-li { animation: hb-yc5-in .24s cubic-bezier(.2, .9, .2, 1) both; }\n.hb-yc5-item {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  width: 100%;\n  height: 30px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n}\n.hb-yc5-item:hover { background: #181818; color: #ededed; }\n.hb-yc5-item:focus-visible { outline: 2px solid var(--hb-yc5-a); outline-offset: -2px; }\n.hb-yc5-item[aria-current=\"true\"] { background: #1c1c1c; color: #ffffff; }\n.hb-yc5-ico { display: grid; flex: none; place-items: center; width: 16px; height: 16px; color: #77777f; transition: color .15s ease; }\n.hb-yc5-ico svg { width: 16px; height: 16px; }\n.hb-yc5-item[aria-current=\"true\"] .hb-yc5-ico { color: var(--hb-yc5-a); }\n.hb-yc5-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc5-mark { background: color-mix(in srgb, var(--hb-yc5-a) 30%, transparent); border-radius: 3px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--hb-yc5-a) 30%, transparent); color: #ffffff; }\n.hb-yc5-tag { flex: none; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--hb-yc5-a) 20%, transparent); color: var(--hb-yc5-a); font-size: 10.5px; font-weight: 700; line-height: 16px; }\n.hb-yc5-empty { margin: 18px 8px 0; color: #77777f; font-size: 12px; line-height: 18px; text-align: center; animation: hb-yc5-in .24s ease both; }\n.hb-yc5-empty b { display: block; margin-bottom: 2px; color: #ededed; font-weight: 600; }\n.hb-yc5-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n@keyframes hb-yc5-in {\n  from { opacity: 0; transform: translateY(4px); }\n  to { opacity: 1; transform: none; }\n}\n@keyframes hb-yc5-pop {\n  from { opacity: 0; transform: scale(.6); }\n  to { opacity: 1; transform: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-yc5-back, .hb-yc5-back svg, .hb-yc5-field, .hb-yc5-item, .hb-yc5-ico { transition: none; }\n  .hb-yc5-li, .hb-yc5-empty, .hb-yc5-clear { animation: none; }\n}\n`;\n\nfunction Highlight({ text, query }: { text: string; query: string }) {\n  const q = query.trim().toLowerCase();\n  const at = q ? text.toLowerCase().indexOf(q) : -1;\n  if (at < 0) return <>{text}</>;\n  return (\n    <>\n      {text.slice(0, at)}\n      <mark className=\"hb-yc5-mark\">{text.slice(at, at + q.length)}</mark>\n      {text.slice(at + q.length)}\n    </>\n  );\n}\n\nexport function SidebarSettingsNav({\n  groups = defaultGroups,\n  active,\n  defaultActive,\n  onChange,\n  query,\n  defaultQuery = \"\",\n  onQueryChange,\n  onBack,\n  backHref,\n  backLabel = \"Back to app\",\n  title = \"Settings\",\n  placeholder = \"Search settings\",\n  emptyText = \"Nothing matches your search.\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: SidebarSettingsNavProps) {\n  const rootRef = React.useRef<HTMLElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [inner, setInner] = React.useState(defaultActive ?? groups[0]?.items[0]?.id ?? \"\");\n  const [innerQuery, setInnerQuery] = React.useState(defaultQuery);\n  const [focusId, setFocusId] = React.useState(\"\");\n  const current = active ?? inner;\n  const q = query ?? innerQuery;\n  const needle = q.trim().toLowerCase();\n\n  const visible = groups\n    .map((g) => ({\n      ...g,\n      items: needle ? g.items.filter((i) => [i.label, ...(i.keywords ?? [])].some((t) => t.toLowerCase().includes(needle))) : g.items,\n    }))\n    .filter((g) => g.items.length > 0);\n  const flat = visible.flatMap((g) => g.items.map((i) => i.id));\n  const tabStop = flat.includes(focusId) ? focusId : flat.includes(current) ? current : flat[0];\n\n  function setQuery(next: string) {\n    if (query === undefined) setInnerQuery(next);\n    onQueryChange?.(next);\n  }\n\n  function select(id: string) {\n    if (active === undefined) setInner(id);\n    onChange?.(id);\n  }\n\n  function items() {\n    return Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-yc5-item]\") ?? []);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    const target = e.target as HTMLElement;\n    if (target === inputRef.current) {\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        if (q) setQuery(\"\");\n        else inputRef.current?.blur();\n      } else if (e.key === \"ArrowDown\" || (e.key === \"Enter\" && needle)) {\n        e.preventDefault();\n        items()[0]?.focus();\n      }\n      return;\n    }\n    if (e.key === \"Escape\") {\n      (document.activeElement as HTMLElement | null)?.blur();\n      return;\n    }\n    if (e.key === \"/\") {\n      e.preventDefault();\n      inputRef.current?.focus();\n      return;\n    }\n    if (!target.hasAttribute(\"data-yc5-item\")) return;\n    const list = items();\n    const at = list.indexOf(target);\n    if (e.key === \"ArrowUp\" && at === 0) {\n      e.preventDefault();\n      inputRef.current?.focus();\n      return;\n    }\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = Math.min(list.length - 1, at + 1);\n    else if (e.key === \"ArrowUp\") next = Math.max(0, at - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = list.length - 1;\n    if (next >= 0) {\n      e.preventDefault();\n      list[next]?.focus();\n    }\n  }\n\n  const vars = { \"--hb-yc5-a\": accent, ...style } as React.CSSProperties;\n\n  const backBody = (\n    <>\n      <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n        <path d=\"M9.5 3.5L5 8l4.5 4.5\" />\n      </svg>\n      {backLabel}\n    </>\n  );\n\n  return (\n    <nav ref={rootRef} className={`hb-yc5 ${className}`} aria-label={title || \"Settings\"} style={vars} onKeyDown={handleKeyDown} {...rest}>\n      <style href=\"hb-sidebar-settings-nav\" precedence=\"default\">{css}</style>\n      <div className=\"hb-yc5-top\">\n        {backHref ? (\n          <a className=\"hb-yc5-back\" href={backHref} onClick={onBack}>\n            {backBody}\n          </a>\n        ) : (\n          <button type=\"button\" className=\"hb-yc5-back\" onClick={onBack}>\n            {backBody}\n          </button>\n        )}\n        {title ? <p className=\"hb-yc5-ttl\">{title}</p> : null}\n        <div className=\"hb-yc5-field\">\n          <svg className=\"hb-yc5-mag\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M9 15a6 6 0 1 0 0-12 6 6 0 0 0 0 12zM17 17l-3.8-3.8\" />\n          </svg>\n          <input\n            ref={inputRef}\n            className=\"hb-yc5-input\"\n            type=\"text\"\n            role=\"searchbox\"\n            autoComplete=\"off\"\n            spellCheck={false}\n            value={q}\n            placeholder={placeholder}\n            aria-label={placeholder}\n            onChange={(e) => setQuery(e.target.value)}\n          />\n          {q ? (\n            <button\n              type=\"button\"\n              className=\"hb-yc5-clear\"\n              aria-label=\"Clear search\"\n              onClick={() => {\n                setQuery(\"\");\n                inputRef.current?.focus();\n              }}\n            >\n              <svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"M2 2l6 6M8 2L2 8\" />\n              </svg>\n            </button>\n          ) : null}\n        </div>\n      </div>\n      <div className=\"hb-yc5-scroll\">\n        {visible.map((g) => (\n          <div key={g.id} role=\"group\" aria-label={g.title}>\n            <p className=\"hb-yc5-head\">{g.title}</p>\n            <ul className=\"hb-yc5-list\" role=\"list\">\n              {g.items.map((item) => (\n                <li key={item.id} className=\"hb-yc5-li\">\n                  <button\n                    type=\"button\"\n                    className=\"hb-yc5-item\"\n                    data-yc5-item=\"\"\n                    aria-current={item.id === current ? true : undefined}\n                    tabIndex={item.id === tabStop ? 0 : -1}\n                    onFocus={() => setFocusId(item.id)}\n                    onClick={() => select(item.id)}\n                  >\n                    <span className=\"hb-yc5-ico\">\n                      <SidebarSettingsIcon name={item.icon ?? \"user\"} />\n                    </span>\n                    <span className=\"hb-yc5-txt\">\n                      <Highlight text={item.label} query={q} />\n                    </span>\n                    {item.badge ? <span className=\"hb-yc5-tag\">{item.badge}</span> : null}\n                  </button>\n                </li>\n              ))}\n            </ul>\n          </div>\n        ))}\n        {visible.length === 0 ? (\n          <p className=\"hb-yc5-empty\">\n            <b>No results for &ldquo;{q.trim()}&rdquo;</b>\n            {emptyText}\n          </p>\n        ) : null}\n        <span className=\"hb-yc5-sr\" role=\"status\">\n          {needle ? `${flat.length} ${flat.length === 1 ? \"result\" : \"results\"}` : \"\"}\n        </span>\n      </div>\n    </nav>\n  );\n}\n"
    }
  ]
}