{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-search-filters",
  "type": "registry:component",
  "title": "Search with Filters",
  "description": "A search field that turns key:value syntax into colored filter tokens, suggesting filter names and then their values as you type. Prefix with a minus to exclude, click a token to edit it, and press Backspace twice to remove the last one.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "search",
    "filters",
    "tokens",
    "query",
    "combobox",
    "issues"
  ],
  "docs": "https://hyperblur.dev/effects/input-search-filters",
  "files": [
    {
      "path": "registry/hyperblur/input-search-filters.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/input-search-filters.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface InputSearchFilter {\n  key: string;\n  label: string;\n  values: string[];\n  color?: string;\n}\n\nexport interface InputSearchToken {\n  key: string;\n  value: string;\n  negate?: boolean;\n}\n\nexport interface InputSearchFiltersValue {\n  text: string;\n  tokens: InputSearchToken[];\n}\n\nexport interface InputSearchFiltersProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"onSubmit\"> {\n  filters?: InputSearchFilter[];\n  defaultTokens?: InputSearchToken[];\n  defaultText?: string;\n  placeholder?: string;\n  onChange?: (value: InputSearchFiltersValue) => void;\n  onSubmit?: (value: InputSearchFiltersValue) => void;\n  resultCount?: number;\n  defaultOpen?: boolean;\n  embedded?: boolean;\n  accent?: string;\n}\n\nexport const inputSearchDefaultFilters: InputSearchFilter[] = [\n  { key: \"status\", label: \"Status\", values: [\"open\", \"in-progress\", \"in-review\", \"closed\"], color: \"#3fbf7f\" },\n  { key: \"assignee\", label: \"Assignee\", values: [\"maya\", \"jonas\", \"priya\", \"leo\", \"me\"], color: \"#7fb3ff\" },\n  { key: \"label\", label: \"Label\", values: [\"bug\", \"design\", \"billing\", \"onboarding\", \"performance\"], color: \"#f5a524\" },\n  { key: \"priority\", label: \"Priority\", values: [\"urgent\", \"high\", \"medium\", \"low\"], color: \"#ff6b8b\" },\n  { key: \"updated\", label: \"Updated\", values: [\"today\", \"this-week\", \"this-month\"], color: \"#b18cff\" },\n];\n\nconst css = `\n.hb-xg11 {\n  --hb-xg11-c: #2f7bff;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xg11 *, .hb-xg11 *::before, .hb-xg11 *::after { box-sizing: border-box; }\n.hb-xg11-field {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  min-height: 44px;\n  padding: 5px 8px 5px 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  cursor: text;\n  transition: border-color 0.2s ease, box-shadow 0.25s ease;\n}\n.hb-xg11-field:hover { border-color: #333; }\n.hb-xg11-field:focus-within {\n  border-color: var(--hb-xg11-c);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 0 0 4px color-mix(in srgb, var(--hb-xg11-c) 16%, transparent);\n}\n.hb-xg11-lead { width: 15px; height: 15px; flex: none; color: #6f6f6f; }\n.hb-xg11-flow { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: 5px; min-width: 0; }\n.hb-xg11-tok {\n  display: inline-flex;\n  align-items: center;\n  height: 26px;\n  max-width: 100%;\n  border: 1px solid #2a2a2a;\n  border-radius: 8px;\n  background: #151515;\n  font-size: 12px;\n  overflow: hidden;\n  animation: hb-xg11-tok 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);\n  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;\n}\n.hb-xg11-tok[data-armed=\"true\"] { border-color: #ff6b6b; box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.16); transform: translateY(-1px); }\n.hb-xg11-tk {\n  height: 100%;\n  margin: 0;\n  padding: 0 7px 0 8px;\n  border: 0;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  cursor: pointer;\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  white-space: nowrap;\n}\n.hb-xg11-tk:focus-visible, .hb-xg11-tx:focus-visible { outline: 2px solid var(--hb-xg11-c); outline-offset: -2px; }\n.hb-xg11-tk i { font-style: normal; color: #5a5a5a; }\n.hb-xg11-tk b { font-weight: 500; color: var(--hb-xg11-t); }\n.hb-xg11-tok[data-neg=\"true\"] .hb-xg11-tk b { text-decoration: line-through; text-decoration-thickness: 1px; }\n.hb-xg11-tok[data-neg=\"true\"] .hb-xg11-tk i { color: #ff8a8a; }\n.hb-xg11-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hb-xg11-t); box-shadow: 0 0 6px var(--hb-xg11-t); }\n.hb-xg11-tx {\n  display: grid;\n  place-items: center;\n  width: 22px;\n  height: 100%;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-left: 1px solid #242424;\n  background: transparent;\n  color: #6f6f6f;\n  cursor: pointer;\n}\n.hb-xg11-tx:hover { color: #ededed; background: rgba(255, 255, 255, 0.05); }\n.hb-xg11-tx svg { width: 9px; height: 9px; }\n.hb-xg11-in {\n  flex: 1 0 90px;\n  min-width: 90px;\n  height: 28px;\n  margin: 0;\n  padding: 0 2px;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 13.5px;\n  caret-color: var(--hb-xg11-c);\n}\n.hb-xg11-in::placeholder { color: #5a5a5a; }\n.hb-xg11-in[data-syntax=\"true\"] { font-family: var(--font-mono), ui-monospace, monospace; font-size: 12.5px; color: #cfe0ff; }\n.hb-xg11-count { flex: none; padding: 0 4px; font-size: 11.5px; color: #6f6f6f; font-variant-numeric: tabular-nums; white-space: nowrap; }\n.hb-xg11-count b { font-weight: 600; color: #ededed; }\n.hb-xg11-kbd {\n  display: inline-grid;\n  place-items: center;\n  height: 20px;\n  padding: 0 6px;\n  flex: none;\n  border: 1px solid #2a2a2a;\n  border-bottom-width: 2px;\n  border-radius: 5px;\n  font-size: 10.5px;\n  color: #8f8f8f;\n}\n.hb-xg11-pop {\n  position: absolute;\n  z-index: 30;\n  left: 0;\n  right: 0;\n  top: calc(100% + 6px);\n  padding: 5px;\n  border: 1px solid #2a2a2a;\n  border-radius: 13px;\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  animation: hb-xg11-in 0.2s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-xg11[data-embedded=\"true\"] .hb-xg11-pop { position: relative; top: auto; margin-top: 6px; animation: none; }\n.hb-xg11-list { margin: 0; padding: 0; list-style: none; max-height: 240px; overflow-y: auto; }\n.hb-xg11-hd { display: flex; justify-content: space-between; padding: 5px 8px 4px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #6f6f6f; }\n.hb-xg11-hd span:last-child { font-weight: 500; letter-spacing: 0; text-transform: none; }\n.hb-xg11-opt {\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  height: 32px;\n  padding: 0 8px;\n  border-radius: 8px;\n  font-size: 12.5px;\n  color: #d4d4d4;\n  cursor: pointer;\n}\n.hb-xg11-opt[data-active=\"true\"] { background: rgba(255, 255, 255, 0.06); color: #fff; }\n.hb-xg11-opt code { font-family: var(--font-mono), ui-monospace, monospace; font-size: 11.5px; color: var(--hb-xg11-t, #8f8f8f); }\n.hb-xg11-opt span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-xg11-opt small { font-size: 11px; color: #6f6f6f; }\n.hb-xg11-opt mark { background: none; color: #fff; font-weight: 600; }\n.hb-xg11-tip { padding: 6px 8px 3px; border-top: 1px solid #1f1f1f; margin-top: 4px; font-size: 11px; color: #6f6f6f; }\n.hb-xg11-tip code { font-family: var(--font-mono), ui-monospace, monospace; color: #a1a1a1; }\n@keyframes hb-xg11-tok { from { opacity: 0; transform: scale(0.7); } }\n@keyframes hb-xg11-in { from { opacity: 0; transform: translateY(-4px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xg11 *, .hb-xg11-pop { transition: none !important; animation: none !important; }\n}\n`;\n\ntype Suggestion =\n  | { kind: \"key\"; filter: InputSearchFilter }\n  | { kind: \"value\"; filter: InputSearchFilter; value: string }\n  | { kind: \"text\"; text: string };\n\nfunction mark(text: string, q: string) {\n  const i = q ? text.toLowerCase().indexOf(q.toLowerCase()) : -1;\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 InputSearchFilters({\n  filters = inputSearchDefaultFilters,\n  defaultTokens = [],\n  defaultText = \"\",\n  placeholder = \"Search issues or type status:\",\n  onChange,\n  onSubmit,\n  resultCount,\n  defaultOpen = false,\n  embedded = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: InputSearchFiltersProps) {\n  const id = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [tokens, setTokens] = React.useState<InputSearchToken[]>(defaultTokens);\n  const [text, setText] = React.useState(defaultText);\n  const [open, setOpen] = React.useState(defaultOpen);\n  const [active, setActive] = React.useState(0);\n  const [armed, setArmed] = React.useState(false);\n\n  const neg = text.startsWith(\"-\");\n  const body = neg ? text.slice(1) : text;\n  const colon = body.indexOf(\":\");\n  const keyPart = colon >= 0 ? body.slice(0, colon).toLowerCase() : \"\";\n  const valPart = colon >= 0 ? body.slice(colon + 1).toLowerCase() : \"\";\n  const keyFilter = colon >= 0 ? filters.find((f) => f.key === keyPart) : undefined;\n\n  let mode: \"keys\" | \"values\" = \"keys\";\n  let suggestions: Suggestion[] = [];\n  if (keyFilter) {\n    mode = \"values\";\n    suggestions = keyFilter.values\n      .filter((v) => v.includes(valPart) && !tokens.some((t) => t.key === keyFilter.key && t.value === v))\n      .map((v) => ({ kind: \"value\" as const, filter: keyFilter, value: v }));\n  } else {\n    const q = body.trim().toLowerCase();\n    suggestions = filters\n      .filter((f) => !q || f.key.includes(q) || f.label.toLowerCase().includes(q))\n      .map((f) => ({ kind: \"key\" as const, filter: f }));\n    if (q && colon < 0) suggestions.push({ kind: \"text\", text: body.trim() });\n  }\n\n  function emit(t: InputSearchToken[], s: string) {\n    onChange?.({ text: s.trim(), tokens: t });\n  }\n\n  function addToken(tok: InputSearchToken) {\n    const next = [...tokens.filter((t) => !(t.key === tok.key && t.value === tok.value)), tok];\n    setTokens(next);\n    setText(\"\");\n    setActive(0);\n    emit(next, \"\");\n  }\n\n  function apply(s: Suggestion | undefined) {\n    if (!s) return;\n    if (s.kind === \"key\") {\n      setText(`${neg ? \"-\" : \"\"}${s.filter.key}:`);\n      setActive(0);\n      inputRef.current?.focus();\n    } else if (s.kind === \"value\") {\n      addToken({ key: s.filter.key, value: s.value, negate: neg || undefined });\n    } else {\n      setOpen(false);\n      onSubmit?.({ text: s.text, tokens });\n    }\n  }\n\n  function removeAt(i: number) {\n    const next = tokens.filter((_, k) => k !== i);\n    setTokens(next);\n    setArmed(false);\n    emit(next, text);\n    inputRef.current?.focus();\n  }\n\n  function edit(i: number) {\n    const t = tokens[i];\n    const next = tokens.filter((_, k) => k !== i);\n    setTokens(next);\n    setText(`${t.negate ? \"-\" : \"\"}${t.key}:${t.value}`);\n    setOpen(true);\n    emit(next, \"\");\n    requestAnimationFrame(() => inputRef.current?.focus());\n  }\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  React.useEffect(() => {\n    function key(e: KeyboardEvent) {\n      if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"k\") {\n        e.preventDefault();\n        inputRef.current?.focus();\n        setOpen(true);\n      }\n    }\n    window.addEventListener(\"keydown\", key);\n    return () => window.removeEventListener(\"keydown\", key);\n  }, []);\n\n  function onKey(e: React.KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      setOpen(true);\n      setActive((a) => (suggestions.length ? (a + 1) % suggestions.length : 0));\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setActive((a) => (suggestions.length ? (a - 1 + suggestions.length) % suggestions.length : 0));\n    } else if (e.key === \"Enter\") {\n      e.preventDefault();\n      if (open && suggestions[active] && (text || mode === \"values\")) apply(suggestions[active]);\n      else {\n        setOpen(false);\n        onSubmit?.({ text: text.trim(), tokens });\n      }\n    } else if (e.key === \"Tab\" && open && text && suggestions[active] && suggestions[active].kind !== \"text\") {\n      e.preventDefault();\n      apply(suggestions[active]);\n    } else if (e.key === \"Backspace\" && text === \"\" && tokens.length) {\n      e.preventDefault();\n      if (armed) removeAt(tokens.length - 1);\n      else setArmed(true);\n    } else if (e.key === \"Escape\") {\n      if (open) setOpen(false);\n      else if (text) setText(\"\");\n    } else {\n      setArmed(false);\n    }\n  }\n\n  function onInput(e: React.ChangeEvent<HTMLInputElement>) {\n    const v = e.target.value;\n    setArmed(false);\n    setOpen(true);\n    setActive(0);\n    const m = /^(-?)([a-z]+):([\\w-]+)\\s$/i.exec(v);\n    if (m) {\n      const f = filters.find((x) => x.key === m[2].toLowerCase());\n      const val = f?.values.find((x) => x === m[3].toLowerCase());\n      if (f && val) {\n        addToken({ key: f.key, value: val, negate: m[1] === \"-\" || undefined });\n        return;\n      }\n    }\n    setText(v);\n    emit(tokens, v);\n  }\n\n  const colorOf = (key: string) => filters.find((f) => f.key === key)?.color ?? accent;\n  const vars = { \"--hb-xg11-c\": accent, ...style } as React.CSSProperties;\n  const listId = `${id}-list`;\n  const syntax = colon >= 0 && !!keyFilter;\n\n  return (\n    <div ref={rootRef} className={`hb-xg11 ${className}`} style={vars} data-embedded={embedded} {...rest}>\n      <style href=\"hb-input-search-filters\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xg11-field\" onClick={(e) => e.target === e.currentTarget && inputRef.current?.focus()}>\n        <svg className=\"hb-xg11-lead\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" aria-hidden=\"true\">\n          <circle cx=\"7\" cy=\"7\" r=\"4.6\" />\n          <path d=\"M10.5 10.5L14 14\" strokeLinecap=\"round\" />\n        </svg>\n        <div className=\"hb-xg11-flow\">\n          {tokens.map((t, i) => (\n            <span\n              key={`${t.key}:${t.value}`}\n              className=\"hb-xg11-tok\"\n              data-armed={armed && i === tokens.length - 1}\n              data-neg={!!t.negate}\n              style={{ \"--hb-xg11-t\": colorOf(t.key) } as React.CSSProperties}\n            >\n              <button type=\"button\" className=\"hb-xg11-tk\" onClick={() => edit(i)} aria-label={`Edit filter ${t.key} ${t.negate ? \"is not\" : \"is\"} ${t.value}`}>\n                <span className=\"hb-xg11-dot\" aria-hidden=\"true\" />\n                {t.key}\n                <i>{t.negate ? \"≠\" : \"=\"}</i>\n                <b>{t.value}</b>\n              </button>\n              <button type=\"button\" className=\"hb-xg11-tx\" aria-label={`Remove filter ${t.key} ${t.value}`} onClick={() => removeAt(i)}>\n                <svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" aria-hidden=\"true\">\n                  <path d=\"M2.5 2.5l5 5M7.5 2.5l-5 5\" strokeLinecap=\"round\" />\n                </svg>\n              </button>\n            </span>\n          ))}\n          <input\n            ref={inputRef}\n            className=\"hb-xg11-in\"\n            data-syntax={syntax}\n            role=\"combobox\"\n            aria-label=\"Search with filters\"\n            aria-expanded={open}\n            aria-controls={listId}\n            aria-autocomplete=\"list\"\n            aria-activedescendant={open && suggestions[active] ? `${id}-o-${active}` : undefined}\n            autoComplete=\"off\"\n            spellCheck={false}\n            placeholder={tokens.length ? \"Add filter or text\" : placeholder}\n            value={text}\n            onChange={onInput}\n            onKeyDown={onKey}\n            onFocus={() => setOpen(true)}\n            onBlur={() => setArmed(false)}\n          />\n        </div>\n        {resultCount !== undefined && (\n          <span className=\"hb-xg11-count\" aria-live=\"polite\">\n            <b>{resultCount.toLocaleString(\"en-US\")}</b> results\n          </span>\n        )}\n        <kbd className=\"hb-xg11-kbd\" aria-hidden=\"true\">\n          ⌘K\n        </kbd>\n      </div>\n      {open && suggestions.length > 0 && (\n        <div className=\"hb-xg11-pop\">\n          <div className=\"hb-xg11-hd\">\n            <span>{mode === \"values\" && keyFilter ? keyFilter.label : \"Filter by\"}</span>\n            <span>{mode === \"values\" ? (neg ? \"excluding\" : \"matching\") : \"Tab to complete\"}</span>\n          </div>\n          <ul className=\"hb-xg11-list\" role=\"listbox\" id={listId} aria-label=\"Suggestions\">\n            {suggestions.map((s, i) => (\n              <li\n                key={s.kind === \"value\" ? `v-${s.value}` : s.kind === \"key\" ? `k-${s.filter.key}` : \"t\"}\n                id={`${id}-o-${i}`}\n                role=\"option\"\n                aria-selected={i === active}\n                data-active={i === active}\n                className=\"hb-xg11-opt\"\n                style={s.kind !== \"text\" ? ({ \"--hb-xg11-t\": s.filter.color ?? accent } as React.CSSProperties) : undefined}\n                onPointerEnter={() => setActive(i)}\n                onPointerDown={(e) => e.preventDefault()}\n                onClick={() => apply(s)}\n              >\n                {s.kind === \"key\" && (\n                  <>\n                    <code>{s.filter.key}:</code>\n                    <span>{mark(s.filter.label, body.trim())}</span>\n                    <small>{s.filter.values.length} values</small>\n                  </>\n                )}\n                {s.kind === \"value\" && (\n                  <>\n                    <span className=\"hb-xg11-dot\" aria-hidden=\"true\" style={{ flex: \"none\" }} />\n                    <span>{mark(s.value, valPart)}</span>\n                    <small>{neg ? \"is not\" : \"is\"}</small>\n                  </>\n                )}\n                {s.kind === \"text\" && (\n                  <>\n                    <code>“”</code>\n                    <span>\n                      Search for <mark>{s.text}</mark>\n                    </span>\n                    <small>Enter</small>\n                  </>\n                )}\n              </li>\n            ))}\n          </ul>\n          <div className=\"hb-xg11-tip\">\n            Prefix with <code>-</code> to exclude, like <code>-status:closed</code>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}