Filters are declared as data, so one panel renders any of them, one hook owns the list, and the bar decides for itself how many fit.

The problem

Orders, customers and products all need different filters. Build a panel per entity and every new entity is another bespoke screen, each with its own idea of how a checkbox adds to the filter list. You get duplicate filters, lost filters, and .filter() calls scattered everywhere.

Then the bar gets designed at one width. Someone opens a side panel, and the row wraps onto two lines or the search box gets crushed.

What I concluded

Declared, not built

Each entity declares its filters as typed data: field, label, control type, and the operators that control allows. One generic panel switches on the type to pick a control and has no idea which entity it’s showing.

type FilterConfig = { id: string; label: string; field: string } & (
  | { type: "checkbox"; op: "IN" | "EQ";
      options: () => Promise<{ value: string; count: number }[]> }
  | { type: "text"; op: "CONTAINS" | "EQ" }
  | { type: "date-range"; op: "BETWEEN" }
);

The union means a date range can’t claim CONTAINS.

One hook owns the list

Controls describe what they want, and every write goes through dedupe. remove and has take any subset of a filter, which covers every case: “is this box checked” is has({ field, value }), and “clear the section” is remove({ field }).

Because the config and the list are plain data, stored lists are saved views. And the config is a schema for anything else that writes filters, like an assistant. I validate its output against the config, drop what doesn’t fit, and apply the rest through the same add the checkboxes use, so the result shows up as ordinary checked boxes the person can undo.

The bar degrades on its own

The bar measures the controls it rendered and keeps what fits, moving the rest into More filters from the end.

Rules

  • The search box never shrinks. It’s the control people use most. Filters overflow instead.
  • Never one filter alone in More. A popover with one control reads as a mistake, so it takes a neighbour with it.
  • The More button counts what it hides. A filtered list behind a clean-looking bar is a trap.
  • Counts load without jumping. Known labels render first. Zero-count values dim but stay selectable if selected.
  • Give the bar its whole row. Inside someone else’s flex row it shrink-wraps, measures itself, and packs everything into the menu.

What you get

A new entity is a config, not a screen. Filter state can’t get into a duplicate or half-removed mess, and saved views and assistant-written filters come almost for free. The bar works at whatever width the layout hands it.

The demo shows the overflow: narrow it and watch filters move into More. Related: Tabs, URL state, Dates and locale.