@drivenets/design-system 0.12.0 → 0.13.0
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/CHANGELOG.md +21 -0
- package/dist/index.cjs +1652 -455
- package/dist/index.d.cts +1226 -989
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1226 -989
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1643 -456
- package/dist/index.js.map +1 -1
- package/dist/index.min.css +1 -1
- package/package.json +31 -31
- package/src/components/ds-catalog-layout/catalog-layout-empty-illustration.tsx +57 -0
- package/src/components/ds-catalog-layout/ds-catalog-layout.context.ts +19 -0
- package/src/components/ds-catalog-layout/ds-catalog-layout.module.scss +167 -0
- package/src/components/ds-catalog-layout/ds-catalog-layout.tsx +130 -0
- package/src/components/ds-catalog-layout/ds-catalog-layout.types.ts +62 -0
- package/src/components/ds-catalog-layout/index.ts +9 -0
- package/src/components/ds-date-input/ds-date-input.utils.ts +2 -2
- package/src/components/ds-drawer/ds-drawer.tsx +2 -0
- package/src/components/ds-form-control/ds-form-control.tsx +14 -11
- package/src/components/ds-form-control/ds-form-control.types.ts +4 -0
- package/src/components/ds-grid/ds-grid.tsx +1 -2
- package/src/components/ds-modal/ds-modal.tsx +3 -0
- package/src/components/ds-smart-tabs/ds-smart-tabs.module.scss +1 -0
- package/src/components/ds-table/components/ds-table-body-virtualized/ds-table-body-virtualized.module.scss +21 -2
- package/src/components/ds-table/components/ds-table-body-virtualized/ds-table-body-virtualized.tsx +14 -11
- package/src/components/ds-table/components/ds-table-body-virtualized/ds-table-body-virtualized.types.ts +1 -6
- package/src/components/ds-table/components/ds-table-bulk-actions/ds-table-bulk-actions.module.scss +2 -2
- package/src/components/ds-table/components/ds-table-cell/ds-table-cell.module.scss +2 -0
- package/src/components/ds-table/components/ds-table-cell/ds-table-cell.tsx +42 -11
- package/src/components/ds-table/components/ds-table-header/ds-table-header.module.scss +24 -4
- package/src/components/ds-table/components/ds-table-header/ds-table-header.tsx +22 -1
- package/src/components/ds-table/components/ds-table-row/ds-table-row.module.scss +22 -0
- package/src/components/ds-table/components/ds-table-row/ds-table-row.tsx +1 -0
- package/src/components/ds-table/components/ds-table-row-virtualized/ds-table-row-virtualized.module.scss +19 -0
- package/src/components/ds-table/components/ds-table-row-virtualized/ds-table-row-virtualized.tsx +2 -1
- package/src/components/ds-table/components/ds-table-row-virtualized/ds-table-row-virtualized.types.ts +1 -1
- package/src/components/ds-table/components/edit/cell-editors/cell-editors.module.scss +3 -0
- package/src/components/ds-table/components/edit/cell-editors/ds-table-edit-cell-checkbox.tsx +27 -0
- package/src/components/ds-table/components/edit/cell-editors/ds-table-edit-cell-date.tsx +50 -0
- package/src/components/ds-table/components/edit/cell-editors/ds-table-edit-cell-number.tsx +51 -0
- package/src/components/ds-table/components/edit/cell-editors/ds-table-edit-cell-select.tsx +36 -0
- package/src/components/ds-table/components/edit/cell-editors/ds-table-edit-cell-text.tsx +50 -0
- package/src/components/ds-table/components/edit/cell-editors/index.ts +14 -0
- package/src/components/ds-table/components/edit/cell-editors/table-edit-form-control.tsx +31 -0
- package/src/components/ds-table/components/edit/ds-table-editable-cell/ds-table-editable-cell.module.scss +28 -0
- package/src/components/ds-table/components/edit/ds-table-editable-cell/ds-table-editable-cell.tsx +39 -0
- package/src/components/ds-table/components/edit/ds-table-editable-cell/ds-table-editable-cell.types.ts +7 -0
- package/src/components/ds-table/components/edit/ds-table-editable-cell/index.ts +2 -0
- package/src/components/ds-table/components/edit/ds-table-editing-cell/ds-table-editing-cell.module.scss +48 -0
- package/src/components/ds-table/components/edit/ds-table-editing-cell/ds-table-editing-cell.tsx +76 -0
- package/src/components/ds-table/components/edit/ds-table-editing-cell/ds-table-editing-cell.types.ts +5 -0
- package/src/components/ds-table/components/edit/ds-table-editing-cell/index.ts +2 -0
- package/src/components/ds-table/context/ds-table-context.ts +79 -1
- package/src/components/ds-table/ds-table-column.types.ts +12 -0
- package/src/components/ds-table/ds-table.module.scss +100 -10
- package/src/components/ds-table/ds-table.tsx +18 -19
- package/src/components/ds-table/ds-table.types.ts +52 -0
- package/src/components/ds-table/filters/adapters/create-checkbox-filter-adapter.tsx +24 -40
- package/src/components/ds-table/filters/adapters/create-dual-range-filter-adapter.tsx +10 -31
- package/src/components/ds-table/filters/adapters/create-filter-adapter.ts +6 -98
- package/src/components/ds-table/filters/components/checkbox-filter/checkbox-filter.module.scss +36 -0
- package/src/components/ds-table/filters/components/checkbox-filter/checkbox-filter.tsx +92 -13
- package/src/components/ds-table/filters/components/checkbox-filter/index.ts +1 -1
- package/src/components/ds-table/filters/components/column-filter-popover/column-filter-popover.module.scss +42 -0
- package/src/components/ds-table/filters/components/column-filter-popover/column-filter-popover.tsx +89 -0
- package/src/components/ds-table/filters/components/column-filter-popover/column-filter-popover.types.ts +25 -0
- package/src/components/ds-table/filters/components/column-filter-popover/index.ts +5 -0
- package/src/components/ds-table/filters/hooks/use-table-filters.ts +113 -78
- package/src/components/ds-table/filters/index.ts +2 -44
- package/src/components/ds-table/filters/types/column-meta.augmentation.ts +19 -0
- package/src/components/ds-table/filters/types/filter-adapter.types.ts +48 -81
- package/src/components/ds-table/hooks/use-cell-editor.ts +81 -0
- package/src/components/ds-table/index.ts +29 -0
- package/src/components/ds-table/utils/column-size.ts +9 -8
- package/src/components/ds-tag/ds-tag.tsx +2 -2
- package/src/components/ds-workspace-layout/ds-workspace-layout.context.ts +19 -0
- package/src/components/ds-workspace-layout/ds-workspace-layout.module.scss +166 -0
- package/src/components/ds-workspace-layout/ds-workspace-layout.tsx +135 -0
- package/src/components/ds-workspace-layout/ds-workspace-layout.types.ts +52 -0
- package/src/components/ds-workspace-layout/index.ts +11 -0
- package/src/index.ts +2 -1
- package/src/styles/_scrollbars.scss +37 -0
- package/src/utils/restore-document-body-modal-styles.ts +44 -0
- package/src/utils/use-ark-dialog-body-lock-cleanup.ts +36 -0
- package/src/components/ds-workspace/ds-workspace.module.scss +0 -55
- package/src/components/ds-workspace/ds-workspace.tsx +0 -37
- package/src/components/ds-workspace/ds-workspace.types.ts +0 -17
- package/src/components/ds-workspace/index.ts +0 -8
|
@@ -1,54 +1,36 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { Row } from '@tanstack/react-table';
|
|
3
3
|
import type { FilterAdapter } from '../types/filter-adapter.types';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type CheckboxFilterItem,
|
|
6
|
+
type CheckboxFilterLocale,
|
|
7
|
+
CheckboxFilter,
|
|
8
|
+
} from '../components/checkbox-filter';
|
|
5
9
|
import { createFilterAdapter } from './create-filter-adapter';
|
|
6
10
|
|
|
7
11
|
export interface CheckboxFilterAdapterConfig<TData, TValue> {
|
|
8
|
-
/**
|
|
9
|
-
* Unique identifier (should match column accessorKey)
|
|
10
|
-
*/
|
|
12
|
+
/** Unique id, should match the column `accessorKey`. */
|
|
11
13
|
id: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Display label for filter navigation
|
|
15
|
-
*/
|
|
16
14
|
label: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Available items to select from
|
|
20
|
-
*/
|
|
15
|
+
/** Selectable items. */
|
|
21
16
|
items: CheckboxFilterItem<TValue>[];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Optional custom renderer for each item
|
|
25
|
-
*/
|
|
17
|
+
/** Custom row renderer; defaults to `item.label`. */
|
|
26
18
|
renderer?: (item: CheckboxFilterItem<TValue>) => ReactNode;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Optional custom chip label generator
|
|
30
|
-
* @default (item) => `${label}: ${item.label}`
|
|
31
|
-
*/
|
|
19
|
+
/** @default (item) => `${label}: ${item.label}` */
|
|
32
20
|
chipLabelTemplate?: (item: CheckboxFilterItem<TValue>) => string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Optional custom cell renderer for table column
|
|
36
|
-
*/
|
|
37
21
|
cellRenderer?: (value: TValue) => ReactNode;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* How to extract the value from a row for comparison
|
|
41
|
-
* @default (row) => row.getValue(id)
|
|
42
|
-
*/
|
|
22
|
+
/** @default (row) => row.getValue(id) */
|
|
43
23
|
getRowValue?: (row: Row<TData>) => TValue;
|
|
24
|
+
/** Show a search input above the list. @default false */
|
|
25
|
+
searchable?: boolean;
|
|
26
|
+
/** Show an "All" toggle that selects / clears every (visible) item. @default false */
|
|
27
|
+
selectAll?: boolean;
|
|
28
|
+
locale?: CheckboxFilterLocale;
|
|
44
29
|
}
|
|
45
30
|
|
|
46
31
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* Handles multi-select checkbox filtering with inclusion model:
|
|
50
|
-
* - Empty selection = show all data (no filter active)
|
|
51
|
-
* - Selected items = show only those items
|
|
32
|
+
* Multi-select inclusion filter: empty selection shows every row, selected
|
|
33
|
+
* items show only those rows.
|
|
52
34
|
*/
|
|
53
35
|
export function createCheckboxFilterAdapter<TData, TValue = string>(
|
|
54
36
|
config: CheckboxFilterAdapterConfig<TData, TValue>,
|
|
@@ -61,20 +43,21 @@ export function createCheckboxFilterAdapter<TData, TValue = string>(
|
|
|
61
43
|
chipLabelTemplate = (item) => `${label}: ${item.label}`,
|
|
62
44
|
cellRenderer,
|
|
63
45
|
getRowValue = (row) => row.getValue(id),
|
|
46
|
+
searchable = false,
|
|
47
|
+
selectAll = false,
|
|
48
|
+
locale,
|
|
64
49
|
} = config;
|
|
65
50
|
|
|
66
51
|
return createFilterAdapter<TData, CheckboxFilterItem<TValue>[], TValue>({
|
|
67
52
|
id,
|
|
68
53
|
label,
|
|
69
|
-
initialValue: [],
|
|
54
|
+
initialValue: [],
|
|
70
55
|
|
|
71
56
|
filterFn: (row, columnId, filterValue) => {
|
|
72
|
-
// Empty selection = no filter = show all
|
|
73
57
|
if (filterValue.length === 0) {
|
|
74
58
|
return true;
|
|
75
59
|
}
|
|
76
60
|
|
|
77
|
-
// Otherwise, show only selected items
|
|
78
61
|
const rowValue = getRowValue(row);
|
|
79
62
|
return filterValue.some((item) => item.value === rowValue);
|
|
80
63
|
},
|
|
@@ -82,7 +65,6 @@ export function createCheckboxFilterAdapter<TData, TValue = string>(
|
|
|
82
65
|
cellRenderer,
|
|
83
66
|
|
|
84
67
|
toChips: (selectedItems) => {
|
|
85
|
-
// Generate chips for all selected items
|
|
86
68
|
return selectedItems.map((item) => ({
|
|
87
69
|
id: `${id}_${String(item.value)}`,
|
|
88
70
|
label: chipLabelTemplate(item),
|
|
@@ -98,7 +80,6 @@ export function createCheckboxFilterAdapter<TData, TValue = string>(
|
|
|
98
80
|
},
|
|
99
81
|
|
|
100
82
|
getActiveFiltersCount: (selectedItems) => {
|
|
101
|
-
// Count = number of selected items (0 means none selected)
|
|
102
83
|
return selectedItems.length;
|
|
103
84
|
},
|
|
104
85
|
|
|
@@ -109,6 +90,9 @@ export function createCheckboxFilterAdapter<TData, TValue = string>(
|
|
|
109
90
|
renderer={renderer}
|
|
110
91
|
selectedItems={value}
|
|
111
92
|
onSelectionChange={onChange}
|
|
93
|
+
searchable={searchable}
|
|
94
|
+
selectAll={selectAll}
|
|
95
|
+
locale={locale}
|
|
112
96
|
/>
|
|
113
97
|
);
|
|
114
98
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Row } from '@tanstack/react-table';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TagFilterItem } from '../../../ds-tag-filter';
|
|
3
3
|
import type { FilterAdapter } from '../types/filter-adapter.types';
|
|
4
4
|
import { RangeFilter } from '../components/range-filter';
|
|
5
5
|
import { createFilterAdapter } from './create-filter-adapter';
|
|
@@ -14,39 +14,18 @@ export interface DualRangeFilterValue {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface DualRangeFilterAdapterConfig<TData> {
|
|
17
|
-
/**
|
|
18
|
-
* Unique identifier (should match column accessorKey)
|
|
19
|
-
*/
|
|
17
|
+
/** Unique id, should match the column `accessorKey`. */
|
|
20
18
|
id: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Display label for filter navigation
|
|
24
|
-
*/
|
|
25
19
|
label: string;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Field configurations: { fieldKey: displayLabel }
|
|
29
|
-
* Example: { running: 'Running', completed: 'Completed' }
|
|
30
|
-
*/
|
|
20
|
+
/** Field key → display label, e.g. `{ running: 'Running' }`. */
|
|
31
21
|
fields: Record<string, string>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Optional formatter for chip display
|
|
35
|
-
* @default (num) => num.toLocaleString('en-US')
|
|
36
|
-
*/
|
|
22
|
+
/** @default (num) => num.toLocaleString('en-US') */
|
|
37
23
|
formatNumber?: (num: number) => string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* How to extract the value object from a row
|
|
41
|
-
* @default (row) => row.getValue(id)
|
|
42
|
-
*/
|
|
24
|
+
/** @default (row) => row.getValue(id) */
|
|
43
25
|
getRowValue?: (row: Row<TData>) => Record<string, number>;
|
|
44
26
|
}
|
|
45
27
|
|
|
46
|
-
/**
|
|
47
|
-
* Factory function to create a dual-range filter adapter
|
|
48
|
-
* Handles filtering on multiple numeric ranges within a single column
|
|
49
|
-
*/
|
|
28
|
+
/** Filter over multiple numeric ranges within one column (AND across fields). */
|
|
50
29
|
export function createDualRangeFilterAdapter<TData>(
|
|
51
30
|
config: DualRangeFilterAdapterConfig<TData>,
|
|
52
31
|
): FilterAdapter<TData, DualRangeFilterValue, Record<string, number>> {
|
|
@@ -71,7 +50,6 @@ export function createDualRangeFilterAdapter<TData>(
|
|
|
71
50
|
filterFn: (row, columnId, filterValue) => {
|
|
72
51
|
const rowValue = getRowValue(row);
|
|
73
52
|
|
|
74
|
-
// Check each field's range
|
|
75
53
|
for (const [fieldKey, range] of Object.entries(filterValue)) {
|
|
76
54
|
const hasFilter = range.from !== undefined || range.to !== undefined;
|
|
77
55
|
const fieldValue = rowValue[fieldKey];
|
|
@@ -80,8 +58,9 @@ export function createDualRangeFilterAdapter<TData>(
|
|
|
80
58
|
const matchesFrom = range.from === undefined || fieldValue >= range.from;
|
|
81
59
|
const matchesTo = range.to === undefined || fieldValue <= range.to;
|
|
82
60
|
|
|
61
|
+
// AND across fields: every range with a bound must match.
|
|
83
62
|
if (!matchesFrom || !matchesTo) {
|
|
84
|
-
return false;
|
|
63
|
+
return false;
|
|
85
64
|
}
|
|
86
65
|
}
|
|
87
66
|
}
|
|
@@ -89,10 +68,10 @@ export function createDualRangeFilterAdapter<TData>(
|
|
|
89
68
|
return true;
|
|
90
69
|
},
|
|
91
70
|
|
|
92
|
-
cellRenderer: undefined,
|
|
71
|
+
cellRenderer: undefined,
|
|
93
72
|
|
|
94
73
|
toChips: (value) => {
|
|
95
|
-
const chips:
|
|
74
|
+
const chips: TagFilterItem[] = [];
|
|
96
75
|
|
|
97
76
|
Object.entries(value).forEach(([fieldKey, range]) => {
|
|
98
77
|
const hasFilter = range.from !== undefined || range.to !== undefined;
|
|
@@ -2,116 +2,24 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
import type { FilterAdapter } from '../types/filter-adapter.types';
|
|
3
3
|
|
|
4
4
|
export interface FilterAdapterConfig<TData, TFilterValue, TCellValue = unknown> {
|
|
5
|
-
/**
|
|
6
|
-
* Unique identifier (should match column accessorKey)
|
|
7
|
-
*/
|
|
5
|
+
/** Unique id, should match the column `accessorKey`. */
|
|
8
6
|
id: string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Display label for filter navigation
|
|
12
|
-
*/
|
|
13
7
|
label: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initial/default value for the filter
|
|
17
|
-
*/
|
|
18
8
|
initialValue: TFilterValue;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Filter function - determines if row matches filter value
|
|
22
|
-
*/
|
|
9
|
+
/** TanStack `filterFn` for this column. */
|
|
23
10
|
filterFn: FilterAdapter<TData, TFilterValue, TCellValue>['columnFilterFn'];
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Convert filter value to display chips
|
|
27
|
-
*/
|
|
28
11
|
toChips: FilterAdapter<TData, TFilterValue, TCellValue>['toChips'];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Remove chip effect from filter value
|
|
32
|
-
*/
|
|
33
12
|
fromChip: FilterAdapter<TData, TFilterValue, TCellValue>['fromChip'];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Calculate active filter count
|
|
37
|
-
*/
|
|
38
13
|
getActiveFiltersCount: FilterAdapter<TData, TFilterValue, TCellValue>['getActiveFiltersCount'];
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Render the filter UI
|
|
42
|
-
*/
|
|
43
14
|
renderFilter: (value: TFilterValue, onChange: (value: TFilterValue) => void) => ReactNode;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Optional custom cell renderer for table cells
|
|
47
|
-
* Note: This receives the cell value from the table, not the filter value
|
|
48
|
-
*/
|
|
15
|
+
/** Cell renderer; receives the cell value, not the filter value. */
|
|
49
16
|
cellRenderer?: (value: TCellValue) => ReactNode;
|
|
50
17
|
}
|
|
51
18
|
|
|
52
19
|
/**
|
|
53
|
-
* Base factory
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* Use this when checkbox or dual-range adapters don't fit your requirements.
|
|
57
|
-
*
|
|
58
|
-
* ## When to use directly:
|
|
59
|
-
* - Complex filtering logic (e.g., editor + date range)
|
|
60
|
-
* - Unique UI that doesn't fit generic patterns
|
|
61
|
-
* - Combining multiple sub-filters
|
|
62
|
-
* - Special chip generation requirements
|
|
63
|
-
*
|
|
64
|
-
* ## When to use specialized helpers instead:
|
|
65
|
-
* - **Checkbox filters**: Use `createCheckboxFilterAdapter` for multi-select
|
|
66
|
-
* - **Range filters**: Use `createDualRangeFilterAdapter` for numeric ranges
|
|
67
|
-
*
|
|
68
|
-
* ## Example:
|
|
69
|
-
* ```typescript
|
|
70
|
-
* interface MyFilterValue {
|
|
71
|
-
* users: string[];
|
|
72
|
-
* dateRange: { from?: Date; to?: Date };
|
|
73
|
-
* }
|
|
74
|
-
*
|
|
75
|
-
* const myFilter = createFilterAdapter<DataType, MyFilterValue>({
|
|
76
|
-
* id: 'myColumn',
|
|
77
|
-
* label: 'My Filter',
|
|
78
|
-
* initialValue: { users: [], dateRange: {} },
|
|
79
|
-
*
|
|
80
|
-
* filterFn: (row, columnId, filterValue) => {
|
|
81
|
-
* // Your custom logic
|
|
82
|
-
* return matchesUsers && matchesDateRange;
|
|
83
|
-
* },
|
|
84
|
-
*
|
|
85
|
-
* toChips: (value) => {
|
|
86
|
-
* // Generate chips from your filter value
|
|
87
|
-
* return chips;
|
|
88
|
-
* },
|
|
89
|
-
*
|
|
90
|
-
* fromChip: (chip, currentValue) => {
|
|
91
|
-
* // Remove chip's effect from value
|
|
92
|
-
* return updatedValue;
|
|
93
|
-
* },
|
|
94
|
-
*
|
|
95
|
-
* getActiveFiltersCount: (value) => {
|
|
96
|
-
* // Count active filters (0 means none active)
|
|
97
|
-
* return count;
|
|
98
|
-
* },
|
|
99
|
-
*
|
|
100
|
-
* renderFilter: (value, onChange) => (
|
|
101
|
-
* <YourCustomFilterComponent
|
|
102
|
-
* value={value}
|
|
103
|
-
* onChange={onChange}
|
|
104
|
-
* />
|
|
105
|
-
* ),
|
|
106
|
-
* });
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* ## Reference Implementation:
|
|
110
|
-
* See `workflow-filters.config.tsx` for a complete example (lastEditedFilterAdapter).
|
|
111
|
-
*
|
|
112
|
-
* ## Note:
|
|
113
|
-
* Most use cases are covered by `createCheckboxFilterAdapter` or `createDualRangeFilterAdapter`.
|
|
114
|
-
* Only use this base function directly when you need completely custom filter logic.
|
|
20
|
+
* Base factory used by every specialized adapter. Reach for it only when
|
|
21
|
+
* `createCheckboxFilterAdapter` / `createDualRangeFilterAdapter` don't fit
|
|
22
|
+
* (custom UI, mixed sub-filters, bespoke chip logic).
|
|
115
23
|
*/
|
|
116
24
|
export function createFilterAdapter<TData, TFilterValue, TCellValue = unknown>(
|
|
117
25
|
config: FilterAdapterConfig<TData, TFilterValue, TCellValue>,
|
package/src/components/ds-table/filters/components/checkbox-filter/checkbox-filter.module.scss
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
@use '../../../../../styles/typography';
|
|
2
|
+
|
|
3
|
+
.root {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
min-width: 248px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.list {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
max-height: 280px;
|
|
13
|
+
overflow-y: auto;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.empty {
|
|
17
|
+
@include typography.body-sm-reg;
|
|
18
|
+
color: var(--font-secondary);
|
|
19
|
+
padding: var(--xs) var(--3xs);
|
|
20
|
+
text-align: center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.checkboxItem {
|
|
24
|
+
display: flex;
|
|
25
|
+
width: 100%;
|
|
26
|
+
align-items: center;
|
|
27
|
+
gap: var(--xs);
|
|
28
|
+
padding: var(--xs);
|
|
29
|
+
min-height: 40px;
|
|
30
|
+
border-radius: 4px;
|
|
31
|
+
|
|
32
|
+
/* Highlight bg is the focus indicator (matches DsDropdownMenu items). */
|
|
33
|
+
&[data-focus-visible] {
|
|
34
|
+
outline: none;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode, useState } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import styles from './checkbox-filter.module.scss';
|
|
2
4
|
import { DsCheckbox } from '../../../../ds-checkbox';
|
|
5
|
+
import { DsTextInput } from '../../../../ds-text-input';
|
|
6
|
+
import { DsIcon } from '../../../../ds-icon';
|
|
3
7
|
|
|
4
8
|
export interface CheckboxFilterItem<TValue = string> {
|
|
5
9
|
value: TValue;
|
|
@@ -7,11 +11,30 @@ export interface CheckboxFilterItem<TValue = string> {
|
|
|
7
11
|
metadata?: Record<string, unknown>;
|
|
8
12
|
}
|
|
9
13
|
|
|
14
|
+
export interface CheckboxFilterLocale {
|
|
15
|
+
/** @default 'All' */
|
|
16
|
+
allLabel?: string;
|
|
17
|
+
/** @default 'Search' */
|
|
18
|
+
searchPlaceholder?: string;
|
|
19
|
+
/** @default 'No matches' */
|
|
20
|
+
noMatchesLabel?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
export interface CheckboxFilterProps<TValue> {
|
|
11
24
|
items: CheckboxFilterItem<TValue>[];
|
|
25
|
+
/** Custom row renderer; defaults to `item.label`. */
|
|
12
26
|
renderer?: (item: CheckboxFilterItem<TValue>) => ReactNode;
|
|
13
27
|
selectedItems: CheckboxFilterItem<TValue>[];
|
|
14
28
|
onSelectionChange: (selectedItems: CheckboxFilterItem<TValue>[]) => void;
|
|
29
|
+
/** Show a case-insensitive substring search above the list. @default false */
|
|
30
|
+
searchable?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Show an "All" toggle. Checked when every visible item is selected,
|
|
33
|
+
* indeterminate when some are, unchecked otherwise. @default false
|
|
34
|
+
*/
|
|
35
|
+
selectAll?: boolean;
|
|
36
|
+
locale?: CheckboxFilterLocale;
|
|
37
|
+
className?: string;
|
|
15
38
|
}
|
|
16
39
|
|
|
17
40
|
export const CheckboxFilter = <TValue,>({
|
|
@@ -19,7 +42,19 @@ export const CheckboxFilter = <TValue,>({
|
|
|
19
42
|
renderer,
|
|
20
43
|
selectedItems,
|
|
21
44
|
onSelectionChange,
|
|
45
|
+
searchable = false,
|
|
46
|
+
selectAll = false,
|
|
47
|
+
locale,
|
|
48
|
+
className,
|
|
22
49
|
}: CheckboxFilterProps<TValue>) => {
|
|
50
|
+
const { allLabel = 'All', searchPlaceholder = 'Search', noMatchesLabel = 'No matches' } = locale ?? {};
|
|
51
|
+
|
|
52
|
+
const [query, setQuery] = useState('');
|
|
53
|
+
|
|
54
|
+
const visibleItems = searchable
|
|
55
|
+
? items.filter((item) => item.label.toLowerCase().includes(query.trim().toLowerCase()))
|
|
56
|
+
: items;
|
|
57
|
+
|
|
23
58
|
const handleCheckedChange = (selected: CheckboxFilterItem<TValue>, checked: boolean) => {
|
|
24
59
|
if (checked) {
|
|
25
60
|
onSelectionChange([...selectedItems, selected]);
|
|
@@ -28,16 +63,60 @@ export const CheckboxFilter = <TValue,>({
|
|
|
28
63
|
}
|
|
29
64
|
};
|
|
30
65
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
|
|
66
|
+
const visibleSelectedCount = visibleItems.filter((item) =>
|
|
67
|
+
selectedItems.some((selected) => selected.value === item.value),
|
|
68
|
+
).length;
|
|
69
|
+
|
|
70
|
+
const allVisibleSelected = visibleItems.length > 0 && visibleSelectedCount === visibleItems.length;
|
|
71
|
+
const someVisibleSelected = visibleSelectedCount > 0 && !allVisibleSelected;
|
|
72
|
+
|
|
73
|
+
const handleSelectAllChange = (next: boolean | 'indeterminate') => {
|
|
74
|
+
const shouldSelect = next === true;
|
|
75
|
+
const visibleValues = new Set(visibleItems.map((item) => item.value));
|
|
76
|
+
const withoutVisible = selectedItems.filter((item) => !visibleValues.has(item.value));
|
|
77
|
+
onSelectionChange(shouldSelect ? [...withoutVisible, ...visibleItems] : withoutVisible);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className={classNames(styles.root, className)}>
|
|
82
|
+
{searchable && (
|
|
83
|
+
<DsTextInput
|
|
84
|
+
value={query}
|
|
85
|
+
placeholder={searchPlaceholder}
|
|
86
|
+
onValueChange={setQuery}
|
|
87
|
+
slots={{
|
|
88
|
+
startAdornment: <DsIcon icon="search" size="tiny" />,
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
|
|
93
|
+
<div className={styles.list} role="group">
|
|
94
|
+
{selectAll && visibleItems.length > 0 && (
|
|
95
|
+
<DsCheckbox
|
|
96
|
+
className={styles.checkboxItem}
|
|
97
|
+
label={allLabel}
|
|
98
|
+
checked={allVisibleSelected ? true : someVisibleSelected ? 'indeterminate' : false}
|
|
99
|
+
onCheckedChange={handleSelectAllChange}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
|
|
103
|
+
{visibleItems.length === 0 && <div className={styles.empty}>{noMatchesLabel}</div>}
|
|
104
|
+
|
|
105
|
+
{visibleItems.map((item) => {
|
|
106
|
+
const label = renderer ? renderer(item) : item.label;
|
|
107
|
+
const checked = selectedItems.some((selected) => selected.value === item.value);
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<DsCheckbox
|
|
111
|
+
key={JSON.stringify(item.value)}
|
|
112
|
+
className={styles.checkboxItem}
|
|
113
|
+
label={label}
|
|
114
|
+
checked={checked}
|
|
115
|
+
onCheckedChange={(next) => handleCheckedChange(item, next === true)}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
})}
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
43
122
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CheckboxFilter } from './checkbox-filter';
|
|
2
|
-
export type { CheckboxFilterProps, CheckboxFilterItem } from './checkbox-filter';
|
|
2
|
+
export type { CheckboxFilterProps, CheckboxFilterItem, CheckboxFilterLocale } from './checkbox-filter';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.trigger {
|
|
2
|
+
min-width: var(--icon-width-tiny);
|
|
3
|
+
padding: 0;
|
|
4
|
+
opacity: 0;
|
|
5
|
+
transition: opacity 0.2s;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.triggerActive,
|
|
9
|
+
.triggerOpen {
|
|
10
|
+
opacity: 1;
|
|
11
|
+
color: var(--icon-information-main, var(--color-dap-primary-500));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.content {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: var(--xs);
|
|
18
|
+
min-width: 280px;
|
|
19
|
+
max-width: 320px;
|
|
20
|
+
padding: var(--standard);
|
|
21
|
+
background: var(--background);
|
|
22
|
+
border: 1px solid var(--border-secondary);
|
|
23
|
+
border-radius: 4px;
|
|
24
|
+
box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.15);
|
|
25
|
+
z-index: 1000;
|
|
26
|
+
|
|
27
|
+
&[hidden] {
|
|
28
|
+
display: none;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.body {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.footer {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: flex-end;
|
|
41
|
+
gap: var(--xs);
|
|
42
|
+
}
|
package/src/components/ds-table/filters/components/column-filter-popover/column-filter-popover.tsx
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type MouseEvent, useState } from 'react';
|
|
2
|
+
import { Popover } from '@ark-ui/react/popover';
|
|
3
|
+
import { Portal } from '@ark-ui/react/portal';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import styles from './column-filter-popover.module.scss';
|
|
6
|
+
import type { DsTableColumnFilterPopoverProps } from './column-filter-popover.types';
|
|
7
|
+
import { DsIcon } from '../../../../ds-icon';
|
|
8
|
+
import { DsButtonV3 } from '../../../../ds-button-v3';
|
|
9
|
+
|
|
10
|
+
// React portals bubble events through the React tree, so clicks inside the
|
|
11
|
+
// popover would otherwise reach the parent `<TableHead onClick={sortHandler}>`
|
|
12
|
+
// and toggle column sorting when applying or clearing the filter.
|
|
13
|
+
const stopPropagation = (event: MouseEvent) => event.stopPropagation();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Per-column filter popover anchored to a header cell: funnel trigger,
|
|
17
|
+
* adapter UI as the body, Clear / Save footer wired to `useTableFilters`.
|
|
18
|
+
*/
|
|
19
|
+
export const DsTableColumnFilterPopover = ({
|
|
20
|
+
children,
|
|
21
|
+
hasActiveFilter,
|
|
22
|
+
onApply,
|
|
23
|
+
onClear,
|
|
24
|
+
onCancel,
|
|
25
|
+
locale,
|
|
26
|
+
className,
|
|
27
|
+
}: DsTableColumnFilterPopoverProps) => {
|
|
28
|
+
const { triggerAriaLabel = 'Filter column', clearLabel = 'Clear', saveLabel = 'Save' } = locale ?? {};
|
|
29
|
+
|
|
30
|
+
const [open, setOpen] = useState(false);
|
|
31
|
+
|
|
32
|
+
const handleOpenChange = (details: { open: boolean }) => {
|
|
33
|
+
if (open && !details.open) {
|
|
34
|
+
onCancel();
|
|
35
|
+
}
|
|
36
|
+
setOpen(details.open);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleSave = () => {
|
|
40
|
+
onApply();
|
|
41
|
+
setOpen(false);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleClear = () => {
|
|
45
|
+
onClear();
|
|
46
|
+
setOpen(false);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Popover.Root
|
|
51
|
+
open={open}
|
|
52
|
+
onOpenChange={handleOpenChange}
|
|
53
|
+
positioning={{ placement: 'bottom-end', gutter: 4 }}
|
|
54
|
+
>
|
|
55
|
+
<Popover.Trigger asChild>
|
|
56
|
+
<DsButtonV3
|
|
57
|
+
variant="tertiary"
|
|
58
|
+
size="tiny"
|
|
59
|
+
className={classNames(
|
|
60
|
+
styles.trigger,
|
|
61
|
+
hasActiveFilter && styles.triggerActive,
|
|
62
|
+
open && styles.triggerOpen,
|
|
63
|
+
)}
|
|
64
|
+
aria-label={triggerAriaLabel}
|
|
65
|
+
data-active={hasActiveFilter ? 'true' : undefined}
|
|
66
|
+
onClick={(event) => event.stopPropagation()}
|
|
67
|
+
>
|
|
68
|
+
<DsIcon icon="filter_alt" variant="outlined" filled={hasActiveFilter} size="tiny" />
|
|
69
|
+
</DsButtonV3>
|
|
70
|
+
</Popover.Trigger>
|
|
71
|
+
|
|
72
|
+
<Portal>
|
|
73
|
+
<Popover.Positioner>
|
|
74
|
+
<Popover.Content className={classNames(styles.content, className)} onClick={stopPropagation}>
|
|
75
|
+
<div className={styles.body}>{children}</div>
|
|
76
|
+
<div className={styles.footer}>
|
|
77
|
+
<DsButtonV3 variant="secondary" size="small" onClick={handleClear}>
|
|
78
|
+
{clearLabel}
|
|
79
|
+
</DsButtonV3>
|
|
80
|
+
<DsButtonV3 variant="primary" size="small" onClick={handleSave}>
|
|
81
|
+
{saveLabel}
|
|
82
|
+
</DsButtonV3>
|
|
83
|
+
</div>
|
|
84
|
+
</Popover.Content>
|
|
85
|
+
</Popover.Positioner>
|
|
86
|
+
</Portal>
|
|
87
|
+
</Popover.Root>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ColumnFilterPopoverLocale {
|
|
4
|
+
/** @default 'Filter column' */
|
|
5
|
+
triggerAriaLabel?: string;
|
|
6
|
+
/** @default 'Clear' */
|
|
7
|
+
clearLabel?: string;
|
|
8
|
+
/** @default 'Save' */
|
|
9
|
+
saveLabel?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DsTableColumnFilterPopoverProps {
|
|
13
|
+
/** Body rendered above the Clear / Save footer. */
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/** Whether the column has an applied filter; drives the trigger's active state. */
|
|
16
|
+
hasActiveFilter: boolean;
|
|
17
|
+
/** Commit the draft for this column. */
|
|
18
|
+
onApply: () => void;
|
|
19
|
+
/** Clear the draft and the applied value for this column. */
|
|
20
|
+
onClear: () => void;
|
|
21
|
+
/** Discard the draft when the popover closes without Save. */
|
|
22
|
+
onCancel: () => void;
|
|
23
|
+
locale?: ColumnFilterPopoverLocale;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|