{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "filter-chips",
  "title": "Filter Chips",
  "description": "A row of pill filters with counts: a check draws in and the chip grows to fit it, neighbours slide over instead of jumping, and a Clear chip appears once anything is on. The demo filters a list of open roles that reflows as you pick.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/filter-chips/filter-chips.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, LayoutGroup, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype Theme = \"dark\" | \"light\";\n\nexport interface FilterChipOption {\n  value: string;\n  label: string;\n  count?: number;\n  icon?: React.ReactNode;\n  disabled?: boolean;\n}\n\nexport interface FilterChipsProps {\n  options: FilterChipOption[];\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n  /** false: picking a chip replaces the previous one. */\n  multiple?: boolean;\n  /** Show a \"Clear\" chip while anything is selected. */\n  clearable?: boolean;\n  size?: \"sm\" | \"md\";\n  label?: string;\n  theme?: Theme;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", faint: \"rgba(245,244,241,0.32)\", border: \"rgba(255,255,255,0.13)\", borderHover: \"rgba(255,255,255,0.26)\", hover: \"rgba(255,255,255,0.06)\", sel: \"#F5F4F1\", onSel: \"#0A0A0A\", panel: \"#0E0E0E\", panelBorder: \"rgba(255,255,255,0.1)\", line: \"rgba(255,255,255,0.06)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", faint: \"rgba(10,10,10,0.32)\", border: \"rgba(10,10,10,0.15)\", borderHover: \"rgba(10,10,10,0.3)\", hover: \"rgba(10,10,10,0.04)\", sel: \"#0A0A0A\", onSel: \"#FFFFFF\", panel: \"#FFFFFF\", panelBorder: \"rgba(10,10,10,0.1)\", line: \"rgba(10,10,10,0.06)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nexport function FilterChips({ options, value, defaultValue = [], onValueChange, multiple = true, clearable = true, size = \"md\", label = \"Filters\", theme = \"dark\", className }: FilterChipsProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(defaultValue);\n  const sel = value ?? internal;\n  const h = size === \"sm\" ? 30 : 34;\n  const font = size === \"sm\" ? 12.5 : 13.5;\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 520, damping: 36 };\n\n  const commit = (next: string[]) => {\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n  const toggle = (v: string) => commit(sel.includes(v) ? sel.filter((x) => x !== v) : multiple ? [...sel, v] : [v]);\n\n  return (\n    <LayoutGroup>\n      <div role=\"group\" aria-label={label} className={cn(\"flex flex-wrap items-center\", className)} style={{ gap: 8, fontFamily: \"Inter, sans-serif\" }}>\n        {options.map((o) => {\n          const on = sel.includes(o.value);\n          return (\n            <motion.button\n              key={o.value}\n              layout=\"position\"\n              type=\"button\"\n              aria-pressed={on}\n              disabled={o.disabled}\n              onClick={() => toggle(o.value)}\n              whileTap={reduce || o.disabled ? undefined : { scale: 0.95 }}\n              transition={spring}\n              className={cn(\"relative flex cursor-pointer items-center rounded-full font-medium whitespace-nowrap outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-40\", !on && \"hover:bg-[var(--fc-hover)] hover:[border-color:var(--fc-border-hover)]\")}\n              style={{\n                height: h,\n                padding: `0 ${size === \"sm\" ? 11 : 13}px`,\n                fontSize: font,\n                color: on ? p.onSel : p.text,\n                background: on ? p.sel : \"transparent\",\n                border: `1px solid ${on ? p.sel : p.border}`,\n                transition: \"background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease\",\n                [\"--fc-hover\" as string]: p.hover,\n                [\"--fc-border-hover\" as string]: p.borderHover,\n                [\"--tw-ring-color\" as string]: p.focus,\n                [\"--tw-ring-offset-color\" as string]: \"transparent\",\n              }}\n            >\n              {/* The check makes room for itself, so the chip grows instead of the text jumping. */}\n              <motion.span className=\"flex items-center overflow-hidden\" initial={false} animate={{ width: on ? font + 5 : 0, opacity: on ? 1 : 0 }} transition={spring} aria-hidden=\"true\">\n                <svg width={font} height={font} viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"shrink-0\">\n                  <motion.path d=\"M2.4 6.3 4.9 8.7 9.6 3.4\" initial={false} animate={{ pathLength: on ? 1 : 0 }} transition={{ duration: reduce ? 0 : 0.22, delay: on && !reduce ? 0.06 : 0 }} />\n                </svg>\n              </motion.span>\n              {o.icon && !on && (\n                <span className=\"flex [&>svg]:h-full [&>svg]:w-full\" style={{ width: font + 1, height: font + 1, marginRight: 6, color: p.muted }}>\n                  {o.icon}\n                </span>\n              )}\n              {o.label}\n              {o.count != null && (\n                <span className=\"tabular-nums\" style={{ marginLeft: 6, fontSize: font - 1.5, color: on ? `color-mix(in srgb, ${p.onSel} 55%, transparent)` : p.faint, transition: \"color 0.18s ease\" }}>\n                  {o.count}\n                </span>\n              )}\n            </motion.button>\n          );\n        })}\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {clearable && sel.length > 0 && (\n            <motion.button\n              key=\"clear\"\n              layout=\"position\"\n              type=\"button\"\n              onClick={() => commit([])}\n              className=\"flex cursor-pointer items-center rounded-full font-medium whitespace-nowrap outline-none hover:text-[var(--fc-text)] focus-visible:ring-2\"\n              style={{ height: h, padding: \"0 10px\", gap: 5, fontSize: font, color: p.muted, [\"--fc-text\" as string]: p.text, [\"--tw-ring-color\" as string]: p.focus }}\n              initial={reduce ? false : { opacity: 0, scale: 0.8 }}\n              animate={{ opacity: 1, scale: 1 }}\n              exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.8 }}\n              transition={spring}\n              aria-label={`Clear ${sel.length} filter${sel.length === 1 ? \"\" : \"s\"}`}\n            >\n              <svg width=\"11\" height=\"11\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"M3 3l6 6M9 3L3 9\" />\n              </svg>\n              Clear\n            </motion.button>\n          )}\n        </AnimatePresence>\n      </div>\n    </LayoutGroup>\n  );\n}\n\n// ——— Demo: filtering a list of open roles ———\n\nconst JOBS = [\n  { title: \"Senior Product Designer\", team: \"Design\", place: \"Remote\", type: \"Full-time\" },\n  { title: \"Frontend Engineer\", team: \"Engineering\", place: \"Remote\", type: \"Full-time\" },\n  { title: \"Brand Designer\", team: \"Design\", place: \"Berlin\", type: \"Contract\" },\n  { title: \"Platform Engineer\", team: \"Engineering\", place: \"Berlin\", type: \"Full-time\" },\n  { title: \"Content Designer\", team: \"Design\", place: \"Remote\", type: \"Contract\" },\n  { title: \"Data Engineer\", team: \"Engineering\", place: \"London\", type: \"Full-time\" },\n  { title: \"Growth Marketer\", team: \"Marketing\", place: \"London\", type: \"Full-time\" },\n];\n\nconst FACETS = [\"Remote\", \"Design\", \"Engineering\", \"Full-time\", \"Contract\"] as const;\nconst tagsOf = (j: (typeof JOBS)[number]) => [j.team, j.place, j.type];\n\nexport function FilterChipsDemo({ theme = \"dark\" }: { theme?: Theme }) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [sel, setSel] = React.useState<string[]>([\"Remote\"]);\n  // Chips in the same facet (Design / Engineering, Full-time / Contract) widen the search; different facets narrow it.\n  const groups = [[\"Design\", \"Engineering\"], [\"Full-time\", \"Contract\"], [\"Remote\"]];\n  const shown = JOBS.filter((j) => groups.every((g) => {\n    const picked = g.filter((x) => sel.includes(x));\n    return picked.length === 0 || picked.some((x) => tagsOf(j).includes(x));\n  }));\n  const countFor = (f: string) => JOBS.filter((j) => tagsOf(j).includes(f)).length;\n\n  return (\n    <div className=\"flex w-full flex-col\" style={{ gap: 14, padding: 18, borderRadius: 18, background: p.panel, border: `1px solid ${p.panelBorder}`, fontFamily: \"Inter, sans-serif\", color: p.text }}>\n      <div className=\"flex items-baseline justify-between\">\n        <span className=\"text-[14.5px] font-semibold\">Open roles</span>\n        <span className=\"text-[12.5px] tabular-nums\" style={{ color: p.muted }} aria-live=\"polite\">\n          {shown.length} of {JOBS.length}\n        </span>\n      </div>\n      <FilterChips theme={theme} label=\"Filter roles\" options={FACETS.map((f) => ({ value: f, label: f, count: countFor(f) }))} value={sel} onValueChange={setSel} />\n      <div className=\"relative flex flex-col overflow-y-auto\" style={{ height: 5 * 52, scrollbarWidth: \"thin\" }}>\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {shown.map((j) => (\n            <motion.div\n              key={j.title}\n              layout\n              className=\"flex shrink-0 items-center justify-between\"\n              style={{ height: 52, borderTop: `1px solid ${p.line}`, gap: 12 }}\n              initial={reduce ? false : { opacity: 0, y: 8 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.97 }}\n              transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 480, damping: 38 }}\n            >\n              <span className=\"flex min-w-0 flex-col\">\n                <span className=\"truncate text-[13.5px] font-medium\">{j.title}</span>\n                <span className=\"truncate text-[12px]\" style={{ color: p.muted }}>\n                  {j.team} · {j.place}\n                </span>\n              </span>\n              <span className=\"shrink-0 text-[11.5px] font-medium\" style={{ padding: \"3px 8px\", borderRadius: 999, border: `1px solid ${p.border}`, color: p.muted }}>\n                {j.type}\n              </span>\n            </motion.div>\n          ))}\n        </AnimatePresence>\n        {shown.length === 0 && (\n          <div className=\"absolute inset-0 flex items-center justify-center text-[13px]\" style={{ color: p.faint }}>\n            No roles match these filters\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default FilterChips;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}