---
title: "Filter Builder | Free React & Tailwind Blocks Component | Motion UI"
canonical: "https://blacknest.dev/motion/c/blocks/filter-builder"
github_source: "https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/filter-builder.tsx"
install_command: "npx motion-ui-skill add filter-builder"
dependencies: ["clsx","lucide-react","motion","react","tailwind-merge"]
category: "blocks"
subcategory: "motion"
---

# Filter Builder

> Faceted stepped query filter builder with dynamic attribute selectors, operator dropdowns, AND/OR logic toggles, and animated chip tags. Inspired by KeenThemes ReUI and shadcn/ui.

## Install

```bash
npx motion-ui-skill add filter-builder
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { FilterBuilder, type FilterField, type FilterRule } from "@/components/motion/filter-builder";
import { useState } from "react";

const FIELDS: FilterField[] = [
  {
    id: "status",
    label: "Status",
    type: "select",
    options: ["Active", "Pending", "Suspended", "Archived"],
  },
  {
    id: "role",
    label: "Team Role",
    type: "select",
    options: ["Admin", "Engineer", "Designer", "Auditor"],
  },
  {
    id: "email",
    label: "User Email",
    type: "text",
  },
  {
    id: "score",
    label: "Health Score",
    type: "number",
  },
];

const INITIAL_RULES: FilterRule[] = [
  {
    id: "r1",
    fieldId: "status",
    operator: "is",
    value: "Active",
  },
  {
    id: "r2",
    fieldId: "score",
    operator: ">",
    value: "80",
  },
];

export function FilterBuilderExample() {
  const [activeRules, setActiveRules] = useState<FilterRule[]>(INITIAL_RULES);

  return (
    <div className="max-w-xl p-4">
      <FilterBuilder
        fields={FIELDS}
        initialRules={INITIAL_RULES}
        conjunction="AND"
        onChange={(rules, conj) => {
          setActiveRules(rules);
          console.log("Updated filters:", rules, "Match:", conj);
        }}
      />
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `fields` | `FilterField[]` | required | Available filterable attributes with type and option definitions. |
| `initialRules` | `FilterRule[]` | `[]` | Initial set of applied filter rules. |
| `conjunction` | `"AND" \| "OR"` | `"AND"` | Boolean conjunction joining rules together. |
| `onChange` | `(rules: FilterRule[], conjunction: "AND" \| "OR") => void` | `undefined` | Callback emitted whenever rules or conjunction changes. |
| `className` | `string` | `undefined` | Custom styling overrides merged via `cn()`. |

## Source Files

- [components/motion/filter-builder.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/filter-builder.tsx)
- [lib/ease.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/ease.ts)
- [lib/utils.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/utils.ts)
