# Product Filters

> Faceted filters for a shop listing. Hand it your products and it counts every facet live: categories with counts, a price range over a histogram with typed min and max, color swatches, a size grid that strikes sizes nothing matches, a rating floor and an in-stock switch. Applied filters gather as chips, and below 1024px it becomes a bottom sheet ending in "Show 12 results". Exports filterProducts.

- Slug: `product-filters`
- Category: [Commerce](https://www.assembli.design/category/commerce.md)
- Type: component
- Tags: filters, faceted-search, ecommerce, product-listing, price-range, histogram, swatches, drawer
- npm dependencies: @base-ui/react, lucide-react, motion
- shadcn/ui dependencies: none
- Live preview: https://www.assembli.design/preview/product-filters
- Page: https://www.assembli.design/components/product-filters

![Product Filters preview](https://www.assembli.design/thumbnails/product-filters-light.png)

## Props

Other props pass through to the root element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `categories` | `FacetOption[]` |  |  |
| `colors` | `ColorOption[]` |  |  |
| `sizes` | `FacetOption[]` |  |  |
| `ratings` | `number[] \| false` | `[4, 3, 2]` | Rating floors to offer. `false` hides the facet. |
| `stockFilter` | `boolean` | `true` | Shows the "In stock only" switch. |
| `products` (required) | `T[]` |  |  |
| `value` | `ProductFilterValue` |  |  |
| `defaultValue` | `ProductFilterValue` | `EMPTY_PRODUCT_FILTERS` |  |
| `onValueChange` | `(value: ProductFilterValue) => void` |  |  |
| `defaultOpen` | `FacetKey[]` |  | Facets open at first. Defaults to all. |
| `priceStep` | `number` | `5` | Rounds the price range to this step. |
| `mode` | `"auto" \| "panel" \| "sheet"` | `"auto"` | `auto` shows the panel from 1024px and a Filters button that opens a bottom sheet below that. |
| `container` | `HTMLElement \| React.RefObject<HTMLElement \| null> \| null` |  | Mount the sheet inside this element instead of `<body>` (a preview frame, a pane). |
| `currency` | `string` | `"USD"` |  |
| `locale` | `string` | `"en-US"` |  |
| `title` | `React.ReactNode` | `"Filters"` |  |

## Install

One-time setup (needs a subscription):

1. Add the registry to the project's `components.json`: `{"@assembli":{"url":"https://www.assembli.design/r/{name}.json","headers":{"Authorization":"Bearer ${ASSEMBLI_API_KEY}"}}}` (merge into `"registries"`).
2. Put an API key from https://www.assembli.design/account in `.env.local` as `ASSEMBLI_API_KEY=asm_…`.

Then install with the shadcn CLI (writes `components/product-filters/product-filters.tsx` and installs dependencies):

```bash
npx shadcn@latest add @assembli/product-filters
```

Registry item JSON: https://www.assembli.design/r/product-filters.json (send `Authorization: Bearer <api key>`)

## Code

> Component source needs an Assembli subscription ($12/month or $96/year) and an API key sent as `Authorization: Bearer <key>`. To get one without copying anything, POST https://www.assembli.design/api/agent/login (or call the MCP tool connect_account), show the user the link it returns, and poll https://www.assembli.design/api/agent/token for the key. Or subscribe at https://www.assembli.design/pricing and create a key at https://www.assembli.design/account.
