Skip to content

Commit 9b7358e

Browse files
Copilothuangyiirene
andcommitted
Add advanced features: date/select fields, clear all button, and enhanced input types
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 3b87d45 commit 9b7358e

3 files changed

Lines changed: 216 additions & 28 deletions

File tree

examples/prototype/src/FilterBuilderDemo.tsx

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const filterBuilderSchema = {
2424
className: 'text-muted-foreground',
2525
body: {
2626
type: 'text',
27-
content: 'Airtable-like filter component for building complex query conditions'
27+
content: 'Airtable-like filter component with advanced field types and operators'
2828
}
2929
}
3030
]
3131
},
3232

33-
// Example 1: User Data Filtering
33+
// Example 1: User Data Filtering with Date and Select
3434
{
3535
type: 'card',
3636
className: 'shadow-lg',
@@ -49,7 +49,7 @@ const filterBuilderSchema = {
4949
className: 'text-sm text-muted-foreground mt-1',
5050
body: {
5151
type: 'text',
52-
content: 'Filter users by name, email, age, and status'
52+
content: 'Advanced filtering with date, select, and boolean fields'
5353
}
5454
}
5555
]
@@ -65,9 +65,29 @@ const filterBuilderSchema = {
6565
{ value: 'name', label: 'Name', type: 'text' },
6666
{ value: 'email', label: 'Email', type: 'text' },
6767
{ value: 'age', label: 'Age', type: 'number' },
68-
{ value: 'status', label: 'Status', type: 'text' },
69-
{ value: 'department', label: 'Department', type: 'text' },
70-
{ value: 'joinDate', label: 'Join Date', type: 'text' }
68+
{
69+
value: 'status',
70+
label: 'Status',
71+
type: 'select',
72+
options: [
73+
{ value: 'active', label: 'Active' },
74+
{ value: 'inactive', label: 'Inactive' },
75+
{ value: 'pending', label: 'Pending' }
76+
]
77+
},
78+
{
79+
value: 'department',
80+
label: 'Department',
81+
type: 'select',
82+
options: [
83+
{ value: 'engineering', label: 'Engineering' },
84+
{ value: 'sales', label: 'Sales' },
85+
{ value: 'marketing', label: 'Marketing' },
86+
{ value: 'support', label: 'Support' }
87+
]
88+
},
89+
{ value: 'joinDate', label: 'Join Date', type: 'date' },
90+
{ value: 'isVerified', label: 'Is Verified', type: 'boolean' }
7191
],
7292
value: {
7393
id: 'root',
@@ -85,8 +105,6 @@ const filterBuilderSchema = {
85105
}
86106
]
87107
},
88-
89-
// Example 2: Product Filtering
90108
{
91109
type: 'card',
92110
className: 'shadow-lg',
@@ -238,6 +256,22 @@ const filterBuilderSchema = {
238256
{ type: 'div', body: { type: 'text', content: 'AND/OR logic toggling' } }
239257
]
240258
},
259+
{
260+
type: 'div',
261+
className: 'flex items-start gap-2',
262+
body: [
263+
{ type: 'div', body: { type: 'text', content: '✓' }, className: 'text-primary font-bold' },
264+
{ type: 'div', body: { type: 'text', content: 'Date & Select field support' } }
265+
]
266+
},
267+
{
268+
type: 'div',
269+
className: 'flex items-start gap-2',
270+
body: [
271+
{ type: 'div', body: { type: 'text', content: '✓' }, className: 'text-primary font-bold' },
272+
{ type: 'div', body: { type: 'text', content: 'Clear all filters button' } }
273+
]
274+
},
241275
{
242276
type: 'div',
243277
className: 'flex items-start gap-2',

packages/components/docs/FilterBuilder.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ The Filter Builder component provides a user-friendly interface for creating and
88

99
- ✅ Dynamic add/remove filter conditions
1010
- ✅ Field selection from configurable list
11-
- ✅ Type-aware operators (text, number, boolean)
11+
- ✅ Type-aware operators (text, number, boolean, date, select)
1212
- ✅ AND/OR logic toggling
13+
- ✅ Clear all filters button
14+
- ✅ Date picker support for date fields
15+
- ✅ Dropdown support for select fields
1316
- ✅ Schema-driven configuration
1417
- ✅ Tailwind CSS styled with Shadcn UI components
1518

@@ -43,7 +46,7 @@ The Filter Builder component provides a user-friendly interface for creating and
4346
}
4447
```
4548

46-
### With Initial Empty State
49+
### With Select Fields
4750

4851
```typescript
4952
{
@@ -53,6 +56,16 @@ The Filter Builder component provides a user-friendly interface for creating and
5356
fields: [
5457
{ value: 'name', label: 'Product Name', type: 'text' },
5558
{ value: 'price', label: 'Price', type: 'number' },
59+
{
60+
value: 'category',
61+
label: 'Category',
62+
type: 'select',
63+
options: [
64+
{ value: 'electronics', label: 'Electronics' },
65+
{ value: 'clothing', label: 'Clothing' },
66+
{ value: 'food', label: 'Food' }
67+
]
68+
},
5669
{ value: 'inStock', label: 'In Stock', type: 'boolean' }
5770
],
5871
value: {
@@ -63,6 +76,23 @@ The Filter Builder component provides a user-friendly interface for creating and
6376
}
6477
```
6578

79+
### With Date Fields
80+
81+
```typescript
82+
{
83+
type: 'filter-builder',
84+
name: 'orderFilters',
85+
label: 'Order Filters',
86+
fields: [
87+
{ value: 'orderId', label: 'Order ID', type: 'text' },
88+
{ value: 'amount', label: 'Amount', type: 'number' },
89+
{ value: 'orderDate', label: 'Order Date', type: 'date' },
90+
{ value: 'shipped', label: 'Shipped', type: 'boolean' }
91+
],
92+
showClearAll: true
93+
}
94+
```
95+
6696
## Props
6797

6898
### Schema Properties
@@ -74,14 +104,16 @@ The Filter Builder component provides a user-friendly interface for creating and
74104
| `label` | `string` || Label displayed above the filter builder |
75105
| `fields` | `Field[]` || Array of available fields for filtering |
76106
| `value` | `FilterGroup` || Initial filter configuration |
107+
| `showClearAll` | `boolean` || Show "Clear all" button (default: true) |
77108

78109
### Field Type
79110

80111
```typescript
81112
interface Field {
82113
value: string; // Field identifier
83114
label: string; // Display label
84-
type?: string; // Field type: 'text' | 'number' | 'boolean'
115+
type?: string; // Field type: 'text' | 'number' | 'boolean' | 'date' | 'select'
116+
options?: Array<{ value: string; label: string }> // For select fields
85117
}
86118
```
87119

@@ -128,6 +160,23 @@ The available operators change based on the field type:
128160
- `equals` - Equals
129161
- `notEquals` - Does not equal
130162

163+
### Date Fields
164+
- `equals` - Equals
165+
- `notEquals` - Does not equal
166+
- `before` - Before
167+
- `after` - After
168+
- `between` - Between
169+
- `isEmpty` - Is empty
170+
- `isNotEmpty` - Is not empty
171+
172+
### Select Fields
173+
- `equals` - Equals
174+
- `notEquals` - Does not equal
175+
- `in` - In
176+
- `notIn` - Not in
177+
- `isEmpty` - Is empty
178+
- `isNotEmpty` - Is not empty
179+
131180
## Events
132181

133182
The component emits change events when the filter configuration is modified:

0 commit comments

Comments
 (0)