@ackplus/react-tanstack-data-table 1.0.34 → 1.1.1
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/LICENSE +21 -0
- package/{src → dist}/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/{src → dist}/lib/components/droupdown/menu-dropdown.d.ts +2 -1
- package/dist/lib/components/droupdown/menu-dropdown.d.ts.map +1 -0
- package/{src → dist}/lib/components/droupdown/menu-dropdown.js +38 -7
- package/{src → dist}/lib/components/filters/filter-value-input.d.ts +3 -1
- package/dist/lib/components/filters/filter-value-input.d.ts.map +1 -0
- package/dist/lib/components/filters/filter-value-input.js +83 -0
- package/{src → dist}/lib/components/filters/index.d.ts +1 -0
- package/dist/lib/components/filters/index.d.ts.map +1 -0
- package/dist/lib/components/filters/index.js +142 -0
- package/{src → dist}/lib/components/headers/draggable-header.d.ts +2 -2
- package/dist/lib/components/headers/draggable-header.d.ts.map +1 -0
- package/{src → dist}/lib/components/headers/draggable-header.js +81 -17
- package/dist/lib/components/headers/index.d.ts +6 -0
- package/dist/lib/components/headers/index.d.ts.map +1 -0
- package/dist/lib/components/headers/index.js +21 -0
- package/{src → dist}/lib/components/headers/table-header.d.ts +15 -1
- package/dist/lib/components/headers/table-header.d.ts.map +1 -0
- package/{src → dist}/lib/components/headers/table-header.js +50 -17
- package/{src → dist}/lib/components/index.d.ts +6 -1
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/components/index.js +32 -0
- package/{src → dist}/lib/components/pagination/data-table-pagination.d.ts +2 -1
- package/dist/lib/components/pagination/data-table-pagination.d.ts.map +1 -0
- package/{src → dist}/lib/components/pagination/data-table-pagination.js +20 -6
- package/dist/lib/components/pagination/index.d.ts +5 -0
- package/dist/lib/components/pagination/index.d.ts.map +1 -0
- package/dist/lib/components/pagination/index.js +20 -0
- package/{src → dist}/lib/components/rows/data-table-row.d.ts +15 -2
- package/dist/lib/components/rows/data-table-row.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/data-table-row.js +58 -25
- package/{src → dist}/lib/components/rows/empty-data-row.d.ts +3 -3
- package/dist/lib/components/rows/empty-data-row.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/empty-data-row.js +12 -4
- package/dist/lib/components/rows/index.d.ts +7 -0
- package/dist/lib/components/rows/index.d.ts.map +1 -0
- package/dist/lib/components/rows/index.js +22 -0
- package/{src → dist}/lib/components/rows/loading-rows.d.ts +3 -1
- package/dist/lib/components/rows/loading-rows.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/loading-rows.js +27 -19
- package/{src → dist}/lib/components/toolbar/bulk-actions-toolbar.d.ts +4 -3
- package/dist/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +1 -0
- package/dist/lib/components/toolbar/bulk-actions-toolbar.js +49 -0
- package/{src → dist}/lib/components/toolbar/column-filter-control.d.ts +3 -1
- package/dist/lib/components/toolbar/column-filter-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-filter-control.js +73 -4
- package/{src → dist}/lib/components/toolbar/column-pinning-control.d.ts +2 -1
- package/dist/lib/components/toolbar/column-pinning-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-pinning-control.js +71 -7
- package/{src → dist}/lib/components/toolbar/column-reset-control.d.ts +3 -1
- package/dist/lib/components/toolbar/column-reset-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-reset-control.js +9 -3
- package/{src → dist}/lib/components/toolbar/column-visibility-control.d.ts +2 -1
- package/dist/lib/components/toolbar/column-visibility-control.d.ts.map +1 -0
- package/dist/lib/components/toolbar/column-visibility-control.js +77 -0
- package/{src → dist}/lib/components/toolbar/data-table-toolbar.d.ts +3 -2
- package/dist/lib/components/toolbar/data-table-toolbar.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/data-table-toolbar.js +17 -4
- package/{src → dist}/lib/components/toolbar/index.d.ts +4 -0
- package/dist/lib/components/toolbar/index.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/index.js +6 -0
- package/dist/lib/components/toolbar/table-export-control.d.ts +12 -0
- package/dist/lib/components/toolbar/table-export-control.d.ts.map +1 -0
- package/dist/lib/components/toolbar/table-export-control.js +67 -0
- package/{src → dist}/lib/components/toolbar/table-search-control.d.ts +3 -1
- package/dist/lib/components/toolbar/table-search-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/table-search-control.js +45 -2
- package/{src → dist}/lib/components/toolbar/table-size-control.d.ts +3 -1
- package/dist/lib/components/toolbar/table-size-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/table-size-control.js +20 -8
- package/{src → dist}/lib/contexts/data-table-context.d.ts +6 -2
- package/dist/lib/contexts/data-table-context.d.ts.map +1 -0
- package/{src → dist}/lib/contexts/data-table-context.js +34 -1
- package/dist/lib/data-table.d.ts +5 -0
- package/dist/lib/data-table.d.ts.map +1 -0
- package/{src/lib/components/table → dist/lib}/data-table.js +449 -151
- package/dist/lib/features/column-filter.feature.d.ts +55 -0
- package/dist/lib/features/column-filter.feature.d.ts.map +1 -0
- package/{src → dist}/lib/features/column-filter.feature.js +116 -18
- package/dist/lib/features/index.d.ts +9 -0
- package/dist/lib/features/index.d.ts.map +1 -0
- package/{src → dist}/lib/features/index.js +7 -0
- package/{src → dist}/lib/features/selection.feature.d.ts +8 -1
- package/dist/lib/features/selection.feature.d.ts.map +1 -0
- package/{src → dist}/lib/features/selection.feature.js +76 -15
- package/dist/lib/icons/add-icon.d.ts +4 -0
- package/dist/lib/icons/add-icon.d.ts.map +1 -0
- package/dist/lib/icons/add-icon.js +12 -0
- package/dist/lib/icons/csv-icon.d.ts +4 -0
- package/dist/lib/icons/csv-icon.d.ts.map +1 -0
- package/dist/lib/icons/csv-icon.js +12 -0
- package/dist/lib/icons/delete-icon.d.ts +4 -0
- package/dist/lib/icons/delete-icon.d.ts.map +1 -0
- package/dist/lib/icons/delete-icon.js +12 -0
- package/dist/lib/icons/excel-icon.d.ts +4 -0
- package/dist/lib/icons/excel-icon.d.ts.map +1 -0
- package/dist/lib/icons/excel-icon.js +12 -0
- package/dist/lib/icons/index.d.ts +8 -0
- package/dist/lib/icons/index.d.ts.map +1 -0
- package/dist/lib/icons/unpin-icon.d.ts +4 -0
- package/dist/lib/icons/unpin-icon.d.ts.map +1 -0
- package/dist/lib/icons/unpin-icon.js +12 -0
- package/{src → dist}/lib/icons/view-comfortable-icon.d.ts +3 -1
- package/dist/lib/icons/view-comfortable-icon.d.ts.map +1 -0
- package/dist/lib/icons/view-comfortable-icon.js +12 -0
- package/dist/lib/icons/view-compact-icon.d.ts +4 -0
- package/dist/lib/icons/view-compact-icon.d.ts.map +1 -0
- package/dist/lib/icons/view-compact-icon.js +12 -0
- package/{src → dist}/lib/types/column.types.d.ts +10 -1
- package/dist/lib/types/column.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/data-table-api.d.ts +2 -1
- package/dist/lib/types/data-table-api.d.ts.map +1 -0
- package/{src/lib/components/table → dist/lib/types}/data-table.types.d.ts +10 -10
- package/dist/lib/types/data-table.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/export.types.d.ts +38 -0
- package/dist/lib/types/export.types.d.ts.map +1 -0
- package/dist/lib/types/export.types.js +6 -0
- package/{src → dist}/lib/types/index.d.ts +5 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +30 -0
- package/{src → dist}/lib/types/slots.types.d.ts +50 -3
- package/dist/lib/types/slots.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/table.types.d.ts +14 -0
- package/dist/lib/types/table.types.d.ts.map +1 -0
- package/{src → dist}/lib/utils/column-helpers.d.ts +10 -0
- package/dist/lib/utils/column-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/column-helpers.js +20 -4
- package/{src → dist}/lib/utils/debounced-fetch.utils.d.ts +3 -5
- package/dist/lib/utils/debounced-fetch.utils.d.ts.map +1 -0
- package/{src → dist}/lib/utils/debounced-fetch.utils.js +12 -6
- package/{src → dist}/lib/utils/export-utils.d.ts +13 -0
- package/dist/lib/utils/export-utils.d.ts.map +1 -0
- package/dist/lib/utils/export-utils.js +252 -0
- package/{src → dist}/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +35 -0
- package/{src → dist}/lib/utils/logger.d.ts +43 -0
- package/dist/lib/utils/logger.d.ts.map +1 -0
- package/{src → dist}/lib/utils/logger.js +22 -2
- package/{src → dist}/lib/utils/slot-helpers.d.ts +39 -1
- package/dist/lib/utils/slot-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/slot-helpers.js +55 -6
- package/{src → dist}/lib/utils/special-columns.utils.d.ts +10 -0
- package/dist/lib/utils/special-columns.utils.d.ts.map +1 -0
- package/{src → dist}/lib/utils/special-columns.utils.js +41 -5
- package/{src → dist}/lib/utils/styling-helpers.d.ts +20 -0
- package/dist/lib/utils/styling-helpers.d.ts.map +1 -0
- package/dist/lib/utils/styling-helpers.js +108 -0
- package/{src → dist}/lib/utils/table-helpers.d.ts +25 -0
- package/dist/lib/utils/table-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/table-helpers.js +24 -0
- package/package.json +36 -11
- package/src/index.ts +71 -0
- package/src/lib/components/droupdown/menu-dropdown.tsx +97 -0
- package/src/lib/components/filters/filter-value-input.tsx +225 -0
- package/src/lib/components/filters/{index.js → index.ts} +3 -6
- package/src/lib/components/headers/draggable-header.tsx +326 -0
- package/src/lib/components/headers/{index.d.ts → index.ts} +4 -0
- package/src/lib/components/headers/table-header.tsx +173 -0
- package/src/lib/components/index.ts +21 -0
- package/src/lib/components/pagination/data-table-pagination.tsx +99 -0
- package/src/lib/components/pagination/index.ts +5 -0
- package/src/lib/components/rows/data-table-row.tsx +208 -0
- package/src/lib/components/rows/empty-data-row.tsx +69 -0
- package/src/lib/components/rows/{index.d.ts → index.ts} +4 -0
- package/src/lib/components/rows/loading-rows.tsx +160 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +125 -0
- package/src/lib/components/toolbar/column-filter-control.tsx +374 -0
- package/src/lib/components/toolbar/column-pinning-control.tsx +275 -0
- package/src/lib/components/toolbar/column-reset-control.tsx +74 -0
- package/src/lib/components/toolbar/column-visibility-control.tsx +105 -0
- package/src/lib/components/toolbar/data-table-toolbar.tsx +229 -0
- package/src/lib/components/toolbar/index.ts +17 -0
- package/src/lib/components/toolbar/table-export-control.tsx +179 -0
- package/src/lib/components/toolbar/table-search-control.tsx +155 -0
- package/src/lib/components/toolbar/table-size-control.tsx +102 -0
- package/src/lib/contexts/data-table-context.tsx +112 -0
- package/src/lib/data-table.tsx +1911 -0
- package/src/lib/features/README.md +161 -0
- package/src/lib/features/column-filter.feature.ts +456 -0
- package/src/lib/features/index.ts +23 -0
- package/src/lib/features/selection.feature.ts +318 -0
- package/src/lib/icons/add-icon.tsx +23 -0
- package/src/lib/icons/csv-icon.tsx +15 -0
- package/src/lib/icons/delete-icon.tsx +30 -0
- package/src/lib/icons/excel-icon.tsx +15 -0
- package/src/lib/icons/unpin-icon.tsx +18 -0
- package/src/lib/icons/view-comfortable-icon.tsx +45 -0
- package/src/lib/icons/view-compact-icon.tsx +55 -0
- package/src/lib/types/column.types.ts +44 -0
- package/src/lib/types/data-table-api.ts +169 -0
- package/src/lib/types/data-table.types.ts +139 -0
- package/src/lib/types/export.types.ts +154 -0
- package/src/lib/types/index.ts +22 -0
- package/src/lib/types/slots.types.ts +332 -0
- package/src/lib/types/table.types.ts +90 -0
- package/src/lib/utils/column-helpers.ts +72 -0
- package/src/lib/utils/debounced-fetch.utils.ts +54 -0
- package/src/lib/utils/export-utils.ts +285 -0
- package/src/lib/utils/index.ts +27 -0
- package/src/lib/utils/logger.ts +203 -0
- package/src/lib/utils/slot-helpers.tsx +194 -0
- package/src/lib/utils/special-columns.utils.ts +94 -0
- package/src/lib/utils/styling-helpers.ts +126 -0
- package/src/lib/utils/table-helpers.ts +106 -0
- package/src/index.js +0 -27
- package/src/lib/components/filters/filter-value-input.js +0 -41
- package/src/lib/components/headers/index.js +0 -5
- package/src/lib/components/index.js +0 -10
- package/src/lib/components/pagination/index.d.ts +0 -1
- package/src/lib/components/pagination/index.js +0 -4
- package/src/lib/components/rows/index.js +0 -6
- package/src/lib/components/table/data-table.d.ts +0 -4
- package/src/lib/components/table/index.d.ts +0 -2
- package/src/lib/components/table/index.js +0 -5
- package/src/lib/components/toolbar/bulk-actions-toolbar.js +0 -30
- package/src/lib/components/toolbar/column-visibility-control.js +0 -31
- package/src/lib/components/toolbar/table-export-control.d.ts +0 -31
- package/src/lib/components/toolbar/table-export-control.js +0 -56
- package/src/lib/examples/advanced-features-example.d.ts +0 -1
- package/src/lib/examples/advanced-features-example.js +0 -269
- package/src/lib/examples/bulk-actions-test.d.ts +0 -1
- package/src/lib/examples/bulk-actions-test.js +0 -44
- package/src/lib/examples/custom-column-filter-example.d.ts +0 -1
- package/src/lib/examples/custom-column-filter-example.js +0 -60
- package/src/lib/examples/index.d.ts +0 -8
- package/src/lib/examples/index.js +0 -19
- package/src/lib/examples/selection-test-example.d.ts +0 -1
- package/src/lib/examples/selection-test-example.js +0 -101
- package/src/lib/examples/server-side-fetching-example.d.ts +0 -1
- package/src/lib/examples/server-side-fetching-example.js +0 -245
- package/src/lib/examples/server-side-test.d.ts +0 -1
- package/src/lib/examples/server-side-test.js +0 -9
- package/src/lib/examples/simple-local-example.d.ts +0 -1
- package/src/lib/examples/simple-local-example.js +0 -95
- package/src/lib/examples/simple-slots-example.d.ts +0 -1
- package/src/lib/examples/simple-slots-example.js +0 -115
- package/src/lib/features/column-filter.feature.d.ts +0 -45
- package/src/lib/features/index.d.ts +0 -2
- package/src/lib/hooks/index.d.ts +0 -1
- package/src/lib/hooks/index.js +0 -4
- package/src/lib/hooks/use-data-table-api.d.ts +0 -46
- package/src/lib/hooks/use-data-table-api.js +0 -690
- package/src/lib/icons/add-icon.d.ts +0 -2
- package/src/lib/icons/add-icon.js +0 -8
- package/src/lib/icons/csv-icon.d.ts +0 -2
- package/src/lib/icons/csv-icon.js +0 -8
- package/src/lib/icons/delete-icon.d.ts +0 -2
- package/src/lib/icons/delete-icon.js +0 -8
- package/src/lib/icons/excel-icon.d.ts +0 -2
- package/src/lib/icons/excel-icon.js +0 -8
- package/src/lib/icons/unpin-icon.d.ts +0 -2
- package/src/lib/icons/unpin-icon.js +0 -8
- package/src/lib/icons/view-comfortable-icon.js +0 -8
- package/src/lib/icons/view-compact-icon.d.ts +0 -2
- package/src/lib/icons/view-compact-icon.js +0 -8
- package/src/lib/types/export.types.js +0 -2
- package/src/lib/types/index.js +0 -8
- package/src/lib/utils/export-utils.js +0 -175
- package/src/lib/utils/index.js +0 -11
- package/src/lib/utils/styling-helpers.js +0 -70
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/lib/icons/index.js +0 -0
- /package/{src → dist}/lib/types/column.types.js +0 -0
- /package/{src → dist}/lib/types/data-table-api.js +0 -0
- /package/{src/lib/components/table → dist/lib/types}/data-table.types.js +0 -0
- /package/{src → dist}/lib/types/slots.types.js +0 -0
- /package/{src → dist}/lib/types/table.types.js +0 -0
- /package/src/lib/icons/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolbar components for DataTable
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Main toolbar component
|
|
6
|
+
export { DataTableToolbar } from './data-table-toolbar';
|
|
7
|
+
|
|
8
|
+
// Individual toolbar building blocks - export for custom toolbars
|
|
9
|
+
export { ColumnVisibilityControl } from './column-visibility-control';
|
|
10
|
+
export { ColumnPinningControl } from './column-pinning-control';
|
|
11
|
+
export { ColumnResetControl } from './column-reset-control';
|
|
12
|
+
export { TableExportControl } from './table-export-control';
|
|
13
|
+
export { TableSizeControl } from './table-size-control';
|
|
14
|
+
export { ColumnFilterControl } from './column-filter-control';
|
|
15
|
+
// Bulk actions
|
|
16
|
+
export { BulkActionsToolbar } from './bulk-actions-toolbar';
|
|
17
|
+
export type { BulkActionsToolbarProps } from './bulk-actions-toolbar';
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { CloudDownloadOutlined } from '@mui/icons-material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
IconButton,
|
|
5
|
+
Tooltip,
|
|
6
|
+
MenuItem,
|
|
7
|
+
ListItemIcon,
|
|
8
|
+
ListItemText,
|
|
9
|
+
Typography,
|
|
10
|
+
Box,
|
|
11
|
+
IconButtonProps,
|
|
12
|
+
SxProps,
|
|
13
|
+
} from '@mui/material';
|
|
14
|
+
|
|
15
|
+
import { MenuDropdown } from '../droupdown/menu-dropdown';
|
|
16
|
+
import { useDataTableContext } from '../../contexts/data-table-context';
|
|
17
|
+
import { ExcelIcon, CsvIcon } from '../../icons';
|
|
18
|
+
import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
|
|
19
|
+
|
|
20
|
+
interface TableExportControlProps {
|
|
21
|
+
// Optional props to override context defaults
|
|
22
|
+
exportFilename?: string;
|
|
23
|
+
// onServerExport?: (filters?: Partial<TableFilters>, selection?: SelectionState) => Promise<{ data: any[]; total: number }>;
|
|
24
|
+
// onExportProgress?: (progress: { processedRows?: number; totalRows?: number; percentage?: number }) => void;
|
|
25
|
+
// onExportComplete?: (result: { success: boolean; filename: string; totalRows: number }) => void;
|
|
26
|
+
// onExportError?: (error: { message: string; code: string }) => void;
|
|
27
|
+
// Enhanced customization props
|
|
28
|
+
iconButtonProps?: IconButtonProps;
|
|
29
|
+
tooltipProps?: any;
|
|
30
|
+
menuSx?: SxProps;
|
|
31
|
+
menuItemProps?: any;
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function TableExportControl(props: TableExportControlProps = {}) {
|
|
36
|
+
const {
|
|
37
|
+
exportFilename: propsExportFilename,
|
|
38
|
+
iconButtonProps,
|
|
39
|
+
tooltipProps,
|
|
40
|
+
menuSx,
|
|
41
|
+
menuItemProps,
|
|
42
|
+
} = props;
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
apiRef,
|
|
46
|
+
slots,
|
|
47
|
+
slotProps,
|
|
48
|
+
isExporting,
|
|
49
|
+
// Export callbacks from context (DataTable props)
|
|
50
|
+
exportFilename: contextExportFilename,
|
|
51
|
+
} = useDataTableContext();
|
|
52
|
+
|
|
53
|
+
// Use props if provided, otherwise fall back to context values
|
|
54
|
+
const exportFilename = propsExportFilename || contextExportFilename || 'export';
|
|
55
|
+
|
|
56
|
+
// Extract slot-specific props with enhanced merging
|
|
57
|
+
const exportIconSlotProps = extractSlotProps(slotProps, 'exportIcon');
|
|
58
|
+
const csvIconSlotProps = extractSlotProps(slotProps, 'csvIcon');
|
|
59
|
+
const excelIconSlotProps = extractSlotProps(slotProps, 'excelIcon');
|
|
60
|
+
|
|
61
|
+
const ExportIconSlot = getSlotComponent(slots, 'exportIcon', CloudDownloadOutlined);
|
|
62
|
+
const CsvIconSlot = getSlotComponent(slots, 'csvIcon', CsvIcon);
|
|
63
|
+
const ExcelIconSlot = getSlotComponent(slots, 'excelIcon', ExcelIcon);
|
|
64
|
+
|
|
65
|
+
const handleExport = async (format: 'csv' | 'excel') => {
|
|
66
|
+
if (!apiRef?.current) return;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
if (format === 'csv') {
|
|
70
|
+
await apiRef.current.export.exportCSV({
|
|
71
|
+
filename: exportFilename,
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
await apiRef.current.export.exportExcel({
|
|
75
|
+
filename: exportFilename,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error('Export failed:', error);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Merge all props for maximum flexibility
|
|
84
|
+
const mergedIconButtonProps = mergeSlotProps(
|
|
85
|
+
{
|
|
86
|
+
size: 'small',
|
|
87
|
+
disabled: isExporting,
|
|
88
|
+
sx: { flexShrink: 0 },
|
|
89
|
+
},
|
|
90
|
+
exportIconSlotProps,
|
|
91
|
+
iconButtonProps || {}
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const mergedMenuItemProps = mergeSlotProps(
|
|
95
|
+
{
|
|
96
|
+
sx: { minWidth: 150 },
|
|
97
|
+
},
|
|
98
|
+
menuItemProps || {}
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<MenuDropdown
|
|
103
|
+
anchor={(
|
|
104
|
+
<Tooltip
|
|
105
|
+
title={isExporting ? 'Export in progress...' : 'Export data'}
|
|
106
|
+
{...tooltipProps}
|
|
107
|
+
>
|
|
108
|
+
<IconButton
|
|
109
|
+
{...mergedIconButtonProps}
|
|
110
|
+
>
|
|
111
|
+
<ExportIconSlot {...exportIconSlotProps} />
|
|
112
|
+
</IconButton>
|
|
113
|
+
</Tooltip>
|
|
114
|
+
)}
|
|
115
|
+
>
|
|
116
|
+
{({ handleClose }: { handleClose: () => void }) => (
|
|
117
|
+
<Box
|
|
118
|
+
sx={{
|
|
119
|
+
minWidth: 200,
|
|
120
|
+
...menuSx,
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<Typography
|
|
124
|
+
variant="subtitle2"
|
|
125
|
+
sx={{ p: 2, pb: 1 }}
|
|
126
|
+
>
|
|
127
|
+
Export Format
|
|
128
|
+
</Typography>
|
|
129
|
+
|
|
130
|
+
<MenuItem
|
|
131
|
+
onClick={() => {
|
|
132
|
+
handleExport('csv');
|
|
133
|
+
handleClose();
|
|
134
|
+
}}
|
|
135
|
+
disabled={isExporting}
|
|
136
|
+
{...mergedMenuItemProps}
|
|
137
|
+
>
|
|
138
|
+
<ListItemIcon>
|
|
139
|
+
<CsvIconSlot {...csvIconSlotProps} />
|
|
140
|
+
</ListItemIcon>
|
|
141
|
+
<ListItemText
|
|
142
|
+
primary="CSV"
|
|
143
|
+
secondary="Comma-separated values"
|
|
144
|
+
/>
|
|
145
|
+
</MenuItem>
|
|
146
|
+
|
|
147
|
+
<MenuItem
|
|
148
|
+
onClick={() => {
|
|
149
|
+
handleExport('excel');
|
|
150
|
+
handleClose();
|
|
151
|
+
}}
|
|
152
|
+
disabled={isExporting}
|
|
153
|
+
{...mergedMenuItemProps}
|
|
154
|
+
>
|
|
155
|
+
<ListItemIcon>
|
|
156
|
+
<ExcelIconSlot {...excelIconSlotProps} />
|
|
157
|
+
</ListItemIcon>
|
|
158
|
+
<ListItemText
|
|
159
|
+
primary="Excel"
|
|
160
|
+
secondary="Microsoft Excel format"
|
|
161
|
+
/>
|
|
162
|
+
</MenuItem>
|
|
163
|
+
|
|
164
|
+
{isExporting && (
|
|
165
|
+
<Box sx={{ p: 2, pt: 1 }}>
|
|
166
|
+
<Typography
|
|
167
|
+
variant="caption"
|
|
168
|
+
color="text.secondary"
|
|
169
|
+
sx={{ display: 'block', textAlign: 'center' }}
|
|
170
|
+
>
|
|
171
|
+
Export in progress...
|
|
172
|
+
</Typography>
|
|
173
|
+
</Box>
|
|
174
|
+
)}
|
|
175
|
+
</Box>
|
|
176
|
+
)}
|
|
177
|
+
</MenuDropdown>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Clear, Search } from '@mui/icons-material';
|
|
2
|
+
import { Box, Tooltip, IconButton, Collapse, OutlinedInput, InputAdornment, IconButtonProps, OutlinedInputProps, SxProps } from '@mui/material';
|
|
3
|
+
import React, { useCallback, useEffect, useRef, useState, ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useDataTableContext } from '../../contexts/data-table-context';
|
|
6
|
+
import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
|
|
7
|
+
|
|
8
|
+
export interface TableSearchControlProps {
|
|
9
|
+
// Allow full customization of any prop
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
autoFocus?: boolean;
|
|
12
|
+
searchIconProps?: IconButtonProps;
|
|
13
|
+
clearIconProps?: IconButtonProps;
|
|
14
|
+
inputProps?: OutlinedInputProps;
|
|
15
|
+
containerSx?: SxProps;
|
|
16
|
+
tooltipProps?: any;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function TableSearchControl(props: TableSearchControlProps = {}): ReactElement {
|
|
21
|
+
const { table, slots, slotProps } = useDataTableContext();
|
|
22
|
+
const [searchVisible, setSearchVisible] = useState(false);
|
|
23
|
+
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
24
|
+
const globalFilter = table.getState().globalFilter || '';
|
|
25
|
+
const hasSearch = globalFilter.length > 0;
|
|
26
|
+
|
|
27
|
+
// Extract slot-specific props with enhanced merging
|
|
28
|
+
const searchIconSlotProps = extractSlotProps(slotProps, 'searchIcon');
|
|
29
|
+
const clearIconSlotProps = extractSlotProps(slotProps, 'clearIcon');
|
|
30
|
+
|
|
31
|
+
const SearchIconSlot = getSlotComponent(slots, 'searchIcon', Search);
|
|
32
|
+
const ClearIconSlot = getSlotComponent(slots, 'clearIcon', Clear);
|
|
33
|
+
|
|
34
|
+
const handleChange = useCallback(
|
|
35
|
+
(e: any) => {
|
|
36
|
+
table.setGlobalFilter(e.target.value);
|
|
37
|
+
},
|
|
38
|
+
[table],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const handleSearchToggle = () => {
|
|
42
|
+
if (searchVisible || hasSearch) {
|
|
43
|
+
// If search is visible or has text, hide it and clear
|
|
44
|
+
setSearchVisible(false);
|
|
45
|
+
table.setGlobalFilter('');
|
|
46
|
+
} else {
|
|
47
|
+
// Show search input
|
|
48
|
+
setSearchVisible(true);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const handleSearchClear = () => {
|
|
53
|
+
table.setGlobalFilter('');
|
|
54
|
+
if (searchInputRef.current) {
|
|
55
|
+
searchInputRef.current.focus();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleSearchBlur = () => {
|
|
60
|
+
// Only auto-hide if search is empty
|
|
61
|
+
if (searchVisible && !hasSearch) {
|
|
62
|
+
setSearchVisible(false);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (searchVisible && searchInputRef.current) {
|
|
68
|
+
// Add a delay to ensure the Collapse animation completes
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
searchInputRef.current?.focus();
|
|
71
|
+
}, 200);
|
|
72
|
+
return () => clearTimeout(timer);
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}, [searchVisible]);
|
|
76
|
+
|
|
77
|
+
// Merge all props for maximum flexibility
|
|
78
|
+
const mergedSearchIconProps = mergeSlotProps(
|
|
79
|
+
{
|
|
80
|
+
size: 'small',
|
|
81
|
+
onClick: handleSearchToggle,
|
|
82
|
+
color: hasSearch ? 'primary' : 'default',
|
|
83
|
+
sx: { flexShrink: 0 },
|
|
84
|
+
},
|
|
85
|
+
searchIconSlotProps,
|
|
86
|
+
props.searchIconProps || {}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const mergedClearIconProps = mergeSlotProps(
|
|
90
|
+
{
|
|
91
|
+
size: 'small',
|
|
92
|
+
onClick: handleSearchClear,
|
|
93
|
+
},
|
|
94
|
+
clearIconSlotProps,
|
|
95
|
+
props.clearIconProps || {}
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const mergedInputProps = mergeSlotProps(
|
|
99
|
+
{
|
|
100
|
+
inputRef: searchInputRef,
|
|
101
|
+
size: 'small',
|
|
102
|
+
placeholder: props.placeholder || 'Search...',
|
|
103
|
+
value: globalFilter,
|
|
104
|
+
onChange: handleChange,
|
|
105
|
+
onBlur: handleSearchBlur,
|
|
106
|
+
autoFocus: props.autoFocus,
|
|
107
|
+
sx: { minWidth: 200 },
|
|
108
|
+
},
|
|
109
|
+
props.inputProps || {}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Box
|
|
114
|
+
sx={{
|
|
115
|
+
display: 'flex',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
...props.containerSx,
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
{!(searchVisible || hasSearch) && (
|
|
121
|
+
<Tooltip
|
|
122
|
+
title="Search"
|
|
123
|
+
{...props.tooltipProps}
|
|
124
|
+
>
|
|
125
|
+
<IconButton
|
|
126
|
+
{...mergedSearchIconProps}
|
|
127
|
+
>
|
|
128
|
+
<SearchIconSlot {...searchIconSlotProps} />
|
|
129
|
+
</IconButton>
|
|
130
|
+
</Tooltip>
|
|
131
|
+
)}
|
|
132
|
+
|
|
133
|
+
<Collapse
|
|
134
|
+
in={searchVisible || hasSearch}
|
|
135
|
+
orientation="horizontal"
|
|
136
|
+
timeout={200}
|
|
137
|
+
>
|
|
138
|
+
<OutlinedInput
|
|
139
|
+
{...mergedInputProps}
|
|
140
|
+
endAdornment={
|
|
141
|
+
hasSearch ? (
|
|
142
|
+
<InputAdornment position="end">
|
|
143
|
+
<IconButton
|
|
144
|
+
{...mergedClearIconProps}
|
|
145
|
+
>
|
|
146
|
+
<ClearIconSlot {...clearIconSlotProps} />
|
|
147
|
+
</IconButton>
|
|
148
|
+
</InputAdornment>
|
|
149
|
+
) : null
|
|
150
|
+
}
|
|
151
|
+
/>
|
|
152
|
+
</Collapse>
|
|
153
|
+
</Box>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { LineWeightOutlined } from '@mui/icons-material';
|
|
3
|
+
import { MenuItem, ListItemIcon, ListItemText, Tooltip, IconButton, IconButtonProps, SxProps } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
import { MenuDropdown } from '../droupdown/menu-dropdown';
|
|
6
|
+
import { useDataTableContext } from '../../contexts/data-table-context';
|
|
7
|
+
import { ViewComfortableIcon, ViewCompactIcon } from '../../icons';
|
|
8
|
+
import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
|
|
9
|
+
|
|
10
|
+
export interface TableSizeControlProps {
|
|
11
|
+
// Allow full customization of any prop
|
|
12
|
+
iconButtonProps?: IconButtonProps;
|
|
13
|
+
menuProps?: any;
|
|
14
|
+
tooltipProps?: any;
|
|
15
|
+
containerSx?: SxProps;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function TableSizeControl(props: TableSizeControlProps = {}): ReactElement {
|
|
20
|
+
const { tableSize, onTableSizeChange, slotProps, slots } = useDataTableContext();
|
|
21
|
+
|
|
22
|
+
// Extract slot-specific props with enhanced merging
|
|
23
|
+
const tableSizeIconSlotProps = extractSlotProps(slotProps, 'tableSizeIcon');
|
|
24
|
+
const tableSizeSmallIconSlotProps = extractSlotProps(slotProps, 'tableSizeSmallIcon');
|
|
25
|
+
const tableSizeMediumIconSlotProps = extractSlotProps(slotProps, 'tableSizeMediumIcon');
|
|
26
|
+
|
|
27
|
+
const TableSizeIconSlot = getSlotComponent(slots, 'tableSizeIcon', LineWeightOutlined);
|
|
28
|
+
const TableSizeSmallIconSlot = getSlotComponent(slots, 'tableSizeSmallIcon', ViewCompactIcon);
|
|
29
|
+
const TableSizeMediumIconSlot = getSlotComponent(slots, 'tableSizeMediumIcon', ViewComfortableIcon);
|
|
30
|
+
|
|
31
|
+
const SIZE_OPTIONS = [
|
|
32
|
+
{
|
|
33
|
+
value: 'small' as const,
|
|
34
|
+
label: 'Compact',
|
|
35
|
+
description: 'Small padding, compact rows',
|
|
36
|
+
icon: <TableSizeSmallIconSlot {...tableSizeSmallIconSlotProps} />,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
value: 'medium' as const,
|
|
40
|
+
label: 'Standard',
|
|
41
|
+
description: 'Default padding and spacing',
|
|
42
|
+
icon: <TableSizeMediumIconSlot {...tableSizeMediumIconSlotProps} />,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Merge all props for maximum flexibility
|
|
47
|
+
const mergedIconButtonProps = mergeSlotProps(
|
|
48
|
+
{
|
|
49
|
+
size: 'small',
|
|
50
|
+
sx: { flexShrink: 0 },
|
|
51
|
+
},
|
|
52
|
+
tableSizeIconSlotProps,
|
|
53
|
+
props.iconButtonProps || {}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<MenuDropdown
|
|
58
|
+
anchor={(
|
|
59
|
+
<Tooltip
|
|
60
|
+
title="Table size"
|
|
61
|
+
{...props.tooltipProps}
|
|
62
|
+
>
|
|
63
|
+
<IconButton
|
|
64
|
+
{...mergedIconButtonProps}
|
|
65
|
+
>
|
|
66
|
+
<TableSizeIconSlot {...tableSizeIconSlotProps} />
|
|
67
|
+
</IconButton>
|
|
68
|
+
</Tooltip>
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
{SIZE_OPTIONS.map((option) => (
|
|
72
|
+
<MenuItem
|
|
73
|
+
key={option.value}
|
|
74
|
+
selected={tableSize === option.value}
|
|
75
|
+
onClick={() => onTableSizeChange(option.value)}
|
|
76
|
+
sx={{
|
|
77
|
+
minWidth: 200,
|
|
78
|
+
...props.containerSx,
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<ListItemIcon sx={{ minWidth: 36 }}>
|
|
82
|
+
{option.icon}
|
|
83
|
+
</ListItemIcon>
|
|
84
|
+
<ListItemText
|
|
85
|
+
primary={option.label}
|
|
86
|
+
secondary={option.description}
|
|
87
|
+
slotProps={{
|
|
88
|
+
primary: {
|
|
89
|
+
variant: 'body2',
|
|
90
|
+
fontWeight: tableSize === option.value ? 600 : 400,
|
|
91
|
+
},
|
|
92
|
+
secondary: {
|
|
93
|
+
variant: 'caption',
|
|
94
|
+
color: 'text.secondary',
|
|
95
|
+
},
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
</MenuItem>
|
|
99
|
+
))}
|
|
100
|
+
</MenuDropdown>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Table } from '@tanstack/react-table';
|
|
2
|
+
import React, { createContext, useContext, ReactNode, useMemo, RefObject, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { ColumnFilterState, TableSize } from '../types';
|
|
5
|
+
import { DataTableApi } from '../types/data-table-api';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Context value for the DataTable
|
|
10
|
+
*/
|
|
11
|
+
interface DataTableContextValue<T = any> {
|
|
12
|
+
table?: Table<T>;
|
|
13
|
+
apiRef?: RefObject<DataTableApi<T> | null>;
|
|
14
|
+
dataMode?: 'client' | 'server';
|
|
15
|
+
tableSize?: TableSize;
|
|
16
|
+
onTableSizeChange?: (size: TableSize) => void;
|
|
17
|
+
columnFilter?: ColumnFilterState;
|
|
18
|
+
onChangeColumnFilter?: (filter: ColumnFilterState) => void;
|
|
19
|
+
slots?: Record<string, any>;
|
|
20
|
+
slotProps?: Record<string, any>;
|
|
21
|
+
|
|
22
|
+
// Export state - managed by the DataTable component
|
|
23
|
+
isExporting?: boolean;
|
|
24
|
+
exportController?: AbortController | null;
|
|
25
|
+
onCancelExport?: () => void;
|
|
26
|
+
|
|
27
|
+
// Export callbacks - passed from DataTable props
|
|
28
|
+
exportFilename?: string;
|
|
29
|
+
onExportProgress?: (progress: { processedRows?: number; totalRows?: number; percentage?: number }) => void;
|
|
30
|
+
onExportComplete?: (result: { success: boolean; filename: string; totalRows: number }) => void;
|
|
31
|
+
onExportError?: (error: { message: string; code: string }) => void;
|
|
32
|
+
onServerExport?: (filters?: Partial<any>) => Promise<{ data: any[]; total: number }>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const DataTableContext = createContext<DataTableContextValue | null>(null);
|
|
36
|
+
|
|
37
|
+
interface DataTableProviderProps<T = any> extends DataTableContextValue<T> {
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function DataTableProvider<T = any>({
|
|
42
|
+
children,
|
|
43
|
+
table,
|
|
44
|
+
apiRef,
|
|
45
|
+
dataMode,
|
|
46
|
+
tableSize,
|
|
47
|
+
onTableSizeChange,
|
|
48
|
+
columnFilter,
|
|
49
|
+
onChangeColumnFilter,
|
|
50
|
+
slots = {},
|
|
51
|
+
slotProps = {},
|
|
52
|
+
isExporting,
|
|
53
|
+
exportController,
|
|
54
|
+
onCancelExport,
|
|
55
|
+
exportFilename,
|
|
56
|
+
onExportProgress,
|
|
57
|
+
onExportComplete,
|
|
58
|
+
onExportError,
|
|
59
|
+
onServerExport,
|
|
60
|
+
}: DataTableProviderProps<T>): ReactElement {
|
|
61
|
+
const value = useMemo(() => ({
|
|
62
|
+
table,
|
|
63
|
+
apiRef,
|
|
64
|
+
dataMode,
|
|
65
|
+
tableSize,
|
|
66
|
+
onTableSizeChange,
|
|
67
|
+
columnFilter,
|
|
68
|
+
onChangeColumnFilter,
|
|
69
|
+
slots,
|
|
70
|
+
slotProps,
|
|
71
|
+
isExporting,
|
|
72
|
+
exportController,
|
|
73
|
+
onCancelExport,
|
|
74
|
+
exportFilename,
|
|
75
|
+
onExportProgress,
|
|
76
|
+
onExportComplete,
|
|
77
|
+
onExportError,
|
|
78
|
+
onServerExport,
|
|
79
|
+
}), [
|
|
80
|
+
table,
|
|
81
|
+
apiRef,
|
|
82
|
+
dataMode,
|
|
83
|
+
tableSize,
|
|
84
|
+
onTableSizeChange,
|
|
85
|
+
columnFilter,
|
|
86
|
+
onChangeColumnFilter,
|
|
87
|
+
slots,
|
|
88
|
+
slotProps,
|
|
89
|
+
isExporting,
|
|
90
|
+
exportController,
|
|
91
|
+
onCancelExport,
|
|
92
|
+
exportFilename,
|
|
93
|
+
onExportProgress,
|
|
94
|
+
onExportComplete,
|
|
95
|
+
onExportError,
|
|
96
|
+
onServerExport,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<DataTableContext.Provider value={value}>
|
|
101
|
+
{children}
|
|
102
|
+
</DataTableContext.Provider>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function useDataTableContext<T = any>(): DataTableContextValue<T> {
|
|
107
|
+
const context = useContext(DataTableContext);
|
|
108
|
+
if (!context) {
|
|
109
|
+
throw new Error('useDataTableContext must be used within a DataTableProvider');
|
|
110
|
+
}
|
|
111
|
+
return context;
|
|
112
|
+
}
|