FacetFilters
The filters beside a product listing as one GET form.
View code
<FacetFilters.Applied label="Applied filters" chips={applied.map((filter) => ({ label: filter.label, href: without(filter) }))} clear={{ label: "Clear all", href: "/shop" }} />
<FacetFilters action="/shop" keep={{ q, sort }} labels={{ apply: "Apply" }}>
<FacetFilters.Group title="Colour">
{colours.map((colour) => (
<FacetFilters.Check name="colour" value={colour.id} label={colour.name} count={colour.count} swatch={colour.hex} checked={selected.has(colour.id)} />
))}
</FacetFilters.Group>
<FacetFilters.Group title="Availability">
<FacetFilters.Toggle name="in_stock" label="In stock" count={inStock} checked={onlyInStock} />
</FacetFilters.Group>
<FacetFilters.Group title="Price">
<FacetFilters.Range minName="min" maxName="max" min={min} max={max} prefix="$" labels={{ min: "Min", max: "Max" }} buckets={buckets} />
</FacetFilters.Group>
</FacetFilters>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { FacetFilters } from "@sdxc/ui/commerce";Renders the form: the kept fields, the groups, then the Apply button, which hides once AutoSubmit takes over submitting.
Composition
The parts the component publishes, each a static property of the host.
FacetFiltersFacetFilters.GroupRenders a group as a<details>whose summary row carries the title and a chevron, open unlessopenis false.FacetFilters.CheckRenders a checkbox row.FacetFilters.ToggleRenders an on/off filter as a switch-styled checkbox that posts1while on.FacetFilters.RangeRenders two number fields side by side, then the bucket links with their counts.FacetFilters.AppliedRenders the applied filters as a row of chips, each a link to the listing without that filter, then a "Clear all" link.
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Required | Description |
|---|---|---|---|
action | string | Yes | The listing page the filters submit to. |
keep | Record<string, string> | No | Query fields the form carries unchanged, such as the search and the sort. |
children | RemixNode | Yes | |
labels | Labels | Yes |
Also accepts everything in Omit<TagProps<"form">, "children" | "method" | "action">.
FacetFilters.Group
| Prop | Type | Required | Description |
|---|---|---|---|
title | RemixNode | Yes | |
open | boolean | No | |
children | RemixNode | Yes |
FacetFilters.Check
| Prop | Type | Required | Description |
|---|---|---|---|
name | string | Yes | |
value | string | Yes | |
label | RemixNode | Yes | |
count | number | Yes | How many results this value has with the other filters applied. |
checked | boolean | No | |
swatch | string | No | A colour dot before the label, as any CSS colour or gradient. |
FacetFilters.Toggle
| Prop | Type | Required | Description |
|---|---|---|---|
name | string | Yes | The field that posts 1 while on. |
label | RemixNode | Yes | |
count | number | Yes | |
checked | boolean | No |
FacetFilters.Range
| Prop | Type | Required | Description |
|---|---|---|---|
minName | string | Yes | |
maxName | string | Yes | |
min | number | null | No | |
max | number | null | No | |
labels | { min: string; max: string } | Yes | The two fields' labels, such as "Min" and "Max". |
prefix | string | No | A symbol before each figure, such as "$". |
buckets | Bucket[] | No |
FacetFilters.Applied
| Prop | Type | Required | Description |
|---|---|---|---|
chips | Chip[] | Yes | |
clear | { label: string; href: string } | No | A link to the listing with every filter removed. |
label | string | Yes | The row's accessible name, such as "Applied filters". |