{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-command",
  "type": "registry:component",
  "title": "Sidebar Command",
  "description": "A keyboard-first sidebar with a fuzzy filter and two-key chords like G then I, shown in a status bar that drains while it waits for the second key. Built for power users who never touch the mouse.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "command",
    "keyboard",
    "shortcuts",
    "fuzzy search",
    "power user"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-command",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-command.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-command.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst PATHS = {\n  inbox: \"M3 11l1.9-5.6a1 1 0 0 1 .9-.7h8.4a1 1 0 0 1 .9.7L17 11M3 11v3.8a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V11M3 11h4l.9 1.8h4.2L13 11h4\",\n  issues: \"M10 16.5a6.5 6.5 0 1 0 0-13 6.5 6.5 0 0 0 0 13zM10 11.2a1.2 1.2 0 1 0 0-2.4 1.2 1.2 0 0 0 0 2.4z\",\n  cycle: \"M15.5 10a5.5 5.5 0 1 1-1.6-3.9M15.5 3.8v2.7h-2.7\",\n  map: \"M3 5l4.5-1.5 5 2L17 4v11l-4.5 1.5-5-2L3 16zM7.5 3.5v11M12.5 5.5v11\",\n  plus: \"M10 4.5v11M4.5 10h11\",\n  moon: \"M15.5 12.2A6 6 0 0 1 7.8 4.5a6 6 0 1 0 7.7 7.7z\",\n  user: \"M10 9.5a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM4 16.5c.7-2.8 3.1-4.2 6-4.2s5.3 1.4 6 4.2\",\n} as const;\n\nexport type SidebarCommandIconName = keyof typeof PATHS;\n\nexport interface SidebarCommandItem {\n  id: string;\n  label: string;\n  group?: string;\n  keys?: string;\n  icon?: SidebarCommandIconName | React.ReactNode;\n  action?: boolean;\n}\n\nexport interface SidebarCommandProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\" | \"onSelect\"> {\n  items?: SidebarCommandItem[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  onAction?: (id: string) => void;\n  placeholder?: string;\n  globalShortcuts?: boolean;\n  chordTimeout?: number;\n  accent?: string;\n}\n\nconst defaultItems: SidebarCommandItem[] = [\n  { id: \"inbox\", label: \"Inbox\", group: \"Go to\", keys: \"g i\", icon: \"inbox\" },\n  { id: \"issues\", label: \"My issues\", group: \"Go to\", keys: \"g m\", icon: \"issues\" },\n  { id: \"cycles\", label: \"Active cycle\", group: \"Go to\", keys: \"g c\", icon: \"cycle\" },\n  { id: \"roadmap\", label: \"Roadmap\", group: \"Go to\", keys: \"g r\", icon: \"map\" },\n  { id: \"new\", label: \"New issue\", group: \"Actions\", keys: \"c\", icon: \"plus\", action: true },\n  { id: \"theme\", label: \"Toggle theme\", group: \"Actions\", keys: \"t\", icon: \"moon\", action: true },\n];\n\nconst css = `\n.hb-xk6 {\n  --hb-xk6-a: #2f7bff;\n  --hb-xk6-t: 1500ms;\n  box-sizing: border-box;\n  display: flex;\n  flex-direction: column;\n  width: 100%;\n  height: 100%;\n  border-right: 1px solid #1f1f1f;\n  background:\n    linear-gradient(180deg, rgba(255, 255, 255, .02), transparent 30%),\n    #0c0c0c;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 12.5px;\n  line-height: 18px;\n}\n.hb-xk6 *, .hb-xk6 *::before, .hb-xk6 *::after { box-sizing: border-box; }\n.hb-xk6-mono { font-family: var(--font-mono, ui-monospace, monospace); }\n.hb-xk6-field {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  height: 34px;\n  margin: 10px 10px 4px;\n  padding: 0 6px 0 10px;\n  border: 1px solid #262626;\n  border-radius: 9px;\n  background: #121212;\n  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5);\n  transition: border-color .18s ease, box-shadow .18s ease;\n}\n.hb-xk6-field:focus-within { border-color: color-mix(in srgb, var(--hb-xk6-a) 60%, #262626); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5), 0 0 0 3px color-mix(in srgb, var(--hb-xk6-a) 18%, transparent); }\n.hb-xk6-caret { color: var(--hb-xk6-a); font-family: var(--font-mono, ui-monospace, monospace); font-size: 13px; font-weight: 600; }\n.hb-xk6-input { flex: 1; min-width: 0; height: 100%; margin: 0; padding: 0; border: 0; background: transparent; color: #ededed; font: inherit; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; outline: none; }\n.hb-xk6-input::placeholder { color: #5f5f66; }\n.hb-xk6-kbd { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border: 1px solid #2c2c2c; border-bottom-width: 2px; border-radius: 5px; background: #181818; color: #8f8f8f; font-family: var(--font-mono, ui-monospace, monospace); font-size: 10px; line-height: 1; }\n.hb-xk6-body { flex: 1; min-height: 0; padding: 0 6px; overflow-y: auto; scrollbar-width: none; }\n.hb-xk6-body::-webkit-scrollbar { display: none; }\n.hb-xk6-gl { margin: 8px 8px 3px; color: #55555c; font-family: var(--font-mono, ui-monospace, monospace); font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; }\n.hb-xk6-list { margin: 0; padding: 0; list-style: none; }\n.hb-xk6-row {\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 6px 0 12px;\n  border: 0;\n  border-radius: 7px;\n  background: transparent;\n  color: #9a9aa1;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .12s ease, color .12s ease;\n}\n.hb-xk6-row svg { flex: none; width: 15px; height: 15px; }\n.hb-xk6-row:hover, .hb-xk6-row[data-hot=\"true\"] { background: #171717; color: #ededed; }\n.hb-xk6-row:focus-visible { outline: none; background: #1a1a1a; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-xk6-a) 55%, transparent); color: #fff; }\n.hb-xk6-row[aria-current=\"page\"] { color: #fff; }\n.hb-xk6-row[aria-current=\"page\"]::before { content: \"\"; position: absolute; left: 3px; top: 50%; border: 4px solid transparent; border-left: 5px solid var(--hb-xk6-a); transform: translateY(-50%); }\n.hb-xk6-row[aria-current=\"page\"] svg { color: var(--hb-xk6-a); }\n.hb-xk6-rl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-xk6-rl mark { border-radius: 2px; background: color-mix(in srgb, var(--hb-xk6-a) 28%, transparent); color: #fff; }\n.hb-xk6-keys { display: inline-flex; gap: 3px; }\n.hb-xk6-keys .hb-xk6-kbd[data-lit=\"true\"] { border-color: var(--hb-xk6-a); background: color-mix(in srgb, var(--hb-xk6-a) 22%, #181818); color: #fff; }\n.hb-xk6-row[data-dim=\"true\"] { opacity: .35; }\n.hb-xk6-empty { margin: 18px 12px; color: #6f6f76; font-size: 12px; text-align: center; }\n.hb-xk6-empty b { color: #ededed; font-weight: 500; }\n.hb-xk6-status {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  flex: none;\n  height: 30px;\n  padding: 0 12px;\n  overflow: hidden;\n  border-top: 1px solid #1c1c1c;\n  background: #0a0a0a;\n  color: #6f6f76;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 10.5px;\n  white-space: nowrap;\n}\n.hb-xk6-mode { padding: 1px 6px; border-radius: 4px; background: #1c1c1c; color: #a1a1a1; font-weight: 600; letter-spacing: .04em; }\n.hb-xk6-status[data-state=\"chord\"] .hb-xk6-mode { background: var(--hb-xk6-a); color: #fff; }\n.hb-xk6-status[data-state=\"done\"] .hb-xk6-mode { background: #30a46c; color: #fff; }\n.hb-xk6-msg { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; animation: hb-xk6-msg .22s cubic-bezier(.22, 1, .36, 1); }\n.hb-xk6-msg b { color: #ededed; font-weight: 500; }\n.hb-xk6-drain { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--hb-xk6-a); transform-origin: left; animation: hb-xk6-drain var(--hb-xk6-t) linear forwards; }\n@keyframes hb-xk6-drain { to { transform: scaleX(0); } }\n@keyframes hb-xk6-msg { from { opacity: 0; transform: translateY(6px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xk6 *, .hb-xk6 *::before, .hb-xk6 *::after { transition: none !important; animation: none !important; }\n}\n`;\n\nfunction Glyph({ icon }: { icon?: SidebarCommandIconName | React.ReactNode }) {\n  if (typeof icon === \"string\" || icon === undefined) {\n    const d = PATHS[(icon as SidebarCommandIconName | undefined) ?? \"inbox\"] ?? PATHS.inbox;\n    return (\n      <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n        <path d={d} />\n      </svg>\n    );\n  }\n  return <>{icon}</>;\n}\n\nfunction fuzzy(label: string, q: string): number[] | null {\n  if (!q) return [];\n  const l = label.toLowerCase();\n  const hits: number[] = [];\n  let from = 0;\n  for (const ch of q.toLowerCase()) {\n    if (ch === \" \") continue;\n    const at = l.indexOf(ch, from);\n    if (at < 0) return null;\n    hits.push(at);\n    from = at + 1;\n  }\n  return hits;\n}\n\nfunction Marked({ text, hits }: { text: string; hits: number[] }) {\n  if (!hits.length) return <>{text}</>;\n  const set = new Set(hits);\n  return (\n    <>\n      {Array.from(text).map((ch, i) => (set.has(i) ? <mark key={i}>{ch}</mark> : <React.Fragment key={i}>{ch}</React.Fragment>))}\n    </>\n  );\n}\n\nfunction isEditable(el: EventTarget | null) {\n  if (!(el instanceof HTMLElement)) return false;\n  return el.isContentEditable || el.tagName === \"INPUT\" || el.tagName === \"TEXTAREA\" || el.tagName === \"SELECT\";\n}\n\nexport function SidebarCommand({\n  items = defaultItems,\n  active,\n  defaultActive,\n  onChange,\n  onAction,\n  placeholder = \"Jump to...\",\n  globalShortcuts = false,\n  chordTimeout = 1500,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: SidebarCommandProps) {\n  const [inner, setInner] = React.useState(defaultActive ?? items.find((i) => !i.action)?.id ?? \"\");\n  const [query, setQuery] = React.useState(\"\");\n  const [chord, setChord] = React.useState<string | null>(null);\n  const [flashState, setFlashState] = React.useState<{ text: string; n: number } | null>(null);\n  const flash = flashState?.text ?? null;\n  const [hot, setHot] = React.useState(0);\n  const current = active ?? inner;\n  const rootRef = React.useRef<HTMLElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  const filtered = items\n    .map((item) => ({ item, hits: fuzzy(item.label, query.trim()) }))\n    .filter((r): r is { item: SidebarCommandItem; hits: number[] } => r.hits !== null);\n  const groups: { name: string; rows: typeof filtered }[] = [];\n  for (const r of filtered) {\n    const name = r.item.group ?? \"\";\n    const g = groups.find((x) => x.name === name);\n    if (g) g.rows.push(r);\n    else groups.push({ name, rows: [r] });\n  }\n  const order = groups.flatMap((g) => g.rows.map((r) => r.item));\n  const hotIndex = Math.min(hot, Math.max(0, order.length - 1));\n\n  const run = React.useCallback(\n    (item: SidebarCommandItem) => {\n      if (item.action) onAction?.(item.id);\n      else {\n        if (active === undefined) setInner(item.id);\n        onChange?.(item.id);\n      }\n      setChord(null);\n      setFlashState((prev) => ({ text: item.action ? `Ran ${item.label}` : `Opened ${item.label}`, n: (prev?.n ?? 0) + 1 }));\n    },\n    [active, onAction, onChange],\n  );\n\n  const handleKey = React.useCallback(\n    (key: string): boolean => {\n      const k = key.toLowerCase();\n      if (chord) {\n        const match = items.find((i) => i.keys && i.keys.toLowerCase() === `${chord} ${k}`);\n        setChord(null);\n        if (match) {\n          run(match);\n          return true;\n        }\n        return k === \"escape\";\n      }\n      if (k.length !== 1) return false;\n      const direct = items.find((i) => i.keys && i.keys.toLowerCase() === k);\n      if (direct) {\n        run(direct);\n        return true;\n      }\n      if (items.some((i) => i.keys && i.keys.toLowerCase().startsWith(`${k} `))) {\n        setChord(k);\n        setFlashState(null);\n        return true;\n      }\n      return false;\n    },\n    [chord, items, run],\n  );\n\n  React.useEffect(() => {\n    if (!globalShortcuts) return;\n    const onWin = (e: KeyboardEvent) => {\n      if (e.metaKey || e.ctrlKey || e.altKey || isEditable(e.target)) return;\n      if (rootRef.current?.contains(e.target as Node)) return;\n      if (e.key === \"/\") {\n        e.preventDefault();\n        inputRef.current?.focus();\n        return;\n      }\n      if (handleKey(e.key)) e.preventDefault();\n    };\n    window.addEventListener(\"keydown\", onWin);\n    return () => window.removeEventListener(\"keydown\", onWin);\n  }, [globalShortcuts, handleKey]);\n\n  React.useEffect(() => {\n    if (!chord) return;\n    const t = window.setTimeout(() => setChord(null), chordTimeout);\n    return () => window.clearTimeout(t);\n  }, [chord, chordTimeout]);\n\n  React.useEffect(() => {\n    if (!flashState) return;\n    const t = window.setTimeout(() => setFlashState(null), 1600);\n    return () => window.clearTimeout(t);\n  }, [flashState]);\n\n  function rows() {\n    return Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-xk6-row]\") ?? []);\n  }\n\n  function onRootKey(e: React.KeyboardEvent<HTMLElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey) return;\n    const onInput = e.target === inputRef.current;\n    if (onInput) {\n      if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n        e.preventDefault();\n        const n = e.key === \"ArrowDown\" ? Math.min(order.length - 1, hotIndex + 1) : Math.max(0, hotIndex - 1);\n        setHot(n);\n      } else if (e.key === \"Enter\") {\n        e.preventDefault();\n        const item = order[hotIndex];\n        if (item) {\n          run(item);\n          setQuery(\"\");\n          setHot(0);\n        }\n      } else if (e.key === \"Escape\") {\n        if (query) {\n          e.preventDefault();\n          setQuery(\"\");\n        } else inputRef.current?.blur();\n      } else if (e.key === \"Tab\" && !e.shiftKey && order.length) {\n        e.preventDefault();\n        rows()[hotIndex]?.focus();\n      }\n      return;\n    }\n    const list = rows();\n    const at = list.indexOf(document.activeElement as HTMLElement);\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      if (at < 0) list[0]?.focus();\n      else if (e.key === \"ArrowUp\" && at === 0) inputRef.current?.focus();\n      else list[e.key === \"ArrowDown\" ? Math.min(list.length - 1, at + 1) : at - 1]?.focus();\n      return;\n    }\n    if (e.key === \"/\") {\n      e.preventDefault();\n      inputRef.current?.focus();\n      return;\n    }\n    if (handleKey(e.key)) e.preventDefault();\n  }\n\n  const lead = chord;\n  const nextKeys = lead ? items.filter((i) => i.keys?.toLowerCase().startsWith(`${lead} `)) : [];\n  const vars = { \"--hb-xk6-a\": accent, \"--hb-xk6-t\": `${chordTimeout}ms`, ...style } as React.CSSProperties;\n\n  return (\n    <nav ref={rootRef} aria-label=\"Command navigation\" className={`hb-xk6 ${className}`} style={vars} onKeyDown={onRootKey} {...rest}>\n      <style href=\"hb-sidebar-command\" precedence=\"default\">{css}</style>\n      <label className=\"hb-xk6-field\">\n        <span className=\"hb-xk6-caret\" aria-hidden=\"true\">&gt;</span>\n        <input\n          ref={inputRef}\n          className=\"hb-xk6-input\"\n          type=\"text\"\n          value={query}\n          placeholder={placeholder}\n          aria-label=\"Filter navigation\"\n          autoComplete=\"off\"\n          spellCheck={false}\n          onChange={(e) => {\n            setQuery(e.target.value);\n            setHot(0);\n          }}\n        />\n        <kbd className=\"hb-xk6-kbd\" aria-hidden=\"true\">/</kbd>\n      </label>\n      <div className=\"hb-xk6-body\">\n        {groups.length === 0 ? (\n          <p className=\"hb-xk6-empty\">\n            Nothing matches <b>{query}</b>\n          </p>\n        ) : (\n          groups.map((g) => (\n            <div key={g.name || \"items\"} role=\"group\" aria-label={g.name || undefined}>\n              {g.name ? <div className=\"hb-xk6-gl\" aria-hidden=\"true\">{g.name}</div> : null}\n              <ul className=\"hb-xk6-list\" role=\"list\">\n                {g.rows.map(({ item, hits }) => {\n                  const flat = order.indexOf(item);\n                  const parts = item.keys ? item.keys.split(\" \") : [];\n                  const dim = !!lead && !item.keys?.toLowerCase().startsWith(`${lead} `);\n                  return (\n                    <li key={item.id}>\n                      <button\n                        type=\"button\"\n                        className=\"hb-xk6-row\"\n                        data-xk6-row=\"\"\n                        data-hot={query !== \"\" && flat === hotIndex}\n                        data-dim={dim}\n                        aria-current={!item.action && item.id === current ? \"page\" : undefined}\n                        aria-keyshortcuts={item.keys ? item.keys.replace(\" \", \" then \") : undefined}\n                        onClick={() => run(item)}\n                      >\n                        <Glyph icon={item.icon} />\n                        <span className=\"hb-xk6-rl\">\n                          <Marked text={item.label} hits={hits} />\n                        </span>\n                        {parts.length ? (\n                          <span className=\"hb-xk6-keys\" aria-hidden=\"true\">\n                            {parts.map((p, i) => (\n                              <kbd key={i} className=\"hb-xk6-kbd\" data-lit={!!lead && i === 0 && p.toLowerCase() === lead}>\n                                {p.toUpperCase()}\n                              </kbd>\n                            ))}\n                          </span>\n                        ) : null}\n                      </button>\n                    </li>\n                  );\n                })}\n              </ul>\n            </div>\n          ))\n        )}\n      </div>\n      <div className=\"hb-xk6-status\" data-state={lead ? \"chord\" : flash ? \"done\" : \"idle\"} aria-live=\"polite\">\n        <span className=\"hb-xk6-mode\">{lead ? lead.toUpperCase() : flash ? \"OK\" : \"NAV\"}</span>\n        {lead ? (\n          <span key={`c-${lead}`} className=\"hb-xk6-msg\">\n            then {nextKeys.map((i) => (i.keys ?? \"\").split(\" \")[1]?.toUpperCase()).join(\" \")}\n          </span>\n        ) : flash ? (\n          <span key={`f-${flashState?.n ?? 0}`} className=\"hb-xk6-msg\">\n            <b>{flash}</b>\n          </span>\n        ) : (\n          <span className=\"hb-xk6-msg\">/ search · G go to</span>\n        )}\n        {lead ? <span key={`d-${lead}`} className=\"hb-xk6-drain\" aria-hidden=\"true\" /> : null}\n      </div>\n    </nav>\n  );\n}\n"
    }
  ]
}