{
  "name": "query-builder-command-filter-demo",
  "type": "registry:example",
  "registryDependencies": [
    "query-builder",
    "button",
    "button-group",
    "command-stack",
    "popover"
  ],
  "files": [
    {
      "path": "examples/query-builder-command-filter-demo.tsx",
      "type": "registry:example",
      "content": "\"use client\";\n\nimport {\n  CheckIcon,\n  CircleCheckIcon,\n  CircleDashedIcon,\n  CircleDotIcon,\n  CircleIcon,\n  ListFilterIcon,\n  SignalHighIcon,\n  SignalLowIcon,\n  SignalMediumIcon,\n  UserIcon,\n  XIcon,\n} from \"lucide-react\";\nimport * as React from \"react\";\n\nimport {\n  getQuerySelection,\n  matchesQuery,\n  type QueryField,\n  type QueryGroup,\n  setQuerySelection,\n} from \"@/registry/bases/radix/lib/query-builder\";\nimport { Button } from \"@/registry/bases/radix/ui/button\";\nimport { ButtonGroup } from \"@/registry/bases/radix/ui/button-group\";\nimport {\n  CommandStack,\n  CommandStackEmpty,\n  CommandStackGroup,\n  CommandStackInput,\n  CommandStackItem,\n  CommandStackList,\n  CommandStackPage,\n} from \"@/registry/bases/radix/ui/command-stack\";\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"@/registry/bases/radix/ui/popover\";\nimport {\n  QueryBuilder,\n  QueryBuilderField,\n  QueryBuilderGroup,\n  QueryBuilderGroupContent,\n  QueryBuilderOperator,\n  QueryBuilderRemove,\n  QueryBuilderRule,\n  QueryBuilderRuleList,\n  QueryBuilderValue,\n} from \"@/registry/bases/radix/ui/query-builder\";\n\nconst statuses = [\n  { label: \"Backlog\", value: \"backlog\", icon: CircleDashedIcon },\n  { label: \"Todo\", value: \"todo\", icon: CircleIcon },\n  { label: \"In progress\", value: \"in-progress\", icon: CircleDotIcon },\n  { label: \"Done\", value: \"done\", icon: CircleCheckIcon },\n];\n\nconst fields: QueryField[] = [\n  { value: \"status\", label: \"Status\", type: \"select\", options: statuses },\n  {\n    value: \"priority\",\n    label: \"Priority\",\n    type: \"select\",\n    options: [\n      { label: \"High\", value: \"high\", icon: SignalHighIcon },\n      { label: \"Medium\", value: \"medium\", icon: SignalMediumIcon },\n      { label: \"Low\", value: \"low\", icon: SignalLowIcon },\n    ],\n  },\n  {\n    value: \"assignee\",\n    label: \"Assignee\",\n    type: \"select\",\n    options: [\n      { label: \"Olivia Martin\", value: \"olivia\" },\n      { label: \"Jackson Lee\", value: \"jackson\" },\n    ],\n  },\n];\n\nconst fieldIcons: Record<string, React.ComponentType> = {\n  status: CircleDashedIcon,\n  priority: SignalHighIcon,\n  assignee: UserIcon,\n};\n\nconst issues = [\n  {\n    id: \"SKT-12\",\n    title: \"Land the first kickflip\",\n    status: \"done\",\n    priority: \"high\",\n    assignee: \"olivia\",\n  },\n  {\n    id: \"SKT-13\",\n    title: \"Wax the ledge at the park\",\n    status: \"todo\",\n    priority: \"low\",\n    assignee: \"jackson\",\n  },\n  {\n    id: \"SKT-14\",\n    title: \"Film a tre flip line\",\n    status: \"in-progress\",\n    priority: \"high\",\n    assignee: \"olivia\",\n  },\n  {\n    id: \"SKT-15\",\n    title: \"Replace worn bearings\",\n    status: \"todo\",\n    priority: \"medium\",\n    assignee: \"olivia\",\n  },\n  {\n    id: \"SKT-16\",\n    title: \"Learn a hardflip\",\n    status: \"backlog\",\n    priority: \"medium\",\n    assignee: \"jackson\",\n  },\n  {\n    id: \"SKT-17\",\n    title: \"Edit the session clips\",\n    status: \"in-progress\",\n    priority: \"low\",\n    assignee: \"jackson\",\n  },\n];\n\nconst defaultQuery: QueryGroup = {\n  id: \"root\",\n  combinator: \"and\",\n  rules: [\n    {\n      id: \"status\",\n      field: \"status\",\n      operator: \"inArray\",\n      value: [\"todo\", \"in-progress\"],\n    },\n  ],\n};\n\nfunction getCount(field: string, value: string) {\n  return issues.filter(\n    (issue) => issue[field as keyof (typeof issues)[number]] === value,\n  ).length;\n}\n\nexport default function QueryBuilderCommandFilterDemo() {\n  const [query, setQuery] = React.useState(defaultQuery);\n\n  const rows = issues.filter((issue) => matchesQuery(issue, query, fields));\n\n  const selection = getQuerySelection(query);\n\n  return (\n    <div className=\"flex w-full max-w-2xl flex-col gap-4\">\n      <QueryBuilder fields={fields} value={query} onValueChange={setQuery}>\n        <QueryBuilderGroup>\n          <QueryBuilderGroupContent className=\"flex-row flex-wrap items-center data-[depth=0]:min-w-0\">\n            <QueryBuilderRuleList className=\"contents\">\n              <QueryBuilderRule>\n                <ButtonGroup className=\"**:data-[slot=query-builder-select-icon]:hidden\">\n                  <QueryBuilderField className=\"w-auto\" />\n                  <QueryBuilderOperator className=\"w-auto\" />\n                  <QueryBuilderValue className=\"w-auto max-w-48\" />\n                  <QueryBuilderRemove variant=\"outline\">\n                    <XIcon />\n                  </QueryBuilderRemove>\n                </ButtonGroup>\n              </QueryBuilderRule>\n            </QueryBuilderRuleList>\n            <Popover>\n              <PopoverTrigger asChild>\n                <Button variant=\"ghost\" size=\"sm\">\n                  <ListFilterIcon />\n                  Filter\n                </Button>\n              </PopoverTrigger>\n              <PopoverContent align=\"start\" className=\"w-64 p-0\">\n                <CommandStack\n                  value={selection}\n                  onValueChange={(next) =>\n                    setQuery(setQuerySelection(query, fields, next))\n                  }\n                >\n                  <CommandStackInput placeholder=\"Add filter...\" />\n                  <CommandStackList>\n                    <CommandStackEmpty>No results found.</CommandStackEmpty>\n                    <CommandStackPage value=\"root\">\n                      {fields.map((field) => {\n                        const Icon = fieldIcons[field.value] ?? UserIcon;\n                        return (\n                          <CommandStackItem\n                            key={field.value}\n                            page={field.value}\n                          >\n                            <Icon />\n                            {field.label}\n                          </CommandStackItem>\n                        );\n                      })}\n                    </CommandStackPage>\n                    {fields.map((field) => (\n                      <CommandStackPage\n                        key={field.value}\n                        value={field.value}\n                        label={field.label}\n                        placeholder={`Filter by ${field.label.toLowerCase()}...`}\n                        selectionMode=\"multiple\"\n                      >\n                        <CommandStackGroup heading={field.label}>\n                          {field.options?.map((option) => (\n                            <CommandStackItem\n                              key={option.value}\n                              value={option.value}\n                              keywords={[option.label]}\n                              className=\"[&>svg:last-child]:hidden\"\n                            >\n                              <span\n                                aria-hidden=\"true\"\n                                className=\"flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input text-primary-foreground group-data-[checked=true]/command-item:border-primary group-data-[checked=true]/command-item:bg-primary\"\n                              >\n                                <CheckIcon className=\"size-3 opacity-0 group-data-[checked=true]/command-item:opacity-100\" />\n                              </span>\n                              {option.icon && <option.icon />}\n                              <span className=\"flex-1 truncate\">\n                                {option.label}\n                              </span>\n                              <span className=\"text-xs text-muted-foreground tabular-nums\">\n                                {getCount(field.value, option.value)}\n                              </span>\n                            </CommandStackItem>\n                          ))}\n                        </CommandStackGroup>\n                      </CommandStackPage>\n                    ))}\n                  </CommandStackList>\n                </CommandStack>\n              </PopoverContent>\n            </Popover>\n            {query.rules.length > 0 && (\n              <Button\n                variant=\"ghost\"\n                size=\"sm\"\n                className=\"text-muted-foreground\"\n                onClick={() => setQuery({ ...query, rules: [] })}\n              >\n                Clear\n              </Button>\n            )}\n          </QueryBuilderGroupContent>\n        </QueryBuilderGroup>\n      </QueryBuilder>\n      <div className=\"divide-y overflow-hidden rounded-lg border\">\n        {rows.map((issue) => {\n          const Icon =\n            statuses.find((status) => status.value === issue.status)?.icon ??\n            CircleIcon;\n          return (\n            <div\n              key={issue.id}\n              className=\"flex items-center gap-3 px-3 py-2 text-sm\"\n            >\n              <span className=\"w-14 text-muted-foreground\">{issue.id}</span>\n              <Icon className=\"size-4 text-muted-foreground\" />\n              <span className=\"truncate\">{issue.title}</span>\n            </div>\n          );\n        })}\n        {rows.length === 0 && (\n          <p className=\"px-3 py-6 text-center text-sm text-muted-foreground\">\n            No issues match.\n          </p>\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "target": ""
    }
  ]
}