{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select-combobox-async",
  "type": "registry:component",
  "title": "Async Combobox",
  "description": "A searchable combobox that debounces input, shows shimmering skeleton rows while results load and drops stale responses. Matches are underlined, rows stagger in and the footer reports the result count and how long the search took.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "combobox",
    "autocomplete",
    "async",
    "search",
    "select",
    "skeleton"
  ],
  "docs": "https://hyperblur.dev/effects/select-combobox-async",
  "files": [
    {
      "path": "registry/hyperblur/select-combobox-async.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/select-combobox-async.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SelectComboboxAsyncOption {\n  id: string;\n  label: string;\n  description?: string;\n  badge?: string;\n  meta?: string;\n}\n\nexport interface SelectComboboxAsyncProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  label?: string;\n  placeholder?: string;\n  options?: SelectComboboxAsyncOption[];\n  loadOptions?: (query: string, signal: AbortSignal) => Promise<SelectComboboxAsyncOption[]>;\n  latency?: number;\n  debounce?: number;\n  maxResults?: number;\n  recent?: SelectComboboxAsyncOption[];\n  value?: SelectComboboxAsyncOption | null;\n  defaultValue?: SelectComboboxAsyncOption | null;\n  onChange?: (option: SelectComboboxAsyncOption | null) => void;\n  defaultQuery?: string;\n  defaultOpen?: boolean;\n  embedded?: boolean;\n  accent?: string;\n}\n\nexport const selectComboboxAirports: SelectComboboxAsyncOption[] = [\n  { id: \"sfo\", badge: \"SFO\", label: \"San Francisco International\", description: \"San Francisco, United States\", meta: \"2h 10m\" },\n  { id: \"jfk\", badge: \"JFK\", label: \"John F. Kennedy International\", description: \"New York, United States\", meta: \"5h 35m\" },\n  { id: \"lhr\", badge: \"LHR\", label: \"Heathrow\", description: \"London, United Kingdom\", meta: \"10h 20m\" },\n  { id: \"lgw\", badge: \"LGW\", label: \"Gatwick\", description: \"London, United Kingdom\", meta: \"10h 45m\" },\n  { id: \"lis\", badge: \"LIS\", label: \"Humberto Delgado\", description: \"Lisbon, Portugal\", meta: \"11h 05m\" },\n  { id: \"cdg\", badge: \"CDG\", label: \"Charles de Gaulle\", description: \"Paris, France\", meta: \"10h 55m\" },\n  { id: \"ams\", badge: \"AMS\", label: \"Schiphol\", description: \"Amsterdam, Netherlands\", meta: \"10h 30m\" },\n  { id: \"ber\", badge: \"BER\", label: \"Brandenburg\", description: \"Berlin, Germany\", meta: \"11h 15m\" },\n  { id: \"bcn\", badge: \"BCN\", label: \"El Prat\", description: \"Barcelona, Spain\", meta: \"11h 40m\" },\n  { id: \"gru\", badge: \"GRU\", label: \"Guarulhos International\", description: \"São Paulo, Brazil\", meta: \"12h 50m\" },\n  { id: \"hnd\", badge: \"HND\", label: \"Haneda\", description: \"Tokyo, Japan\", meta: \"11h 25m\" },\n  { id: \"sin\", badge: \"SIN\", label: \"Changi\", description: \"Singapore\", meta: \"17h 10m\" },\n  { id: \"syd\", badge: \"SYD\", label: \"Kingsford Smith\", description: \"Sydney, Australia\", meta: \"15h 30m\" },\n  { id: \"dxb\", badge: \"DXB\", label: \"Dubai International\", description: \"Dubai, United Arab Emirates\", meta: \"15h 40m\" },\n  { id: \"yyz\", badge: \"YYZ\", label: \"Pearson International\", description: \"Toronto, Canada\", meta: \"4h 50m\" },\n  { id: \"mex\", badge: \"MEX\", label: \"Benito Juárez International\", description: \"Mexico City, Mexico\", meta: \"4h 15m\" },\n  { id: \"sea\", badge: \"SEA\", label: \"Seattle–Tacoma International\", description: \"Seattle, United States\", meta: \"2h 55m\" },\n  { id: \"lax\", badge: \"LAX\", label: \"Los Angeles International\", description: \"Los Angeles, United States\", meta: \"1h 25m\" },\n];\n\nconst css = `\n.hb-xg5 {\n  --hb-xg5-c: #2f7bff;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xg5 *, .hb-xg5 *::before, .hb-xg5 *::after { box-sizing: border-box; }\n.hb-xg5-label { display: block; margin: 0 0 7px; font-size: 12.5px; font-weight: 500; color: #a1a1a1; }\n.hb-xg5-field {\n  position: relative;\n  display: flex;\n  align-items: center;\n  height: 44px;\n  padding: 0 6px 0 12px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: linear-gradient(180deg, #161616, #0f0f0f);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 1px 2px rgba(0, 0, 0, 0.5);\n  transition: border-color 0.2s ease, box-shadow 0.25s ease;\n}\n.hb-xg5-field:hover { border-color: #333; }\n.hb-xg5-field:focus-within {\n  border-color: var(--hb-xg5-c);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 0 0 4px color-mix(in srgb, var(--hb-xg5-c) 16%, transparent);\n}\n.hb-xg5-lead { width: 16px; height: 16px; flex: none; color: #6f6f6f; transition: color 0.2s ease; }\n.hb-xg5-field:focus-within .hb-xg5-lead { color: var(--hb-xg5-c); }\n.hb-xg5-in {\n  flex: 1;\n  min-width: 0;\n  height: 100%;\n  margin: 0;\n  padding: 0 8px 0 10px;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 14px;\n  caret-color: var(--hb-xg5-c);\n}\n.hb-xg5-in::placeholder { color: #5a5a5a; }\n.hb-xg5-spin {\n  width: 16px;\n  height: 16px;\n  flex: none;\n  margin-right: 6px;\n  border-radius: 50%;\n  background: conic-gradient(from 0deg, transparent 0 25%, var(--hb-xg5-c));\n  -webkit-mask: radial-gradient(circle, transparent 5.5px, #000 6px);\n  mask: radial-gradient(circle, transparent 5.5px, #000 6px);\n  animation: hb-xg5-spin 0.7s linear infinite;\n}\n.hb-xg5-clear {\n  display: grid;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  flex: none;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #6f6f6f;\n  cursor: pointer;\n}\n.hb-xg5-clear:hover { color: #ededed; background: rgba(255, 255, 255, 0.05); }\n.hb-xg5-clear:focus-visible { outline: 2px solid var(--hb-xg5-c); outline-offset: -2px; }\n.hb-xg5-clear svg { width: 12px; height: 12px; }\n.hb-xg5-pop {\n  position: absolute;\n  z-index: 30;\n  left: 0;\n  right: 0;\n  top: calc(100% + 6px);\n  border: 1px solid #2a2a2a;\n  border-radius: 14px;\n  background: rgba(19, 19, 19, 0.97);\n  backdrop-filter: blur(14px);\n  -webkit-backdrop-filter: blur(14px);\n  box-shadow: 0 24px 48px -16px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.05);\n  overflow: hidden;\n  transform-origin: top center;\n  animation: hb-xg5-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-xg5[data-embedded=\"true\"] .hb-xg5-pop { position: relative; top: auto; margin-top: 6px; animation: none; }\n.hb-xg5-list { margin: 0; padding: 5px; list-style: none; max-height: 260px; overflow-y: auto; scrollbar-width: thin; }\n.hb-xg5-head { padding: 6px 8px 4px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #6f6f6f; }\n.hb-xg5-opt {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  height: 40px;\n  padding: 0 8px;\n  border-radius: 9px;\n  cursor: pointer;\n  animation: hb-xg5-row 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;\n  animation-delay: calc(var(--hb-xg5-i) * 35ms);\n}\n.hb-xg5-opt[data-active=\"true\"] { background: rgba(255, 255, 255, 0.06); }\n.hb-xg5-opt[data-active=\"true\"]::before { content: \"\"; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--hb-xg5-c); }\n.hb-xg5-badge {\n  display: grid;\n  place-items: center;\n  min-width: 38px;\n  height: 24px;\n  padding: 0 5px;\n  border: 1px solid #2c2c2c;\n  border-radius: 6px;\n  background: linear-gradient(180deg, #1c1c1c, #141414);\n  font-family: var(--font-mono), ui-monospace, monospace;\n  font-size: 11px;\n  font-weight: 600;\n  letter-spacing: 0.04em;\n  color: #d4d4d4;\n}\n.hb-xg5-opt[data-active=\"true\"] .hb-xg5-badge { border-color: color-mix(in srgb, var(--hb-xg5-c) 50%, #2c2c2c); color: #fff; }\n.hb-xg5-text { flex: 1; min-width: 0; line-height: 1.2; }\n.hb-xg5-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }\n.hb-xg5-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: #7a7a7a; }\n.hb-xg5-text mark { background: none; color: #fff; font-weight: 600; box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--hb-xg5-c) 70%, transparent); }\n.hb-xg5-meta { flex: none; font-size: 11.5px; color: #6f6f6f; font-variant-numeric: tabular-nums; }\n.hb-xg5-check { width: 14px; height: 14px; color: var(--hb-xg5-c); flex: none; }\n.hb-xg5-sk { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 8px; }\n.hb-xg5-sk i {\n  display: block;\n  height: 10px;\n  border-radius: 5px;\n  background: linear-gradient(90deg, #1a1a1a 0%, #262626 40%, #1a1a1a 80%);\n  background-size: 220% 100%;\n  animation: hb-xg5-shim 1.1s ease-in-out infinite;\n}\n.hb-xg5-sk i:first-child { width: 38px; height: 24px; border-radius: 6px; flex: none; }\n.hb-xg5-sk div { display: flex; flex: 1; flex-direction: column; gap: 6px; }\n.hb-xg5-empty { padding: 14px 10px; font-size: 12.5px; color: #8f8f8f; text-align: center; }\n.hb-xg5-foot {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 8px;\n  height: 30px;\n  padding: 0 11px;\n  border-top: 1px solid #1f1f1f;\n  font-size: 11px;\n  color: #6f6f6f;\n  font-variant-numeric: tabular-nums;\n}\n.hb-xg5-keys { display: flex; align-items: center; gap: 4px; }\n.hb-xg5-keys kbd {\n  display: inline-grid;\n  place-items: center;\n  min-width: 17px;\n  height: 17px;\n  padding: 0 4px;\n  border: 1px solid #2a2a2a;\n  border-bottom-width: 2px;\n  border-radius: 4px;\n  font-family: inherit;\n  font-size: 10px;\n  color: #a1a1a1;\n}\n.hb-xg5-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: #3fbf7f; box-shadow: 0 0 0 3px rgba(63, 191, 127, 0.15); vertical-align: 1px; }\n.hb-xg5[data-loading=\"true\"] .hb-xg5-dot { background: #e5a93b; box-shadow: 0 0 0 3px rgba(229, 169, 59, 0.15); }\n@keyframes hb-xg5-spin { to { transform: rotate(360deg); } }\n@keyframes hb-xg5-shim { 0% { background-position: 120% 0; } 100% { background-position: -120% 0; } }\n@keyframes hb-xg5-in { from { opacity: 0; transform: translateY(-4px) scale(0.985); } }\n@keyframes hb-xg5-row { from { opacity: 0; transform: translateY(4px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xg5 *, .hb-xg5-pop { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction highlight(text: string, q: string) {\n  if (!q) return text;\n  const i = text.toLowerCase().indexOf(q.toLowerCase());\n  if (i < 0) return text;\n  return (\n    <>\n      {text.slice(0, i)}\n      <mark>{text.slice(i, i + q.length)}</mark>\n      {text.slice(i + q.length)}\n    </>\n  );\n}\n\nexport function SelectComboboxAsync({\n  label = \"Flying to\",\n  placeholder = \"City, airport or code\",\n  options = selectComboboxAirports,\n  loadOptions,\n  latency = 420,\n  debounce = 160,\n  maxResults = 6,\n  recent,\n  value,\n  defaultValue = null,\n  onChange,\n  defaultQuery = \"\",\n  defaultOpen = false,\n  embedded = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SelectComboboxAsyncProps) {\n  const id = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<SelectComboboxAsyncOption | null>(defaultValue);\n  const selected = controlled ? value : inner;\n  const [query, setQuery] = React.useState(defaultQuery || selected?.label || \"\");\n  const [open, setOpen] = React.useState(defaultOpen);\n  const [results, setResults] = React.useState<SelectComboboxAsyncOption[]>([]);\n  const [loading, setLoading] = React.useState(false);\n  const [took, setTook] = React.useState<number | null>(null);\n  const [active, setActive] = React.useState(0);\n  const [searched, setSearched] = React.useState(\"\");\n  const recentList = recent ?? options.slice(0, 3);\n  const q = query.trim();\n  const showRecent = q === \"\" || (selected !== null && q === selected.label);\n\n  React.useEffect(() => {\n    if (!open || showRecent) return;\n    const ctrl = new AbortController();\n    const t0 = performance.now();\n    const startT = window.setTimeout(() => setLoading(true), 0);\n    const timer = window.setTimeout(() => {\n      const run =\n        loadOptions ??\n        ((text: string, signal: AbortSignal) =>\n          new Promise<SelectComboboxAsyncOption[]>((resolve, reject) => {\n            const lower = text.toLowerCase();\n            const hits = options.filter((o) =>\n              [o.label, o.description ?? \"\", o.badge ?? \"\"].some((f) => f.toLowerCase().includes(lower)),\n            );\n            const wait = window.setTimeout(() => resolve(hits), Math.max(0, latency - 60 + (hits.length % 4) * 40));\n            signal.addEventListener(\"abort\", () => {\n              window.clearTimeout(wait);\n              reject(new DOMException(\"Aborted\", \"AbortError\"));\n            });\n          }));\n      run(q, ctrl.signal)\n        .then((r) => {\n          if (ctrl.signal.aborted) return;\n          setResults(r.slice(0, maxResults));\n          setSearched(q);\n          setTook(Math.round(performance.now() - t0));\n          setActive(0);\n          setLoading(false);\n        })\n        .catch(() => {\n          if (!ctrl.signal.aborted) setLoading(false);\n        });\n    }, debounce);\n    return () => {\n      ctrl.abort();\n      window.clearTimeout(timer);\n      window.clearTimeout(startT);\n    };\n  }, [q, open, showRecent, loadOptions, options, latency, debounce, maxResults]);\n\n  React.useEffect(() => {\n    if (!open || embedded) return;\n    function down(e: PointerEvent) {\n      if (!rootRef.current?.contains(e.target as Node)) setOpen(false);\n    }\n    document.addEventListener(\"pointerdown\", down);\n    return () => document.removeEventListener(\"pointerdown\", down);\n  }, [open, embedded]);\n\n  const items = showRecent ? recentList : results;\n\n  function choose(o: SelectComboboxAsyncOption | null) {\n    if (!controlled) setInner(o);\n    onChange?.(o);\n    setQuery(o?.label ?? \"\");\n    setOpen(false);\n  }\n\n  function onKey(e: React.KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      if (!open) setOpen(true);\n      else setActive((a) => (items.length ? (a + 1) % items.length : 0));\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setActive((a) => (items.length ? (a - 1 + items.length) % items.length : 0));\n    } else if (e.key === \"Home\" && open) {\n      setActive(0);\n    } else if (e.key === \"End\" && open) {\n      setActive(Math.max(0, items.length - 1));\n    } else if (e.key === \"Enter\") {\n      if (open && items[active]) {\n        e.preventDefault();\n        choose(items[active]);\n      }\n    } else if (e.key === \"Escape\") {\n      if (open) {\n        e.preventDefault();\n        setOpen(false);\n      } else if (query) {\n        setQuery(\"\");\n      }\n    }\n  }\n\n  const stale = !showRecent && searched !== q;\n  const showSkeleton = !showRecent && (loading || stale) && results.length === 0;\n  const listId = `${id}-list`;\n  const vars = { \"--hb-xg5-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-xg5 ${className}`}\n      style={vars}\n      data-loading={loading}\n      data-embedded={embedded}\n      {...rest}\n    >\n      <style href=\"hb-select-combobox-async\" precedence=\"default\">{css}</style>\n      {label && (\n        <label className=\"hb-xg5-label\" htmlFor={`${id}-in`}>\n          {label}\n        </label>\n      )}\n      <div className=\"hb-xg5-field\">\n        <svg className=\"hb-xg5-lead\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" aria-hidden=\"true\">\n          <path d=\"M14 9.6l-5.2-2.3V3.2a1.3 1.3 0 0 0-2.6 0v4.1L1 9.6v1.6l5.2-1.2v2.8l-1.6 1.1v1.1L8 14.2l2.4.8v-1.1l-1.6-1.1V10l5.2 1.2z\" strokeLinejoin=\"round\" />\n        </svg>\n        <input\n          ref={inputRef}\n          id={`${id}-in`}\n          className=\"hb-xg5-in\"\n          role=\"combobox\"\n          aria-expanded={open}\n          aria-controls={listId}\n          aria-autocomplete=\"list\"\n          aria-activedescendant={open && items[active] ? `${id}-o-${active}` : undefined}\n          autoComplete=\"off\"\n          spellCheck={false}\n          placeholder={placeholder}\n          value={query}\n          onChange={(e) => {\n            setQuery(e.target.value);\n            setOpen(true);\n            setActive(0);\n          }}\n          onFocus={() => setOpen(true)}\n          onClick={() => setOpen(true)}\n          onKeyDown={onKey}\n        />\n        {loading && <span className=\"hb-xg5-spin\" aria-hidden=\"true\" />}\n        {query && (\n          <button\n            type=\"button\"\n            className=\"hb-xg5-clear\"\n            aria-label=\"Clear\"\n            onClick={() => {\n              choose(null);\n              setOpen(true);\n              inputRef.current?.focus();\n            }}\n          >\n            <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" aria-hidden=\"true\">\n              <path d=\"M3 3l6 6M9 3l-6 6\" strokeLinecap=\"round\" />\n            </svg>\n          </button>\n        )}\n      </div>\n      {open && (\n        <div className=\"hb-xg5-pop\">\n          <ul className=\"hb-xg5-list\" id={listId} role=\"listbox\" aria-label={showRecent ? \"Recent\" : \"Suggestions\"} aria-busy={loading}>\n            {showRecent && recentList.length > 0 && (\n              <li className=\"hb-xg5-head\" role=\"presentation\">\n                Recent\n              </li>\n            )}\n            {showSkeleton\n              ? [0, 1, 2].map((i) => (\n                  <li key={`sk${i}`} className=\"hb-xg5-sk\" role=\"presentation\" aria-hidden=\"true\">\n                    <i />\n                    <div>\n                      <i style={{ width: `${70 - i * 12}%` }} />\n                      <i style={{ width: `${45 + i * 8}%`, height: 8 }} />\n                    </div>\n                  </li>\n                ))\n              : items.map((o, i) => (\n                  <li\n                    key={`${searched}-${o.id}`}\n                    id={`${id}-o-${i}`}\n                    role=\"option\"\n                    aria-selected={selected?.id === o.id}\n                    data-active={i === active}\n                    className=\"hb-xg5-opt\"\n                    style={{ \"--hb-xg5-i\": i } as React.CSSProperties}\n                    onPointerEnter={() => setActive(i)}\n                    onPointerDown={(e) => e.preventDefault()}\n                    onClick={() => choose(o)}\n                  >\n                    {o.badge && <span className=\"hb-xg5-badge\">{o.badge}</span>}\n                    <span className=\"hb-xg5-text\">\n                      <span>{highlight(o.label, showRecent ? \"\" : searched)}</span>\n                      {o.description && <small>{highlight(o.description, showRecent ? \"\" : searched)}</small>}\n                    </span>\n                    {selected?.id === o.id ? (\n                      <svg className=\"hb-xg5-check\" viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" aria-hidden=\"true\">\n                        <path d=\"M3 7.4l2.6 2.6L11 4.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                      </svg>\n                    ) : (\n                      o.meta && <span className=\"hb-xg5-meta\">{o.meta}</span>\n                    )}\n                  </li>\n                ))}\n            {!showRecent && !showSkeleton && !loading && !stale && results.length === 0 && (\n              <li className=\"hb-xg5-empty\" role=\"presentation\">\n                Nothing matches “{q}”. Try a city or a three-letter code.\n              </li>\n            )}\n          </ul>\n          <div className=\"hb-xg5-foot\" aria-live=\"polite\">\n            <span>\n              <span className=\"hb-xg5-dot\" aria-hidden=\"true\" />\n              {showRecent\n                ? `${recentList.length} recent`\n                : loading || stale\n                  ? \"Searching…\"\n                  : `${results.length} result${results.length === 1 ? \"\" : \"s\"}${took !== null ? ` · ${took} ms` : \"\"}`}\n            </span>\n            <span className=\"hb-xg5-keys\" aria-hidden=\"true\">\n              <kbd>↑</kbd>\n              <kbd>↓</kbd>\n              <kbd>↵</kbd>\n            </span>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}