{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search-winnow",
  "title": "Search Winnow",
  "description": "Search input that winnows its list like grain from chaff: non-matching rows tumble aside with a slight rotation and fade, then their slot collapses so survivors settle together. Clearing the query lets the chaff drift back in. Full combobox keyboard pattern with a live match counter.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/search-winnow/component.tsx",
      "content": "\"use client\";\n\nimport { useId, useMemo, useRef, useState } from \"react\";\n\n// Search input that winnows its list like grain from chaff: as the query\n// narrows, non-matching rows lose their weight — drifting aside with a slight\n// tumble and fading — then their slot collapses so the survivors settle\n// together. Matches keep full ink with the matched span emphasized. Two-phase\n// exit (drift, then collapse) is pure CSS: an outer grid-rows 1fr->0fr\n// collapse delayed behind the inner drift. Combobox keyboard pattern:\n// ArrowUp/Down roves an active option, Enter selects, Escape clears.\n\nexport interface ChaffWinnowItem {\n  id: string;\n  label: string;\n  hint?: string;\n}\n\nexport interface ChaffWinnowProps {\n  /** the searchable items */\n  items: ChaffWinnowItem[];\n  /** input placeholder text */\n  placeholder?: string;\n  /** accessible name for the search input */\n  label?: string;\n  /** called with the chosen item when one is selected */\n  onSelect?: (item: ChaffWinnowItem) => void;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nfunction Highlight({ text, query }: { text: string; query: string }) {\n  if (!query) return <>{text}</>;\n  const i = text.toLowerCase().indexOf(query.toLowerCase());\n  if (i === -1) return <>{text}</>;\n  return (\n    <>\n      {text.slice(0, i)}\n      <mark className=\"rounded-[3px] bg-border/80 px-0.5 font-medium text-foreground\">\n        {text.slice(i, i + query.length)}\n      </mark>\n      {text.slice(i + query.length)}\n    </>\n  );\n}\n\nexport function ChaffWinnow({\n  items,\n  placeholder = \"Search…\",\n  label = \"Search\",\n  onSelect,\n  className = \"\",\n}: ChaffWinnowProps) {\n  const [query, setQuery] = useState(\"\");\n  const [active, setActive] = useState(-1);\n  const listId = useId();\n  const reduced = useRef(\n    typeof window !== \"undefined\" &&\n      window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n  ).current;\n\n  const q = query.trim();\n  const matched = useMemo(() => {\n    if (!q) return new Set(items.map((it) => it.id));\n    const lq = q.toLowerCase();\n    return new Set(\n      items\n        .filter(\n          (it) =>\n            it.label.toLowerCase().includes(lq) || it.hint?.toLowerCase().includes(lq),\n        )\n        .map((it) => it.id),\n    );\n  }, [items, q]);\n\n  const visible = items.filter((it) => matched.has(it.id));\n  const clampedActive = Math.min(active, visible.length - 1);\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      setActive((a) => Math.min((a < 0 ? -1 : Math.min(a, visible.length - 1)) + 1, visible.length - 1));\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setActive((a) => Math.max(Math.min(a, visible.length - 1) - 1, 0));\n    } else if (e.key === \"Enter\" && clampedActive >= 0 && visible[clampedActive]) {\n      e.preventDefault();\n      onSelect?.(visible[clampedActive]);\n    } else if (e.key === \"Escape\") {\n      setQuery(\"\");\n      setActive(-1);\n    }\n  };\n\n  return (\n    <div className={[\"w-full rounded-md border border-border bg-surface\", className].join(\" \")}>\n      <div className=\"flex items-center gap-2.5 border-b border-border px-4 py-3\">\n        <svg aria-hidden width={15} height={15} viewBox=\"0 0 15 15\" className=\"shrink-0 text-ns-muted\">\n          <circle cx={6.5} cy={6.5} r={4.5} fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} />\n          <path d=\"M 10 10 L 13.5 13.5\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" />\n        </svg>\n        <input\n          type=\"text\"\n          role=\"combobox\"\n          aria-label={label}\n          aria-expanded={visible.length > 0}\n          aria-controls={listId}\n          aria-activedescendant={\n            clampedActive >= 0 && visible[clampedActive]\n              ? `${listId}-${visible[clampedActive].id}`\n              : undefined\n          }\n          aria-autocomplete=\"list\"\n          value={query}\n          placeholder={placeholder}\n          onChange={(e) => {\n            setQuery(e.target.value);\n            setActive(-1);\n          }}\n          onKeyDown={onKeyDown}\n          className=\"w-full bg-transparent text-sm text-foreground outline-none placeholder:text-ns-muted\"\n        />\n        <span aria-live=\"polite\" className=\"shrink-0 font-mono text-[11px] tabular-nums text-ns-muted\">\n          {visible.length}/{items.length}\n        </span>\n      </div>\n      <ul id={listId} role=\"listbox\" aria-label={label} className=\"py-1\">\n        {items.map((it) => {\n          const out = !matched.has(it.id);\n          const vi = visible.findIndex((v) => v.id === it.id);\n          const isActive = vi >= 0 && vi === clampedActive;\n          return (\n            // outer: slot collapse, delayed behind the inner drift so the\n            // row visibly blows aside before its space closes\n            <li\n              key={it.id}\n              role={out ? \"presentation\" : \"option\"}\n              id={out ? undefined : `${listId}-${it.id}`}\n              aria-selected={out ? undefined : isActive}\n              className=\"grid\"\n              style={{\n                gridTemplateRows: out ? \"0fr\" : \"1fr\",\n                transition: reduced\n                  ? \"none\"\n                  : `grid-template-rows 280ms cubic-bezier(0.22, 1, 0.36, 1) ${out ? \"140ms\" : \"0ms\"}`,\n              }}\n            >\n              <div className=\"min-h-0 overflow-hidden\">\n                <div\n                  onClick={out ? undefined : () => onSelect?.(it)}\n                  className={[\n                    \"mx-1 flex items-baseline gap-3 rounded-sm px-3 py-2\",\n                    out ? \"\" : \"cursor-pointer\",\n                    isActive ? \"bg-border/60\" : out ? \"\" : \"hover:bg-border/40\",\n                    \"transition-[background-color] duration-150\",\n                  ].join(\" \")}\n                  style={{\n                    opacity: out ? 0 : 1,\n                    transform: out\n                      ? \"translateX(14px) rotate(1.5deg)\"\n                      : \"translateX(0) rotate(0deg)\",\n                    transition: reduced\n                      ? \"opacity 0ms\"\n                      : `opacity 220ms ease, transform 260ms cubic-bezier(0.55, 0, 0.55, 0.2), background-color 150ms ease`,\n                  }}\n                >\n                  <span className=\"min-w-0 flex-1 truncate text-sm text-foreground\">\n                    <Highlight text={it.label} query={q} />\n                  </span>\n                  {it.hint ? (\n                    <span className=\"shrink-0 font-mono text-[11px] text-ns-muted\">\n                      <Highlight text={it.hint} query={q} />\n                    </span>\n                  ) : null}\n                </div>\n              </div>\n            </li>\n          );\n        })}\n        <li\n          role=\"presentation\"\n          className=\"grid\"\n          style={{\n            gridTemplateRows: visible.length === 0 ? \"1fr\" : \"0fr\",\n            transition: reduced\n              ? \"none\"\n              : \"grid-template-rows 280ms cubic-bezier(0.22, 1, 0.36, 1) 140ms\",\n          }}\n        >\n          <div className=\"min-h-0 overflow-hidden\">\n            <p className=\"px-4 py-2 font-mono text-[11px] text-ns-muted\">\n              nothing survives “{q}”\n            </p>\n          </div>\n        </li>\n      </ul>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/search-winnow.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-surface": "var(--surface)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "surface": "#fafafa"
    },
    "dark": {
      "ns-muted": "#8f8f8f",
      "surface": "#171717"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "search",
      "filter",
      "combobox",
      "input",
      "form",
      "micro-interaction"
    ],
    "instruction": "Build a filtering search list where rejection is a physical winnowing motion, in two phases driven purely by CSS. STRUCTURE: bordered bg-surface card; header row with an inline SVG magnifier (stroke=currentColor on text-ns-muted), a borderless text input, and an aria-live 'visible/total' mono counter; below, a <ul role=listbox>. Each item renders inside a two-layer exit shell: an outer <li class=grid> whose gridTemplateRows transitions 1fr -> 0fr (280ms ease-out, DELAYED 140ms) and an inner div (min-h-0 overflow-hidden wrapper) that drifts translateX(14px) rotate(1.5deg) and fades over ~240ms with an ease-in curve. The delay ordering is the mechanism: the row visibly tumbles aside first, THEN its slot closes and the survivors settle up; re-matching reverses both with zero delay so returns feel immediate. FILTERING: case-insensitive substring over label and hint; the matched span in both is wrapped in a <mark> tinted bg-border/80 with font-medium (token-only highlight, no accent — accent is reserved for interaction states). A trailing 'nothing survives \\\"query\\\"' row collapses in via the same grid mechanism when zero match. KEYBOARD: the input is role=combobox with aria-expanded, aria-controls, aria-autocomplete=list and aria-activedescendant pointing at the active option; ArrowDown/ArrowUp rove the active row (clamped to the visible set), Enter fires onSelect with the active item, Escape clears the query; filtered-out rows drop their option role and id so the accessibility tree only contains real matches. Active row tints bg-border/60, hover bg-border/40. INK: tokens only — surface, border, muted, foreground; both themes render. Reduced motion: all transitions none, rows appear/disappear instantly. No canvas, no timers, no observers, no JS animation — state is the query string and active index, everything kinetic is CSS transitions."
  },
  "type": "registry:ui"
}