Tally UI

ProductFilterBar

WCPOS v2's always-on product filter chips, with In Stock on by default

Import

import { ProductFilterBar, DEFAULT_PRODUCT_FILTERS } from '@tallyui/components';

Usage

const [filters, setFilters] = useState(DEFAULT_PRODUCT_FILTERS);

<ProductFilterBar
  value={filters}
  onChange={setFilters}
  onTermPress={(chip) => openTermPicker(chip)}
/>

A horizontal row of chips in WCPOS v2's order: In Stock, Featured, On Sale, Category, Tag and Brand. The first three toggle a field of ProductFilters. A term chip with an entry in terms is v2's searchable picker pill; one without calls onTermPress, and a term chip with neither is hidden. DEFAULT_PRODUCT_FILTERS starts with In Stock on, as v2 does. The bar only reports filters; the app or Catalogue (showFilterBar) applies them.

Term picker pills

<ProductFilterBar
  value={filters}
  onChange={setFilters}
  terms={{ tag: { options: tags, value: tagId, onChange: setTagId } }}
/>

The Tag chip opens a searchable list of tags ({ value, label }). A picked tag shows its name and an x that clears it (onChange(undefined)). Pass onSearch to search the app's terms instead of filtering options by label.

Props

PropTypeDefaultDescription
valueProductFiltersrequiredCurrent filters
onChange(next: ProductFilters) => voidrequiredReceives the filters with the tapped chip toggled
chipsreadonly ProductFilterChip[]PRODUCT_FILTER_CHIPSChips to show, in this order
termsPartial<Record<'category' | 'tag' | 'brand', ProductTermFilter>>—Turns those term chips into searchable picker pills
termGroupsreadonly (ProductTermFilter & { id: string; label: string; searchPlaceholder?: string })[]—Extra searchable term pills after the built-in chips, one per group and in this order (e.g. one per Vendure facet)
onTermPress(chip: 'category' | 'tag' | 'brand') => void—Opens the app's term picker for a term chip without terms; such chips are hidden without it
classNamestring—Override container styles

ProductFilters

interface ProductFilters {
  inStock: boolean;
  featured: boolean;
  onSale: boolean;
}

ProductTermFilter

interface ProductTermFilter {
  options: readonly FilterOption[]; // { value: string; label: string }
  value?: string; // the picked term; undefined when none is picked
  onChange: (next: string | undefined) => void;
  onSearch?: (text: string) => void; // search server-side; without it the pill filters options by label
}