AND/OR condition trees for segments and automations: every rule shows how many records are left after it, so the rule doing the work, and the one doing nothing, are visible at a glance.
Change the valueChange the value
Segments
Trial accounts in EMEA
Accounts where
660601234567896012345678900123456789660 accounts
Plan
is
Trial
Region
is
EMEA
Signed up
after
Jan 28, 2026Dec 31, 2025
Seats
>=
10101234567890012345678910
Status
is
Churned
query-builder · , lively
query-builder-demo.tsx
When to use
Use where people write conditions as rules in all/any groups. With a count function each rule shows how many records remain after it. Presets: tree, inline, sentence.
When not to use
For a few simple filters above a table use Filter Bar. For picking one value use Combobox.
Use it wherever people write conditions: CRM segments, helpdesk macros and automation rules, analytics cohorts, discount rules, access rules. Each rule reads as a sentence ("Plan is Trial"): the field, the operator as a plain word, the value. A group joins its rules with "all" or "any" and can hold one level of nested groups; the guide that hangs the rules is a solid line for "all" and a line of beads for "any". For a handful of fixed filters above a table, use a filter bar; for one field, a combobox.
The question a person building a segment asks is not only "how many" but which rule does the work. With a count function, the tree is a funnel: the rail starts at "From 4,310" and every rule ends with its count, "after this rule" in an all group and the rule's own matches in an any group; a group's count is its result. A rule that changes nothing gets a hollow bead on the rail ("No effect"). Counts are facts, not judgements: no colour.
When a change commits, the beads of the rules whose count is about to change sink a pixel and their digits pinch while the count is in flight (the pill's dot breathes). Then the new counts run down the rail, one stagger step apart from the first changed rule to the total, each bead hopping 4 px as its number passes, and the total pill squashes on its wall as its number lands.
The motion follows the three beats. Pressing the other stop of the switch charges the 16 px ball, stretching it toward that stop; release throws it there and it squashes on the stop. The guide then breaks into 4 px beads from the switch downward, one stagger step per bead (healing back into a line the same way), and the count pill rolls to the new number once the count settles. "+ Group" is a pill that becomes the nested tile: the pill leaves its place, one surface grows from its box to the tile's, then the switch, the guide and the first rule rise in as it lands; removed rows sink and fade while the guide shortens on the calm reflow. At calm the ball glides without squash and the beads arrive together; the count still rolls.
Rules are { id, field, operator, value } and groups { id, combinator: "and" | "or", rules } (the root's id is optional, nested groups need one). count is a number, or a function of the pruned query (incomplete rules left out) that returns a promise: it runs 300 ms after the last change, the pill keeps its last value and its dot breathes while the promise is pending (aria-busy). initialCount fills the pill before the first answer, onCountChange(total) fires when an answer lands.
In the tree preset a count function also counts each step of the funnel, in the same debounced batch: for a rule in an all group, the query up to and including that rule (inside the groups around it); for a rule in an any group, the rule alone (inside the same context); for a group, the group itself. Steps share most of their queries, so a segment of five rules costs about seven distinct calls, all in parallel. A server that can do it in one round trip answers { total, byRule } (counts keyed by rule or group id) and the builder is given countRules={false}: then count runs once per change. A plain number count shows the total only. toPredicate(query) turns a query into a JavaScript filter for client-side counts; isComplete(query) and pruneQuery(query) help with saving.
Values: select and boolean fields use the suite's combobox, number fields the suite's NumberInput (compact preset, rolling digits, no native spinner), date fields the DatePickerfield preset (the value is stored as a local "YYYY-MM-DD" string) and text fields the suite field; between takes two. renderValue(rule, api) swaps in your own editor: return undefined to keep the built-in one. Operators default to a table per type (is, is not, contains, starts with, >, >=, <, <=, between, before, after, is empty, is set); override it with operators or per field. actionsRef.current.validate() marks every incomplete rule (the same error a blurred empty value shows) and returns whether the query is complete.
Pick a layout with preset: tree (the tile with the guide and nested groups, the default), inline (one wrapping row of rule chips with the switch at the start, for a segments toolbar) or sentence (the rules read as a sentence with the switch laid horizontally as the first "and", for automation "when / if" screens). inline and sentence show the root's rules only. A tree rule's terms are sized to their text and wrap as words do; below 34rem of width each rule sits in its own tile so a wrapped rule still reads as one. Inline chips below 34rem keep one grid each (field, operator and × on top, value below), so a chip wraps as a unit. maxDepth caps nesting, size is sm (32 px rows) or md (36 px), labels translates every string, and temperament sets the motion character.
The preview above: "Trial accounts in EMEA" over 4,310 placeholder accounts. At rest the funnel reads From 4,310, Plan is Trial 2,980, Region is EMEA 2,500, Signed up after 31 Dec 2025 2,500 with a hollow bead (every account signed up this year: the rule does nothing), then the usage group. On first view the group flips to "any" and the new counts run down the rail to the total, 660 to 2,068; the Save button carries the same number. "Replay" plays it again.
The root is role="group" named "Conditions"; each group is a role="group" named by its combinator ("Match all"). Rules are <li> in a <ul>.
The switch is a role="radiogroup" with two role="radio" stops ("All of these" / "Any of these"), one tab stop on the checked one; the ball, the guide, the beads and the branches are aria-hidden.
Every part is named: "Field", "Operator", "Value for Status"; the × is "Remove rule: Status is Open".
Each funnel count is read with its meaning: "2,500 after this rule", "820 match this rule", and ", No effect" when the rule changes nothing (also the count's title). The beads are aria-hidden; "From 4,310" is plain text. Counts are muted-foreground, AA in both themes.
A polite live region announces the settled count ("2,105 accounts match", set with labels.announce), "Rule added", "Rule removed" and "Group added".
An incomplete rule shows the destructive rim on the missing part only after it is blurred or after validate(); the count pill reads "—" and "1 rule is incomplete" rises under the tile.
Hit areas: switch stops and × 24 px, Add pills 28 px. The × fades in on hover and focus and is always visible on touch screens. Text stays foreground or muted-foreground, AA in both themes, disabled included.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") the funnel counts land together and crossfade, with no wave, no sink, no hop and no pill squash; the ball glides to its stop with no stretch or squash, the guide crossfades between the solid line and the beads, changed digits crossfade, new rules and groups fade in place (no flight from the pill) and removed rows fade without sinking. Every state looks the same as with motion.
The ball, the beads, the line and the rows move on transform and opacity. The guide's height is the one layout property animated (one 4 px element, measured once per change by a ResizeObserver), and the "+ Group" flight animates the size of one decorative tile.
Beads are at most 48 small elements per group, counted from the guide's height; nothing paints per row.
A count function is debounced (300 ms), the funnel's queries go out as one parallel batch with duplicates merged, and stale answers are dropped. The pending dot's breath is the only loop and stops when the promise settles; nothing runs at rest.
Peers: motion. The combobox (with @radix-ui/react-popover and cmdk), the number input and the date picker (with react-day-picker) are registry dependencies in their own items; their lists and calendars portal above the tile, so they are never clipped at 320 px.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 40.3 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
@radix-ui/react-popover
cmdk
motion · peer
react-day-picker
Triggers
a value change, click, press
Reduced motion
Counts land together and crossfade (no wave, sink or hop); the ball glides with no squash, the guide crossfades between line and beads, rows fade in place and removed rows fade without sinking.
Keyboard
Tab / Shift + Tab
Moves through the switch, then each rule's field, operator, value and ×, then + Rule and + Group
ArrowUp / ArrowDown
On the all / any switch: throws the ball to the other stop (ArrowLeft / ArrowRight in inline and sentence). On a rule's ×: moves to the previous / next rule
Space / Enter
On a stop: charges the ball and selects it. On + Rule / + Group: adds
Ctrl / Cmd + Enter
Inside a rule: adds an empty rule after it and focuses its field
Delete / Backspace
On a rule's ×: removes the rule, focus moves to the next ×
Escape
Closes an open field, operator or value list
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)