Skip to content

FilterBar

URL-param-backed filters with resolved-value chips.
Implemented
Status
Implemented
Family
5 of 13
Registry
@lopifi/filter-bar
npx shadcn@latest add @lopifi/theme @lopifi/filter-bar

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

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.

components/ledger/filter-bar.tsx
"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

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

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.

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.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.