{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-quick-find",
  "type": "registry:component",
  "title": "Sidebar Quick Find",
  "description": "A settings sidebar whose search folds away every page and section that does not match, also searching hidden keywords and showing which one matched. Enter opens the first hit and an empty search suggests terms.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "search",
    "filter",
    "settings",
    "keywords",
    "navigation"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-quick-find",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-quick-find.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-quick-find.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SidebarQuickFindPage {\n  id: string;\n  label: string;\n  keywords?: string[];\n  badge?: string;\n}\n\nexport interface SidebarQuickFindSection {\n  id: string;\n  label: string;\n  pages: SidebarQuickFindPage[];\n}\n\nexport interface SidebarQuickFindProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  sections?: SidebarQuickFindSection[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  query?: string;\n  defaultQuery?: string;\n  onQueryChange?: (query: string) => void;\n  placeholder?: string;\n  suggestions?: string[];\n  globalShortcut?: boolean;\n  footer?: React.ReactNode;\n  accent?: string;\n}\n\nconst defaultSections: SidebarQuickFindSection[] = [\n  {\n    id: \"account\",\n    label: \"Account\",\n    pages: [\n      { id: \"profile\", label: \"Profile\", keywords: [\"avatar\", \"name\", \"email\"] },\n      { id: \"security\", label: \"Security\", keywords: [\"password\", \"2fa\", \"sessions\", \"passkey\"] },\n      { id: \"notifications\", label: \"Notifications\", keywords: [\"email\", \"digest\", \"push\"] },\n    ],\n  },\n  {\n    id: \"workspace\",\n    label: \"Workspace\",\n    pages: [\n      { id: \"members\", label: \"Members\", keywords: [\"invite\", \"roles\", \"seats\"], badge: \"8\" },\n      { id: \"billing\", label: \"Billing\", keywords: [\"invoice\", \"card\", \"plan\", \"receipt\"] },\n      { id: \"domains\", label: \"Domains\", keywords: [\"dns\", \"ssl\", \"custom domain\"] },\n    ],\n  },\n  {\n    id: \"developers\",\n    label: \"Developers\",\n    pages: [\n      { id: \"api\", label: \"API tokens\", keywords: [\"keys\", \"secret\", \"token\"] },\n      { id: \"webhooks\", label: \"Webhooks\", keywords: [\"events\", \"endpoint\", \"retry\"] },\n    ],\n  },\n];\n\nconst css = `\n.hb-xk7 {\n  --hb-xk7-a: #2f7bff;\n  box-sizing: border-box;\n  display: flex;\n  flex-direction: column;\n  width: 100%;\n  height: 100%;\n  padding: 10px 8px;\n  border-right: 1px solid #1f1f1f;\n  background: #0e0e0e;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 18px;\n}\n.hb-xk7 *, .hb-xk7 *::before, .hb-xk7 *::after { box-sizing: border-box; }\n.hb-xk7-search {\n  position: relative;\n  display: flex;\n  flex: none;\n  align-items: center;\n  gap: 7px;\n  height: 32px;\n  margin: 0 2px 6px;\n  padding: 0 6px 0 9px;\n  border: 1px solid #262626;\n  border-radius: 9px;\n  background: linear-gradient(180deg, #141414, #111);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);\n  color: #6f6f76;\n  transition: border-color .2s ease, box-shadow .2s ease, color .2s ease;\n}\n.hb-xk7-search:focus-within { border-color: color-mix(in srgb, var(--hb-xk7-a) 65%, #262626); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-xk7-a) 16%, transparent); color: var(--hb-xk7-a); }\n.hb-xk7-search svg { flex: none; width: 14px; height: 14px; }\n.hb-xk7-input { flex: 1; min-width: 0; height: 100%; margin: 0; padding: 0; border: 0; background: transparent; color: #ededed; font: inherit; font-size: 12.5px; outline: none; }\n.hb-xk7-input::placeholder { color: #5f5f66; }\n.hb-xk7-input::-webkit-search-cancel-button { display: none; }\n.hb-xk7-kbd { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border: 1px solid #2c2c2c; border-radius: 5px; background: #181818; color: #8f8f8f; font-family: var(--font-mono, ui-monospace, monospace); font-size: 10px; }\n.hb-xk7-clear { display: grid; place-items: center; width: 18px; height: 18px; margin: 0; padding: 0; border: 0; border-radius: 5px; background: #262626; color: #a1a1a1; cursor: pointer; animation: hb-xk7-pop .2s cubic-bezier(.22, 1, .36, 1); }\n.hb-xk7-clear:hover { background: #333; color: #fff; }\n.hb-xk7-clear:focus-visible { outline: 2px solid var(--hb-xk7-a); outline-offset: 1px; }\n.hb-xk7-clear svg { width: 10px; height: 10px; }\n.hb-xk7-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; }\n.hb-xk7-body::-webkit-scrollbar { display: none; }\n.hb-xk7-sec { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .36s cubic-bezier(.22, 1, .36, 1), opacity .25s ease; }\n.hb-xk7-sec[data-hidden=\"true\"] { grid-template-rows: 0fr; opacity: 0; }\n.hb-xk7-clip { min-height: 0; overflow: hidden; }\n.hb-xk7-sh { display: flex; align-items: center; justify-content: space-between; height: 26px; padding: 6px 10px 0; color: #6f6f76; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }\n.hb-xk7-sc { color: #55555c; font-family: var(--font-mono, ui-monospace, monospace); font-size: 10px; font-weight: 500; letter-spacing: 0; text-transform: none; animation: hb-xk7-pop .25s cubic-bezier(.22, 1, .36, 1); }\n.hb-xk7-list { margin: 0; padding: 0; list-style: none; }\n.hb-xk7-li { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .32s cubic-bezier(.22, 1, .36, 1), opacity .2s ease; }\n.hb-xk7-li[data-hidden=\"true\"] { grid-template-rows: 0fr; opacity: 0; }\n.hb-xk7-li > div { min-height: 0; overflow: hidden; }\n.hb-xk7-row {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  min-height: 30px;\n  margin: 1px 0;\n  padding: 4px 10px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #9a9aa1;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .14s ease, color .14s ease;\n}\n.hb-xk7-row:hover { background: rgba(255, 255, 255, .04); color: #ededed; }\n.hb-xk7-row:focus-visible { outline: 2px solid var(--hb-xk7-a); outline-offset: -2px; }\n.hb-xk7-row[data-first=\"true\"] { background: rgba(255, 255, 255, .045); color: #ededed; }\n.hb-xk7-row[aria-current=\"page\"] { background: color-mix(in srgb, var(--hb-xk7-a) 14%, transparent); color: #fff; }\n.hb-xk7-txt { display: flex; flex: 1; flex-direction: column; min-width: 0; }\n.hb-xk7-name { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }\n.hb-xk7-name mark { border-radius: 3px; background: color-mix(in srgb, var(--hb-xk7-a) 30%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--hb-xk7-a) 30%, transparent); color: #fff; }\n.hb-xk7-why { display: flex; align-items: center; gap: 4px; color: #6f6f76; font-size: 10.5px; line-height: 15px; animation: hb-xk7-pop .22s cubic-bezier(.22, 1, .36, 1); }\n.hb-xk7-why span { padding: 0 5px; border: 1px solid #2a2a2a; border-radius: 4px; color: #a1a1a1; }\n.hb-xk7-badge { flex: none; padding: 0 6px; border-radius: 99px; background: #1f1f1f; color: #a1a1a1; font-size: 10.5px; line-height: 17px; }\n.hb-xk7-enter { flex: none; color: #55555c; font-family: var(--font-mono, ui-monospace, monospace); font-size: 10px; }\n.hb-xk7-empty { padding: 18px 10px 0; color: #6f6f76; font-size: 12px; text-align: center; animation: hb-xk7-pop .25s cubic-bezier(.22, 1, .36, 1); }\n.hb-xk7-empty b { color: #ededed; font-weight: 500; }\n.hb-xk7-sugg { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; margin-top: 10px; }\n.hb-xk7-chip { margin: 0; padding: 2px 9px; border: 1px solid #2a2a2a; border-radius: 99px; background: #151515; color: #a1a1a1; font: inherit; font-size: 11px; cursor: pointer; transition: border-color .15s ease, color .15s ease; }\n.hb-xk7-chip:hover { border-color: #3a3a3a; color: #fff; }\n.hb-xk7-chip:focus-visible { outline: 2px solid var(--hb-xk7-a); outline-offset: 1px; }\n.hb-xk7-foot { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; height: 26px; margin-top: 4px; padding: 0 8px; border-top: 1px solid #1c1c1c; color: #55555c; font-size: 10.5px; }\n@keyframes hb-xk7-pop { from { opacity: 0; transform: translateY(-3px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xk7 *, .hb-xk7 *::before, .hb-xk7 *::after { transition: none !important; animation: none !important; }\n}\n`;\n\nfunction Highlight({ text, q }: { text: string; q: string }) {\n  if (!q) return <>{text}</>;\n  const at = text.toLowerCase().indexOf(q.toLowerCase());\n  if (at < 0) return <>{text}</>;\n  return (\n    <>\n      {text.slice(0, at)}\n      <mark>{text.slice(at, at + q.length)}</mark>\n      {text.slice(at + q.length)}\n    </>\n  );\n}\n\nexport function SidebarQuickFind({\n  sections = defaultSections,\n  active,\n  defaultActive,\n  onChange,\n  query,\n  defaultQuery = \"\",\n  onQueryChange,\n  placeholder = \"Find a setting\",\n  suggestions = [\"invoice\", \"password\", \"webhook\"],\n  globalShortcut = false,\n  footer,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: SidebarQuickFindProps) {\n  const [inner, setInner] = React.useState(defaultActive ?? sections[0]?.pages[0]?.id ?? \"\");\n  const [innerQ, setInnerQ] = React.useState(defaultQuery);\n  const current = active ?? inner;\n  const q = (query ?? innerQ).trim();\n  const raw = query ?? innerQ;\n  const rootRef = React.useRef<HTMLElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  function setQ(v: string) {\n    if (query === undefined) setInnerQ(v);\n    onQueryChange?.(v);\n  }\n\n  React.useEffect(() => {\n    if (!globalShortcut) return;\n    const onWin = (e: KeyboardEvent) => {\n      const t = e.target as HTMLElement | null;\n      if (e.key !== \"/\" || e.metaKey || e.ctrlKey || !t) return;\n      if (t.isContentEditable || t.tagName === \"INPUT\" || t.tagName === \"TEXTAREA\" || t.tagName === \"SELECT\") return;\n      e.preventDefault();\n      inputRef.current?.focus();\n    };\n    window.addEventListener(\"keydown\", onWin);\n    return () => window.removeEventListener(\"keydown\", onWin);\n  }, [globalShortcut]);\n\n  const lower = q.toLowerCase();\n  const results = sections.map((s) => {\n    const pages = s.pages.map((p) => {\n      if (!lower) return { page: p, hit: true, why: \"\" };\n      if (p.label.toLowerCase().includes(lower)) return { page: p, hit: true, why: \"\" };\n      const kw = p.keywords?.find((k) => k.toLowerCase().includes(lower));\n      return { page: p, hit: !!kw, why: kw ?? \"\" };\n    });\n    return { section: s, pages, count: pages.filter((p) => p.hit).length };\n  });\n  const total = results.reduce((n, r) => n + r.count, 0);\n  const firstHit = lower ? results.flatMap((r) => r.pages.filter((p) => p.hit))[0]?.page.id : undefined;\n\n  function pick(id: string) {\n    if (active === undefined) setInner(id);\n    onChange?.(id);\n  }\n\n  function visibleRows() {\n    return Array.from(rootRef.current?.querySelectorAll<HTMLElement>('[data-xk7-row]:not([tabindex=\"-1\"])') ?? []);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    const onInput = e.target === inputRef.current;\n    if (onInput) {\n      if (e.key === \"ArrowDown\") {\n        e.preventDefault();\n        visibleRows()[0]?.focus();\n      } else if (e.key === \"Enter\" && firstHit) {\n        e.preventDefault();\n        pick(firstHit);\n      } else if (e.key === \"Escape\" && raw) {\n        e.preventDefault();\n        setQ(\"\");\n      }\n      return;\n    }\n    if (e.key === \"/\" && !e.metaKey && !e.ctrlKey) {\n      e.preventDefault();\n      inputRef.current?.focus();\n      return;\n    }\n    const list = visibleRows();\n    const at = list.indexOf(document.activeElement as HTMLElement);\n    if (at < 0) return;\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      list[Math.min(list.length - 1, at + 1)]?.focus();\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      if (at === 0) inputRef.current?.focus();\n      else list[at - 1]?.focus();\n    } else if (e.key === \"Escape\") {\n      e.preventDefault();\n      inputRef.current?.focus();\n    }\n  }\n\n  const vars = { \"--hb-xk7-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <nav ref={rootRef} aria-label=\"Settings\" className={`hb-xk7 ${className}`} style={vars} onKeyDown={handleKeyDown} {...rest}>\n      <style href=\"hb-sidebar-quick-find\" precedence=\"default\">{css}</style>\n      <label className=\"hb-xk7-search\">\n        <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n          <path d=\"M7 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10zM10.8 10.8L14 14\" />\n        </svg>\n        <input\n          ref={inputRef}\n          className=\"hb-xk7-input\"\n          type=\"search\"\n          value={raw}\n          placeholder={placeholder}\n          aria-label={placeholder}\n          autoComplete=\"off\"\n          spellCheck={false}\n          onChange={(e) => setQ(e.target.value)}\n        />\n        {raw ? (\n          <button\n            type=\"button\"\n            className=\"hb-xk7-clear\"\n            aria-label=\"Clear search\"\n            onClick={() => {\n              setQ(\"\");\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.5 2.5l5 5M7.5 2.5l-5 5\" />\n            </svg>\n          </button>\n        ) : (\n          <kbd className=\"hb-xk7-kbd\" aria-hidden=\"true\">/</kbd>\n        )}\n      </label>\n      <div className=\"hb-xk7-body\">\n        {results.map((r) => (\n          <div key={r.section.id} className=\"hb-xk7-sec\" data-hidden={r.count === 0} inert={r.count === 0}>\n            <div className=\"hb-xk7-clip\">\n              <div className=\"hb-xk7-sh\">\n                <span>{r.section.label}</span>\n                {lower ? (\n                  <span key={`${r.count}/${r.pages.length}`} className=\"hb-xk7-sc\">\n                    {r.count} of {r.pages.length}\n                  </span>\n                ) : null}\n              </div>\n              <ul className=\"hb-xk7-list\" role=\"list\">\n                {r.pages.map(({ page, hit, why }) => (\n                  <li key={page.id} className=\"hb-xk7-li\" data-hidden={!hit}>\n                    <div>\n                      <button\n                        type=\"button\"\n                        className=\"hb-xk7-row\"\n                        data-xk7-row=\"\"\n                        data-first={page.id === firstHit}\n                        tabIndex={hit ? 0 : -1}\n                        aria-hidden={!hit}\n                        aria-current={page.id === current ? \"page\" : undefined}\n                        onClick={() => pick(page.id)}\n                      >\n                        <span className=\"hb-xk7-txt\">\n                          <span className=\"hb-xk7-name\">\n                            <Highlight text={page.label} q={q} />\n                          </span>\n                          {why ? (\n                            <span className=\"hb-xk7-why\">\n                              matches <span>{why}</span>\n                            </span>\n                          ) : null}\n                        </span>\n                        {page.id === firstHit ? (\n                          <span className=\"hb-xk7-enter\" aria-hidden=\"true\">enter</span>\n                        ) : page.badge ? (\n                          <span className=\"hb-xk7-badge\">{page.badge}</span>\n                        ) : null}\n                      </button>\n                    </div>\n                  </li>\n                ))}\n              </ul>\n            </div>\n          </div>\n        ))}\n        {lower && total === 0 ? (\n          <div className=\"hb-xk7-empty\" role=\"status\">\n            No settings match <b>{q}</b>\n            {suggestions.length ? (\n              <div className=\"hb-xk7-sugg\">\n                {suggestions.map((s) => (\n                  <button key={s} type=\"button\" className=\"hb-xk7-chip\" onClick={() => setQ(s)}>\n                    {s}\n                  </button>\n                ))}\n              </div>\n            ) : null}\n          </div>\n        ) : null}\n      </div>\n      {footer !== undefined ? (\n        footer\n      ) : (\n        <div className=\"hb-xk7-foot\" aria-live=\"polite\">\n          <span>{lower ? `${total} ${total === 1 ? \"result\" : \"results\"}` : `${sections.reduce((n, s) => n + s.pages.length, 0)} pages`}</span>\n          <span>{lower ? \"esc to clear\" : \"/ to search\"}</span>\n        </div>\n      )}\n    </nav>\n  );\n}\n"
    }
  ]
}