SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

FacetFilters

The filters beside a product listing as one GET form.

Colour
Availability
Price
View code
tsx
<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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
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.

  • FacetFilters
  • FacetFilters.GroupRenders a group as a <details> whose summary row carries the title and a chevron, open unless open is false.
  • FacetFilters.CheckRenders a checkbox row.
  • FacetFilters.ToggleRenders an on/off filter as a switch-styled checkbox that posts 1 while 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.

PropTypeRequiredDescription
actionstringYesThe listing page the filters submit to.
keepRecord<string, string>NoQuery fields the form carries unchanged, such as the search and the sort.
childrenRemixNodeYes
labelsLabelsYes

Also accepts everything in Omit<TagProps<"form">, "children" | "method" | "action">.

FacetFilters.Group

PropTypeRequiredDescription
titleRemixNodeYes
openbooleanNo
childrenRemixNodeYes

FacetFilters.Check

PropTypeRequiredDescription
namestringYes
valuestringYes
labelRemixNodeYes
countnumberYesHow many results this value has with the other filters applied.
checkedbooleanNo
swatchstringNoA colour dot before the label, as any CSS colour or gradient.

FacetFilters.Toggle

PropTypeRequiredDescription
namestringYesThe field that posts 1 while on.
labelRemixNodeYes
countnumberYes
checkedbooleanNo

FacetFilters.Range

PropTypeRequiredDescription
minNamestringYes
maxNamestringYes
minnumber | nullNo
maxnumber | nullNo
labels{ min: string; max: string }YesThe two fields' labels, such as "Min" and "Max".
prefixstringNoA symbol before each figure, such as "$".
bucketsBucket[]No

FacetFilters.Applied

PropTypeRequiredDescription
chipsChip[]Yes
clear{ label: string; href: string }NoA link to the listing with every filter removed.
labelstringYesThe row's accessible name, such as "Applied filters".
@sdxc/ui

Can’t find it? Contact us