@appdirect/design-system 0.0.17 → 0.0.18
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/bin/ad-sync-design-md.mjs +0 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
- package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
- package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
- package/dist/ComplexComponents/DataTable/index.js +5 -1
- package/dist/ComplexComponents/DataTable/index.ts +13 -2
- package/dist/ComplexComponents/DataTable/table.module.css +9 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
- package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
- package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
- package/dist/ComplexComponents/DataTable/types.js +5 -0
- package/dist/ComplexComponents/DataTable/types.ts +17 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
- package/dist/DESIGN.md +9 -10
- package/dist/contracts/DataTable.json +83 -6
- package/dist/contracts/index.json +1 -1
- package/dist/css/foundations.css +4 -0
- package/dist/css/mantine.css +1 -1
- package/dist/css/tokens.css +3145 -0
- package/dist/index.js +3 -0
- package/dist/index.ts +14 -1
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
- package/dist/stories/index.json +13 -15
- package/package.json +5 -3
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
- package/dist/hooks/useTableHandlers.js +0 -136
- package/dist/hooks/useTableHandlers.ts +0 -179
- package/dist/hooks/useTableRenderFunctions.js +0 -164
- package/dist/hooks/useTableRenderFunctions.tsx +0 -283
- package/dist/hooks/useTableState.js +0 -70
- package/dist/hooks/useTableState.ts +0 -81
package/dist/stories/index.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.18",
|
|
3
3
|
"stories": [
|
|
4
4
|
{
|
|
5
5
|
"title": "Design System/Buttons/ActionIcon",
|
|
@@ -243,27 +243,25 @@
|
|
|
243
243
|
},
|
|
244
244
|
{
|
|
245
245
|
"title": "Design System/Complex Components/DataTable",
|
|
246
|
-
"component": "
|
|
247
|
-
"description": "
|
|
246
|
+
"component": "DemoTable",
|
|
247
|
+
"description": "Controlled table built on TanStack Table v9 and the micro-ui-ts table pieces (shell, grid, toolbars). The consumer owns all state (pagination, selection, density, filters, sorting), matching the production `Table` page in micro-ui-ts. Prototype code therefore ports to marketplace code by swapping the data source.",
|
|
248
248
|
"stories": [
|
|
249
249
|
"Default",
|
|
250
|
-
"
|
|
251
|
-
"
|
|
252
|
-
"LoadingState",
|
|
250
|
+
"Loading",
|
|
251
|
+
"Empty",
|
|
253
252
|
"ErrorState",
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"
|
|
257
|
-
"Interactive"
|
|
253
|
+
"WithSelection",
|
|
254
|
+
"Compact",
|
|
255
|
+
"Comfortable"
|
|
258
256
|
],
|
|
259
257
|
"file": "ComplexComponents/DataTable/DataTable.stories.tsx",
|
|
260
258
|
"designSystem": [
|
|
261
|
-
"
|
|
262
|
-
"Button",
|
|
259
|
+
"CellHoverReveal",
|
|
263
260
|
"DataTable",
|
|
264
|
-
"
|
|
265
|
-
"
|
|
266
|
-
"Title"
|
|
261
|
+
"SortDirection",
|
|
262
|
+
"SortableHeaderCell",
|
|
263
|
+
"Title",
|
|
264
|
+
"createDataTableColumnHelper"
|
|
267
265
|
],
|
|
268
266
|
"mantine": [
|
|
269
267
|
"Stack"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appdirect/design-system",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "AppDirect Design System components. Wraps Mantine v9 with standardized props, variants, and tokens.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.ts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"default": "./dist/types.js"
|
|
25
25
|
},
|
|
26
26
|
"./css/foundations.css": "./dist/css/foundations.css",
|
|
27
|
+
"./css/tokens.css": "./dist/css/tokens.css",
|
|
27
28
|
"./css/mantine.css": "./dist/css/mantine.css",
|
|
28
29
|
"./contracts": "./dist/contracts/index.json",
|
|
29
30
|
"./contracts/*": "./dist/contracts/*",
|
|
@@ -44,11 +45,12 @@
|
|
|
44
45
|
"prepublishOnly": "npm run build"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@appdirect/ad-design-tokens": "0.0.
|
|
48
|
+
"@appdirect/ad-design-tokens": "0.0.18",
|
|
48
49
|
"@mantine/dropzone": "^9.6.0",
|
|
49
50
|
"@remixicon/react": "^4.6.0",
|
|
50
51
|
"@tabler/icons-react": "^3.33.0",
|
|
51
|
-
"
|
|
52
|
+
"@tanstack/react-table": "^9.2.4",
|
|
53
|
+
"clsx": "^2.1.1"
|
|
52
54
|
},
|
|
53
55
|
"peerDependencies": {
|
|
54
56
|
"@mantine/core": "^9.6.0",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { Text } from "@mantine/core";
|
|
4
|
-
import { translate } from '../../translations/index.js';
|
|
5
|
-
const ResultCount = ({ resultCount, totalCount, isLoading, hasActiveFilters }) => {
|
|
6
|
-
if (isLoading) {
|
|
7
|
-
return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.loading") }));
|
|
8
|
-
}
|
|
9
|
-
// When filters are active, show filtered results
|
|
10
|
-
if (hasActiveFilters) {
|
|
11
|
-
const filteredCount = resultCount || 0;
|
|
12
|
-
const total = totalCount || 0;
|
|
13
|
-
if (filteredCount === 0) {
|
|
14
|
-
return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.filtered.none", { total }) }));
|
|
15
|
-
}
|
|
16
|
-
if (filteredCount === 1) {
|
|
17
|
-
return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.filtered.one", { total }) }));
|
|
18
|
-
}
|
|
19
|
-
return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.filtered.many", {
|
|
20
|
-
count: filteredCount,
|
|
21
|
-
total
|
|
22
|
-
}) }));
|
|
23
|
-
}
|
|
24
|
-
// When no filters, show total records
|
|
25
|
-
const count = totalCount || resultCount || 0;
|
|
26
|
-
if (count === 1) {
|
|
27
|
-
return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.total.one") }));
|
|
28
|
-
}
|
|
29
|
-
return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.total.many", { count }) }));
|
|
30
|
-
};
|
|
31
|
-
export default ResultCount;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React, { ReactElement } from "react";
|
|
2
|
-
import { Text } from "@mantine/core";
|
|
3
|
-
import { translate } from '../../translations';
|
|
4
|
-
|
|
5
|
-
interface ResultCountProps {
|
|
6
|
-
resultCount?: number;
|
|
7
|
-
totalCount?: number;
|
|
8
|
-
isLoading: boolean;
|
|
9
|
-
hasActiveFilters: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const ResultCount = ({
|
|
13
|
-
resultCount,
|
|
14
|
-
totalCount,
|
|
15
|
-
isLoading,
|
|
16
|
-
hasActiveFilters
|
|
17
|
-
}: ResultCountProps): ReactElement => {
|
|
18
|
-
|
|
19
|
-
if (isLoading) {
|
|
20
|
-
return (
|
|
21
|
-
<Text size="xs" span>
|
|
22
|
-
{translate("table.filters.result.count.loading")}
|
|
23
|
-
</Text>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// When filters are active, show filtered results
|
|
28
|
-
if (hasActiveFilters) {
|
|
29
|
-
const filteredCount = resultCount || 0;
|
|
30
|
-
const total = totalCount || 0;
|
|
31
|
-
|
|
32
|
-
if (filteredCount === 0) {
|
|
33
|
-
return (
|
|
34
|
-
<Text size="xs" span>
|
|
35
|
-
{translate("table.filters.result.count.filtered.none", { total })}
|
|
36
|
-
</Text>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (filteredCount === 1) {
|
|
41
|
-
return (
|
|
42
|
-
<Text size="xs" span>
|
|
43
|
-
{translate("table.filters.result.count.filtered.one", { total })}
|
|
44
|
-
</Text>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Text size="xs" span>
|
|
50
|
-
{translate("table.filters.result.count.filtered.many", {
|
|
51
|
-
count: filteredCount,
|
|
52
|
-
total
|
|
53
|
-
})}
|
|
54
|
-
</Text>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// When no filters, show total records
|
|
59
|
-
const count = totalCount || resultCount || 0;
|
|
60
|
-
|
|
61
|
-
if (count === 1) {
|
|
62
|
-
return (
|
|
63
|
-
<Text size="xs" span>
|
|
64
|
-
{translate("table.filters.result.count.total.one")}
|
|
65
|
-
</Text>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<Text size="xs" span>
|
|
71
|
-
{translate("table.filters.result.count.total.many", { count })}
|
|
72
|
-
</Text>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default ResultCount;
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Custom hook for table event handlers
|
|
4
|
-
*
|
|
5
|
-
* Manages all user interactions and state updates with proper memoization.
|
|
6
|
-
* Provides handlers for pagination, row selection, density changes, and sorting.
|
|
7
|
-
* All handlers are memoized to prevent unnecessary re-renders.
|
|
8
|
-
*
|
|
9
|
-
* @param tableState - Current table state from useTableState hook
|
|
10
|
-
* @param props - Callback props passed from parent component
|
|
11
|
-
* @returns Object containing all memoized event handlers
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* const tableState = useTableState(10, 'xs');
|
|
16
|
-
* const handlers = useTableHandlers(tableState, {
|
|
17
|
-
* onPaginationChange: (pagination) => {
|
|
18
|
-
* console.log('Page changed:', pagination);
|
|
19
|
-
* },
|
|
20
|
-
* onRowSelectionChange: (selection) => {
|
|
21
|
-
* console.log('Selection changed:', selection);
|
|
22
|
-
* },
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Use handlers in table configuration
|
|
26
|
-
* const { handlePaginationChange, handleRowSelectionChange } = handlers;
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* // With sorting and density change handlers
|
|
32
|
-
* const handlers = useTableHandlers(tableState, {
|
|
33
|
-
* onSortChange: (field, direction) => {
|
|
34
|
-
* console.log(`Sorting ${field} in ${direction} order`);
|
|
35
|
-
* },
|
|
36
|
-
* onDensityChange: (density) => {
|
|
37
|
-
* console.log('Density changed:', density);
|
|
38
|
-
* },
|
|
39
|
-
* });
|
|
40
|
-
*
|
|
41
|
-
* // Clear all selections
|
|
42
|
-
* handlers.handleClearSelection();
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```tsx
|
|
47
|
-
* // Complete table setup with all handlers
|
|
48
|
-
* const tableState = useTableState(20, 'md');
|
|
49
|
-
* const handlers = useTableHandlers(tableState, {
|
|
50
|
-
* onPaginationChange: async (pagination) => {
|
|
51
|
-
* await fetchData(pagination.pageIndex, pagination.pageSize);
|
|
52
|
-
* },
|
|
53
|
-
* onRowSelectionChange: (selection) => {
|
|
54
|
-
* setSelectedRows(selection);
|
|
55
|
-
* updateBulkActions(Object.keys(selection));
|
|
56
|
-
* },
|
|
57
|
-
* onSortChange: async (field, direction) => {
|
|
58
|
-
* await fetchSortedData(field, direction);
|
|
59
|
-
* },
|
|
60
|
-
* onDensityChange: (density) => {
|
|
61
|
-
* localStorage.setItem('tableDensity', density);
|
|
62
|
-
* },
|
|
63
|
-
* });
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export function useTableHandlers(tableState, props) {
|
|
67
|
-
// Extract state and callbacks for cleaner code
|
|
68
|
-
const { pagination, setPagination, rowSelection, setRowSelection, density, setDensity } = tableState;
|
|
69
|
-
const { onPaginationChange, onRowSelectionChange, onDensityChange, onSortChange } = props;
|
|
70
|
-
/**
|
|
71
|
-
* Handles pagination state changes (page navigation, page size changes)
|
|
72
|
-
* Updates internal state and notifies parent component
|
|
73
|
-
*/
|
|
74
|
-
const handlePaginationChange = useCallback((updater) => {
|
|
75
|
-
// Handle both direct values and updater functions
|
|
76
|
-
const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
|
|
77
|
-
setPagination(newPagination);
|
|
78
|
-
// Notify parent component of pagination change
|
|
79
|
-
onPaginationChange?.(newPagination);
|
|
80
|
-
}, [pagination, onPaginationChange, setPagination]);
|
|
81
|
-
/**
|
|
82
|
-
* Handles row selection state changes
|
|
83
|
-
* Maintains selection state across pagination and notifies parent
|
|
84
|
-
*/
|
|
85
|
-
const handleRowSelectionChange = useCallback((updater) => {
|
|
86
|
-
// Handle both direct values and updater functions
|
|
87
|
-
const newRowSelection = typeof updater === 'function' ? updater(rowSelection) : updater;
|
|
88
|
-
setRowSelection(newRowSelection);
|
|
89
|
-
// Notify parent component of selection change
|
|
90
|
-
onRowSelectionChange?.(newRowSelection);
|
|
91
|
-
}, [rowSelection, onRowSelectionChange, setRowSelection]);
|
|
92
|
-
/**
|
|
93
|
-
* Handles table density changes (affects row height and spacing)
|
|
94
|
-
* Updates UI density and notifies parent component
|
|
95
|
-
*/
|
|
96
|
-
const handleDensityChange = useCallback((updater) => {
|
|
97
|
-
// Handle both direct values and updater functions
|
|
98
|
-
const newDensity = typeof updater === 'function' ? updater(density) : updater;
|
|
99
|
-
setDensity(newDensity);
|
|
100
|
-
// Notify parent component of density change
|
|
101
|
-
onDensityChange?.(newDensity);
|
|
102
|
-
}, [density, onDensityChange, setDensity]);
|
|
103
|
-
/**
|
|
104
|
-
* Clears all selected rows and notifies parent component
|
|
105
|
-
* Used by the "Clear Selection" button in the alert banner
|
|
106
|
-
*/
|
|
107
|
-
const handleClearSelection = useCallback(() => {
|
|
108
|
-
setRowSelection({});
|
|
109
|
-
onRowSelectionChange?.({});
|
|
110
|
-
}, [onRowSelectionChange, setRowSelection]);
|
|
111
|
-
/**
|
|
112
|
-
* Handles column sorting changes
|
|
113
|
-
* Converts Mantine React Table sorting format to our simplified format
|
|
114
|
-
*/
|
|
115
|
-
const handleSortingChange = useCallback((updater) => {
|
|
116
|
-
// Handle both direct values and updater functions
|
|
117
|
-
const sorting = typeof updater === 'function' ? updater([]) : updater;
|
|
118
|
-
if (sorting.length > 0) {
|
|
119
|
-
// Extract sorting information from first sort (single column sorting)
|
|
120
|
-
const { id, desc } = sorting[0];
|
|
121
|
-
onSortChange?.(id, desc ? 'desc' : 'asc');
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
// No sorting applied
|
|
125
|
-
onSortChange?.('', null);
|
|
126
|
-
}
|
|
127
|
-
}, [onSortChange]);
|
|
128
|
-
// Return all memoized handlers
|
|
129
|
-
return {
|
|
130
|
-
handlePaginationChange,
|
|
131
|
-
handleRowSelectionChange,
|
|
132
|
-
handleDensityChange,
|
|
133
|
-
handleClearSelection,
|
|
134
|
-
handleSortingChange,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
MRT_PaginationState as PaginationState,
|
|
4
|
-
MRT_RowSelectionState as RowSelectionState,
|
|
5
|
-
MRT_DensityState as DensityState,
|
|
6
|
-
MRT_SortingState as SortingState,
|
|
7
|
-
} from 'mantine-react-table-open';
|
|
8
|
-
import { useTableState } from './useTableState';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Generic type for state updater functions used by React state setters
|
|
12
|
-
* Can accept either a direct value or a function that takes the previous value
|
|
13
|
-
*/
|
|
14
|
-
type OnChangeFn<T> = (updater: T | ((old: T) => T)) => void;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Union type for sort directions used throughout the table
|
|
18
|
-
* null represents no sorting applied to a column
|
|
19
|
-
*/
|
|
20
|
-
type SortDirection = 'asc' | 'desc' | null;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Props interface for the useTableHandlers hook
|
|
24
|
-
*/
|
|
25
|
-
export interface UseTableHandlersProps {
|
|
26
|
-
/** Callback fired when pagination state changes (page or page size) */
|
|
27
|
-
onPaginationChange?: (pagination: PaginationState) => void;
|
|
28
|
-
/** Callback fired when row selection changes */
|
|
29
|
-
onRowSelectionChange?: (rowSelection: RowSelectionState) => void;
|
|
30
|
-
/** Callback fired when table density (row height) changes */
|
|
31
|
-
onDensityChange?: (density: DensityState) => void;
|
|
32
|
-
/** Callback fired when column sorting changes */
|
|
33
|
-
onSortChange?: (field: string, direction: SortDirection) => void;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Custom hook for table event handlers
|
|
38
|
-
*
|
|
39
|
-
* Manages all user interactions and state updates with proper memoization.
|
|
40
|
-
* Provides handlers for pagination, row selection, density changes, and sorting.
|
|
41
|
-
* All handlers are memoized to prevent unnecessary re-renders.
|
|
42
|
-
*
|
|
43
|
-
* @param tableState - Current table state from useTableState hook
|
|
44
|
-
* @param props - Callback props passed from parent component
|
|
45
|
-
* @returns Object containing all memoized event handlers
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```tsx
|
|
49
|
-
* const tableState = useTableState(10, 'xs');
|
|
50
|
-
* const handlers = useTableHandlers(tableState, {
|
|
51
|
-
* onPaginationChange: (pagination) => {
|
|
52
|
-
* console.log('Page changed:', pagination);
|
|
53
|
-
* },
|
|
54
|
-
* onRowSelectionChange: (selection) => {
|
|
55
|
-
* console.log('Selection changed:', selection);
|
|
56
|
-
* },
|
|
57
|
-
* });
|
|
58
|
-
*
|
|
59
|
-
* // Use handlers in table configuration
|
|
60
|
-
* const { handlePaginationChange, handleRowSelectionChange } = handlers;
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```tsx
|
|
65
|
-
* // With sorting and density change handlers
|
|
66
|
-
* const handlers = useTableHandlers(tableState, {
|
|
67
|
-
* onSortChange: (field, direction) => {
|
|
68
|
-
* console.log(`Sorting ${field} in ${direction} order`);
|
|
69
|
-
* },
|
|
70
|
-
* onDensityChange: (density) => {
|
|
71
|
-
* console.log('Density changed:', density);
|
|
72
|
-
* },
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* // Clear all selections
|
|
76
|
-
* handlers.handleClearSelection();
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```tsx
|
|
81
|
-
* // Complete table setup with all handlers
|
|
82
|
-
* const tableState = useTableState(20, 'md');
|
|
83
|
-
* const handlers = useTableHandlers(tableState, {
|
|
84
|
-
* onPaginationChange: async (pagination) => {
|
|
85
|
-
* await fetchData(pagination.pageIndex, pagination.pageSize);
|
|
86
|
-
* },
|
|
87
|
-
* onRowSelectionChange: (selection) => {
|
|
88
|
-
* setSelectedRows(selection);
|
|
89
|
-
* updateBulkActions(Object.keys(selection));
|
|
90
|
-
* },
|
|
91
|
-
* onSortChange: async (field, direction) => {
|
|
92
|
-
* await fetchSortedData(field, direction);
|
|
93
|
-
* },
|
|
94
|
-
* onDensityChange: (density) => {
|
|
95
|
-
* localStorage.setItem('tableDensity', density);
|
|
96
|
-
* },
|
|
97
|
-
* });
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export function useTableHandlers(
|
|
101
|
-
tableState: ReturnType<typeof useTableState>,
|
|
102
|
-
props: UseTableHandlersProps
|
|
103
|
-
) {
|
|
104
|
-
// Extract state and callbacks for cleaner code
|
|
105
|
-
const { pagination, setPagination, rowSelection, setRowSelection, density, setDensity } = tableState;
|
|
106
|
-
const { onPaginationChange, onRowSelectionChange, onDensityChange, onSortChange } = props;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Handles pagination state changes (page navigation, page size changes)
|
|
110
|
-
* Updates internal state and notifies parent component
|
|
111
|
-
*/
|
|
112
|
-
const handlePaginationChange: OnChangeFn<PaginationState> = useCallback((updater) => {
|
|
113
|
-
// Handle both direct values and updater functions
|
|
114
|
-
const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
|
|
115
|
-
setPagination(newPagination);
|
|
116
|
-
// Notify parent component of pagination change
|
|
117
|
-
onPaginationChange?.(newPagination);
|
|
118
|
-
}, [pagination, onPaginationChange, setPagination]);
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Handles row selection state changes
|
|
122
|
-
* Maintains selection state across pagination and notifies parent
|
|
123
|
-
*/
|
|
124
|
-
const handleRowSelectionChange: OnChangeFn<RowSelectionState> = useCallback((updater) => {
|
|
125
|
-
// Handle both direct values and updater functions
|
|
126
|
-
const newRowSelection = typeof updater === 'function' ? updater(rowSelection) : updater;
|
|
127
|
-
setRowSelection(newRowSelection);
|
|
128
|
-
// Notify parent component of selection change
|
|
129
|
-
onRowSelectionChange?.(newRowSelection);
|
|
130
|
-
}, [rowSelection, onRowSelectionChange, setRowSelection]);
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Handles table density changes (affects row height and spacing)
|
|
134
|
-
* Updates UI density and notifies parent component
|
|
135
|
-
*/
|
|
136
|
-
const handleDensityChange: OnChangeFn<DensityState> = useCallback((updater) => {
|
|
137
|
-
// Handle both direct values and updater functions
|
|
138
|
-
const newDensity = typeof updater === 'function' ? updater(density) : updater;
|
|
139
|
-
setDensity(newDensity);
|
|
140
|
-
// Notify parent component of density change
|
|
141
|
-
onDensityChange?.(newDensity);
|
|
142
|
-
}, [density, onDensityChange, setDensity]);
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Clears all selected rows and notifies parent component
|
|
146
|
-
* Used by the "Clear Selection" button in the alert banner
|
|
147
|
-
*/
|
|
148
|
-
const handleClearSelection = useCallback(() => {
|
|
149
|
-
setRowSelection({});
|
|
150
|
-
onRowSelectionChange?.({});
|
|
151
|
-
}, [onRowSelectionChange, setRowSelection]);
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Handles column sorting changes
|
|
155
|
-
* Converts Mantine React Table sorting format to our simplified format
|
|
156
|
-
*/
|
|
157
|
-
const handleSortingChange = useCallback((updater: SortingState | ((old: SortingState) => SortingState)) => {
|
|
158
|
-
// Handle both direct values and updater functions
|
|
159
|
-
const sorting = typeof updater === 'function' ? updater([]) : updater;
|
|
160
|
-
|
|
161
|
-
if (sorting.length > 0) {
|
|
162
|
-
// Extract sorting information from first sort (single column sorting)
|
|
163
|
-
const { id, desc } = sorting[0];
|
|
164
|
-
onSortChange?.(id, desc ? 'desc' : 'asc');
|
|
165
|
-
} else {
|
|
166
|
-
// No sorting applied
|
|
167
|
-
onSortChange?.('', null);
|
|
168
|
-
}
|
|
169
|
-
}, [onSortChange]);
|
|
170
|
-
|
|
171
|
-
// Return all memoized handlers
|
|
172
|
-
return {
|
|
173
|
-
handlePaginationChange,
|
|
174
|
-
handleRowSelectionChange,
|
|
175
|
-
handleDensityChange,
|
|
176
|
-
handleClearSelection,
|
|
177
|
-
handleSortingChange,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { useCallback } from 'react';
|
|
3
|
-
import CustomTopToolbar from '../ComplexComponents/DataTable/CustomTopToolbar/index.js';
|
|
4
|
-
import CustomBottomToolbar from '../ComplexComponents/DataTable/CustomBottomToolbar/index.js';
|
|
5
|
-
import CustomToolbarAlertBannerContent from '../ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js';
|
|
6
|
-
import ErrorOverlay from '../ComplexComponents/DataTable/ErrorOverlay/index.js';
|
|
7
|
-
import SortableHeaderCell from '../ComplexComponents/DataTable/SortableHeaderCell/index.js';
|
|
8
|
-
/**
|
|
9
|
-
* ID used by Mantine React Table for the row selection column
|
|
10
|
-
* Stored as constant to avoid magic strings
|
|
11
|
-
*/
|
|
12
|
-
const SELECTION_COLUMN_ID = 'mrt-row-select';
|
|
13
|
-
/**
|
|
14
|
-
* Styling constants using Mantine design tokens
|
|
15
|
-
* Ensures consistent theming and easy maintenance
|
|
16
|
-
*/
|
|
17
|
-
const TABLE_STYLES = {
|
|
18
|
-
/** Styling for table header cells */
|
|
19
|
-
headerCell: {
|
|
20
|
-
fontWeight: 'bold',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Custom hook for table render functions
|
|
25
|
-
*
|
|
26
|
-
* Manages all custom rendering logic with proper memoization.
|
|
27
|
-
* Provides render functions for toolbars, alert banners, empty states, and header cells.
|
|
28
|
-
* All render functions are memoized to prevent unnecessary re-renders.
|
|
29
|
-
*
|
|
30
|
-
* @param props - Props needed for rendering (data, filters, etc.)
|
|
31
|
-
* @param tableState - Current table state (selection count, etc.)
|
|
32
|
-
* @param handlers - Event handlers for user interactions
|
|
33
|
-
* @returns Object containing all memoized render functions
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* const renderFunctions = useTableRenderFunctions(
|
|
38
|
-
* {
|
|
39
|
-
* filtersState: filters,
|
|
40
|
-
* locale: 'en',
|
|
41
|
-
* onFiltersChange: setFilters,
|
|
42
|
-
* data: tableData,
|
|
43
|
-
* showFilters: true,
|
|
44
|
-
* isLoading: false,
|
|
45
|
-
* totalCount: 100,
|
|
46
|
-
* pageInfo: { hasNextPage: true, hasPreviousPage: false },
|
|
47
|
-
* },
|
|
48
|
-
* { numberOfSelectedRows: 3 },
|
|
49
|
-
* { handleClearSelection: () => setSelection({}) }
|
|
50
|
-
* );
|
|
51
|
-
*
|
|
52
|
-
* // Use in table configuration
|
|
53
|
-
* const tableConfig = {
|
|
54
|
-
* renderTopToolbar: renderFunctions.renderTopToolbar,
|
|
55
|
-
* renderBottomToolbar: renderFunctions.renderBottomToolbar,
|
|
56
|
-
* // ... other render functions
|
|
57
|
-
* };
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```tsx
|
|
62
|
-
* // Complete setup with error handling
|
|
63
|
-
* const renderFunctions = useTableRenderFunctions(
|
|
64
|
-
* {
|
|
65
|
-
* filtersState: {},
|
|
66
|
-
* locale: 'en',
|
|
67
|
-
* onFiltersChange: () => {},
|
|
68
|
-
* data: [],
|
|
69
|
-
* showFilters: false,
|
|
70
|
-
* isLoading: true,
|
|
71
|
-
* totalCount: 0,
|
|
72
|
-
* error: 'Failed to load data',
|
|
73
|
-
* onRetry: () => refetch(),
|
|
74
|
-
* },
|
|
75
|
-
* { numberOfSelectedRows: 0 },
|
|
76
|
-
* { handleClearSelection: () => {} }
|
|
77
|
-
* );
|
|
78
|
-
*
|
|
79
|
-
* // Error state will be handled by renderEmptyRowsFallback
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```tsx
|
|
84
|
-
* // With custom header rendering
|
|
85
|
-
* const renderFunctions = useTableRenderFunctions(
|
|
86
|
-
* {
|
|
87
|
-
* filtersState: activeFilters,
|
|
88
|
-
* locale: userLocale,
|
|
89
|
-
* onFiltersChange: updateFilters,
|
|
90
|
-
* data: rows,
|
|
91
|
-
* showFilters: true,
|
|
92
|
-
* isLoading: false,
|
|
93
|
-
* totalCount: totalRows,
|
|
94
|
-
* pageInfo: paginationInfo,
|
|
95
|
-
* },
|
|
96
|
-
* { numberOfSelectedRows: selectedCount },
|
|
97
|
-
* { handleClearSelection: clearAll }
|
|
98
|
-
* );
|
|
99
|
-
*
|
|
100
|
-
* // Custom header cells with sorting support
|
|
101
|
-
* const headerProps = renderFunctions.renderTableHeadCell({ column });
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
export function useTableRenderFunctions(props, tableState, handlers) {
|
|
105
|
-
// Extract props for cleaner destructuring
|
|
106
|
-
const { filtersState, locale, onFiltersChange, data, showFilters, isLoading, totalCount, pageInfo, error, onRetry, } = props;
|
|
107
|
-
const { numberOfSelectedRows } = tableState;
|
|
108
|
-
const { handleClearSelection } = handlers;
|
|
109
|
-
/**
|
|
110
|
-
* Renders the top toolbar with filters, search, and action buttons
|
|
111
|
-
* Memoized to prevent unnecessary re-renders
|
|
112
|
-
*/
|
|
113
|
-
const renderTopToolbar = useCallback((toolbarProps) => (_jsx(CustomTopToolbar, { ...toolbarProps, filtersState: filtersState, locale: locale, onChange: onFiltersChange, resultCount: data.length, totalCount: totalCount, showFilters: showFilters, numberOfSelectedRows: numberOfSelectedRows, onFilterToggleChange: () => { }, isLoading: isLoading })), [filtersState, locale, onFiltersChange, data.length, totalCount, showFilters, numberOfSelectedRows, isLoading]);
|
|
114
|
-
/**
|
|
115
|
-
* Renders the bottom toolbar with pagination controls and row count
|
|
116
|
-
* Includes custom cursor-based pagination with ActionIcon chevrons
|
|
117
|
-
*/
|
|
118
|
-
const renderBottomToolbar = useCallback((toolbarProps) => (_jsx(CustomBottomToolbar, { ...toolbarProps, totalCount: totalCount, pageInfo: pageInfo, numberOfSelectedRows: numberOfSelectedRows })), [totalCount, pageInfo, numberOfSelectedRows]);
|
|
119
|
-
/**
|
|
120
|
-
* Renders the alert banner content shown when rows are selected
|
|
121
|
-
* Displays selection count and clear selection button
|
|
122
|
-
*/
|
|
123
|
-
const renderToolbarAlertBannerContent = useCallback(() => (_jsx(CustomToolbarAlertBannerContent, { numberOfSelectedRows: numberOfSelectedRows, onClearSelection: handleClearSelection })), [numberOfSelectedRows, handleClearSelection]);
|
|
124
|
-
/**
|
|
125
|
-
* Renders the fallback content when the table is empty or has errors
|
|
126
|
-
* Shows error message with retry button when applicable
|
|
127
|
-
*/
|
|
128
|
-
const renderEmptyRowsFallback = useCallback(() => (_jsx(ErrorOverlay, { error: error, onRetry: onRetry })), [error, onRetry]);
|
|
129
|
-
/**
|
|
130
|
-
* Custom renderer for table header cells
|
|
131
|
-
* Provides custom styling while preserving column actions functionality
|
|
132
|
-
* Excludes the row selection column to let Mantine React Table handle it
|
|
133
|
-
*/
|
|
134
|
-
const renderTableHeadCell = useCallback(({ column }) => {
|
|
135
|
-
// Don't override the select column header - let Mantine React Table handle it
|
|
136
|
-
if (column.id === SELECTION_COLUMN_ID) {
|
|
137
|
-
return {};
|
|
138
|
-
}
|
|
139
|
-
// Don't override the actions column header - let Mantine React Table handle it for proper pinning
|
|
140
|
-
if (column.id === 'actions') {
|
|
141
|
-
return {};
|
|
142
|
-
}
|
|
143
|
-
const header = column.columnDef.header;
|
|
144
|
-
// If header is a function (custom Header component), let it render
|
|
145
|
-
if (typeof header === 'function' || column.columnDef.Header) {
|
|
146
|
-
return {
|
|
147
|
-
style: TABLE_STYLES.headerCell,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
// For string headers, provide custom styling with SortableHeaderCell
|
|
151
|
-
return {
|
|
152
|
-
style: TABLE_STYLES.headerCell,
|
|
153
|
-
children: (_jsx(SortableHeaderCell, { label: header, sortDirection: column.getIsSorted(), onSort: () => column.toggleSorting(), isSortable: column.getCanSort() })),
|
|
154
|
-
};
|
|
155
|
-
}, []);
|
|
156
|
-
// Return all memoized render functions
|
|
157
|
-
return {
|
|
158
|
-
renderTopToolbar,
|
|
159
|
-
renderBottomToolbar,
|
|
160
|
-
renderToolbarAlertBannerContent,
|
|
161
|
-
renderEmptyRowsFallback,
|
|
162
|
-
renderTableHeadCell,
|
|
163
|
-
};
|
|
164
|
-
}
|