Data display
QueryBuilder
Build editable filter rules from a field schema and store them as structured application state.
import { QueryBuilder } from '@reactloom/ui';Examples
Order filters example
import { useState } from 'react';
import { QueryBuilder, type QueryField, type QueryValue } from '@reactloom/ui';
const fields: QueryField[] = [
{ id: 'customer', label: 'Customer', type: 'text' },
{ id: 'total', label: 'Order total', type: 'number' },
{ id: 'status', label: 'Status', type: 'choice', options: [
{ value: 'open', label: 'Open' }, { value: 'closed', label: 'Closed' },
] },
];
export default function Example() {
const [value, setValue] = useState<QueryValue>({ match: 'all', rules: [] });
return <QueryBuilder label="Order filters" fields={fields} value={value} onChange={setValue} />;
}Read-only review criteria
import { QueryBuilder } from '@reactloom/ui';
export default function Example() {
return <QueryBuilder label="Saved review criteria" disabled onChange={() => {}}
fields={[{ id: 'days', label: 'Days overdue', type: 'number' }]}
value={{ match: 'all', rules: [{ id: 'overdue', field: 'days', operator: 'gt', value: '30' }] }} />;
}API reference
| Prop | Type | Default |
|---|---|---|
fieldsText, number, and choice fields. | readonly QueryField[] | — |
value · defaultValueControlled or initial filter model. The default matches all rules and starts with an empty list. | QueryValue | — |
onChangeReceives the next filter model in either mode. | (value: QueryValue) => void | — |
labelLegend for the builder. | string | — |
disabledShow read-only criteria. | boolean | — |
operatorLabelsOverride operator names. | Partial<Record<QueryOperator, string>> | — |
Pass className, style, or a ref to customize or access the root fieldset.
Keyboard interaction
| Key | Action |
|---|---|
| Tab | Move between controls |
| Enter / Space | Activate Add or Remove |
Usage guidelines
Do
- Validate and interpret the resulting rules where you apply the filter. Numeric input is stored as text so the application can decide how to parse it.
Don’t
- Avoid applying incomplete rules before the user confirms them.