{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select-command",
  "type": "registry:component",
  "title": "Command Select",
  "description": "A searchable select. Type to filter with highlighted matches, move with the arrow keys, group options and close with Escape.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "select",
    "combobox",
    "search",
    "listbox",
    "dropdown",
    "form"
  ],
  "docs": "https://hyperblur.dev/effects/select-command",
  "files": [
    {
      "path": "registry/hyperblur/select-command.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/select-command.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SelectCommandOption {\n  value: string;\n  label: string;\n  group?: string;\n  description?: string;\n  disabled?: boolean;\n}\n\nexport interface SelectCommandProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n  options: SelectCommandOption[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  placeholder?: string;\n  searchPlaceholder?: string;\n  emptyText?: string;\n  maxHeight?: number;\n  placement?: \"bottom\" | \"top\";\n  defaultOpen?: boolean;\n  label?: string;\n  name?: string;\n  disabled?: boolean;\n  accent?: string;\n}\n\nconst css = `\n.hb-qna {\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  font: inherit;\n  color: #ededed;\n}\n.hb-qna *, .hb-qna *::before, .hb-qna *::after { box-sizing: border-box; }\n.hb-qna-trigger {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 10px;\n  width: 100%;\n  height: 40px;\n  margin: 0;\n  padding: 0 12px 0 14px;\n  border: 1px solid #262626;\n  border-radius: 11px;\n  background: #111;\n  color: #ededed;\n  font: inherit;\n  font-size: 14px;\n  text-align: left;\n  cursor: pointer;\n  transition: border-color 0.2s ease, box-shadow 0.2s ease;\n}\n.hb-qna-trigger:hover { border-color: #3a3a3a; }\n.hb-qna-trigger:focus-visible,\n.hb-qna[data-open=\"true\"] .hb-qna-trigger {\n  outline: 0;\n  border-color: var(--hb-qna-a);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qna-a) 18%, transparent);\n}\n.hb-qna-trigger:disabled { opacity: 0.5; cursor: not-allowed; }\n.hb-qna-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-qna-value[data-empty=\"true\"] { color: #6f6f6f; }\n.hb-qna-chev { flex: none; width: 16px; height: 16px; color: #8f8f8f; transition: transform 0.25s cubic-bezier(0.3, 1.2, 0.5, 1); }\n.hb-qna[data-open=\"true\"] .hb-qna-chev { transform: rotate(180deg); }\n.hb-qna-chev path, .hb-qna-search svg path, .hb-qna-search svg circle { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }\n.hb-qna-panel {\n  position: absolute;\n  right: 0;\n  left: 0;\n  z-index: 30;\n  overflow: hidden;\n  border: 1px solid #2a2a2a;\n  border-radius: 12px;\n  background: #121212;\n  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.02);\n}\n.hb-qna[data-placement=\"bottom\"] .hb-qna-panel { top: calc(100% + 6px); transform-origin: top center; animation: hb-qna-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.1); }\n.hb-qna[data-placement=\"top\"] .hb-qna-panel { bottom: calc(100% + 6px); transform-origin: bottom center; animation: hb-qna-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.1); }\n.hb-qna-search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-bottom: 1px solid #222; color: #6f6f6f; }\n.hb-qna-search svg { flex: none; width: 15px; height: 15px; }\n.hb-qna-input {\n  flex: 1;\n  min-width: 0;\n  height: 100%;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 14px;\n}\n.hb-qna-input::placeholder { color: #5f5f5f; }\n.hb-qna-list { margin: 0; padding: 4px; overflow-y: auto; list-style: none; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #2a2a2a transparent; }\n.hb-qna-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #6f6f6f; }\n.hb-qna-opt {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  min-height: 32px;\n  padding: 0 10px;\n  border-radius: 8px;\n  font-size: 14px;\n  color: #d4d4d4;\n  cursor: pointer;\n}\n.hb-qna-opt[data-active=\"true\"] { background: color-mix(in srgb, var(--hb-qna-a) 18%, #1a1a1a); color: #fff; }\n.hb-qna-opt[aria-disabled=\"true\"] { opacity: 0.4; cursor: not-allowed; }\n.hb-qna-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-qna-desc { flex: none; margin-left: auto; font-size: 12px; color: #6f6f6f; font-variant-numeric: tabular-nums; }\n.hb-qna-opt[data-active=\"true\"] .hb-qna-desc { color: #a1a1a1; }\n.hb-qna-mark { border-radius: 3px; background: color-mix(in srgb, var(--hb-qna-a) 38%, transparent); color: #fff; }\n.hb-qna-check { flex: none; width: 14px; height: 14px; margin-left: auto; color: var(--hb-qna-a); }\n.hb-qna-check path { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-qna-desc + .hb-qna-check { margin-left: 4px; }\n.hb-qna-empty { padding: 14px 10px; font-size: 13px; text-align: center; color: #6f6f6f; }\n.hb-qna-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }\n@keyframes hb-qna-in {\n  0% { opacity: 0; transform: scale(0.97) translateY(-4px); }\n  100% { opacity: 1; transform: scale(1) translateY(0); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qna-trigger, .hb-qna-chev { transition: none; }\n  .hb-qna[data-placement] .hb-qna-panel { animation: none; }\n}\n`;\n\ntype Row =\n  | { type: \"group\"; name: string }\n  | { type: \"option\"; option: SelectCommandOption; index: number };\n\nfunction arrange(options: SelectCommandOption[], query: string) {\n  const q = query.trim().toLowerCase();\n  const matched = options.filter((o) => !q || o.label.toLowerCase().includes(q));\n  const buckets = new Map<string, SelectCommandOption[]>();\n  for (const option of matched) {\n    const key = option.group ?? \"\";\n    const list = buckets.get(key);\n    if (list) list.push(option);\n    else buckets.set(key, [option]);\n  }\n  const flat: SelectCommandOption[] = [];\n  const rows: Row[] = [];\n  buckets.forEach((list, group) => {\n    if (group) rows.push({ type: \"group\", name: group });\n    for (const option of list) {\n      rows.push({ type: \"option\", option, index: flat.length });\n      flat.push(option);\n    }\n  });\n  return { flat, rows };\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-qna-mark\">{text.slice(at, at + q.length)}</mark>\n      {text.slice(at + q.length)}\n    </>\n  );\n}\n\nexport function SelectCommand({\n  options,\n  value,\n  defaultValue,\n  onValueChange,\n  placeholder = \"Select an option\",\n  searchPlaceholder = \"Search...\",\n  emptyText = \"No results found\",\n  maxHeight = 240,\n  placement = \"bottom\",\n  defaultOpen = false,\n  label = \"Select\",\n  name,\n  disabled = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SelectCommandProps) {\n  const baseId = React.useId();\n  const listId = `${baseId}-list`;\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<string | undefined>(defaultValue);\n  const current = controlled ? value : inner;\n  const [open, setOpen] = React.useState(defaultOpen);\n  const [query, setQuery] = React.useState(\"\");\n  const [active, setActive] = React.useState(() => {\n    const first = arrange(options, \"\").flat.findIndex((o) => !o.disabled);\n    const picked = arrange(options, \"\").flat.findIndex((o) => o.value === (value ?? defaultValue));\n    return picked >= 0 ? picked : Math.max(0, first);\n  });\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const listRef = React.useRef<HTMLUListElement>(null);\n  const focusInput = React.useRef(false);\n\n  const { flat, rows } = arrange(options, query);\n  const selected = options.find((o) => o.value === current);\n  const activeOption = flat[active];\n\n  React.useEffect(() => {\n    if (!open || !focusInput.current) return;\n    const el = inputRef.current;\n    if (!el) return;\n    el.focus({ preventScroll: true });\n    el.setSelectionRange(el.value.length, el.value.length);\n  }, [open]);\n\n  React.useEffect(() => {\n    if (!open) return;\n    function onDown(e: PointerEvent) {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) {\n        setOpen(false);\n      }\n    }\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open]);\n\n  React.useEffect(() => {\n    if (!open) return;\n    const el = listRef.current?.querySelector<HTMLElement>('[data-active=\"true\"]');\n    el?.scrollIntoView({ block: \"nearest\" });\n  }, [open, active, query]);\n\n  function openPanel(initial = \"\") {\n    if (disabled) return;\n    const next = arrange(options, initial).flat;\n    const picked = initial ? -1 : next.findIndex((o) => o.value === current);\n    const first = next.findIndex((o) => !o.disabled);\n    focusInput.current = true;\n    setQuery(initial);\n    setActive(picked >= 0 ? picked : Math.max(0, first));\n    setOpen(true);\n  }\n\n  function closePanel(returnFocus: boolean) {\n    setOpen(false);\n    setQuery(\"\");\n    if (returnFocus) triggerRef.current?.focus();\n  }\n\n  function choose(option: SelectCommandOption | undefined) {\n    if (!option || option.disabled) return;\n    if (!controlled) setInner(option.value);\n    onValueChange?.(option.value);\n    closePanel(true);\n  }\n\n  function move(delta: number) {\n    if (flat.length === 0) return;\n    let i = active;\n    for (let n = 0; n < flat.length; n += 1) {\n      i = (i + delta + flat.length) % flat.length;\n      if (!flat[i].disabled) {\n        setActive(i);\n        return;\n      }\n    }\n  }\n\n  function onTriggerKey(e: React.KeyboardEvent<HTMLButtonElement>) {\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      openPanel();\n    } else if (e.key.length === 1 && e.key !== \" \" && !e.ctrlKey && !e.metaKey && !e.altKey) {\n      e.preventDefault();\n      openPanel(e.key);\n    }\n  }\n\n  function onInputKey(e: React.KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      move(1);\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      move(-1);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      const i = flat.findIndex((o) => !o.disabled);\n      if (i >= 0) setActive(i);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      for (let i = flat.length - 1; i >= 0; i -= 1) {\n        if (!flat[i].disabled) {\n          setActive(i);\n          break;\n        }\n      }\n    } else if (e.key === \"Enter\") {\n      e.preventDefault();\n      choose(activeOption);\n    } else if (e.key === \"Escape\") {\n      e.preventDefault();\n      e.stopPropagation();\n      closePanel(true);\n    } else if (e.key === \"Tab\") {\n      closePanel(true);\n    }\n  }\n\n  const vars = { \"--hb-qna-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-select-command\" precedence=\"default\">{css}</style>\n      <div\n        ref={rootRef}\n        className={`hb-qna ${className}`}\n        style={vars}\n        data-open={open}\n        data-placement={placement}\n        {...rest}\n      >\n        <button\n          ref={triggerRef}\n          type=\"button\"\n          className=\"hb-qna-trigger\"\n          aria-haspopup=\"listbox\"\n          aria-expanded={open}\n          aria-controls={open ? listId : undefined}\n          aria-label={selected ? `${label}: ${selected.label}` : label}\n          disabled={disabled}\n          onClick={() => (open ? closePanel(false) : openPanel())}\n          onKeyDown={onTriggerKey}\n        >\n          <span className=\"hb-qna-value\" data-empty={!selected}>\n            {selected ? selected.label : placeholder}\n          </span>\n          <svg className=\"hb-qna-chev\" viewBox=\"0 0 16 16\" focusable=\"false\" aria-hidden=\"true\">\n            <path d=\"M4 6.2l4 4 4-4\" />\n          </svg>\n        </button>\n        {open ? (\n          <div className=\"hb-qna-panel\">\n            <div className=\"hb-qna-search\">\n              <svg viewBox=\"0 0 16 16\" focusable=\"false\" aria-hidden=\"true\">\n                <circle cx=\"7\" cy=\"7\" r=\"4.6\" />\n                <path d=\"M10.5 10.5L14 14\" />\n              </svg>\n              <input\n                ref={inputRef}\n                className=\"hb-qna-input\"\n                role=\"combobox\"\n                aria-expanded=\"true\"\n                aria-controls={listId}\n                aria-autocomplete=\"list\"\n                aria-activedescendant={activeOption ? `${baseId}-o${active}` : undefined}\n                aria-label={`Search ${label.toLowerCase()}`}\n                placeholder={searchPlaceholder}\n                value={query}\n                autoComplete=\"off\"\n                spellCheck={false}\n                onChange={(e) => {\n                  const next = e.target.value;\n                  setQuery(next);\n                  const first = arrange(options, next).flat.findIndex((o) => !o.disabled);\n                  setActive(Math.max(0, first));\n                }}\n                onKeyDown={onInputKey}\n              />\n            </div>\n            <ul\n              ref={listRef}\n              id={listId}\n              role=\"listbox\"\n              aria-label={label}\n              className=\"hb-qna-list\"\n              style={{ maxHeight }}\n            >\n              {rows.map((row) => {\n                if (row.type === \"group\") {\n                  return (\n                    <li key={`g-${row.name}`} role=\"presentation\" className=\"hb-qna-group\" aria-hidden=\"true\">\n                      {row.name}\n                    </li>\n                  );\n                }\n                const { option, index } = row;\n                const isSelected = option.value === current;\n                return (\n                  <li\n                    key={option.value}\n                    id={`${baseId}-o${index}`}\n                    role=\"option\"\n                    className=\"hb-qna-opt\"\n                    aria-selected={isSelected}\n                    aria-disabled={option.disabled || undefined}\n                    data-active={index === active}\n                    onPointerDown={(e) => e.preventDefault()}\n                    onPointerMove={() => {\n                      if (!option.disabled && index !== active) setActive(index);\n                    }}\n                    onClick={() => choose(option)}\n                  >\n                    <span className=\"hb-qna-label\">\n                      <Highlight text={option.label} query={query} />\n                    </span>\n                    {option.description ? <span className=\"hb-qna-desc\">{option.description}</span> : null}\n                    {isSelected ? (\n                      <svg className=\"hb-qna-check\" viewBox=\"0 0 16 16\" focusable=\"false\" aria-hidden=\"true\">\n                        <path d=\"M3.5 8.4l3 3 6-6.6\" />\n                      </svg>\n                    ) : null}\n                  </li>\n                );\n              })}\n              {flat.length === 0 ? <li className=\"hb-qna-empty\" role=\"presentation\">{emptyText}</li> : null}\n            </ul>\n          </div>\n        ) : null}\n        {name ? <input type=\"hidden\" name={name} value={current ?? \"\"} /> : null}\n        <span className=\"hb-qna-sr\" role=\"status\" aria-live=\"polite\">\n          {open ? `${flat.length} ${flat.length === 1 ? \"option\" : \"options\"} available` : \"\"}\n        </span>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}