{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "product-filters-sidebar",
  "title": "Product Filters Sidebar",
  "description": "A collection page with a filter sidebar: collapsible groups for category with live counts, a dual-handle price range over a price histogram, color swatches, minimum rating, in-stock and on-sale switches, removable active-filter chips, sorting, a result count and a grid that updates instantly (a toggle panel on phones).",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/product-filters-sidebar/product-filters-sidebar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, 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\nexport interface FilterProduct {\n  id: string;\n  title: string;\n  category: string;\n  price: number;\n  compareAtPrice?: number;\n  rating: number;\n  colors: string[];\n  inStock: boolean;\n  image?: string;\n}\n\nexport interface ProductFiltersSidebarProps {\n  products?: FilterProduct[];\n  currency?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", title: \"#FFFFFF\", muted: \"rgba(255,255,255,0.45)\", body: \"rgba(255,255,255,0.62)\", line: \"rgba(255,255,255,0.12)\", card: \"#141414\", photo: \"#F1F1F1\", chip: \"rgba(255,255,255,0.08)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", sale: \"#FF6B57\", track: \"rgba(255,255,255,0.12)\", ring: \"rgba(255,255,255,0.5)\" },\n  light: { bg: \"#FFFFFF\", title: \"#111111\", muted: \"rgba(0,0,0,0.45)\", body: \"rgba(0,0,0,0.62)\", line: \"rgba(0,0,0,0.1)\", card: \"#F7F7F6\", photo: \"#F1F1F1\", chip: \"rgba(0,0,0,0.06)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", sale: \"#D9480F\", track: \"rgba(0,0,0,0.1)\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst COLOR_HEX: Record<string, string> = { Black: \"#1A1A1A\", White: \"#F4F4F2\", Silver: \"#C9CBCF\", Olive: \"#5E6B4E\", Stone: \"#D8D3CB\", Navy: \"#26324F\" };\nconst F = (id: string, title: string, category: string, price: number, rating: number, colors: string[], inStock: boolean, image: string, compareAtPrice?: number): FilterProduct => ({ id, title, category, price, rating, colors, inStock, image, compareAtPrice });\nconst PRODUCTS: FilterProduct[] = [\n  F(\"p1\", \"Wireless Earbuds\", \"Audio\", 129, 4.8, [\"Black\", \"Stone\"], true, \"/demo/wireless-earbuds.webp\"),\n  F(\"p2\", \"Noise Cancelling Headphones\", \"Audio\", 199, 4.7, [\"Black\", \"Silver\"], true, \"/demo/blocks/product-list/headphones.webp\"),\n  F(\"p3\", \"Minimal Watch\", \"Accessories\", 79, 4.9, [\"Black\", \"Silver\", \"Olive\"], true, \"/demo/minimal-watch.webp\", 129),\n  F(\"p4\", \"Running Shoes\", \"Sport\", 99, 4.6, [\"White\", \"Black\"], true, \"/demo/running-shoes.webp\", 149),\n  F(\"p5\", \"Insulated Water Bottle\", \"Sport\", 39, 4.8, [\"Black\", \"Olive\", \"Navy\"], true, \"/demo/insulated-water-bottle.webp\"),\n  F(\"p6\", \"Laptop Stand\", \"Desk\", 49, 4.8, [\"Black\", \"Silver\"], true, \"/demo/laptop-stand.webp\", 89),\n  F(\"p7\", \"LED Desk Lamp\", \"Desk\", 59, 4.5, [\"Black\", \"White\"], false, \"/demo/blocks/product-list/lamp.webp\"),\n  F(\"p8\", \"Premium Notebook\", \"Desk\", 24, 4.8, [\"Black\", \"Navy\"], true, \"/demo/notebook.webp\"),\n  F(\"p9\", \"Everyday Backpack\", \"Accessories\", 89, 4.7, [\"Black\", \"Olive\"], true, \"/demo/blocks/product-list/backpack.webp\"),\n  F(\"p10\", \"Studio Earbuds\", \"Audio\", 89, 4.3, [\"White\"], false, \"/demo/wireless-earbuds.webp\", 109),\n  F(\"p11\", \"Trail Bottle 1L\", \"Sport\", 45, 4.4, [\"Olive\"], true, \"/demo/insulated-water-bottle.webp\"),\n  F(\"p12\", \"Field Watch\", \"Accessories\", 119, 4.6, [\"Olive\", \"Black\"], true, \"/demo/minimal-watch.webp\"),\n];\nconst SORTS = { featured: \"Featured\", \"price-asc\": \"Price: low to high\", \"price-desc\": \"Price: high to low\", rating: \"Top rated\" } as const;\n\nexport function ProductFiltersSidebar({ products = PRODUCTS, currency = \"$\", theme = \"dark\", className }: ProductFiltersSidebarProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const maxP = Math.ceil(Math.max(...products.map((x) => x.price)) / 10) * 10;\n  const [cats, setCats] = React.useState<string[]>([]);\n  const [colors, setColors] = React.useState<string[]>([]);\n  const [range, setRange] = React.useState<[number, number]>([0, maxP]);\n  const [minRating, setMinRating] = React.useState(0);\n  const [stockOnly, setStockOnly] = React.useState(false);\n  const [saleOnly, setSaleOnly] = React.useState(false);\n  const [sort, setSort] = React.useState<keyof typeof SORTS>(\"featured\");\n  const [openGroups, setOpenGroups] = React.useState<Record<string, boolean>>({ category: true, price: true, color: true, rating: true });\n  const [mobileOpen, setMobileOpen] = React.useState(false);\n\n  const categories = Array.from(new Set(products.map((x) => x.category)));\n  const allColors = Array.from(new Set(products.flatMap((x) => x.colors)));\n  const matches = (x: FilterProduct, skip?: string) =>\n    (skip === \"cat\" || !cats.length || cats.includes(x.category)) &&\n    (skip === \"color\" || !colors.length || x.colors.some((c) => colors.includes(c))) &&\n    x.price >= range[0] &&\n    x.price <= range[1] &&\n    x.rating >= minRating &&\n    (!stockOnly || x.inStock) &&\n    (!saleOnly || !!x.compareAtPrice);\n  const results = products\n    .filter((x) => matches(x))\n    .sort((a, b) => (sort === \"price-asc\" ? a.price - b.price : sort === \"price-desc\" ? b.price - a.price : sort === \"rating\" ? b.rating - a.rating : 0));\n  const buckets = Array.from({ length: 10 }, (_, i) => products.filter((x) => x.price >= (i * maxP) / 10 && x.price < ((i + 1) * maxP) / 10 + (i === 9 ? 1 : 0)).length);\n  const maxBucket = Math.max(...buckets, 1);\n\n  const chips = [\n    ...cats.map((c) => ({ key: `c-${c}`, label: c, clear: () => setCats((s) => s.filter((x) => x !== c)) })),\n    ...colors.map((c) => ({ key: `k-${c}`, label: c, clear: () => setColors((s) => s.filter((x) => x !== c)) })),\n    ...(range[0] > 0 || range[1] < maxP ? [{ key: \"price\", label: `${currency}${range[0]}–${currency}${range[1]}`, clear: () => setRange([0, maxP]) }] : []),\n    ...(minRating ? [{ key: \"rating\", label: `${minRating}★ & up`, clear: () => setMinRating(0) }] : []),\n    ...(stockOnly ? [{ key: \"stock\", label: \"In stock\", clear: () => setStockOnly(false) }] : []),\n    ...(saleOnly ? [{ key: \"sale\", label: \"On sale\", clear: () => setSaleOnly(false) }] : []),\n  ];\n  const clearAll = () => {\n    setCats([]);\n    setColors([]);\n    setRange([0, maxP]);\n    setMinRating(0);\n    setStockOnly(false);\n    setSaleOnly(false);\n  };\n  const toggle = (list: string[], set: (v: string[]) => void, v: string) => set(list.includes(v) ? list.filter((x) => x !== v) : [...list, v]);\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const group = (id: string, title: string, children: React.ReactNode) => (\n    <div className=\"border-b py-4\" style={{ borderColor: p.line }}>\n      <button type=\"button\" onClick={() => setOpenGroups((g) => ({ ...g, [id]: !g[id] }))} aria-expanded={!!openGroups[id]} aria-controls={`${uid}-${id}`} className={cn(\"flex w-full cursor-pointer items-center justify-between border-0 bg-transparent p-0 text-[13.5px] font-semibold\", focus)} style={{ color: p.title, ...ring }}>\n        {title}\n        <motion.svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" animate={{ rotate: openGroups[id] ? 180 : 0 }} aria-hidden=\"true\">\n          <path d=\"m6 9 6 6 6-6\" />\n        </motion.svg>\n      </button>\n      <AnimatePresence initial={false}>\n        {openGroups[id] && (\n          <motion.div key=\"b\" id={`${uid}-${id}`} initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} transition={{ duration: 0.22 }} className=\"overflow-hidden\">\n            <div className=\"pt-3\">{children}</div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n\n  const sidebar = (\n    <div>\n      {group(\n        \"category\",\n        \"Category\",\n        <ul className=\"m-0 flex list-none flex-col gap-0.5 p-0\">\n          {categories.map((c) => {\n            const n = products.filter((x) => x.category === c && matches(x, \"cat\")).length;\n            return (\n              <li key={c}>\n                <label className=\"flex cursor-pointer items-center gap-2.5 rounded-lg px-1 py-1.5 text-[13.5px] has-[:focus-visible]:ring-2\" style={{ color: n ? p.title : p.muted, ...ring }}>\n                  <input type=\"checkbox\" checked={cats.includes(c)} onChange={() => toggle(cats, setCats, c)} className=\"h-4 w-4 cursor-pointer\" style={{ accentColor: p.title }} />\n                  <span className=\"flex-1\">{c}</span>\n                  <span className=\"text-[12px] tabular-nums\" style={{ color: p.muted }}>\n                    {n}\n                  </span>\n                </label>\n              </li>\n            );\n          })}\n        </ul>,\n      )}\n      {group(\n        \"price\",\n        \"Price\",\n        <div>\n          <div className=\"flex h-12 items-end gap-[3px]\" aria-hidden=\"true\">\n            {buckets.map((b, i) => {\n              const inside = (i * maxP) / 10 >= range[0] - maxP / 10 + 0.01 && ((i + 1) * maxP) / 10 <= range[1] + maxP / 10 - 0.01;\n              return <motion.span key={i} className=\"flex-1 rounded-t-[3px]\" animate={{ height: `${Math.max(6, (b / maxBucket) * 100)}%`, backgroundColor: inside ? p.title : p.track }} transition={{ duration: reduce ? 0 : 0.2 }} />;\n            })}\n          </div>\n          <div className=\"relative mt-1 h-5\">\n            <span className=\"absolute top-1/2 right-0 left-0 h-1 -translate-y-1/2 rounded-full\" style={{ background: p.track }} />\n            <span className=\"absolute top-1/2 h-1 -translate-y-1/2 rounded-full\" style={{ left: `${(range[0] / maxP) * 100}%`, right: `${100 - (range[1] / maxP) * 100}%`, background: p.title }} />\n            {[0, 1].map((k) => (\n              <input\n                key={k}\n                type=\"range\"\n                min={0}\n                max={maxP}\n                step={5}\n                value={range[k]}\n                aria-label={k === 0 ? \"Minimum price\" : \"Maximum price\"}\n                aria-valuetext={`${currency}${range[k]}`}\n                onChange={(e) => {\n                  const v = Number(e.target.value);\n                  setRange((r) => (k === 0 ? [Math.min(v, r[1] - 10), r[1]] : [r[0], Math.max(v, r[0] + 10)]));\n                }}\n                className=\"pf-range pointer-events-none absolute inset-0 h-5 w-full cursor-pointer appearance-none bg-transparent\"\n                style={{ [\"--thumb\" as string]: p.title, [\"--thumb-ring\" as string]: p.bg }}\n              />\n            ))}\n          </div>\n          <div className=\"mt-2 flex justify-between text-[12.5px] tabular-nums\" style={{ color: p.body }}>\n            <span>\n              {currency}\n              {range[0]}\n            </span>\n            <span>\n              {currency}\n              {range[1]}\n            </span>\n          </div>\n        </div>,\n      )}\n      {group(\n        \"color\",\n        \"Color\",\n        <div className=\"flex flex-wrap gap-2\">\n          {allColors.map((c) => {\n            const on = colors.includes(c);\n            return (\n              <button key={c} type=\"button\" onClick={() => toggle(colors, setColors, c)} aria-pressed={on} aria-label={c} title={c} className={cn(\"grid h-8 w-8 cursor-pointer place-items-center rounded-full border-0 p-0\", focus)} style={{ boxShadow: on ? `0 0 0 2px ${p.bg}, 0 0 0 4px ${p.title}` : \"none\", ...ring }}>\n                <span className=\"h-7 w-7 rounded-full border\" style={{ background: COLOR_HEX[c] ?? c, borderColor: p.line }} />\n              </button>\n            );\n          })}\n        </div>,\n      )}\n      {group(\n        \"rating\",\n        \"Rating\",\n        <div role=\"radiogroup\" aria-label=\"Minimum rating\" className=\"flex flex-col gap-0.5\">\n          {[4.5, 4, 0].map((r) => (\n            <label key={r} className=\"flex cursor-pointer items-center gap-2.5 rounded-lg px-1 py-1.5 text-[13.5px] has-[:focus-visible]:ring-2\" style={ring}>\n              <input type=\"radio\" name={`${uid}-rating`} checked={minRating === r} onChange={() => setMinRating(r)} className=\"h-4 w-4 cursor-pointer\" style={{ accentColor: p.title }} />\n              {r ? `${r} ★ & up` : \"Any rating\"}\n            </label>\n          ))}\n        </div>,\n      )}\n      <div className=\"flex flex-col gap-3 py-4\">\n        {[\n          { label: \"In stock only\", on: stockOnly, set: setStockOnly },\n          { label: \"On sale\", on: saleOnly, set: setSaleOnly },\n        ].map((s) => (\n          <div key={s.label} className=\"flex items-center justify-between text-[13.5px]\">\n            <span aria-hidden=\"true\">{s.label}</span>\n            <button type=\"button\" role=\"switch\" aria-checked={s.on} aria-label={s.label} onClick={() => s.set(!s.on)} className={cn(\"relative h-6 w-11 shrink-0 cursor-pointer rounded-full border-0\", focus)} style={{ background: s.on ? p.accent : p.track, ...ring }}>\n              <motion.span className=\"absolute top-0.5 h-5 w-5 rounded-full bg-white shadow\" initial={false} animate={{ left: s.on ? 22 : 2 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 34 }} />\n            </button>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }}>\n      <style>{`.pf-range::-webkit-slider-thumb{pointer-events:auto;-webkit-appearance:none;appearance:none;width:18px;height:18px;border-radius:999px;background:var(--thumb);border:3px solid var(--thumb-ring);box-shadow:0 1px 4px rgba(0,0,0,.4);cursor:grab}.pf-range::-moz-range-thumb{pointer-events:auto;width:14px;height:14px;border-radius:999px;background:var(--thumb);border:3px solid var(--thumb-ring);cursor:grab}.pf-range::-webkit-slider-runnable-track{background:transparent}.pf-range:focus-visible::-webkit-slider-thumb{outline:2px solid var(--thumb);outline-offset:2px}`}</style>\n      <div className=\"mx-auto max-w-6xl px-4 py-10 @[640px]:px-8\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"m-0 text-[28px] font-semibold tracking-[-0.03em] @[640px]:text-[34px]\">All products</h2>\n            <p className=\"m-0 mt-1 text-[13.5px] tabular-nums\" style={{ color: p.muted }} aria-live=\"polite\">\n              {results.length} of {products.length} products\n            </p>\n          </div>\n          <div className=\"flex items-center gap-2\">\n            <button type=\"button\" onClick={() => setMobileOpen((o) => !o)} aria-expanded={mobileOpen} className={cn(\"flex h-10 cursor-pointer items-center gap-2 rounded-full border px-4 text-[13px] font-medium @[860px]:hidden\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title, ...ring }}>\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"M4 6h16M7 12h10M10 18h4\" />\n              </svg>\n              Filters{chips.length ? ` (${chips.length})` : \"\"}\n            </button>\n            <label className=\"sr-only\" htmlFor={`${uid}-sort`}>\n              Sort by\n            </label>\n            <select id={`${uid}-sort`} value={sort} onChange={(e) => setSort(e.target.value as keyof typeof SORTS)} className={cn(\"h-10 cursor-pointer rounded-full border px-4 text-[13px]\", focus)} style={{ borderColor: p.line, background: p.bg, color: p.title, ...ring }}>\n              {Object.entries(SORTS).map(([k, v]) => (\n                <option key={k} value={k}>\n                  {v}\n                </option>\n              ))}\n            </select>\n          </div>\n        </div>\n\n        <div className=\"mt-6 grid grid-cols-1 gap-8 @[860px]:grid-cols-[240px_minmax(0,1fr)]\">\n          <aside aria-label=\"Filters\" className={cn(mobileOpen ? \"block\" : \"hidden\", \"rounded-2xl border px-4 @[860px]:block @[860px]:rounded-none @[860px]:border-0 @[860px]:px-0\")} style={{ borderColor: p.line }}>\n            {sidebar}\n          </aside>\n          <div className=\"min-w-0\">\n            <AnimatePresence initial={false}>\n              {chips.length > 0 && (\n                <motion.div key=\"chips\" initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} className=\"overflow-hidden\">\n                  <div className=\"mb-4 flex flex-wrap items-center gap-2\">\n                    <AnimatePresence initial={false}>\n                      {chips.map((c) => (\n                        <motion.button key={c.key} type=\"button\" onClick={c.clear} initial={reduce ? false : { opacity: 0, scale: 0.8 }} animate={{ opacity: 1, scale: 1 }} exit={reduce ? undefined : { opacity: 0, scale: 0.8 }} aria-label={`Remove filter ${c.label}`} className={cn(\"flex h-8 cursor-pointer items-center gap-1.5 rounded-full border-0 px-3 text-[12.5px]\", focus)} style={{ background: p.chip, color: p.title, ...ring }}>\n                          {c.label}\n                          <span aria-hidden=\"true\" style={{ color: p.muted }}>\n                            ×\n                          </span>\n                        </motion.button>\n                      ))}\n                    </AnimatePresence>\n                    <button type=\"button\" onClick={clearAll} className={cn(\"h-8 cursor-pointer border-0 bg-transparent px-2 text-[12.5px] underline-offset-2 hover:underline\", focus)} style={{ color: p.body, ...ring }}>\n                      Clear all\n                    </button>\n                  </div>\n                </motion.div>\n              )}\n            </AnimatePresence>\n            {results.length ? (\n              <ul className=\"m-0 grid list-none grid-cols-2 gap-x-4 gap-y-6 p-0 @[1000px]:grid-cols-3\">\n                {results.map((x, i) => (\n                  <motion.li key={x.id} initial={reduce ? false : { opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.3, delay: reduce ? 0 : Math.min(i, 8) * 0.03 }} className=\"min-w-0\">\n                    <div className=\"relative aspect-square overflow-hidden rounded-2xl\" style={{ background: p.photo }}>\n                      {/* eslint-disable-next-line @next/next/no-img-element */}\n                      {x.image && <img src={x.image} alt={x.title} className=\"h-full w-full object-cover\" style={{ opacity: x.inStock ? 1 : 0.5 }} />}\n                      {x.compareAtPrice && (\n                        <span className=\"absolute top-2.5 left-2.5 rounded-full px-2 py-0.5 text-[11px] font-semibold text-white\" style={{ background: p.sale }}>\n                          Sale\n                        </span>\n                      )}\n                      {!x.inStock && <span className=\"absolute bottom-2.5 left-2.5 rounded-full bg-white/90 px-2 py-0.5 text-[11px] font-medium text-[#111]\">Sold out</span>}\n                    </div>\n                    <p className=\"m-0 mt-2.5 truncate text-[13.5px] font-medium\">{x.title}</p>\n                    <p className=\"m-0 mt-0.5 flex items-center justify-between text-[13px]\">\n                      <span className=\"tabular-nums\">\n                        {currency}\n                        {x.price}\n                        {x.compareAtPrice && (\n                          <span className=\"ml-1.5 line-through\" style={{ color: p.muted }}>\n                            {currency}\n                            {x.compareAtPrice}\n                          </span>\n                        )}\n                      </span>\n                      <span className=\"flex items-center gap-1 text-[12px]\" style={{ color: p.muted }}>\n                        <span className=\"h-2.5 w-2.5 rounded-full border\" style={{ background: COLOR_HEX[x.colors[0]], borderColor: p.line }} />\n                        {x.colors.length > 1 && `+${x.colors.length - 1}`}\n                      </span>\n                    </p>\n                  </motion.li>\n                ))}\n              </ul>\n            ) : (\n              <div className=\"rounded-2xl border px-6 py-14 text-center\" style={{ borderColor: p.line }}>\n                <p className=\"m-0 text-[15px] font-medium\">No products match these filters</p>\n                <button type=\"button\" onClick={clearAll} className={cn(\"mt-3 h-10 cursor-pointer rounded-full border-0 px-5 text-[13px] font-semibold\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                  Clear all filters\n                </button>\n              </div>\n            )}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default ProductFiltersSidebar;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}