{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hud-filter-chips",
  "type": "registry:component",
  "title": "HUD Filter Chips",
  "description": "A row of bracket-cornered filter chips with single or multiple selection, an All option and arrow key navigation.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hud",
    "filter",
    "chips",
    "tags",
    "toggle",
    "hud",
    "toolbar"
  ],
  "docs": "https://hyperblur.dev/effects/hud-filter-chips",
  "files": [
    {
      "path": "registry/hyperblur/hud-filter-chips.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hud-filter-chips.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HudFilterOption {\n  id: string;\n  label: string;\n  count?: number;\n}\n\nexport interface HudFilterChipsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  options?: HudFilterOption[];\n  value?: string[];\n  defaultValue?: string[];\n  onChange?: (value: string[]) => void;\n  multiple?: boolean;\n  allId?: string;\n  label?: string;\n  accent?: string;\n}\n\nconst defaultOptions: HudFilterOption[] = [\n  { id: \"all\", label: \"All\", count: 34 },\n  { id: \"xr\", label: \"XR\", count: 6 },\n  { id: \"map\", label: \"Map\", count: 5 },\n  { id: \"tool\", label: \"Tool\", count: 11 },\n  { id: \"graphics\", label: \"Graphics\", count: 12 },\n];\n\nconst css = `\n.hb-ua5 {\n  --hb-ua5-accent: #ff4d4d;\n  box-sizing: border-box;\n  display: flex;\n  flex-wrap: wrap;\n  gap: 6px;\n  width: 100%;\n  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;\n}\n.hb-ua5 *, .hb-ua5 *::before, .hb-ua5 *::after { box-sizing: border-box; }\n.hb-ua5-chip {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: 7px;\n  height: 28px;\n  margin: 0;\n  padding: 0 11px;\n  border: 1px solid rgba(255,255,255,.1);\n  border-radius: 0;\n  background: rgba(255,255,255,.025);\n  color: #a1a1a1;\n  font: inherit;\n  font-size: 10px;\n  letter-spacing: .14em;\n  text-transform: uppercase;\n  white-space: nowrap;\n  cursor: pointer;\n  outline: none;\n  -webkit-tap-highlight-color: transparent;\n  transition: color .2s ease, border-color .2s ease, background-color .2s ease, box-shadow .25s ease, transform .12s ease;\n}\n.hb-ua5-chip::before, .hb-ua5-chip::after {\n  content: \"\";\n  position: absolute;\n  width: 6px;\n  height: 6px;\n  border: 0 solid rgba(255,255,255,.45);\n  pointer-events: none;\n  transition: border-color .2s ease, width .2s ease, height .2s ease;\n}\n.hb-ua5-chip::before { left: -1px; top: -1px; border-left-width: 1px; border-top-width: 1px; }\n.hb-ua5-chip::after { right: -1px; bottom: -1px; border-right-width: 1px; border-bottom-width: 1px; }\n.hb-ua5-chip:hover { color: #ededed; border-color: rgba(255,255,255,.2); }\n.hb-ua5-chip:hover::before, .hb-ua5-chip:hover::after { width: 9px; height: 9px; }\n.hb-ua5-chip:active { transform: translateY(1px); }\n.hb-ua5-chip:focus-visible { border-color: rgba(255,255,255,.4); color: #ededed; }\n.hb-ua5-chip[aria-pressed=\"true\"] {\n  color: #fff;\n  border-color: color-mix(in srgb, var(--hb-ua5-accent) 65%, transparent);\n  background: color-mix(in srgb, var(--hb-ua5-accent) 14%, transparent);\n  box-shadow: 0 0 16px -4px color-mix(in srgb, var(--hb-ua5-accent) 70%, transparent), inset 0 0 12px -6px var(--hb-ua5-accent);\n}\n.hb-ua5-chip[aria-pressed=\"true\"]::before, .hb-ua5-chip[aria-pressed=\"true\"]::after { border-color: var(--hb-ua5-accent); width: 9px; height: 9px; }\n.hb-ua5-count { color: #5f5f5f; font-variant-numeric: tabular-nums; transition: color .2s ease; }\n.hb-ua5-chip[aria-pressed=\"true\"] .hb-ua5-count { color: var(--hb-ua5-accent); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-ua5-chip, .hb-ua5-chip::before, .hb-ua5-chip::after, .hb-ua5-count { transition: none; }\n}\n`;\n\nexport function HudFilterChips({\n  options = defaultOptions,\n  value,\n  defaultValue,\n  onChange,\n  multiple = false,\n  allId = \"all\",\n  label = \"Filter\",\n  accent = \"#ff4d4d\",\n  className,\n  style,\n  ...rest\n}: HudFilterChipsProps) {\n  const hasAll = options.some((o) => o.id === allId);\n  const fallback = hasAll ? [allId] : options[0] ? [options[0].id] : [];\n  const [inner, setInner] = React.useState<string[]>(() => defaultValue ?? fallback);\n  const selected = value ?? inner;\n  const [focusIndex, setFocusIndex] = React.useState(() => Math.max(0, options.findIndex((o) => selected.includes(o.id))));\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n\n  const set = (next: string[]) => {\n    if (value === undefined) setInner(next);\n    onChange?.(next);\n  };\n\n  const toggle = (id: string) => {\n    if (!multiple) {\n      if (selected.length === 1 && selected[0] === id) return;\n      set([id]);\n      return;\n    }\n    if (id === allId) {\n      set([allId]);\n      return;\n    }\n    const base = selected.filter((s) => s !== allId);\n    const next = base.includes(id) ? base.filter((s) => s !== id) : [...base, id];\n    set(next.length ? next : fallback);\n  };\n\n  const move = (i: number) => {\n    const n = options.length;\n    const next = ((i % n) + n) % n;\n    setFocusIndex(next);\n    refs.current[next]?.focus();\n  };\n\n  const onKey = (e: React.KeyboardEvent<HTMLButtonElement>, i: number) => {\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      move(i + 1);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      move(i - 1);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      move(0);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      move(options.length - 1);\n    }\n  };\n\n  const tabStop = Math.min(focusIndex, options.length - 1);\n\n  return (\n    <div\n      role=\"toolbar\"\n      aria-label={label}\n      className={[\"hb-ua5\", className].filter(Boolean).join(\" \")}\n      style={{ [\"--hb-ua5-accent\" as string]: accent, ...style }}\n      {...rest}\n    >\n      <style href=\"hb-hud-filter-chips\" precedence=\"default\">{css}</style>\n      {options.map((o, i) => (\n        <button\n          key={o.id}\n          ref={(el) => {\n            refs.current[i] = el;\n          }}\n          type=\"button\"\n          className=\"hb-ua5-chip\"\n          aria-pressed={selected.includes(o.id)}\n          tabIndex={i === tabStop ? 0 : -1}\n          onFocus={() => setFocusIndex(i)}\n          onKeyDown={(e) => onKey(e, i)}\n          onClick={() => toggle(o.id)}\n        >\n          {o.label}\n          {o.count !== undefined ? <span className=\"hb-ua5-count\">{String(o.count).padStart(2, \"0\")}</span> : null}\n        </button>\n      ))}\n    </div>\n  );\n}\n\nexport default HudFilterChips;\n"
    }
  ]
}