{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select-glide",
  "type": "registry:component",
  "title": "Glide Select",
  "description": "A custom select whose highlight glides between options on a spring and whose arrow rotates open. Supports arrow keys, Home, End, Enter, Escape and type-ahead.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "select",
    "dropdown",
    "listbox",
    "spring",
    "type-ahead",
    "form"
  ],
  "docs": "https://hyperblur.dev/effects/select-glide",
  "files": [
    {
      "path": "registry/hyperblur/select-glide.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/select-glide.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface GlideOption {\n  value: string;\n  label: string;\n  hint?: string;\n  disabled?: boolean;\n}\n\nexport interface GlideSelectProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  options?: GlideOption[];\n  value?: string;\n  defaultValue?: string;\n  onChange?: (value: string, option: GlideOption) => void;\n  placeholder?: string;\n  label?: string;\n  accent?: string;\n  disabled?: boolean;\n  defaultOpen?: boolean;\n}\n\nconst defaultOptions: GlideOption[] = [\n  { value: \"fra\", label: \"Frankfurt\", hint: \"eu-central\" },\n  { value: \"iad\", label: \"Virginia\", hint: \"us-east\" },\n  { value: \"sfo\", label: \"San Francisco\", hint: \"us-west\" },\n  { value: \"sin\", label: \"Singapore\", hint: \"ap-south\" },\n  { value: \"syd\", label: \"Sydney\", hint: \"ap-east\" },\n];\n\nconst css = `\n.hb-qs3 {\n  --hb-qs3-c: #2f7bff;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  font: inherit;\n  font-size: 14px;\n  color: #ededed;\n}\n.hb-qs3 *, .hb-qs3 *::before, .hb-qs3 *::after { box-sizing: border-box; font-family: inherit; }\n.hb-qs3-t {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  width: 100%;\n  height: 40px;\n  margin: 0;\n  padding: 0 12px;\n  font: inherit;\n  font-weight: 500;\n  text-align: left;\n  color: inherit;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 10px;\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.25s ease;\n}\n.hb-qs3-t:hover { border-color: #3a3a3a; background: #141414; }\n.hb-qs3-t:focus-visible { outline: 2px solid var(--hb-qs3-c); outline-offset: 2px; }\n.hb-qs3[data-open=\"true\"] .hb-qs3-t {\n  border-color: var(--hb-qs3-c);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qs3-c) 22%, transparent);\n}\n.hb-qs3[data-disabled=\"true\"] .hb-qs3-t { opacity: 0.45; cursor: not-allowed; }\n.hb-qs3-v { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-qs3-v[data-empty=\"true\"] { color: #8f8f8f; }\n.hb-qs3-a {\n  flex: none;\n  width: 16px;\n  height: 16px;\n  color: #8f8f8f;\n  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;\n}\n.hb-qs3[data-open=\"true\"] .hb-qs3-a { transform: rotate(180deg); color: var(--hb-qs3-c); }\n.hb-qs3-p {\n  position: absolute;\n  top: calc(100% + 6px);\n  left: 0;\n  right: 0;\n  z-index: 30;\n  margin: 0;\n  padding: 4px;\n  list-style: none;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);\n  visibility: hidden;\n  opacity: 0;\n  transform: translateY(-6px) scale(0.97);\n  transform-origin: top center;\n  transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;\n}\n.hb-qs3[data-open=\"true\"] .hb-qs3-p {\n  visibility: visible;\n  opacity: 1;\n  transform: translateY(0) scale(1);\n  transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;\n}\n.hb-qs3-h {\n  position: absolute;\n  left: 4px;\n  right: 4px;\n  top: 0;\n  height: var(--hb-qs3-h, 0px);\n  border-radius: 8px;\n  background: color-mix(in srgb, var(--hb-qs3-c) 20%, #1a1a1a);\n  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-qs3-c) 38%, transparent);\n  transform: translateY(var(--hb-qs3-y, 0px));\n  pointer-events: none;\n}\n.hb-qs3-p[data-ready=\"true\"] .hb-qs3-h {\n  transition: transform 0.5s cubic-bezier(0.34, 1.5, 0.5, 1), height 0.3s cubic-bezier(0.34, 1.3, 0.5, 1);\n}\n.hb-qs3-o {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  height: 34px;\n  padding: 0 10px;\n  border-radius: 8px;\n  color: #a1a1a1;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  transition: color 0.2s ease;\n}\n.hb-qs3-o[data-active=\"true\"] { color: #fff; }\n.hb-qs3-o[aria-disabled=\"true\"] { opacity: 0.4; cursor: not-allowed; }\n.hb-qs3-l { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }\n.hb-qs3-i { flex: none; font-size: 11px; color: #6f6f6f; letter-spacing: 0.02em; }\n.hb-qs3-o[data-active=\"true\"] .hb-qs3-i { color: #a9c8ff; }\n.hb-qs3-k {\n  flex: none;\n  width: 14px;\n  height: 14px;\n  color: var(--hb-qs3-c);\n  opacity: 0;\n  transform: scale(0.5);\n  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-qs3-o[aria-selected=\"true\"] .hb-qs3-k { opacity: 1; transform: scale(1); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qs3-t, .hb-qs3-a, .hb-qs3-p, .hb-qs3-h, .hb-qs3-o, .hb-qs3-k { transition: none !important; }\n}\n`;\n\nexport function GlideSelect({\n  options = defaultOptions,\n  value,\n  defaultValue,\n  onChange,\n  placeholder = \"Select an option\",\n  label = \"Select\",\n  accent = \"#2f7bff\",\n  disabled = false,\n  defaultOpen = false,\n  className = \"\",\n  style,\n  ...rest\n}: GlideSelectProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const listRef = React.useRef<HTMLUListElement>(null);\n  const optionRefs = React.useRef<Array<HTMLLIElement | null>>([]);\n  const buffer = React.useRef(\"\");\n  const bufferTimer = React.useRef(0);\n  const baseId = React.useId();\n  const [inner, setInner] = React.useState<string | undefined>(defaultValue);\n  const [open, setOpen] = React.useState(defaultOpen);\n  const [active, setActive] = React.useState(() => {\n    if (!defaultOpen) return -1;\n    const i = options.findIndex((o) => o.value === defaultValue);\n    return i >= 0 ? i : options.findIndex((o) => !o.disabled);\n  });\n  const [ready, setReady] = React.useState(false);\n  const current = value !== undefined ? value : inner;\n  const selectedIndex = options.findIndex((o) => o.value === current);\n  const selected = selectedIndex >= 0 ? options[selectedIndex] : undefined;\n\n  const firstEnabled = React.useCallback(() => options.findIndex((o) => !o.disabled), [options]);\n\n  React.useEffect(() => {\n    return () => {\n      window.clearTimeout(bufferTimer.current);\n    };\n  }, []);\n\n  const hide = React.useCallback(() => {\n    setOpen(false);\n    setReady(false);\n    setActive(-1);\n  }, []);\n\n  function show() {\n    setOpen(true);\n    setActive(selectedIndex >= 0 ? selectedIndex : firstEnabled());\n  }\n\n  React.useEffect(() => {\n    if (!open) return;\n    let frame = requestAnimationFrame(() => {\n      frame = requestAnimationFrame(() => setReady(true));\n    });\n    function onDown(e: PointerEvent) {\n      if (!rootRef.current?.contains(e.target as Node)) hide();\n    }\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => {\n      cancelAnimationFrame(frame);\n      document.removeEventListener(\"pointerdown\", onDown);\n    };\n  }, [open, hide]);\n\n  React.useLayoutEffect(() => {\n    const list = listRef.current;\n    const el = optionRefs.current[active];\n    if (!list || !el || !open) return;\n    list.style.setProperty(\"--hb-qs3-y\", `${el.offsetTop.toFixed(1)}px`);\n    list.style.setProperty(\"--hb-qs3-h\", `${el.offsetHeight.toFixed(1)}px`);\n  }, [active, open]);\n\n  function commit(index: number) {\n    const option = options[index];\n    if (!option || option.disabled) return;\n    if (value === undefined) setInner(option.value);\n    onChange?.(option.value, option);\n    hide();\n  }\n\n  function step(from: number, dir: 1 | -1) {\n    let i = from;\n    for (let n = 0; n < options.length; n++) {\n      i += dir;\n      if (i < 0 || i >= options.length) return from;\n      if (!options[i].disabled) return i;\n    }\n    return from;\n  }\n\n  function typeAhead(key: string) {\n    window.clearTimeout(bufferTimer.current);\n    buffer.current += key.toLowerCase();\n    bufferTimer.current = window.setTimeout(() => {\n      buffer.current = \"\";\n    }, 650);\n    const text = buffer.current;\n    const from = open ? active : selectedIndex;\n    const repeat = text.length > 1 && text.split(\"\").every((c) => c === text[0]);\n    const needle = repeat ? text[0] : text;\n    const begin = repeat || text.length === 1 ? from + 1 : from;\n    for (let n = 0; n < options.length; n++) {\n      const i = (((begin + n) % options.length) + options.length) % options.length;\n      const o = options[i];\n      if (!o.disabled && o.label.toLowerCase().startsWith(needle)) {\n        if (open) setActive(i);\n        else if (value === undefined) setInner(o.value);\n        if (!open) onChange?.(o.value, o);\n        return;\n      }\n    }\n  }\n\n  function onKeyDown(e: React.KeyboardEvent<HTMLButtonElement>) {\n    if (disabled) return;\n    const k = e.key;\n    if (k === \"ArrowDown\" || k === \"ArrowUp\") {\n      e.preventDefault();\n      if (!open) {\n        show();\n        return;\n      }\n      const base = active < 0 ? (k === \"ArrowDown\" ? -1 : options.length) : active;\n      setActive(step(base, k === \"ArrowDown\" ? 1 : -1));\n    } else if (k === \"Home\" || k === \"End\") {\n      if (!open) return;\n      e.preventDefault();\n      if (k === \"Home\") setActive(firstEnabled());\n      else {\n        let i = options.length - 1;\n        while (i > 0 && options[i].disabled) i--;\n        setActive(i);\n      }\n    } else if (k === \"Enter\" || k === \" \") {\n      e.preventDefault();\n      if (!open) show();\n      else if (k === \" \" && buffer.current) typeAhead(\" \");\n      else commit(active);\n    } else if (k === \"Escape\") {\n      if (open) {\n        e.preventDefault();\n        hide();\n      }\n    } else if (k === \"Tab\") {\n      hide();\n    } else if (k.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {\n      typeAhead(k);\n    }\n  }\n\n  const vars = { \"--hb-qs3-c\": accent, ...style } as React.CSSProperties;\n  const listId = `${baseId}-list`;\n\n  return (\n    <>\n      <style href=\"hb-select-glide\" precedence=\"default\">{css}</style>\n      <div\n        ref={rootRef}\n        className={`hb-qs3 ${className}`}\n        style={vars}\n        data-open={open}\n        data-disabled={disabled}\n        {...rest}\n      >\n        <button\n          type=\"button\"\n          role=\"combobox\"\n          aria-label={label}\n          aria-haspopup=\"listbox\"\n          aria-expanded={open}\n          aria-controls={listId}\n          aria-activedescendant={open && active >= 0 ? `${baseId}-o${active}` : undefined}\n          disabled={disabled}\n          className=\"hb-qs3-t\"\n          onClick={() => (open ? hide() : show())}\n          onKeyDown={onKeyDown}\n        >\n          <span className=\"hb-qs3-v\" data-empty={!selected}>\n            {selected ? selected.label : placeholder}\n          </span>\n          <svg className=\"hb-qs3-a\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M3.5 6 8 10.5 12.5 6\" />\n          </svg>\n        </button>\n        <ul\n          ref={listRef}\n          id={listId}\n          role=\"listbox\"\n          aria-label={label}\n          className=\"hb-qs3-p\"\n          data-ready={ready}\n          onPointerLeave={() => setActive(selectedIndex >= 0 ? selectedIndex : active)}\n        >\n          <li className=\"hb-qs3-h\" role=\"presentation\" aria-hidden=\"true\" />\n          {options.map((o, i) => (\n            <li\n              key={o.value}\n              id={`${baseId}-o${i}`}\n              ref={(el) => {\n                optionRefs.current[i] = el;\n              }}\n              role=\"option\"\n              aria-selected={i === selectedIndex}\n              aria-disabled={o.disabled || undefined}\n              data-active={i === active}\n              className=\"hb-qs3-o\"\n              onPointerMove={() => {\n                if (!o.disabled && active !== i) setActive(i);\n              }}\n              onClick={() => commit(i)}\n            >\n              <span className=\"hb-qs3-l\">{o.label}</span>\n              {o.hint ? <span className=\"hb-qs3-i\">{o.hint}</span> : null}\n              <svg className=\"hb-qs3-k\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"m3.5 8.5 3 3 6-7\" />\n              </svg>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}