Skip to main content
Clever Ops

Collection Filter Bar

A controlled filter-and-sort toolbar for React product grids, aria-pressed Tailwind chips with honest counts, a native sort select, a live results tally and one quiet accent.

Preview & code

Loading Collection Filter Bar preview

Installation

pnpm dlx shadcn@latest add @cleverui/collection-filter-bar

Requires the @cleverui registry in your components.json, a one-off, two-line setup.

Usage

tsx
import { CollectionFilterBar } from '@/components/ui/collection-filter-bar'
Exampletsx
'use client'

import { useMemo, useState } from 'react'
import { CollectionFilterBar } from '@/components/ui/collection-filter-bar'

const FILTERS = [
  { label: 'Waterproof', count: 24 },
  { label: 'Insulated', count: 18 },
  { label: 'Packable', count: 31 },
  { label: 'Recycled shell', count: 12 },
  { label: 'Under $150', count: 47 },
]

const SORT_OPTIONS = [
  'Featured',
  'Newest',
  'Price: low to high',
  'Price: high to low',
]

/** Demo tally keyed by sorted filter labels, consumer owns the filtering math. */
const RESULTS: Record<string, string> = {
  '': '128 styles',
  Waterproof: '24 styles',
  Insulated: '18 styles',
  Packable: '31 styles',
  'Recycled shell': '12 styles',
  'Under $150': '47 styles',
  'Insulated,Waterproof': '9 styles',
  'Packable,Waterproof': '14 styles',
  'Insulated,Packable': '7 styles',
  'Insulated,Packable,Waterproof': '4 styles',
  'Recycled shell,Waterproof': '6 styles',
  'Under $150,Waterproof': '11 styles',
  'Insulated,Under $150': '8 styles',
  'Packable,Under $150': '19 styles',
  'Recycled shell,Under $150': '5 styles',
  'Insulated,Packable,Under $150,Waterproof': '2 styles',
}

export default function CollectionFilterBarDemo() {
  const [selected, setSelected] = useState(['Waterproof', 'Insulated'])
  const [sort, setSort] = useState('Featured')

  const resultsLabel = useMemo(() => {
    const key = [...selected].sort().join(',')
    return RESULTS[key] ?? `${Math.max(2, 128 - selected.length * 11)} styles`
  }, [selected])

  return (
    <div className="mx-auto w-full max-w-5xl px-4 py-10 sm:px-6 sm:py-14">
      <CollectionFilterBar
        filters={FILTERS}
        selected={selected}
        onToggle={(label) => {
          setSelected((prev) =>
            prev.includes(label)
              ? prev.filter((x) => x !== label)
              : [...prev, label]
          )
        }}
        sortOptions={SORT_OPTIONS}
        sortValue={sort}
        onSortChange={setSort}
        resultsLabel={resultsLabel}
        onClearAll={() => setSelected([])}
      />
    </div>
  )
}

API reference

CollectionFilterBar accepts the following props.

PropTypeDefaultDescription
filters*CollectionFilter[]
selected*string[]labels currently applied, fully controlled
onToggle*(label: string) => void
sortOptionsstring[]
sortValuestring
onSortChange(value: string) => void
sortLabelstring'Sort by'sr-only label on the native select
resultsLabelstringPREFORMATTED tally, e.g. "128 styles"
clearLabelstring'Clear all'
onClearAll() => void

…plus everything from Omit<React.HTMLAttributes<HTMLElement>, 'onToggle'>: className, event handlers, aria attributes and the rest pass straight through.

Referenced types

Typestsx
export interface CollectionFilter {
  label: string
  /** honest matching-item tally */
  count?: number
}

Frequently asked questions

How do I install the Collection Filter Bar component?

Register the @cleverui registry in your components.json ("@cleverui": "https://cleverops.com.au/r/{name}.json"), then run `npx shadcn@latest add @cleverui/collection-filter-bar`. The shadcn CLI copies the source into your project, you own the code from that point. You can also copy the source directly from this page.

What dependencies does Collection Filter Bar require?

Collection Filter Bar uses motion and lucide-react on top of React and Tailwind CSS. You don't need to install them manually, the shadcn CLI resolves and installs npm dependencies automatically when you add the component.

Can I theme Collection Filter Bar to match my brand?

Yes. The component is styled entirely with Tailwind utilities over standard design tokens (primary, background, muted, border), so it inherits your existing shadcn/ui theme automatically. Change your CSS variables and the component follows, no source edits needed for palette, radius, or fonts.

Want this built for you?

CleverUI is built by the Clever Ops web team. If you'd rather ship a hand-coded, fast, custom website than assemble one, we build them for Australian businesses every week.

Explore web development services