Command Palette
The ⌘K switcher done properly: focus stays in the input while aria-activedescendant moves, arrows wrap, and the highlight resets on every query change.
Faceted search with result counts on every option, zero-count options kept visible and disabled so the list stays stable, and a note explaining why the counts do not sum.
components/search-facet-panel.tsxnpx hoverlab add search-facet-panel
Or over MCP, from your editor's agent — no account needed.
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.
Start a page with this section — add more, order them, and leave with the page source.
Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.
'use client'
/**
* <SearchFacetPanel> — refinement with counts, including the zeroes.
*
* The catalog has a product filter sidebar and an applied-filters bar. This
* is the third piece and the one that makes faceted search usable rather
* than merely present: the panel that shows how many results each option
* would leave, before it is clicked.
*
* THE ZERO-COUNT DECISION
*
* Every faceted search has to choose what to do with an option that would
* return nothing. Hiding it makes the list shorter and makes the facet
* *look different every time you refine*, which is disorienting — options
* vanish and reappear as you click around. Showing it disabled keeps the
* list stable and tells you the option exists but is excluded by something
* else. This shows them, greyed and unclickable, and that is a deliberate
* choice rather than an oversight.
*
* MULTI-SELECT WITHIN A FACET, AND WHY THE COUNTS LOOK ODD
*
* Within one facet the options are OR-ed — picking Blue and Green shows
* both — while separate facets are AND-ed. That is what every good search
* does and what makes the counts within a facet not sum to the result
* total. A note says so, because the alternative is a support ticket.
*
* COLLAPSING REMEMBERS. A facet the user collapsed stays collapsed as they
* refine; nothing here springs back open on re-render.
*
* ACCESSIBILITY: each facet is a `<fieldset>` with a `<legend>` inside a
* disclosure whose button carries both `aria-expanded` and `aria-controls`
* — the audit flags the first without the second. Counts are inside each
* checkbox's label so they are announced with the option.
*/
import * as React from 'react'
import { ChevronDown, RotateCcw } from 'lucide-react'
export interface FacetOption {
id: string
label: string
/** Results remaining if this option were selected. Zero renders disabled. */
count: number
}
export interface Facet {
id: string
label: string
options: FacetOption[]
/** Options beyond this are behind a "Show all". */
visibleLimit?: number
}
export interface SearchFacetPanelProps {
facets?: Facet[]
resultCount?: number
className?: string
}
/*
Deliberately NOT this catalog's own numbers.
These facets used to read Effects 973, Blocks 194, Pages 21 — Hoverlab's
counts at the moment the block was written, baked into demo data that
ships into other people's repositories. Two things were wrong with that.
They went stale immediately, and nothing checks them because a
component's example data is not a claim anyone thought to verify; and a
reader who recognised the numbers would reasonably read the block as
hard-wired to this catalog rather than as a generic facet panel.
A neutral domain avoids both. Nothing here can go out of date, because
nothing here is a fact about anything.
*/
const DEFAULT_FACETS: Facet[] = [
{
id: 'type',
label: 'Type',
options: [
{ id: 'doc', label: 'Documents', count: 1240 },
{ id: 'spreadsheet', label: 'Spreadsheets', count: 318 },
{ id: 'slide', label: 'Presentations', count: 96 },
{ id: 'archive', label: 'Archived', count: 44 },
],
},
{
id: 'owner',
label: 'Owner',
options: [
{ id: 'me', label: 'Me', count: 212 },
{ id: 'team', label: 'My team', count: 884 },
{ id: 'shared', label: 'Shared with me', count: 402 },
{ id: 'external', label: 'External', count: 61 },
{ id: 'unassigned', label: 'Unassigned', count: 0 },
],
},
{
id: 'category',
label: 'Category',
visibleLimit: 4,
options: [
{ id: 'contracts', label: 'Contracts', count: 59 },
{ id: 'invoices', label: 'Invoices', count: 39 },
{ id: 'reports', label: 'Reports', count: 36 },
{ id: 'notes', label: 'Meeting notes', count: 38 },
{ id: 'specs', label: 'Specifications', count: 37 },
{ id: 'policies', label: 'Policies', count: 30 },
{ id: 'research', label: 'Research', count: 31 },
],
},
{
id: 'licence',
label: 'Licence',
options: [
{ id: 'free', label: 'Free', count: 1_188 },
{ id: 'pro', label: 'Pro', count: 6 },
],
},
]
export function SearchFacetPanel({
facets = DEFAULT_FACETS,
resultCount = 1_195,
className = '',
}: SearchFacetPanelProps) {
// Per-instance ids. A literal id in a reusable component is a
// collision waiting for the second copy on the page — and a <label>
// then resolves to whichever input rendered first.
const uid = React.useId()
const [selected, setSelected] = React.useState<Record<string, string[]>>({
type: ['block'],
})
const [collapsed, setCollapsed] = React.useState<string[]>([])
const [expandedLists, setExpandedLists] = React.useState<string[]>([])
const totalSelected = Object.values(selected).flat().length
function toggleOption(facetId: string, optionId: string) {
setSelected((current) => {
const existing = current[facetId] ?? []
const next = existing.includes(optionId)
? existing.filter((id) => id !== optionId)
: [...existing, optionId]
// An empty array and an absent key mean the same thing; keeping only
// one of the two representations stops `totalSelected` drifting.
const copy = { ...current }
if (next.length === 0) delete copy[facetId]
else copy[facetId] = next
return copy
})
}
return (
<aside
className={`w-full max-w-xs rounded-2xl border border-border bg-card text-card-foreground ${className}`}
>
<header className="flex items-center justify-between gap-3 border-b border-border p-4">
<div>
<h2 className="text-sm font-semibold">Refine</h2>
<p aria-live="polite" className="text-xs text-muted-foreground">
{resultCount.toLocaleString('en-US')} results
</p>
</div>
{totalSelected > 0 ? (
<button
type="button"
onClick={() => setSelected({})}
className="inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<RotateCcw aria-hidden className="h-3 w-3" />
Clear {totalSelected}
</button>
) : null}
</header>
<div className="divide-y divide-border">
{facets.map((facet) => {
const open = !collapsed.includes(facet.id)
const listId = `${uid}-facet-${facet.id}`
const limit = facet.visibleLimit ?? facet.options.length
const showingAll = expandedLists.includes(facet.id)
const options = showingAll ? facet.options : facet.options.slice(0, limit)
const chosen = selected[facet.id] ?? []
return (
<fieldset key={facet.id} className="p-4">
<legend className="sr-only">{facet.label}</legend>
<button
type="button"
aria-expanded={open}
aria-controls={listId}
onClick={() =>
setCollapsed((current) =>
current.includes(facet.id)
? current.filter((id) => id !== facet.id)
: [...current, facet.id],
)
}
className="flex w-full items-center justify-between gap-2 text-sm font-medium transition-colors hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<span aria-hidden>{facet.label}</span>
<span className="sr-only">
{facet.label}
{chosen.length > 0 ? `, ${chosen.length} selected` : ''}
</span>
<span className="flex items-center gap-1.5">
{chosen.length > 0 ? (
<span className="rounded-full bg-primary/10 px-1.5 text-[11px] font-semibold text-primary">
{chosen.length}
</span>
) : null}
<ChevronDown
aria-hidden
className={`h-4 w-4 text-muted-foreground transition-transform ${open ? '' : '-rotate-90'}`}
/>
</span>
</button>
<div id={listId} hidden={!open} className="mt-3 space-y-1.5">
{options.map((option) => {
const empty = option.count === 0
return (
<label
key={option.id}
className={`flex items-center gap-2.5 text-sm ${
empty ? 'cursor-not-allowed opacity-45' : 'cursor-pointer'
}`}
>
<input
type="checkbox"
disabled={empty}
checked={chosen.includes(option.id)}
onChange={() => toggleOption(facet.id, option.id)}
className="h-3.5 w-3.5 accent-primary"
/>
<span className="flex-1">{option.label}</span>
<span className="tabular-nums text-xs text-muted-foreground">
{option.count.toLocaleString('en-US')}
</span>
</label>
)
})}
{facet.options.length > limit ? (
<button
type="button"
onClick={() =>
setExpandedLists((current) =>
current.includes(facet.id)
? current.filter((id) => id !== facet.id)
: [...current, facet.id],
)
}
className="pt-1 text-xs font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
{showingAll ? 'Show fewer' : `Show all ${facet.options.length}`}
</button>
) : null}
</div>
</fieldset>
)
})}
</div>
{/* The sentence that prevents the "these numbers do not add up" ticket. */}
<p className="border-t border-border p-4 text-xs text-muted-foreground">
Options within one group are combined with OR; separate groups are combined
with AND. Counts show what each option alone would leave, so they do not sum
to the total.
</p>
</aside>
)
}
bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.Drop it at components/search-facet-panel.tsx and import it where you need the section:
import { SearchFacetPanel } from '@/components/search-facet-panel'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.
| Prop | Type | Default |
|---|---|---|
facets | Facet[] | DEFAULT_FACETS |
resultCount | number | 1_195 |
className | string | '' |
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.
<!--
Faceted Refinement Panel — 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 max-w-xs rounded-2xl border border-border bg-card text-card-foreground ">
<header class="flex items-center justify-between gap-3 border-b border-border p-4">
<div>
<h2 class="text-sm font-semibold">Refine</h2>
<p aria-live="polite" class="text-xs text-muted-foreground">1,195 results</p>
</div>
<button type="button" class="inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-rotate-ccw h-3 w-3" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path><path d="M3 3v5h5"></path></svg>Clear 1</button>
</header>
<div class="divide-y divide-border">
<fieldset class="p-4">
<legend class="sr-only">Type</legend>
<button type="button" aria-expanded="true" aria-controls="_R_0_-facet-type" class="flex w-full items-center justify-between gap-2 text-sm font-medium transition-colors hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
<span aria-hidden="true">Type</span>
<span class="sr-only">Type, 1 selected</span>
<span class="flex items-center gap-1.5">
<span class="rounded-full bg-primary/10 px-1.5 text-[11px] font-semibold text-primary">1</span>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down h-4 w-4 text-muted-foreground transition-transform" aria-hidden="true">
<path d="m6 9 6 6 6-6"></path>
</svg>
</span>
</button>
<div id="_R_0_-facet-type" class="mt-3 space-y-1.5">
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Documents</span>
<span class="tabular-nums text-xs text-muted-foreground">1,240</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Spreadsheets</span>
<span class="tabular-nums text-xs text-muted-foreground">318</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Presentations</span>
<span class="tabular-nums text-xs text-muted-foreground">96</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Archived</span>
<span class="tabular-nums text-xs text-muted-foreground">44</span>
</label>
</div>
</fieldset>
<fieldset class="p-4">
<legend class="sr-only">Owner</legend>
<button type="button" aria-expanded="true" aria-controls="_R_0_-facet-owner" class="flex w-full items-center justify-between gap-2 text-sm font-medium transition-colors hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
<span aria-hidden="true">Owner</span>
<span class="sr-only">Owner</span>
<span class="flex items-center gap-1.5">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down h-4 w-4 text-muted-foreground transition-transform" aria-hidden="true">
<path d="m6 9 6 6 6-6"></path>
</svg>
</span>
</button>
<div id="_R_0_-facet-owner" class="mt-3 space-y-1.5">
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Me</span>
<span class="tabular-nums text-xs text-muted-foreground">212</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">My team</span>
<span class="tabular-nums text-xs text-muted-foreground">884</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Shared with me</span>
<span class="tabular-nums text-xs text-muted-foreground">402</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">External</span>
<span class="tabular-nums text-xs text-muted-foreground">61</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-not-allowed opacity-45">
<input type="checkbox" disabled="" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Unassigned</span>
<span class="tabular-nums text-xs text-muted-foreground">0</span>
</label>
</div>
</fieldset>
<fieldset class="p-4">
<legend class="sr-only">Category</legend>
<button type="button" aria-expanded="true" aria-controls="_R_0_-facet-category" class="flex w-full items-center justify-between gap-2 text-sm font-medium transition-colors hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
<span aria-hidden="true">Category</span>
<span class="sr-only">Category</span>
<span class="flex items-center gap-1.5">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down h-4 w-4 text-muted-foreground transition-transform" aria-hidden="true">
<path d="m6 9 6 6 6-6"></path>
</svg>
</span>
</button>
<div id="_R_0_-facet-category" class="mt-3 space-y-1.5">
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Contracts</span>
<span class="tabular-nums text-xs text-muted-foreground">59</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Invoices</span>
<span class="tabular-nums text-xs text-muted-foreground">39</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Reports</span>
<span class="tabular-nums text-xs text-muted-foreground">36</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Meeting notes</span>
<span class="tabular-nums text-xs text-muted-foreground">38</span>
</label>
<button type="button" class="pt-1 text-xs font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">Show all 7</button>
</div>
</fieldset>
<fieldset class="p-4">
<legend class="sr-only">Licence</legend>
<button type="button" aria-expanded="true" aria-controls="_R_0_-facet-licence" class="flex w-full items-center justify-between gap-2 text-sm font-medium transition-colors hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
<span aria-hidden="true">Licence</span>
<span class="sr-only">Licence</span>
<span class="flex items-center gap-1.5">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down h-4 w-4 text-muted-foreground transition-transform" aria-hidden="true">
<path d="m6 9 6 6 6-6"></path>
</svg>
</span>
</button>
<div id="_R_0_-facet-licence" class="mt-3 space-y-1.5">
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Free</span>
<span class="tabular-nums text-xs text-muted-foreground">1,188</span>
</label>
<label class="flex items-center gap-2.5 text-sm cursor-pointer">
<input type="checkbox" class="h-3.5 w-3.5 accent-primary" />
<span class="flex-1">Pro</span>
<span class="tabular-nums text-xs text-muted-foreground">6</span>
</label>
</div>
</fieldset>
</div>
<p class="border-t border-border p-4 text-xs text-muted-foreground">Options within one group are combined with OR; separate groups are combined with AND. Counts show what each option alone would leave, so they do not sum to the total.</p>
</aside>
What each framework gets across the whole catalog — effects convert properly; this rung is markup.
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.
Want the whole screen instead of this one section? Open a page and copy it entire.
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 Command & SearchCopying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.
The ⌘K switcher done properly: focus stays in the input while aria-activedescendant moves, arrows wrap, and the highlight resets on every query change.
Results grouped by section with visible breadcrumb paths and <mark>-highlighted matches — users recognise where a result lives faster than they read its snippet.
The "?" overlay, with chords written once in one notation and rendered per platform — mod becomes Command on Apple and Ctrl everywhere else, decided after mount so the markup never mismatches.
The strip above a result set that answers "why am I only seeing four things" — every active constraint as a removable chip, with the excluded count beside it.
The field in the header, not the palette over it: Enter searches for what you typed unless you arrowed to a suggestion, late responses are dropped by sequence number, and recent searches are removable one at a time.
One query counted across every scope it could have matched, as a real tablist with arrow-key movement — so an answer that is nowhere is visible without opening four tabs.
The empty state of a search box, filled with the searches that are worth repeating and the ones worth saving.
The whole faceted search assembled - rail, chips, live count and sort - with the intersection actually applied and relevance offered only when there is a query.
The facet that is a number: a distribution over a dual-thumb slider built from two real range inputs, with typed bounds clamped on blur rather than per keystroke.