@ackplus/react-tanstack-data-table 1.1.20 → 1.1.21

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.
Files changed (61) hide show
  1. package/dist/lib/hooks/use-data-table-engine.d.ts.map +1 -1
  2. package/dist/lib/hooks/use-data-table-engine.js +4 -0
  3. package/package.json +3 -4
  4. package/src/index.ts +0 -75
  5. package/src/lib/components/data-table-view.tsx +0 -386
  6. package/src/lib/components/droupdown/menu-dropdown.tsx +0 -103
  7. package/src/lib/components/filters/filter-value-input.tsx +0 -225
  8. package/src/lib/components/filters/index.ts +0 -126
  9. package/src/lib/components/headers/draggable-header.tsx +0 -326
  10. package/src/lib/components/headers/index.ts +0 -6
  11. package/src/lib/components/headers/table-header.tsx +0 -175
  12. package/src/lib/components/index.ts +0 -21
  13. package/src/lib/components/pagination/data-table-pagination.tsx +0 -111
  14. package/src/lib/components/pagination/index.ts +0 -5
  15. package/src/lib/components/rows/data-table-row.tsx +0 -218
  16. package/src/lib/components/rows/empty-data-row.tsx +0 -69
  17. package/src/lib/components/rows/index.ts +0 -7
  18. package/src/lib/components/rows/loading-rows.tsx +0 -164
  19. package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +0 -125
  20. package/src/lib/components/toolbar/column-filter-control.tsx +0 -432
  21. package/src/lib/components/toolbar/column-pinning-control.tsx +0 -275
  22. package/src/lib/components/toolbar/column-reset-control.tsx +0 -74
  23. package/src/lib/components/toolbar/column-visibility-control.tsx +0 -105
  24. package/src/lib/components/toolbar/data-table-toolbar.tsx +0 -257
  25. package/src/lib/components/toolbar/index.ts +0 -17
  26. package/src/lib/components/toolbar/table-export-control.tsx +0 -233
  27. package/src/lib/components/toolbar/table-refresh-control.tsx +0 -62
  28. package/src/lib/components/toolbar/table-search-control.tsx +0 -155
  29. package/src/lib/components/toolbar/table-size-control.tsx +0 -102
  30. package/src/lib/contexts/data-table-context.tsx +0 -126
  31. package/src/lib/data-table.tsx +0 -29
  32. package/src/lib/features/README.md +0 -161
  33. package/src/lib/features/column-filter.feature.ts +0 -493
  34. package/src/lib/features/index.ts +0 -23
  35. package/src/lib/features/selection.feature.ts +0 -322
  36. package/src/lib/hooks/index.ts +0 -2
  37. package/src/lib/hooks/use-data-table-engine.ts +0 -1552
  38. package/src/lib/icons/add-icon.tsx +0 -23
  39. package/src/lib/icons/csv-icon.tsx +0 -15
  40. package/src/lib/icons/delete-icon.tsx +0 -30
  41. package/src/lib/icons/excel-icon.tsx +0 -15
  42. package/src/lib/icons/index.ts +0 -7
  43. package/src/lib/icons/unpin-icon.tsx +0 -18
  44. package/src/lib/icons/view-comfortable-icon.tsx +0 -45
  45. package/src/lib/icons/view-compact-icon.tsx +0 -55
  46. package/src/lib/types/column.types.ts +0 -63
  47. package/src/lib/types/data-table-api.ts +0 -191
  48. package/src/lib/types/data-table.types.ts +0 -193
  49. package/src/lib/types/export.types.ts +0 -223
  50. package/src/lib/types/index.ts +0 -24
  51. package/src/lib/types/slots.types.ts +0 -342
  52. package/src/lib/types/table.types.ts +0 -88
  53. package/src/lib/utils/column-helpers.ts +0 -72
  54. package/src/lib/utils/debounced-fetch.utils.ts +0 -131
  55. package/src/lib/utils/export-utils.ts +0 -712
  56. package/src/lib/utils/index.ts +0 -27
  57. package/src/lib/utils/logger.ts +0 -203
  58. package/src/lib/utils/slot-helpers.tsx +0 -194
  59. package/src/lib/utils/special-columns.utils.ts +0 -101
  60. package/src/lib/utils/styling-helpers.ts +0 -126
  61. package/src/lib/utils/table-helpers.ts +0 -106
@@ -1,275 +0,0 @@
1
- import { ArrowLeftOutlined, ArrowRightOutlined, PushPinOutlined } from '@mui/icons-material';
2
- import {
3
- Box,
4
- Typography,
5
- Divider,
6
- IconButton,
7
- Tooltip,
8
- List,
9
- ListItem,
10
- ListItemText,
11
- IconButtonProps,
12
- SxProps,
13
- } from '@mui/material';
14
- import { ColumnPinningState, Column } from '@tanstack/react-table';
15
- import React, { useCallback, useMemo } from 'react';
16
-
17
- import { MenuDropdown } from '../droupdown/menu-dropdown';
18
- import { useDataTableContext } from '../../contexts/data-table-context';
19
- import {
20
- UnpinIcon,
21
- } from '../../icons';
22
- import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
23
-
24
- export interface ColumnPinningControlProps {
25
- // Allow full customization of any prop
26
- title?: string;
27
- titleSx?: SxProps;
28
- menuSx?: SxProps;
29
- iconButtonProps?: IconButtonProps;
30
- tooltipProps?: any;
31
- badgeProps?: any;
32
- clearButtonProps?: any;
33
- [key: string]: any;
34
- }
35
-
36
- export function ColumnPinningControl(props: ColumnPinningControlProps = {}) {
37
- // Use context if no props provided (MUI DataGrid style)
38
- const { table, slots, slotProps } = useDataTableContext();
39
-
40
- // Extract slot-specific props with enhanced merging
41
- const pinIconSlotProps = extractSlotProps(slotProps, 'pinIcon');
42
- const unpinIconSlotProps = extractSlotProps(slotProps, 'unpinIcon');
43
- const leftIconSlotProps = extractSlotProps(slotProps, 'leftIcon');
44
- const rightIconSlotProps = extractSlotProps(slotProps, 'rightIcon');
45
-
46
- const PinIconSlot = getSlotComponent(slots, 'pinIcon', PushPinOutlined);
47
- const UnpinIconSlot = getSlotComponent(slots, 'unpinIcon', UnpinIcon);
48
- const LeftIconSlot = getSlotComponent(slots, 'leftIcon', ArrowLeftOutlined);
49
- const RightIconSlot = getSlotComponent(slots, 'rightIcon', ArrowRightOutlined);
50
-
51
- const columnPinning = table?.getState().columnPinning || {};
52
-
53
- const allColumns: Column<any, unknown>[] = useMemo(() => {
54
- if (slotProps?.columnsPanel?.getPinnableColumns) {
55
- return slotProps?.columnsPanel?.getPinnableColumns(table?.getAllLeafColumns() || []);
56
- }
57
- return table?.getAllLeafColumns()?.filter(column => column.getCanPin()) || [];
58
- }, [slotProps?.columnsPanel, table]);
59
-
60
- const handlePinColumn = (columnId: string, position: 'left' | 'right' | 'none') => {
61
- const currentPinning = table?.getState().columnPinning || {};
62
- const newPinning: ColumnPinningState = { ...currentPinning };
63
-
64
- // Remove from current position
65
- newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
66
- newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
67
-
68
- // Add to new position
69
- if (position === 'left') {
70
- // Left-pinned: append to end (appears leftmost to rightmost)
71
- newPinning.left = [...(newPinning.left || []), columnId];
72
- } else if (position === 'right') {
73
- // Right-pinned: prepend to beginning (appears rightmost to leftmost)
74
- // First column pinned appears rightmost, second appears to its left, etc.
75
- newPinning.right = [columnId, ...(newPinning.right || [])];
76
- }
77
-
78
- table?.setColumnPinning(newPinning);
79
- };
80
-
81
- const getColumnPinStatus = (columnId: string): 'left' | 'right' | 'none' => {
82
- if (columnPinning.left?.includes(columnId)) return 'left';
83
- if (columnPinning.right?.includes(columnId)) return 'right';
84
- return 'none';
85
- };
86
-
87
- const getColumnDisplayName = (column: any) => {
88
- if (typeof column.columnDef.header === 'string') {
89
- return column.columnDef.header;
90
- }
91
- return column.id;
92
- };
93
-
94
- const handleUnpinAll = useCallback(() => {
95
- table?.setColumnPinning(table?.initialState?.columnPinning || {});
96
- }, [table]);
97
-
98
- // Count only user-pinned columns (exclude system columns like select and action)
99
- const userPinnedLeft = (columnPinning.left?.filter((id) => allColumns.some((column: any) => column.id === id)) || []);
100
- const userPinnedRight = (columnPinning.right?.filter((id) => allColumns.some((column: any) => column.id === id)) || []);
101
- const totalPinned = userPinnedLeft.length + userPinnedRight.length;
102
-
103
- // Merge all props for maximum flexibility
104
- const mergedIconButtonProps = mergeSlotProps(
105
- {
106
- size: 'small',
107
- sx: { flexShrink: 0 },
108
- },
109
- pinIconSlotProps,
110
- props.iconButtonProps || {}
111
- );
112
-
113
- return (
114
- <MenuDropdown
115
- anchor={(
116
- <Tooltip
117
- title="Pin columns"
118
- {...props.tooltipProps}
119
- >
120
- <IconButton
121
- {...mergedIconButtonProps}
122
- >
123
- <PinIconSlot {...pinIconSlotProps} />
124
- {totalPinned > 0 && (
125
- <Box
126
- sx={{
127
- position: 'absolute',
128
- top: -2,
129
- right: -2,
130
- backgroundColor: 'primary.main',
131
- color: 'white',
132
- borderRadius: '50%',
133
- width: 16,
134
- height: 16,
135
- fontSize: 10,
136
- display: 'flex',
137
- alignItems: 'center',
138
- justifyContent: 'center',
139
- ...props.badgeProps?.sx,
140
- }}
141
- {...props.badgeProps}
142
- >
143
- {totalPinned}
144
- </Box>
145
- )}
146
- </IconButton>
147
- </Tooltip>
148
- )}
149
- >
150
-
151
- <Box
152
- sx={{
153
- p: 2,
154
- minWidth: 300,
155
- maxWidth: 400,
156
- ...props.menuSx,
157
- }}
158
- >
159
- <Typography
160
- variant="subtitle2"
161
- sx={{
162
- mb: 1,
163
- ...props.titleSx,
164
- }}
165
- >
166
- {props.title || 'Pin Columns'}
167
- </Typography>
168
- <Divider sx={{ mb: 2 }} />
169
-
170
- {totalPinned > 0 && (
171
- <Box sx={{ mb: 2 }}>
172
- <IconButton
173
- size="small"
174
- onClick={handleUnpinAll}
175
- color="warning"
176
- {...props.clearButtonProps}
177
- >
178
- <UnpinIconSlot {...unpinIconSlotProps} />
179
- </IconButton>
180
- <Typography variant="caption" sx={{ ml: 1 }}>
181
- Unpin all columns
182
- </Typography>
183
- </Box>
184
- )}
185
-
186
- <List
187
- dense
188
- sx={{ py: 0 }}
189
- >
190
- {allColumns.map((column: any) => {
191
- const pinStatus = getColumnPinStatus(column.id);
192
- const displayName = getColumnDisplayName(column);
193
-
194
- return (
195
- <ListItem
196
- key={column.id}
197
- sx={{ py: 0.25 }}
198
- secondaryAction={(
199
- <Box
200
- sx={{
201
- display: 'flex',
202
- gap: 0.5,
203
- }}
204
- >
205
- {/* Pin Left */}
206
- <Tooltip title="Pin left">
207
- <IconButton
208
- size="small"
209
- onClick={() => handlePinColumn(column.id, pinStatus === 'left' ? 'none' : 'left')}
210
- color={pinStatus === 'left' ? 'primary' : 'default'}
211
- >
212
- <LeftIconSlot
213
- fontSize="small"
214
- {...leftIconSlotProps}
215
- />
216
- </IconButton>
217
- </Tooltip>
218
-
219
- {/* Pin Right */}
220
- <Tooltip title="Pin right">
221
- <IconButton
222
- size="small"
223
- onClick={() => handlePinColumn(column.id, pinStatus === 'right' ? 'none' : 'right')}
224
- color={pinStatus === 'right' ? 'secondary' : 'default'}
225
- >
226
- <RightIconSlot
227
- fontSize="small"
228
- {...rightIconSlotProps}
229
- />
230
- </IconButton>
231
- </Tooltip>
232
-
233
- {/* Unpin */}
234
- {pinStatus !== 'none' && (
235
- <Tooltip title="Unpin">
236
- <IconButton
237
- size="small"
238
- onClick={() => handlePinColumn(column.id, 'none')}
239
- >
240
- <UnpinIconSlot
241
- fontSize="small"
242
- {...unpinIconSlotProps}
243
- />
244
- </IconButton>
245
- </Tooltip>
246
- )}
247
- </Box>
248
- )}
249
- >
250
- <ListItemText
251
- primary={displayName}
252
- secondary={
253
- pinStatus === 'left' ? 'Pinned left' :
254
- pinStatus === 'right' ? 'Pinned right' :
255
- 'Not pinned'
256
- }
257
- slotProps={{
258
- primary: {
259
- variant: 'body2',
260
- fontWeight: pinStatus !== 'none' ? 600 : 400,
261
- },
262
- secondary: {
263
- variant: 'caption',
264
- color: pinStatus !== 'none' ? 'primary.main' : 'text.secondary',
265
- },
266
- }}
267
- />
268
- </ListItem>
269
- );
270
- })}
271
- </List>
272
- </Box>
273
- </MenuDropdown>
274
- );
275
- }
@@ -1,74 +0,0 @@
1
- import React, { ReactElement } from 'react';
2
- import { Autorenew } from '@mui/icons-material';
3
- import { IconButton, Tooltip, IconButtonProps } from '@mui/material';
4
-
5
- import { useDataTableContext } from '../../contexts/data-table-context';
6
- import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
7
-
8
- export interface ColumnResetControlProps {
9
- // Allow full customization of any prop
10
- iconButtonProps?: IconButtonProps;
11
- tooltipProps?: any;
12
- resetActions?: ('columnOrder' | 'columnPinning' | 'columnSizing' | 'columnVisibility' | 'filters' | 'sorting' | 'pagination')[];
13
- [key: string]: any;
14
- }
15
-
16
- export function ColumnResetControl(props: ColumnResetControlProps = {}): ReactElement {
17
- const { apiRef, slots, slotProps } = useDataTableContext();
18
-
19
- // Extract slot-specific props with enhanced merging
20
- const resetIconSlotProps = extractSlotProps(slotProps, 'resetIcon');
21
- const ResetIconSlot = getSlotComponent(slots, 'resetIcon', Autorenew);
22
-
23
- const handleResetLayout = () => {
24
- const actions = props.resetActions || ['columnOrder', 'columnPinning', 'columnSizing'];
25
- if (!apiRef?.current) return;
26
-
27
- // Reset based on specified actions
28
- if (actions.includes('columnOrder')) {
29
- apiRef?.current?.columnOrdering?.resetColumnOrder();
30
- }
31
- if (actions.includes('columnPinning')) {
32
- apiRef?.current?.columnPinning?.resetColumnPinning();
33
- }
34
- if (actions.includes('columnSizing')) {
35
- apiRef?.current?.columnResizing?.resetColumnSizing();
36
- }
37
- if (actions.includes('columnVisibility')) {
38
- apiRef?.current?.columnVisibility?.resetColumnVisibility();
39
- }
40
- if (actions.includes('filters')) {
41
- apiRef?.current?.filtering?.clearAllFilters();
42
- }
43
- if (actions.includes('sorting')) {
44
- apiRef?.current?.sorting?.resetSorting();
45
- }
46
- if (actions.includes('pagination')) {
47
- apiRef?.current?.pagination?.resetPagination();
48
- }
49
- };
50
-
51
- // Merge all props for maximum flexibility
52
- const mergedIconButtonProps = mergeSlotProps(
53
- {
54
- size: 'small',
55
- onClick: handleResetLayout,
56
- sx: { flexShrink: 0 },
57
- },
58
- resetIconSlotProps,
59
- props.iconButtonProps || {}
60
- );
61
-
62
- return (
63
- <Tooltip
64
- title="Reset layout"
65
- {...props.tooltipProps}
66
- >
67
- <IconButton
68
- {...mergedIconButtonProps}
69
- >
70
- <ResetIconSlot {...resetIconSlotProps} />
71
- </IconButton>
72
- </Tooltip>
73
- );
74
- }
@@ -1,105 +0,0 @@
1
- import { ViewColumnOutlined } from '@mui/icons-material';
2
- import { Box, Checkbox, CheckboxProps, Divider, FormControlLabel, SxProps, FormGroup, IconButton, Tooltip, Typography, FormControlLabelProps } from '@mui/material';
3
- import React, { useMemo } from 'react';
4
-
5
- import { MenuDropdown } from '../droupdown/menu-dropdown';
6
- import { useDataTableContext } from '../../contexts/data-table-context';
7
- import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
8
-
9
- export interface ColumnVisibilityControlProps {
10
- // Allow full customization of any prop
11
- title?: string;
12
- titleSx?: SxProps;
13
- menuSx?: SxProps;
14
- checkboxProps?: CheckboxProps;
15
- labelProps?: FormControlLabelProps;
16
- [key: string]: any;
17
- }
18
-
19
- export function ColumnVisibilityControl(props: ColumnVisibilityControlProps = {}) {
20
- // Use context if no props provided (MUI DataGrid style)
21
- const { table, slots, slotProps } = useDataTableContext();
22
-
23
- // Extract slot-specific props with enhanced merging
24
- const iconSlotProps = extractSlotProps(slotProps, 'columnIcon');
25
- const ColumnIconSlot = getSlotComponent(slots, 'columnIcon', ViewColumnOutlined);
26
-
27
- const columns = useMemo(() => {
28
- if (slotProps?.columnsPanel?.getTogglableColumns) {
29
- return slotProps?.columnsPanel?.getTogglableColumns(table?.getAllLeafColumns() || []);
30
- }
31
- return table?.getAllLeafColumns()?.filter(column => column.getCanHide()) || [];
32
- }, [slotProps?.columnsPanel, table]);
33
-
34
- const handleColumnVisibilityChange = ((columnId: string, visible: boolean) => {
35
- table?.getColumn(columnId)?.toggleVisibility(visible);
36
- });
37
-
38
- // Merge all props for maximum flexibility
39
- const mergedProps = mergeSlotProps(
40
- {
41
- // Default props
42
- size: 'small',
43
- sx: { flexShrink: 0 },
44
- },
45
- slotProps?.columnVisibilityControl || {},
46
- props
47
- );
48
-
49
- return (
50
- <MenuDropdown
51
- anchor={(
52
- <Tooltip title="Column visibility">
53
- <IconButton
54
- {...mergedProps}
55
- >
56
- <ColumnIconSlot
57
- {...iconSlotProps}
58
- />
59
- </IconButton>
60
- </Tooltip>
61
- )}
62
- >
63
- <Box
64
- sx={{
65
- p: 2,
66
- minWidth: 200,
67
- // Allow user to override these styles
68
- ...mergedProps.menuSx,
69
- }}
70
- >
71
- <Typography
72
- variant="subtitle2"
73
- sx={{
74
- mb: 1,
75
- // Allow user to override title styles
76
- ...mergedProps.titleSx,
77
- }}
78
- >
79
- {mergedProps.title || 'Show/Hide Columns'}
80
- </Typography>
81
- <Divider sx={{ mb: 1 }} />
82
- <FormGroup>
83
- {columns.map((column: any) => (
84
- <FormControlLabel
85
- key={column.id}
86
- control={(
87
- <Checkbox
88
- disabled={!column.getCanHide()}
89
- checked={column.getIsVisible()}
90
- onChange={(e: any) => handleColumnVisibilityChange(column.id, e.target.checked)}
91
- size="small"
92
- // Allow user to override checkbox props
93
- {...mergedProps.checkboxProps}
94
- />
95
- )}
96
- label={typeof column.columnDef.header === 'string' ? column.columnDef.header : column.id}
97
- // Allow user to override label props
98
- {...mergedProps.labelProps}
99
- />
100
- ))}
101
- </FormGroup>
102
- </Box>
103
- </MenuDropdown>
104
- );
105
- }