@k3-tech/react-kit 0.0.69 → 0.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2240 -754
- package/dist/kit/builder/data-table/components/DataTable.d.ts +15 -1
- package/dist/kit/builder/data-table/components/DataTable.d.ts.map +1 -1
- package/dist/kit/builder/data-table/components/DataTableFilterPanel.d.ts +15 -0
- package/dist/kit/builder/data-table/components/DataTableFilterPanel.d.ts.map +1 -0
- package/dist/kit/builder/form/components/FormBuilder.d.ts +1 -1
- package/dist/kit/builder/form/components/FormBuilder.d.ts.map +1 -1
- package/dist/kit/builder/form/types.d.ts +3 -0
- package/dist/kit/builder/form/types.d.ts.map +1 -1
- package/dist/kit/layouts/admin/components/AdminLayout.d.ts.map +1 -1
- package/dist/kit/themes/base.css +1 -1
- package/dist/kit/themes/clean-slate.css +319 -109
- package/dist/kit/themes/default.css +319 -109
- package/dist/kit/themes/minimal-modern.css +319 -109
- package/dist/kit/themes/spotify.css +319 -109
- package/dist/shadcn/ui/form.d.ts +1 -1
- package/dist/shadcn/ui/form.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/kit/builder/data-table/components/DataTable.tsx +147 -62
- package/src/kit/builder/data-table/components/DataTableFilterPanel.tsx +160 -0
- package/src/kit/builder/form/components/FormBuilder.tsx +8 -0
- package/src/kit/builder/form/types.ts +3 -0
- package/src/kit/layouts/admin/components/AdminLayout.tsx +261 -149
package/dist/shadcn/ui/form.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Slot } from '@radix-ui/react-slot';
|
|
|
2
2
|
import { ControllerProps, FieldPath, FieldValues } from 'react-hook-form';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import type * as LabelPrimitive from '@radix-ui/react-label';
|
|
5
|
-
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>(props: import('react-hook-form').FormProviderProps<TFieldValues, TContext, TTransformedValues>) =>
|
|
5
|
+
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>(props: import('react-hook-form').FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React.JSX.Element;
|
|
6
6
|
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
declare const useFormField: () => {
|
|
8
8
|
invalid: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/shadcn/ui/form.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,cAAc,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAKzB,QAAA,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/shadcn/ui/form.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,cAAc,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAKzB,QAAA,MAAM,IAAI,4MAAe,CAAC;AAa1B,QAAA,MAAM,SAAS,GACb,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,EAC/D,cAEC,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,4CAMtC,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;CAqBjB,CAAC;AAUF,iBAAS,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,2CAYrE;AAED,iBAAS,SAAS,CAAC,EACjB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,cAAc,CAAC,IAAI,CAAC,2CAYlD;AAED,iBAAS,WAAW,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,2CAiBnE;AAED,iBAAS,eAAe,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,2CAW1E;AAED,iBAAS,WAAW,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,kDAkBtE;AAED,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,eAAe,EACf,WAAW,EACX,SAAS,GACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -39,9 +39,23 @@ import type {
|
|
|
39
39
|
DataTableBatchAction,
|
|
40
40
|
DataTableFiltersProp,
|
|
41
41
|
} from '../types';
|
|
42
|
+
import { DataTableFilterPanel } from './DataTableFilterPanel';
|
|
42
43
|
import { DataTablePagination } from './DataTablePagination';
|
|
43
44
|
import { DataTableViewOptions } from './DataTableViewOptions';
|
|
44
45
|
|
|
46
|
+
// Slim 6px scrollbar for the table's scroll area. Chrome/Edge/Safari use the
|
|
47
|
+
// ::-webkit-scrollbar rules; Firefox only understands scrollbar-width, so it
|
|
48
|
+
// is scoped to Firefox — setting it makes Chrome ignore the webkit rules.
|
|
49
|
+
const THIN_SCROLLBAR = [
|
|
50
|
+
'[&::-webkit-scrollbar]:size-1.5',
|
|
51
|
+
'[&::-webkit-scrollbar-track]:bg-transparent',
|
|
52
|
+
'[&::-webkit-scrollbar-corner]:bg-transparent',
|
|
53
|
+
'[&::-webkit-scrollbar-thumb]:rounded-full',
|
|
54
|
+
'[&::-webkit-scrollbar-thumb]:bg-muted-foreground/30',
|
|
55
|
+
'[&::-webkit-scrollbar-thumb:hover]:bg-muted-foreground/50',
|
|
56
|
+
'supports-[-moz-appearance:none]:[scrollbar-width:thin]',
|
|
57
|
+
].join(' ');
|
|
58
|
+
|
|
45
59
|
export interface DataTableProps<TData, TValue> {
|
|
46
60
|
columns: ColumnDef<TData, TValue>[];
|
|
47
61
|
data: TData[];
|
|
@@ -72,6 +86,12 @@ export interface DataTableProps<TData, TValue> {
|
|
|
72
86
|
// UI
|
|
73
87
|
className?: string;
|
|
74
88
|
emptyText?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Rows shown before the table body starts scrolling (the header stays
|
|
91
|
+
* pinned), so long pages don't stretch the page. Set to 0 to let the table
|
|
92
|
+
* grow with its rows. Defaults to 10.
|
|
93
|
+
*/
|
|
94
|
+
maxVisibleRows?: number;
|
|
75
95
|
// Filters UI (section-based or simple) // what's so simple about this
|
|
76
96
|
formFilters?: DataTableFiltersProp;
|
|
77
97
|
formFilterValues?: Record<string, unknown> | null;
|
|
@@ -87,6 +107,14 @@ export interface DataTableProps<TData, TValue> {
|
|
|
87
107
|
// Row interactions
|
|
88
108
|
onRowClick?: (row: TData) => void;
|
|
89
109
|
// Filters wrapper options
|
|
110
|
+
/**
|
|
111
|
+
* Render filters in the collapsible filter panel (header toggle, active
|
|
112
|
+
* count, Apply/Clear). Defaults to true; `filterWrapper` only applies when
|
|
113
|
+
* this is false.
|
|
114
|
+
*/
|
|
115
|
+
filterCollapsible?: boolean;
|
|
116
|
+
/** Whether the collapsible filter panel starts open. Defaults to true. */
|
|
117
|
+
filterDefaultOpen?: boolean;
|
|
90
118
|
filterWrapper?: 'accordion' | 'card' | 'none';
|
|
91
119
|
filterTitle?: string;
|
|
92
120
|
filterShowActionsSeparator?: boolean;
|
|
@@ -123,6 +151,7 @@ export function DataTable<TData, TValue>({
|
|
|
123
151
|
onTable,
|
|
124
152
|
className,
|
|
125
153
|
emptyText = 'No results.',
|
|
154
|
+
maxVisibleRows = 10,
|
|
126
155
|
formFilterForm,
|
|
127
156
|
formFilters,
|
|
128
157
|
formFilterValues,
|
|
@@ -133,6 +162,8 @@ export function DataTable<TData, TValue>({
|
|
|
133
162
|
showStandardActions,
|
|
134
163
|
onRefresh,
|
|
135
164
|
onRowClick,
|
|
165
|
+
filterCollapsible = true,
|
|
166
|
+
filterDefaultOpen = true,
|
|
136
167
|
filterWrapper,
|
|
137
168
|
filterTitle,
|
|
138
169
|
filterShowActionsSeparator,
|
|
@@ -300,6 +331,39 @@ export function DataTable<TData, TValue>({
|
|
|
300
331
|
[effectivePaginationState.pageSize],
|
|
301
332
|
);
|
|
302
333
|
|
|
334
|
+
// Cap the scroll area at the height of the first `maxVisibleRows` rows.
|
|
335
|
+
// Measured rather than fixed because row height depends on cell content.
|
|
336
|
+
const scrollRef = React.useRef<HTMLDivElement>(null);
|
|
337
|
+
const [scrollMaxHeight, setScrollMaxHeight] = React.useState<number>();
|
|
338
|
+
|
|
339
|
+
React.useLayoutEffect(() => {
|
|
340
|
+
const container = scrollRef.current;
|
|
341
|
+
const tableEl = container?.querySelector('table');
|
|
342
|
+
if (!container || !tableEl || maxVisibleRows <= 0) {
|
|
343
|
+
setScrollMaxHeight(undefined);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const measure = () => {
|
|
347
|
+
const rows = tableEl.tBodies[0]?.rows;
|
|
348
|
+
if (!rows || rows.length <= maxVisibleRows) {
|
|
349
|
+
setScrollMaxHeight(undefined);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
// Header + first N rows, plus the horizontal scrollbar if one shows.
|
|
353
|
+
const height =
|
|
354
|
+
rows[maxVisibleRows - 1].getBoundingClientRect().bottom -
|
|
355
|
+
tableEl.getBoundingClientRect().top +
|
|
356
|
+
(container.offsetHeight - container.clientHeight);
|
|
357
|
+
// 0 while hidden (e.g. inactive tab); remeasured once it resizes.
|
|
358
|
+
setScrollMaxHeight(height > 0 ? Math.ceil(height) : undefined);
|
|
359
|
+
};
|
|
360
|
+
measure();
|
|
361
|
+
const observer = new ResizeObserver(measure);
|
|
362
|
+
observer.observe(tableEl);
|
|
363
|
+
observer.observe(container);
|
|
364
|
+
return () => observer.disconnect();
|
|
365
|
+
}, [maxVisibleRows]);
|
|
366
|
+
|
|
303
367
|
// Standard actions state
|
|
304
368
|
const handleRefresh = React.useCallback(async () => {
|
|
305
369
|
if (!onRefresh) return;
|
|
@@ -384,7 +448,17 @@ export function DataTable<TData, TValue>({
|
|
|
384
448
|
) : (
|
|
385
449
|
<>
|
|
386
450
|
{formFilters?.length ? (
|
|
387
|
-
|
|
451
|
+
filterCollapsible ? (
|
|
452
|
+
<DataTableFilterPanel
|
|
453
|
+
filters={formFilters}
|
|
454
|
+
title={effectiveFilterTitle}
|
|
455
|
+
form={formFilterForm}
|
|
456
|
+
values={formFilterValues}
|
|
457
|
+
onChange={onFormFilterChange}
|
|
458
|
+
showActionsSeparator={filterShowActionsSeparator}
|
|
459
|
+
defaultOpen={filterDefaultOpen}
|
|
460
|
+
/>
|
|
461
|
+
) : effectiveFilterWrapper === 'accordion' ? (
|
|
388
462
|
<div className="rounded-md border border-border">
|
|
389
463
|
<Accordion
|
|
390
464
|
type="single"
|
|
@@ -496,70 +570,81 @@ export function DataTable<TData, TValue>({
|
|
|
496
570
|
</span>
|
|
497
571
|
</div>
|
|
498
572
|
)}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
<Skeleton className="h-4 w-full" />
|
|
523
|
-
</TableCell>
|
|
573
|
+
{/* Scrolls both axes itself (the Table's own x-scroll wrapper is
|
|
574
|
+
neutralised) so the sticky header pins to this box. */}
|
|
575
|
+
<div
|
|
576
|
+
ref={scrollRef}
|
|
577
|
+
className={cn(
|
|
578
|
+
'overflow-auto *:data-[slot=table-container]:overflow-visible',
|
|
579
|
+
THIN_SCROLLBAR,
|
|
580
|
+
)}
|
|
581
|
+
style={{ maxHeight: scrollMaxHeight }}
|
|
582
|
+
>
|
|
583
|
+
<Table>
|
|
584
|
+
<TableHeader className="sticky top-0 z-1">
|
|
585
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
586
|
+
<TableRow key={headerGroup.id}>
|
|
587
|
+
{headerGroup.headers.map((header) => (
|
|
588
|
+
<TableHead key={header.id}>
|
|
589
|
+
{header.isPlaceholder
|
|
590
|
+
? null
|
|
591
|
+
: flexRender(
|
|
592
|
+
header.column.columnDef.header,
|
|
593
|
+
header.getContext(),
|
|
594
|
+
)}
|
|
595
|
+
</TableHead>
|
|
524
596
|
))}
|
|
525
597
|
</TableRow>
|
|
526
|
-
))
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
598
|
+
))}
|
|
599
|
+
</TableHeader>
|
|
600
|
+
<TableBody>
|
|
601
|
+
{loading ? (
|
|
602
|
+
skeletonRowKeys.map((rowKey) => (
|
|
603
|
+
<TableRow key={`skeleton-${rowKey}`}>
|
|
604
|
+
{table.getVisibleLeafColumns().map((col) => (
|
|
605
|
+
<TableCell key={`skeleton-cell-${rowKey}-${col.id}`}>
|
|
606
|
+
<Skeleton className="h-4 w-full" />
|
|
607
|
+
</TableCell>
|
|
608
|
+
))}
|
|
609
|
+
</TableRow>
|
|
610
|
+
))
|
|
611
|
+
) : table.getRowModel().rows?.length ? (
|
|
612
|
+
table.getRowModel().rows.map((row) => (
|
|
613
|
+
<TableRow
|
|
614
|
+
key={row.id}
|
|
615
|
+
data-state={row.getIsSelected() && 'selected'}
|
|
616
|
+
className={cn(
|
|
617
|
+
onRowClick && 'cursor-pointer hover:bg-muted/50',
|
|
618
|
+
)}
|
|
619
|
+
onClick={
|
|
620
|
+
onRowClick
|
|
621
|
+
? () => onRowClick(row.original as TData)
|
|
622
|
+
: undefined
|
|
623
|
+
}
|
|
624
|
+
>
|
|
625
|
+
{row.getVisibleCells().map((cell) => (
|
|
626
|
+
<TableCell key={cell.id}>
|
|
627
|
+
{flexRender(
|
|
628
|
+
cell.column.columnDef.cell,
|
|
629
|
+
cell.getContext(),
|
|
630
|
+
)}
|
|
631
|
+
</TableCell>
|
|
632
|
+
))}
|
|
633
|
+
</TableRow>
|
|
634
|
+
))
|
|
635
|
+
) : (
|
|
636
|
+
<TableRow>
|
|
637
|
+
<TableCell
|
|
638
|
+
colSpan={table.getVisibleLeafColumns().length}
|
|
639
|
+
className="h-24 text-center"
|
|
640
|
+
>
|
|
641
|
+
{emptyText}
|
|
642
|
+
</TableCell>
|
|
549
643
|
</TableRow>
|
|
550
|
-
)
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
colSpan={table.getVisibleLeafColumns().length}
|
|
555
|
-
className="h-24 text-center"
|
|
556
|
-
>
|
|
557
|
-
{emptyText}
|
|
558
|
-
</TableCell>
|
|
559
|
-
</TableRow>
|
|
560
|
-
)}
|
|
561
|
-
</TableBody>
|
|
562
|
-
</Table>
|
|
644
|
+
)}
|
|
645
|
+
</TableBody>
|
|
646
|
+
</Table>
|
|
647
|
+
</div>
|
|
563
648
|
</div>
|
|
564
649
|
|
|
565
650
|
{isPaginationEnabled && (
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Check, ChevronDown, RotateCcw, SlidersHorizontal } from 'lucide-react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type { UseFormReturn } from 'react-hook-form';
|
|
4
|
+
import { cn } from '../../../../shadcn/lib/utils';
|
|
5
|
+
import { FormBuilder, type FormBuilderSectionConfig } from '../../form';
|
|
6
|
+
import type { DataTableFiltersProp } from '../types';
|
|
7
|
+
|
|
8
|
+
type FilterValues = Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export interface DataTableFilterPanelProps {
|
|
11
|
+
filters: DataTableFiltersProp;
|
|
12
|
+
title?: string;
|
|
13
|
+
form?: UseFormReturn<any>;
|
|
14
|
+
values?: FilterValues | null;
|
|
15
|
+
onChange?: (values: FilterValues) => void;
|
|
16
|
+
showActionsSeparator?: boolean;
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const safeStringify = (value: unknown) => {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(value ?? {});
|
|
23
|
+
} catch {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isEmptyValue = (value: unknown) =>
|
|
29
|
+
value === undefined ||
|
|
30
|
+
value === null ||
|
|
31
|
+
value === '' ||
|
|
32
|
+
(Array.isArray(value) && value.length === 0);
|
|
33
|
+
|
|
34
|
+
// Applied filters that differ from the field's own default — so preset values
|
|
35
|
+
// (e.g. a "search by" selector) don't read as active filters.
|
|
36
|
+
function countActiveFilters(
|
|
37
|
+
values: FilterValues | null | undefined,
|
|
38
|
+
filters: DataTableFiltersProp,
|
|
39
|
+
) {
|
|
40
|
+
if (!values) return 0;
|
|
41
|
+
const defaults = new Map<string, unknown>();
|
|
42
|
+
for (const section of filters) {
|
|
43
|
+
for (const field of section.fields ?? []) {
|
|
44
|
+
defaults.set(String(field.name), field.defaultValue);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return Object.entries(values).filter(
|
|
48
|
+
([name, value]) =>
|
|
49
|
+
!isEmptyValue(value) &&
|
|
50
|
+
safeStringify(value) !== safeStringify(defaults.get(name)),
|
|
51
|
+
).length;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function DataTableFilterPanel({
|
|
55
|
+
filters,
|
|
56
|
+
title = 'Filters',
|
|
57
|
+
form,
|
|
58
|
+
values,
|
|
59
|
+
onChange,
|
|
60
|
+
showActionsSeparator,
|
|
61
|
+
defaultOpen = true,
|
|
62
|
+
}: DataTableFilterPanelProps) {
|
|
63
|
+
const [open, setOpen] = React.useState(defaultOpen);
|
|
64
|
+
const [applied, setApplied] = React.useState(values);
|
|
65
|
+
const contentId = React.useId();
|
|
66
|
+
|
|
67
|
+
// Compare by content: callers often pass a fresh object every render.
|
|
68
|
+
const valuesKey = safeStringify(values);
|
|
69
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: keyed on content
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
setApplied(values);
|
|
72
|
+
}, [valuesKey]);
|
|
73
|
+
|
|
74
|
+
const activeCount = React.useMemo(
|
|
75
|
+
() => countActiveFilters(applied, filters),
|
|
76
|
+
[applied, filters],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className="rounded-lg border border-border bg-card shadow-xs">
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
aria-expanded={open}
|
|
84
|
+
aria-controls={contentId}
|
|
85
|
+
onClick={() => setOpen((prev) => !prev)}
|
|
86
|
+
className={cn(
|
|
87
|
+
'flex w-full items-center gap-3 px-4 py-3 text-left outline-none transition-colors hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-ring/50',
|
|
88
|
+
open ? 'rounded-t-lg' : 'rounded-lg',
|
|
89
|
+
)}
|
|
90
|
+
>
|
|
91
|
+
<span className="flex size-8 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary">
|
|
92
|
+
<SlidersHorizontal className="size-4" />
|
|
93
|
+
</span>
|
|
94
|
+
<span className="flex min-w-0 flex-1 items-center gap-2">
|
|
95
|
+
<span className="truncate text-sm font-semibold text-foreground">
|
|
96
|
+
{title}
|
|
97
|
+
</span>
|
|
98
|
+
{activeCount > 0 && (
|
|
99
|
+
<span className="shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary">
|
|
100
|
+
{activeCount} active
|
|
101
|
+
</span>
|
|
102
|
+
)}
|
|
103
|
+
</span>
|
|
104
|
+
<span className="text-xs text-muted-foreground">
|
|
105
|
+
{open ? 'Hide' : 'Show'}
|
|
106
|
+
</span>
|
|
107
|
+
<ChevronDown
|
|
108
|
+
className={cn(
|
|
109
|
+
'size-4 shrink-0 text-muted-foreground transition-transform duration-200',
|
|
110
|
+
open && 'rotate-180',
|
|
111
|
+
)}
|
|
112
|
+
/>
|
|
113
|
+
</button>
|
|
114
|
+
|
|
115
|
+
{/* Stays mounted while collapsed so typed-but-unapplied values survive;
|
|
116
|
+
the grid-rows trick animates the height. Dropdowns are portalled, so
|
|
117
|
+
overflow-hidden doesn't clip them. */}
|
|
118
|
+
<div
|
|
119
|
+
id={contentId}
|
|
120
|
+
className={cn(
|
|
121
|
+
'grid transition-[grid-template-rows] duration-200 ease-out',
|
|
122
|
+
open ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]',
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
<div className="min-h-0 overflow-hidden" inert={!open}>
|
|
126
|
+
<div className="border-t border-border p-4">
|
|
127
|
+
<FormBuilder
|
|
128
|
+
key={valuesKey}
|
|
129
|
+
form={form}
|
|
130
|
+
sections={filters as FormBuilderSectionConfig[]}
|
|
131
|
+
defaultValues={values}
|
|
132
|
+
onSubmit={(data) => {
|
|
133
|
+
const next = data as FilterValues;
|
|
134
|
+
setApplied(next);
|
|
135
|
+
onChange?.(next);
|
|
136
|
+
}}
|
|
137
|
+
onReset={() => {
|
|
138
|
+
setApplied({});
|
|
139
|
+
onChange?.({});
|
|
140
|
+
}}
|
|
141
|
+
showActions
|
|
142
|
+
submitLabel="Apply"
|
|
143
|
+
resetLabel="Clear"
|
|
144
|
+
submitIcon={<Check />}
|
|
145
|
+
resetIcon={<RotateCcw />}
|
|
146
|
+
actionsSize="sm"
|
|
147
|
+
className="space-y-4"
|
|
148
|
+
formClassName="space-y-4"
|
|
149
|
+
actionsClassName={cn(
|
|
150
|
+
'sm:justify-end',
|
|
151
|
+
showActionsSeparator !== false && 'pt-4',
|
|
152
|
+
)}
|
|
153
|
+
showActionsSeparator={showActionsSeparator}
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
@@ -43,6 +43,9 @@ function FormBuilderInner<TFieldValues extends FieldValues = FieldValues>(
|
|
|
43
43
|
showActions = true,
|
|
44
44
|
customActions,
|
|
45
45
|
showActionsSeparator = true,
|
|
46
|
+
submitIcon,
|
|
47
|
+
resetIcon,
|
|
48
|
+
actionsSize = 'default',
|
|
46
49
|
form,
|
|
47
50
|
extendValidation,
|
|
48
51
|
}: FormBuilderProps<TFieldValues>,
|
|
@@ -277,9 +280,11 @@ function FormBuilderInner<TFieldValues extends FieldValues = FieldValues>(
|
|
|
277
280
|
>
|
|
278
281
|
<Button
|
|
279
282
|
type="submit"
|
|
283
|
+
size={actionsSize}
|
|
280
284
|
disabled={isSubmitting}
|
|
281
285
|
className="sm:order-last"
|
|
282
286
|
>
|
|
287
|
+
{submitIcon}
|
|
283
288
|
{isSubmitting ? 'Submitting...' : submitLabel}
|
|
284
289
|
</Button>
|
|
285
290
|
|
|
@@ -287,6 +292,7 @@ function FormBuilderInner<TFieldValues extends FieldValues = FieldValues>(
|
|
|
287
292
|
<Button
|
|
288
293
|
type="button"
|
|
289
294
|
variant="outline"
|
|
295
|
+
size={actionsSize}
|
|
290
296
|
onClick={onCancel}
|
|
291
297
|
disabled={isSubmitting}
|
|
292
298
|
>
|
|
@@ -298,9 +304,11 @@ function FormBuilderInner<TFieldValues extends FieldValues = FieldValues>(
|
|
|
298
304
|
<Button
|
|
299
305
|
type="button"
|
|
300
306
|
variant="outline"
|
|
307
|
+
size={actionsSize}
|
|
301
308
|
onClick={handleReset}
|
|
302
309
|
disabled={isSubmitting}
|
|
303
310
|
>
|
|
311
|
+
{resetIcon}
|
|
304
312
|
{resetLabel}
|
|
305
313
|
</Button>
|
|
306
314
|
)}
|
|
@@ -273,6 +273,9 @@ export interface FormBuilderProps<
|
|
|
273
273
|
showActions?: boolean;
|
|
274
274
|
customActions?: React.ReactNode;
|
|
275
275
|
showActionsSeparator?: boolean;
|
|
276
|
+
submitIcon?: React.ReactNode;
|
|
277
|
+
resetIcon?: React.ReactNode;
|
|
278
|
+
actionsSize?: 'default' | 'sm';
|
|
276
279
|
|
|
277
280
|
// Validation extender
|
|
278
281
|
extendValidation?: (originalSchema: z.ZodType<TFieldValues>) => z.ZodType<TFieldValues>,
|