FilterBar
- Status
- Implemented
- Family
- 5 of 13
- Registry
- @lopifi/filter-bar
npx shadcn@latest add @lopifi/theme @lopifi/filter-barThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
URL-param-backed, so a filtered view is shareable and survives a refresh. Chips show resolved values — "1–30 Sep 2026", not "Last 30 days". Clear-all always present. Result count updates live. Filter state changes are instant, no animation.
Lifted verbatim from Ledger & tables. The doc and this page are the same paragraphs, so they cannot disagree.
What lands in your repository
One component is never one file. Everything below is copied into your project, where you own it.
- Files
components/ledger/filter-bar.tsx
- Lopifi dependencies · 3
- buttoncnicons
- npm packages
- class-variance-authorityclsxtailwind-merge
- Registry entry
- /r/filter-bar.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
"use client";
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import { Button } from "@/components/ledger/button";
import { FunnelIcon, XMarkIcon } from "@/components/ledger/icons";
export type FilterChip = {
key: string;
label: string;
/** The resolved value — "1–30 Sep 2026", never "Last 30 days". */
value: string;
};
export interface FilterBarProps {
children?: React.ReactNode;
chips: FilterChip[];
className?: string;
onClearAll: () => void;
onRemove: (key: string) => void;
resultCount: number;
}
/**
* URL-param-backed, so a filtered view is shareable and survives a refresh.
* Chips show resolved values. Clear-all is always present. Filter state
* changes are instant — no animation.
*/
export function FilterBar({ chips, onRemove, onClearAll, resultCount, children, className }: FilterBarProps) {
return (
<div className={cn("flex flex-wrap items-center gap-2", className)}>
<FunnelIcon aria-hidden="true" className="size-4 shrink-0 text-text-tertiary" />
{children}
{chips.map((chip) => (
<span
className="inline-flex h-8 items-center gap-1.5 rounded-sm bg-surface-sunken pl-3 pr-1 text-label"
key={chip.key}
>
<span className="text-text-secondary">{chip.label}:</span>
<span className="font-medium">{chip.value}</span>
<button
aria-label={`Remove filter ${chip.label} ${chip.value}`}
className="press grid size-6 place-items-center rounded-xs text-text-tertiary hover:bg-surface-hover"
onClick={() => onRemove(chip.key)}
type="button"
>
<XMarkIcon aria-hidden="true" className="size-3" />
</button>
</span>
))}
{chips.length > 0 ? (
<Button onClick={onClearAll} size="sm" variant="ghost">
Clear all
</Button>
) : null}
<span aria-live="polite" className="numeric ml-auto text-caption text-text-secondary">
{resultCount.toLocaleString()} results
</span>
</div>
);
}
/** URL-backed filter state. A shared link opens the same view. */
export function useUrlFilters(): {
filters: Record<string, string>;
set: (key: string, value: string | null) => void;
clear: () => void;
} {
const [filters, setFilters] = React.useState<Record<string, string>>({});
React.useEffect(() => {
const params = new URLSearchParams(window.location.search);
const next: Record<string, string> = {};
params.forEach((v, k) => {
next[k] = v;
});
setFilters(next);
}, []);
const sync = React.useCallback((next: Record<string, string>) => {
setFilters(next);
const params = new URLSearchParams(next);
const query = params.toString();
window.history.replaceState(
null,
"",
query ? `${window.location.pathname}?${query}` : window.location.pathname,
);
}, []);
return {
clear: () => sync({}),
filters,
set: (key, value) => {
const next = { ...filters };
if (value === null) delete next[key];
else next[key] = value;
sync(next);
},
};
}
Also in Ledger & tables
- TransactionTableThe workhorse. Virtualized, sticky, priority-collapsing.
- TransactionRowDesktop row.Spec
- TransactionCardThe mobile re-rank.
- TransactionDetailFull detail sheet with attachments and audit trail.
- LedgerTableDouble-entry with debit/credit columns and a balance check.
- AgingTableAR/AP buckets, 0-30-60-90+.
- ReconciliationViewTwo-pane matcher. The match animation.
- CategoryPickerHierarchical with rule creation.
- BulkActionBarSelection count + actions, safe-area aware.
- ColumnManagerShow/hide/reorder with drag.
- GroupPickerOne cut through a table, with subtotals per group.
- ExportMenuCSV/XLSX/PDF with a stated scope.
- TableColumnsSort and resize for a table that renders on the server.
- ColumnHeaderThe sortable, draggable header cell.
- PeriodGridThe ruled grid. Frozen panes, hidden columns, hover change, ⌘C.
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Ledger & tables — the family specThe four-layer specification this component was built against, before it was written.Doc
- Ledger tables and transaction registersThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
Elsewhere in the system
Where FilterBar sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.
- FilterBar, runningThe tables showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Ledger & tablesThe table is the product. It gets the same design investment as the hero card. Specs for 15 React components: TransactionTable, TransactionRow, TransactionCard, TransactionDetail and 11 more.Doc
Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.
Told when Ledger & tables changes
Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.