# Query Builder
URL: /docs/web/components/query-builder
Query Builder component.
**Demo:**
```tsx
'use client';
import { useState } from 'react';
import { QueryBuilderKiva } from '@kivacore/ui/components/query-builder';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue
} from '@kivacore/ui/primitives/ui/select';
import { cn } from '@kivacore/ui/primitives/lib/utils';
import { PropControls } from '@/components/prop-controls';
import { useDemoData } from '@/data/query-builder-data';
export function QueryBuilderDemo() {
type Variant = 'default' | 'bordered' | 'compact' | 'striped';
const [variant, setVariant] = useState
Size
);
}
```
## Installation
```bash
pnpm dlx @kivacore/ui-cli add @kivacore/ui-query-builder
```
**Dependencies:**
- [@react-querybuilder/dnd](https://www.npmjs.com/package/@react-querybuilder/dnd)
- [@atlaskit/pragmatic-drag-and-drop](https://www.npmjs.com/package/@atlaskit/pragmatic-drag-and-drop)
- [@dnd-kit/core](https://www.npmjs.com/package/@dnd-kit/core)
- [react-dnd](https://www.npmjs.com/package/react-dnd)
- [react-dnd-html5-backend](https://www.npmjs.com/package/react-dnd-html5-backend)
- [react-dnd-touch-backend](https://www.npmjs.com/package/react-dnd-touch-backend)
- [react-querybuilder](https://www.npmjs.com/package/react-querybuilder)
- [lucide-react](https://www.npmjs.com/package/lucide-react)
- [class-variance-authority](https://www.npmjs.com/package/class-variance-authority)
- [jsonata](https://www.npmjs.com/package/jsonata)
## Usage
```tsx
import {
QueryBuilderKiva
} from "@kivacore/ui/components/query-builder";
import type {
QueryBuilderKivaProps,
KivaQBField,
RuleGroupType,
RuleGroupTypeIC,
RuleType,
Field,
FullField,
FullOperator,
FullCombinator,
QueryBuilderProps,
ActionProps,
ValueSelectorProps,
ValueEditorProps,
NotToggleProps,
DragHandleProps,
CombinatorSelectorProps,
FieldSelectorProps,
OperatorSelectorProps,
RuleGroupTypeAny,
VersatileSelectorProps,
QueryJsonataContext,
EvaluateOptions,
UseQuery2JsonataConverterOptions,
UseQuery2JsonataConverterResult,
ConvertQueryOptions,
ConvertQueryResult,
DateBindingSpec,
OperatorApi,
FilterGroup
} from "@kivacore/ui/components/query-builder";
## Components
| Component | Description |
|-----------|-------------|
| `QueryBuilderKiva` | Public export |
## Type Exports
| Type | Description |
|------|-------------|
| `QueryBuilderKivaProps` | — |
| `QBAsyncOptions` | Server-side option loading config for one field |
| `QBValueOption` | One option (`FlatOption`) returned by an async loader |
| `KivaQBField` | — |
| `RuleGroupType` | — |
| `RuleGroupTypeIC` | — |
| `RuleType` | — |
| `Field` | — |
| `FullField` | — |
| `FullOperator` | — |
| `FullCombinator` | — |
| `QueryBuilderProps` | — |
| `ActionProps` | — |
| `ValueSelectorProps` | — |
| `ValueEditorProps` | — |
| `NotToggleProps` | — |
| `DragHandleProps` | — |
| `CombinatorSelectorProps` | — |
| `FieldSelectorProps` | — |
| `OperatorSelectorProps` | — |
| `RuleGroupTypeAny` | — |
| `VersatileSelectorProps` | — |
| `QueryJsonataContext` | — |
| `EvaluateOptions` | — |
| `UseQuery2JsonataConverterOptions` | — |
| `UseQuery2JsonataConverterResult` | — |
| `ConvertQueryOptions` | — |
| `ConvertQueryResult` | — |
| `DateBindingSpec` | — |
| `OperatorApi` | — |
| `FilterGroup` | — |
## Type Reference
### KivaQBField
| Field | Type | Description |
|-------|------|-------------|
| `filterGroup` | `FilterGroup` | — |
| `fieldType` | `string` | — |
| `operatorValues` | `Record` | — |
| `operatorValueEditorType` | `Partial>` | — |
| `asyncOptions` | `QBAsyncOptions` | Server-side option loading for this field. Set it for a relation or user column whose options cannot be shipped in `values`. |
### QBAsyncOptions
| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `load` | `(params: { search, page, pageSize, signal? }) => Promise<{ items: Array; hasMore?: boolean }>` | — | Fetch one page of options. Aborted when the editor unmounts or a fresh search supersedes it. |
| `resolveByIds` | `(params: { ids: Array; signal? }) => Promise>` | — | Labels for values that are **already** selected, so a rule reopened from storage doesn't print raw ids. |
| `pageSize` | `number` | `25` | Items per page. |
| `debounceMs` | `number` | `300` | Debounce before a new search fires. |
### QueryJsonataContext
| Field | Type | Description |
|-------|------|-------------|
| `activeUserId` | `string` | — |
| `activeUserTeamMemberIds` | `string[]` | — |
### EvaluateOptions
| Field | Type | Description |
|-------|------|-------------|
| `now` | `Date \| number` | — |
| `bindings` | `Record` | — |
### UseQuery2JsonataConverterOptions
| Field | Type | Description |
|-------|------|-------------|
### UseQuery2JsonataConverterResult
| Field | Type | Description |
|-------|------|-------------|
| `expression` | `string` | — |
| `dateBindings` | `DateBindingSpec[]` | — |
| `unsupportedOperators` | `string[]` | — |
| `warnings` | `string[]` | — |
| `isValid` | `boolean` | — |
| `error` | `Error \| null` | — |
| `evaluate` | `(data: unknown, options?: EvaluateOptions) => Promise` | — |
### ConvertQueryOptions
| Field | Type | Description |
|-------|------|-------------|
| `resolveGroup` | `(field: string) => FilterGroup \| undefined` | — |
| `fieldResolver` | `(field: string) => string` | — |
| `operatorOverrides` | `Record string \| null>` | — |
| `unsupportedFallback` | `boolean` | — |
| `weekStartsOn` | `0 \| 1` | — |
### ConvertQueryResult
| Field | Type | Description |
|-------|------|-------------|
| `expression` | `string` | — |
| `dateBindings` | `DateBindingSpec[]` | — |
| `unsupportedOperators` | `string[]` | — |
| `warnings` | `string[]` | — |
### DateBindingSpec
| Field | Type | Description |
|-------|------|-------------|
| `id` | `string` | — |
| `operator` | `string` | — |
| `amount` | `number` | — |
### OperatorApi
| Field | Type | Description |
|-------|------|-------------|
| `field` | `string` | — |
| `str` | `(value: unknown) => string` | — |
| `num` | `(value: unknown) => string` | — |
| `strArr` | `(values: unknown[]) => string` | — |
| `fieldRef` | `(name: string) => string` | — |
### FilterGroup
`"ALPHA"`