Skip to content
Commerce block

Faceted Filter Sidebar

Category, size, colour and price facets as proper fieldsets, with colour swatches that carry their name as well as their hue.

220 lineslucide-reactAdded 8 Aug 2026Updated 2 Sept 2026
  • filters
  • facets
  • sidebar
  • refine
  • shop

What's included

  • components/product-filter-sidebar.tsx
  • Needs lucide-react

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add product-filter-sidebar

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/product-filter-sidebar.tsx
'use client'

/**
 * <ProductFilterSidebar> — faceted filters for a collection page.
 *
 * Each facet group is a <fieldset> with a <legend>, which is what makes a
 * screen reader announce "Size, group" before reading the options instead
 * of reciting twelve unattached checkboxes. It is the single most-skipped
 * bit of markup in filter UIs.
 *
 * Colour swatches carry a visible label as well as the colour. A swatch row
 * that conveys its options by hue alone is unusable for anyone who cannot
 * distinguish them, and "Sage" is more precise than a green square anyway.
 *
 * The applied count and the Clear control are pinned at the top rather than
 * the bottom: after selecting four facets the user is at the top of the
 * panel, and that is where they look to undo it.
 */

import * as React from 'react'
import { X } from 'lucide-react'

export interface FacetOption {
  value: string
  label: string
  count?: number
  /** Tailwind background class, for colour facets. */
  swatch?: string
}

export interface Facet {
  id: string
  legend: string
  type: 'checkbox' | 'swatch'
  options: FacetOption[]
}

export interface ProductFilterSidebarProps {
  facets?: Facet[]
  maxPrice?: number
  currency?: string
  onChange?: (selected: Record<string, string[]>) => void
  className?: string
}

const DEFAULT_FACETS: Facet[] = [
  {
    id: 'category',
    legend: 'Category',
    type: 'checkbox',
    options: [
      { value: 'knitwear', label: 'Knitwear', count: 24 },
      { value: 'shirts', label: 'Shirts', count: 31 },
      { value: 'outerwear', label: 'Outerwear', count: 12 },
      { value: 'accessories', label: 'Accessories', count: 47 },
    ],
  },
  {
    id: 'size',
    legend: 'Size',
    type: 'checkbox',
    options: [
      { value: 's', label: 'Small', count: 62 },
      { value: 'm', label: 'Medium', count: 88 },
      { value: 'l', label: 'Large', count: 74 },
      { value: 'xl', label: 'Extra large', count: 29 },
    ],
  },
  {
    id: 'colour',
    legend: 'Colour',
    type: 'swatch',
    options: [
      { value: 'stone', label: 'Stone', swatch: 'bg-stone-400' },
      { value: 'navy', label: 'Navy', swatch: 'bg-indigo-800' },
      { value: 'sage', label: 'Sage', swatch: 'bg-emerald-600' },
      { value: 'rust', label: 'Rust', swatch: 'bg-orange-700' },
      { value: 'black', label: 'Black', swatch: 'bg-zinc-900' },
    ],
  },
]

export function ProductFilterSidebar({
  facets = DEFAULT_FACETS,
  maxPrice = 250,
  currency = '£',
  onChange,
  className = '',
}: ProductFilterSidebarProps) {
  const [selected, setSelected] = React.useState<Record<string, string[]>>({})
  const [price, setPrice] = React.useState(maxPrice)

  const appliedCount = Object.values(selected).reduce((n, list) => n + list.length, 0)

  function toggle(facetId: string, value: string) {
    setSelected((prev) => {
      const current = prev[facetId] ?? []
      const next = current.includes(value)
        ? current.filter((v) => v !== value)
        : [...current, value]

      const updated = { ...prev, [facetId]: next }
      if (next.length === 0) delete updated[facetId]

      onChange?.(updated)
      return updated
    })
  }

  function clearAll() {
    setSelected({})
    setPrice(maxPrice)
    onChange?.({})
  }

  return (
    <aside className={`w-full ${className}`}>
      <div className="flex items-center justify-between gap-3 border-b border-border/60 pb-3">
        <h2 className="font-semibold tracking-tight">
          Filters
          {appliedCount > 0 ? (
            <span className="ms-2 rounded-full bg-primary/15 px-2 py-0.5 text-xs font-semibold text-primary">
              {appliedCount}
            </span>
          ) : null}
        </h2>

        {appliedCount > 0 ? (
          <button
            type="button"
            onClick={clearAll}
            className="inline-flex items-center gap-1 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground"
          >
            <X aria-hidden className="h-3.5 w-3.5" />
            Clear
          </button>
        ) : null}
      </div>

      <div className="divide-y divide-border/40">
        {facets.map((facet) => (
          <fieldset key={facet.id} className="py-4">
            <legend className="mb-2.5 text-sm font-medium">{facet.legend}</legend>

            {facet.type === 'swatch' ? (
              <div className="flex flex-wrap gap-2">
                {facet.options.map((option) => {
                  const checked = selected[facet.id]?.includes(option.value) ?? false
                  return (
                    <label
                      key={option.value}
                      className={`flex cursor-pointer items-center gap-1.5 rounded-full border px-2 py-1 text-xs transition-colors ${
                        checked
                          ? 'border-primary bg-primary/10 text-foreground'
                          : 'border-border/60 text-muted-foreground hover:text-foreground'
                      }`}
                    >
                      <input
                        type="checkbox"
                        checked={checked}
                        onChange={() => toggle(facet.id, option.value)}
                        className="sr-only"
                      />
                      <span aria-hidden className={`h-3.5 w-3.5 rounded-full border border-transparent ring-1 ring-border ${option.swatch}`} />
                      {/* The name, not just the colour. */}
                      {option.label}
                    </label>
                  )
                })}
              </div>
            ) : (
              <ul className="space-y-2">
                {facet.options.map((option) => {
                  const checked = selected[facet.id]?.includes(option.value) ?? false
                  return (
                    <li key={option.value}>
                      <label className="flex cursor-pointer items-center gap-2.5 text-sm">
                        <input
                          type="checkbox"
                          checked={checked}
                          onChange={() => toggle(facet.id, option.value)}
                          className="h-4 w-4 rounded border-border/60 accent-primary"
                        />
                        <span className="flex-1 text-muted-foreground">{option.label}</span>
                        {typeof option.count === 'number' ? (
                          <span className="text-xs text-muted-foreground/60">{option.count}</span>
                        ) : null}
                      </label>
                    </li>
                  )
                })}
              </ul>
            )}
          </fieldset>
        ))}

        <fieldset className="py-4">
          <legend className="mb-2.5 text-sm font-medium">Maximum price</legend>
          <input
            type="range"
            min={0}
            max={maxPrice}
            value={price}
            onChange={(e) => setPrice(Number(e.target.value))}
            aria-label="Maximum price"
            className="w-full accent-primary"
          />
          <p className="mt-1.5 text-sm text-muted-foreground">
            Up to{' '}
            <span className="font-medium text-foreground">
              {currency}
              {price}
            </span>
          </p>
        </fieldset>
      </div>
    </aside>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Install: npm i lucide-react
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/product-filter-sidebar.tsx and import it where you need the section:

import { ProductFilterSidebar } from '@/components/product-filter-sidebar'

Customize

2 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.

Props

Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.

PropTypeDefault
facetsFacet[]DEFAULT_FACETS
maxPricenumber250
currencystring'£'
onChange(selected: Record<string, string[]>) => void—
classNamestring''

Not using React?

The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.

This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.

product-filter-sidebar.html
<!--
  Faceted Filter Sidebar — markup from the Hoverlab catalog.

  This is the block rendered once to HTML and wrapped as a component
  file. It is not a port of the React source: the Tailwind classes carry
  the design, which is the part that took the work, and they are the same
  in every framework.

  This block is interactive in React and the handlers are NOT here.
  Buttons, toggles and menus render in their initial state and do
  nothing until you wire them up.
-->
<aside class="w-full ">
  <div class="flex items-center justify-between gap-3 border-b border-border/60 pb-3">
    <h2 class="font-semibold tracking-tight">Filters</h2>
  </div>
  <div class="divide-y divide-border/40">
    <fieldset class="py-4">
      <legend class="mb-2.5 text-sm font-medium">Category</legend>
      <ul class="space-y-2">
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Knitwear</span>
            <span class="text-xs text-muted-foreground/60">24</span>
          </label>
        </li>
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Shirts</span>
            <span class="text-xs text-muted-foreground/60">31</span>
          </label>
        </li>
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Outerwear</span>
            <span class="text-xs text-muted-foreground/60">12</span>
          </label>
        </li>
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Accessories</span>
            <span class="text-xs text-muted-foreground/60">47</span>
          </label>
        </li>
      </ul>
    </fieldset>
    <fieldset class="py-4">
      <legend class="mb-2.5 text-sm font-medium">Size</legend>
      <ul class="space-y-2">
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Small</span>
            <span class="text-xs text-muted-foreground/60">62</span>
          </label>
        </li>
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Medium</span>
            <span class="text-xs text-muted-foreground/60">88</span>
          </label>
        </li>
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Large</span>
            <span class="text-xs text-muted-foreground/60">74</span>
          </label>
        </li>
        <li>
          <label class="flex cursor-pointer items-center gap-2.5 text-sm">
            <input type="checkbox" class="h-4 w-4 rounded border-border/60 accent-primary" />
            <span class="flex-1 text-muted-foreground">Extra large</span>
            <span class="text-xs text-muted-foreground/60">29</span>
          </label>
        </li>
      </ul>
    </fieldset>
    <fieldset class="py-4">
      <legend class="mb-2.5 text-sm font-medium">Colour</legend>
      <div class="flex flex-wrap gap-2">
        <label class="flex cursor-pointer items-center gap-1.5 rounded-full border px-2 py-1 text-xs transition-colors border-border/60 text-muted-foreground hover:text-foreground"><input type="checkbox" class="sr-only" /><span aria-hidden="true" class="h-3.5 w-3.5 rounded-full border border-transparent ring-1 ring-border bg-stone-400"></span>Stone</label>
        <label class="flex cursor-pointer items-center gap-1.5 rounded-full border px-2 py-1 text-xs transition-colors border-border/60 text-muted-foreground hover:text-foreground"><input type="checkbox" class="sr-only" /><span aria-hidden="true" class="h-3.5 w-3.5 rounded-full border border-transparent ring-1 ring-border bg-indigo-800"></span>Navy</label>
        <label class="flex cursor-pointer items-center gap-1.5 rounded-full border px-2 py-1 text-xs transition-colors border-border/60 text-muted-foreground hover:text-foreground"><input type="checkbox" class="sr-only" /><span aria-hidden="true" class="h-3.5 w-3.5 rounded-full border border-transparent ring-1 ring-border bg-emerald-600"></span>Sage</label>
        <label class="flex cursor-pointer items-center gap-1.5 rounded-full border px-2 py-1 text-xs transition-colors border-border/60 text-muted-foreground hover:text-foreground"><input type="checkbox" class="sr-only" /><span aria-hidden="true" class="h-3.5 w-3.5 rounded-full border border-transparent ring-1 ring-border bg-orange-700"></span>Rust</label>
        <label class="flex cursor-pointer items-center gap-1.5 rounded-full border px-2 py-1 text-xs transition-colors border-border/60 text-muted-foreground hover:text-foreground"><input type="checkbox" class="sr-only" /><span aria-hidden="true" class="h-3.5 w-3.5 rounded-full border border-transparent ring-1 ring-border bg-zinc-900"></span>Black</label>
      </div>
    </fieldset>
    <fieldset class="py-4">
      <legend class="mb-2.5 text-sm font-medium">Maximum price</legend>
      <input type="range" min="0" max="250" aria-label="Maximum price" class="w-full accent-primary" value="250" />
      <p class="mt-1.5 text-sm text-muted-foreground">Up to <span class="font-medium text-foreground">£250</span></p>
    </fieldset>
  </div>
</aside>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

8 more blocks in Product Listings

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Product Listings

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Product Listings blocks

View category
Open the full page for this block

Product Card Grid

Responsive product cards with sale badges, ratings and a wishlist button layered above the card link so it stays clickable.

Product Listings142 lines1 dep
Open the full page for this block

Collection Sort Toolbar

Result count, sort and density switch — with the count in an aria-live region, since it is the only feedback a filter change gives some users.

Product Listings131 lines1 dep
Open the full page for this block

Product Comparison Table

Three products side by side with the row labels pinned through a horizontal scroll, an "only show differences" toggle that says how many rows it hid, and "best" marked only where better means something.

Product Listings341 lines1 dep
Open the full page for this block

Stock Availability List

Availability per variant stated before the cart, because discovering it at checkout is where the basket gets abandoned.

Product Listings149 linesNo deps
Open the full page for this block

Collection Story Split

The editorial header above a collection grid, carrying the four facts that decide a considered purchase.

Product Listings157 linesNo deps

Map and Results Split

Results on one side, a drawn map on the other, scrolling independently. The map is explicitly decorative and out of the tab order — the list is the content, not its companion.

Product Listings329 lines1 dep
Open the full page for this block

Menu Course List

A restaurant menu typeset as a bill of fare rather than a product grid — dotted leaders to the price, dietary marks as abbreviations with a key, and prices as strings so “market price” still fits.

Product Listings282 linesNo deps