@ackplus/react-tanstack-data-table 1.0.19-beta-0.7 → 1.0.19-beta-0.8
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/README.md +599 -0
- package/package.json +1 -1
- package/src/index.d.ts +19 -0
- package/src/index.js +31 -0
- package/src/lib/components/droupdown/menu-dropdown.d.ts +17 -0
- package/src/lib/components/droupdown/menu-dropdown.js +52 -0
- package/src/lib/components/filters/filter-value-input.d.ts +9 -0
- package/src/lib/components/filters/filter-value-input.js +58 -0
- package/src/lib/components/filters/index.d.ts +23 -0
- package/src/lib/components/filters/index.js +129 -0
- package/src/lib/components/headers/draggable-header.d.ts +12 -0
- package/src/lib/components/headers/draggable-header.js +212 -0
- package/src/lib/components/headers/index.d.ts +2 -0
- package/src/lib/components/headers/index.js +5 -0
- package/src/lib/components/headers/table-header.d.ts +10 -0
- package/src/lib/components/headers/table-header.js +48 -0
- package/src/lib/components/index.d.ts +7 -0
- package/src/lib/components/index.js +10 -0
- package/src/lib/components/pagination/data-table-pagination.d.ts +11 -0
- package/src/lib/components/pagination/data-table-pagination.js +25 -0
- package/src/lib/components/pagination/index.d.ts +1 -0
- package/src/lib/components/pagination/index.js +4 -0
- package/src/lib/components/rows/data-table-row.d.ts +13 -0
- package/src/lib/components/rows/data-table-row.js +31 -0
- package/src/lib/components/rows/empty-data-row.d.ts +6 -0
- package/src/lib/components/rows/empty-data-row.js +11 -0
- package/src/lib/components/rows/index.d.ts +3 -0
- package/src/lib/components/rows/index.js +6 -0
- package/src/lib/components/rows/loading-rows.d.ts +5 -0
- package/src/lib/components/rows/loading-rows.js +49 -0
- package/src/lib/components/table/data-table.d.ts +3 -0
- package/src/lib/components/table/data-table.js +492 -0
- package/src/lib/components/table/data-table.types.d.ts +114 -0
- package/src/lib/components/table/data-table.types.js +2 -0
- package/src/lib/components/table/index.d.ts +2 -0
- package/src/lib/components/table/index.js +5 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.d.ts +9 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.js +25 -0
- package/src/lib/components/toolbar/column-custom-filter-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-custom-filter-control.js +137 -0
- package/src/lib/components/toolbar/column-pinning-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-pinning-control.js +105 -0
- package/src/lib/components/toolbar/column-reset-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-reset-control.js +16 -0
- package/src/lib/components/toolbar/column-visibility-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-visibility-control.js +31 -0
- package/src/lib/components/toolbar/data-table-toolbar.d.ts +14 -0
- package/src/lib/components/toolbar/data-table-toolbar.js +26 -0
- package/src/lib/components/toolbar/index.d.ts +8 -0
- package/src/lib/components/toolbar/index.js +17 -0
- package/src/lib/components/toolbar/table-export-control.d.ts +25 -0
- package/src/lib/components/toolbar/table-export-control.js +93 -0
- package/src/lib/components/toolbar/table-search-control.d.ts +1 -0
- package/src/lib/components/toolbar/table-search-control.js +61 -0
- package/src/lib/components/toolbar/table-size-control.d.ts +1 -0
- package/src/lib/components/toolbar/table-size-control.js +36 -0
- package/src/lib/contexts/data-table-context.d.ts +43 -0
- package/src/lib/contexts/data-table-context.js +54 -0
- package/src/lib/examples/advanced-features-example.d.ts +1 -0
- package/src/lib/examples/advanced-features-example.js +264 -0
- package/src/lib/examples/bulk-actions-test.d.ts +1 -0
- package/src/lib/examples/bulk-actions-test.js +44 -0
- package/src/lib/examples/custom-column-filter-example.d.ts +1 -0
- package/src/lib/examples/custom-column-filter-example.js +60 -0
- package/src/lib/examples/index.d.ts +5 -0
- package/src/lib/examples/index.js +13 -0
- package/src/lib/examples/selection-test-example.d.ts +1 -0
- package/src/lib/examples/selection-test-example.js +101 -0
- package/src/lib/examples/simple-local-example.d.ts +1 -0
- package/src/lib/examples/simple-local-example.js +97 -0
- package/src/lib/features/custom-column-filter.feature.d.ts +45 -0
- package/src/lib/features/custom-column-filter.feature.js +247 -0
- package/src/lib/features/custom-selection.feature.d.ts +46 -0
- package/src/lib/features/custom-selection.feature.js +172 -0
- package/src/lib/features/index.d.ts +2 -0
- package/src/lib/features/index.js +8 -0
- package/src/lib/hooks/index.d.ts +1 -0
- package/src/lib/hooks/index.js +4 -0
- package/src/lib/hooks/use-data-table-api.d.ts +56 -0
- package/src/lib/hooks/use-data-table-api.js +616 -0
- package/src/lib/icons/add-icon.d.ts +2 -0
- package/src/lib/icons/add-icon.js +8 -0
- package/src/lib/icons/csv-icon.d.ts +2 -0
- package/src/lib/icons/csv-icon.js +8 -0
- package/src/lib/icons/delete-icon.d.ts +2 -0
- package/src/lib/icons/delete-icon.js +8 -0
- package/src/lib/icons/excel-icon.d.ts +2 -0
- package/src/lib/icons/excel-icon.js +8 -0
- package/src/lib/icons/index.d.ts +7 -0
- package/src/lib/icons/index.js +17 -0
- package/src/lib/icons/unpin-icon.d.ts +2 -0
- package/src/lib/icons/unpin-icon.js +8 -0
- package/src/lib/icons/view-comfortable-icon.d.ts +2 -0
- package/src/lib/icons/view-comfortable-icon.js +8 -0
- package/src/lib/icons/view-compact-icon.d.ts +2 -0
- package/src/lib/icons/view-compact-icon.js +8 -0
- package/src/lib/types/column.types.d.ts +29 -0
- package/src/lib/types/column.types.js +5 -0
- package/src/lib/types/data-table-api.d.ts +134 -0
- package/src/lib/types/data-table-api.js +2 -0
- package/src/lib/types/export.types.d.ts +99 -0
- package/src/lib/types/export.types.js +2 -0
- package/src/lib/types/index.d.ts +6 -0
- package/src/lib/types/index.js +8 -0
- package/src/lib/types/slots.types.d.ts +272 -0
- package/src/lib/types/slots.types.js +2 -0
- package/src/lib/types/table.types.d.ts +63 -0
- package/src/lib/types/table.types.js +2 -0
- package/src/lib/utils/column-helpers.d.ts +7 -0
- package/src/lib/utils/column-helpers.js +43 -0
- package/src/lib/utils/debounced-fetch.utils.d.ts +11 -0
- package/src/lib/utils/debounced-fetch.utils.js +49 -0
- package/src/lib/utils/export-utils.d.ts +30 -0
- package/src/lib/utils/export-utils.js +152 -0
- package/src/lib/utils/index.d.ts +7 -0
- package/src/lib/utils/index.js +10 -0
- package/src/lib/utils/slot-helpers.d.ts +9 -0
- package/src/lib/utils/slot-helpers.js +21 -0
- package/src/lib/utils/special-columns.utils.d.ts +6 -0
- package/src/lib/utils/special-columns.utils.js +52 -0
- package/src/lib/utils/styling-helpers.d.ts +36 -0
- package/src/lib/utils/styling-helpers.js +61 -0
- package/src/lib/utils/table-helpers.d.ts +9 -0
- package/src/lib/utils/table-helpers.js +57 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MenuDropdown = MenuDropdown;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
function MenuDropdown(_a) {
|
|
9
|
+
var { children, anchor, label, component, sx } = _a, props = tslib_1.__rest(_a, ["children", "anchor", "label", "component", "sx"]);
|
|
10
|
+
const [anchorEl, setAnchorEl] = (0, react_1.useState)(null);
|
|
11
|
+
const isOpen = (0, react_1.useMemo)(() => Boolean(anchorEl), [anchorEl]);
|
|
12
|
+
const handleClick = (0, react_1.useCallback)((event) => {
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
event.stopPropagation();
|
|
15
|
+
setAnchorEl(event.currentTarget);
|
|
16
|
+
}, []);
|
|
17
|
+
const handleClose = (0, react_1.useCallback)((event) => {
|
|
18
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
19
|
+
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
20
|
+
setAnchorEl(null);
|
|
21
|
+
}, []);
|
|
22
|
+
const anchorNode = (0, react_1.useMemo)(() => {
|
|
23
|
+
if (anchor) {
|
|
24
|
+
let node = anchor;
|
|
25
|
+
if (typeof anchor === 'function') {
|
|
26
|
+
node = anchor({ isOpen: isOpen });
|
|
27
|
+
}
|
|
28
|
+
return (0, react_1.cloneElement)(node, {
|
|
29
|
+
onClick: handleClick,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: handleClick, children: label });
|
|
33
|
+
}, [
|
|
34
|
+
anchor,
|
|
35
|
+
handleClick,
|
|
36
|
+
isOpen,
|
|
37
|
+
label,
|
|
38
|
+
]);
|
|
39
|
+
const DropDownComponent = (component || material_1.Popover);
|
|
40
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [anchorNode, (0, jsx_runtime_1.jsx)(DropDownComponent, Object.assign({ anchorEl: anchorEl, open: isOpen, onClose: handleClose, anchorOrigin: {
|
|
41
|
+
vertical: 'bottom',
|
|
42
|
+
horizontal: 'left',
|
|
43
|
+
}, transformOrigin: {
|
|
44
|
+
vertical: 'top',
|
|
45
|
+
horizontal: 'left',
|
|
46
|
+
} }, props, { children: typeof children === 'function' ?
|
|
47
|
+
children({
|
|
48
|
+
handleClose,
|
|
49
|
+
open: isOpen,
|
|
50
|
+
}) :
|
|
51
|
+
children }))] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Column } from '@tanstack/react-table';
|
|
2
|
+
import { ColumnFilterRule } from '../../features';
|
|
3
|
+
interface FilterValueInputProps<T> {
|
|
4
|
+
filter: ColumnFilterRule;
|
|
5
|
+
column: Column<T, any>;
|
|
6
|
+
onValueChange: (value: any) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function FilterValueInput<T>({ filter, column, onValueChange, }: FilterValueInputProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterValueInput = FilterValueInput;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const DatePicker_1 = require("@mui/x-date-pickers/DatePicker");
|
|
8
|
+
const moment_1 = tslib_1.__importDefault(require("moment"));
|
|
9
|
+
const column_helpers_1 = require("../../utils/column-helpers");
|
|
10
|
+
const AdapterMoment_1 = require("@mui/x-date-pickers/AdapterMoment");
|
|
11
|
+
const x_date_pickers_1 = require("@mui/x-date-pickers");
|
|
12
|
+
function FilterValueInput({ filter, column, onValueChange, }) {
|
|
13
|
+
const columnType = (0, column_helpers_1.getColumnType)(column);
|
|
14
|
+
const customComponent = (0, column_helpers_1.getCustomFilterComponent)(column);
|
|
15
|
+
const options = (0, column_helpers_1.getColumnOptions)(column);
|
|
16
|
+
const operator = filter.operator;
|
|
17
|
+
if (customComponent) {
|
|
18
|
+
const CustomComponent = customComponent;
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(CustomComponent, { value: filter.value, onChange: onValueChange, filter: filter, column: column }));
|
|
20
|
+
}
|
|
21
|
+
if (columnType === 'boolean') {
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.FormControl, { size: "small", sx: {
|
|
23
|
+
flex: 1,
|
|
24
|
+
minWidth: 120,
|
|
25
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { children: "Value" }), (0, jsx_runtime_1.jsxs)(material_1.Select, { value: filter.value || 'any', label: "Value", onChange: (e) => onValueChange(e.target.value), children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: 'any', children: "Any" }, 'any'), (0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: 'true', children: "True" }, 'true'), (0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: 'false', children: "False" }, 'false')] })] }));
|
|
26
|
+
}
|
|
27
|
+
if (columnType === 'select' && options.length > 0) {
|
|
28
|
+
if (operator === 'in' || operator === 'notIn') {
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.FormControl, { size: "small", sx: { flex: 1, minWidth: 120 }, children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { children: "Value" }), (0, jsx_runtime_1.jsx)(material_1.Select, { multiple: true, value: Array.isArray(filter.value) ? filter.value : [], label: "Value", onChange: (e) => onValueChange(e.target.value), renderValue: (selected) => selected.map(val => {
|
|
30
|
+
const opt = options.find(o => o.value === val);
|
|
31
|
+
return opt ? opt.label : val;
|
|
32
|
+
}).join(', '), children: options.map(option => ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { value: option.value, children: [(0, jsx_runtime_1.jsx)(material_1.Checkbox, { checked: Array.isArray(filter.value) && filter.value.indexOf(option.value) > -1 }), (0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: option.label })] }, String(option.value)))) })] }));
|
|
33
|
+
}
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.FormControl, { size: "small", sx: { flex: 1, minWidth: 120 }, children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { children: "Value" }), (0, jsx_runtime_1.jsx)(material_1.Select, { value: filter.value, label: "Value", onChange: (e) => onValueChange(e.target.value), children: options.map(option => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: option.value, children: option.label }, String(option.value)))) })] }));
|
|
35
|
+
}
|
|
36
|
+
if (columnType === 'date') {
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(x_date_pickers_1.LocalizationProvider, { dateAdapter: AdapterMoment_1.AdapterMoment, children: (0, jsx_runtime_1.jsx)(DatePicker_1.DatePicker, { value: filter.value ? (0, moment_1.default)(filter.value) : null, onChange: (e) => onValueChange(e === null || e === void 0 ? void 0 : e.toDate()), slotProps: {
|
|
38
|
+
textField: {
|
|
39
|
+
size: 'small',
|
|
40
|
+
label: 'Value',
|
|
41
|
+
sx: {
|
|
42
|
+
flex: 1,
|
|
43
|
+
minWidth: 120,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
} }) }));
|
|
47
|
+
}
|
|
48
|
+
if (columnType === 'number') {
|
|
49
|
+
return ((0, jsx_runtime_1.jsx)(material_1.TextField, { size: "small", label: "Value", value: filter.value, onChange: (e) => onValueChange(e.target.value), type: "number", sx: {
|
|
50
|
+
flex: 1,
|
|
51
|
+
minWidth: 120,
|
|
52
|
+
} }));
|
|
53
|
+
}
|
|
54
|
+
return ((0, jsx_runtime_1.jsx)(material_1.TextField, { size: "small", label: "Value", value: filter.value, onChange: (e) => onValueChange(e.target.value), sx: {
|
|
55
|
+
flex: 1,
|
|
56
|
+
minWidth: 120,
|
|
57
|
+
} }));
|
|
58
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const FILTER_OPERATORS: {
|
|
2
|
+
text: {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}[];
|
|
6
|
+
boolean: {
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}[];
|
|
10
|
+
number: {
|
|
11
|
+
value: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}[];
|
|
14
|
+
date: {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
select: {
|
|
19
|
+
value: string;
|
|
20
|
+
label: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
export * from './filter-value-input';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FILTER_OPERATORS = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
exports.FILTER_OPERATORS = {
|
|
6
|
+
text: [
|
|
7
|
+
{
|
|
8
|
+
value: 'contains',
|
|
9
|
+
label: 'Contains',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
value: 'startsWith',
|
|
13
|
+
label: 'Starts with',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
value: 'endsWith',
|
|
17
|
+
label: 'Ends with',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: 'equals',
|
|
21
|
+
label: 'Equals',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: 'notEquals',
|
|
25
|
+
label: 'Not equals',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: 'isEmpty',
|
|
29
|
+
label: 'Is empty',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
value: 'isNotEmpty',
|
|
33
|
+
label: 'Is not empty',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
boolean: [
|
|
37
|
+
{
|
|
38
|
+
value: 'is',
|
|
39
|
+
label: 'Is',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
number: [
|
|
43
|
+
{
|
|
44
|
+
value: 'equals',
|
|
45
|
+
label: 'Equals',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
value: 'notEquals',
|
|
49
|
+
label: 'Not equals',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
value: 'greaterThan',
|
|
53
|
+
label: 'Greater than',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
value: 'lessThan',
|
|
57
|
+
label: 'Less than',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
value: 'greaterThanOrEqual',
|
|
61
|
+
label: 'Greater than or equal',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
value: 'lessThanOrEqual',
|
|
65
|
+
label: 'Less than or equal',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
value: 'isEmpty',
|
|
69
|
+
label: 'Is empty',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
value: 'isNotEmpty',
|
|
73
|
+
label: 'Is not empty',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
date: [
|
|
77
|
+
{
|
|
78
|
+
value: 'equals',
|
|
79
|
+
label: 'Equals',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: 'notEquals',
|
|
83
|
+
label: 'Not equals',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
value: 'after',
|
|
87
|
+
label: 'After',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
value: 'before',
|
|
91
|
+
label: 'Before',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
value: 'isEmpty',
|
|
95
|
+
label: 'Is empty',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
value: 'isNotEmpty',
|
|
99
|
+
label: 'Is not empty',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
select: [
|
|
103
|
+
{
|
|
104
|
+
value: 'equals',
|
|
105
|
+
label: 'Equals',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
value: 'notEquals',
|
|
109
|
+
label: 'Not equals',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
value: 'in',
|
|
113
|
+
label: 'In',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
value: 'notIn',
|
|
117
|
+
label: 'Not in',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
value: 'isEmpty',
|
|
121
|
+
label: 'Is empty',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
value: 'isNotEmpty',
|
|
125
|
+
label: 'Is not empty',
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
tslib_1.__exportStar(require("./filter-value-input"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Header } from '@tanstack/react-table';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface DraggableHeaderProps<T> {
|
|
4
|
+
header: Header<T, unknown>;
|
|
5
|
+
enableSorting?: boolean;
|
|
6
|
+
draggable?: boolean;
|
|
7
|
+
onColumnReorder?: (draggedColumnId: string, targetColumnId: string) => void;
|
|
8
|
+
slots?: Record<string, any>;
|
|
9
|
+
slotProps?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export declare function DraggableHeader<T>({ header, enableSorting, draggable, onColumnReorder, slots, slotProps, }: DraggableHeaderProps<T>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>> | import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DraggableHeader = DraggableHeader;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const react_table_1 = require("@tanstack/react-table");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
10
|
+
function DraggableHeader({ header, enableSorting = true, draggable = false, onColumnReorder, slots, slotProps, }) {
|
|
11
|
+
const [isDragging, setIsDragging] = (0, react_1.useState)(false);
|
|
12
|
+
const [dragOver, setDragOver] = (0, react_1.useState)(false);
|
|
13
|
+
const autoScrollIntervalRef = (0, react_1.useRef)(null);
|
|
14
|
+
const dragStartPositionRef = (0, react_1.useRef)(null);
|
|
15
|
+
const headerElementRef = (0, react_1.useRef)(null);
|
|
16
|
+
const SortIconAscSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'sortIconAsc', icons_material_1.ArrowUpwardOutlined);
|
|
17
|
+
const SortIconDescSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'sortIconDesc', icons_material_1.ArrowDownwardOutlined);
|
|
18
|
+
const AUTO_SCROLL_THRESHOLD = 50;
|
|
19
|
+
const AUTO_SCROLL_SPEED = 10;
|
|
20
|
+
const AUTO_SCROLL_INTERVAL = 16;
|
|
21
|
+
const findScrollableContainer = (0, react_1.useCallback)((element) => {
|
|
22
|
+
let searchElement = element;
|
|
23
|
+
if (!searchElement) {
|
|
24
|
+
if (headerElementRef.current) {
|
|
25
|
+
searchElement = headerElementRef.current.closest('table');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!searchElement) {
|
|
29
|
+
const tables = Array.from(document.querySelectorAll('table'));
|
|
30
|
+
for (const table of tables) {
|
|
31
|
+
const headerExists = table.querySelector('th');
|
|
32
|
+
if (headerExists) {
|
|
33
|
+
searchElement = table;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!searchElement) {
|
|
39
|
+
searchElement = document.querySelector('table');
|
|
40
|
+
}
|
|
41
|
+
if (!searchElement)
|
|
42
|
+
return null;
|
|
43
|
+
let container = searchElement;
|
|
44
|
+
while (container && container !== document.body) {
|
|
45
|
+
const styles = window.getComputedStyle(container);
|
|
46
|
+
if (styles.overflowX === 'auto' || styles.overflowX === 'scroll') {
|
|
47
|
+
return container;
|
|
48
|
+
}
|
|
49
|
+
container = container.parentElement;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}, []);
|
|
53
|
+
const startAutoScroll = (0, react_1.useCallback)((direction) => {
|
|
54
|
+
if (autoScrollIntervalRef.current) {
|
|
55
|
+
clearInterval(autoScrollIntervalRef.current);
|
|
56
|
+
}
|
|
57
|
+
const container = findScrollableContainer();
|
|
58
|
+
if (!container)
|
|
59
|
+
return;
|
|
60
|
+
autoScrollIntervalRef.current = setInterval(() => {
|
|
61
|
+
const scrollAmount = direction === 'left' ? -AUTO_SCROLL_SPEED : AUTO_SCROLL_SPEED;
|
|
62
|
+
const newScrollLeft = container.scrollLeft + scrollAmount;
|
|
63
|
+
if (direction === 'left' && newScrollLeft <= 0) {
|
|
64
|
+
container.scrollLeft = 0;
|
|
65
|
+
clearInterval(autoScrollIntervalRef.current);
|
|
66
|
+
autoScrollIntervalRef.current = null;
|
|
67
|
+
}
|
|
68
|
+
else if (direction === 'right' && newScrollLeft >= container.scrollWidth - container.clientWidth) {
|
|
69
|
+
container.scrollLeft = container.scrollWidth - container.clientWidth;
|
|
70
|
+
clearInterval(autoScrollIntervalRef.current);
|
|
71
|
+
autoScrollIntervalRef.current = null;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
container.scrollLeft = newScrollLeft;
|
|
75
|
+
}
|
|
76
|
+
}, AUTO_SCROLL_INTERVAL);
|
|
77
|
+
}, [findScrollableContainer]);
|
|
78
|
+
const stopAutoScroll = (0, react_1.useCallback)(() => {
|
|
79
|
+
if (autoScrollIntervalRef.current) {
|
|
80
|
+
clearInterval(autoScrollIntervalRef.current);
|
|
81
|
+
autoScrollIntervalRef.current = null;
|
|
82
|
+
}
|
|
83
|
+
}, []);
|
|
84
|
+
const checkAutoScroll = (0, react_1.useCallback)((clientX) => {
|
|
85
|
+
const container = findScrollableContainer();
|
|
86
|
+
if (!container) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const rect = container.getBoundingClientRect();
|
|
90
|
+
const distanceFromLeft = clientX - rect.left;
|
|
91
|
+
const distanceFromRight = rect.right - clientX;
|
|
92
|
+
stopAutoScroll();
|
|
93
|
+
if (distanceFromLeft < AUTO_SCROLL_THRESHOLD && container.scrollLeft > 0) {
|
|
94
|
+
startAutoScroll('left');
|
|
95
|
+
}
|
|
96
|
+
else if (distanceFromRight < AUTO_SCROLL_THRESHOLD &&
|
|
97
|
+
container.scrollLeft < container.scrollWidth - container.clientWidth) {
|
|
98
|
+
startAutoScroll('right');
|
|
99
|
+
}
|
|
100
|
+
}, [
|
|
101
|
+
findScrollableContainer,
|
|
102
|
+
startAutoScroll,
|
|
103
|
+
stopAutoScroll,
|
|
104
|
+
]);
|
|
105
|
+
const handleDragStart = (e) => {
|
|
106
|
+
if (!draggable)
|
|
107
|
+
return;
|
|
108
|
+
setIsDragging(true);
|
|
109
|
+
dragStartPositionRef.current = {
|
|
110
|
+
x: e.clientX,
|
|
111
|
+
y: e.clientY,
|
|
112
|
+
};
|
|
113
|
+
e.dataTransfer.setData('text/plain', header.id);
|
|
114
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
115
|
+
};
|
|
116
|
+
const handleDrag = (0, react_1.useCallback)((e) => {
|
|
117
|
+
if (!isDragging || !draggable)
|
|
118
|
+
return;
|
|
119
|
+
if (e.clientX > 0 && e.clientY > 0) {
|
|
120
|
+
checkAutoScroll(e.clientX);
|
|
121
|
+
}
|
|
122
|
+
}, [
|
|
123
|
+
isDragging,
|
|
124
|
+
draggable,
|
|
125
|
+
checkAutoScroll,
|
|
126
|
+
]);
|
|
127
|
+
const getSortIcon = () => {
|
|
128
|
+
if (!enableSorting)
|
|
129
|
+
return null;
|
|
130
|
+
const sortDirection = header.column.getIsSorted();
|
|
131
|
+
if (sortDirection === 'asc') {
|
|
132
|
+
return ((0, jsx_runtime_1.jsx)(SortIconAscSlot, Object.assign({ fontSize: "small" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.sortIconAsc)));
|
|
133
|
+
}
|
|
134
|
+
if (sortDirection === 'desc') {
|
|
135
|
+
return ((0, jsx_runtime_1.jsx)(SortIconDescSlot, Object.assign({ fontSize: "small" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.sortIconDesc)));
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
const handleDragEnd = () => {
|
|
140
|
+
setIsDragging(false);
|
|
141
|
+
setDragOver(false);
|
|
142
|
+
stopAutoScroll();
|
|
143
|
+
dragStartPositionRef.current = null;
|
|
144
|
+
};
|
|
145
|
+
const handleDragOver = (e) => {
|
|
146
|
+
if (!draggable)
|
|
147
|
+
return;
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
e.dataTransfer.dropEffect = 'move';
|
|
150
|
+
setDragOver(true);
|
|
151
|
+
checkAutoScroll(e.clientX);
|
|
152
|
+
};
|
|
153
|
+
const handleDragLeave = () => {
|
|
154
|
+
setDragOver(false);
|
|
155
|
+
};
|
|
156
|
+
const handleDrop = (e) => {
|
|
157
|
+
if (!draggable)
|
|
158
|
+
return;
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
const draggedColumnId = e.dataTransfer.getData('text/plain');
|
|
161
|
+
if (draggedColumnId !== header.id && onColumnReorder) {
|
|
162
|
+
onColumnReorder(draggedColumnId, header.id);
|
|
163
|
+
}
|
|
164
|
+
setDragOver(false);
|
|
165
|
+
stopAutoScroll();
|
|
166
|
+
};
|
|
167
|
+
const handleSort = () => {
|
|
168
|
+
if (!enableSorting || !header.column.getCanSort())
|
|
169
|
+
return;
|
|
170
|
+
const currentSort = header.column.getIsSorted();
|
|
171
|
+
if (currentSort === false) {
|
|
172
|
+
header.column.toggleSorting(false);
|
|
173
|
+
}
|
|
174
|
+
else if (currentSort === 'asc') {
|
|
175
|
+
header.column.toggleSorting(true);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
header.column.clearSorting();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const getCursor = () => {
|
|
182
|
+
if (draggable)
|
|
183
|
+
return 'grab';
|
|
184
|
+
if (enableSorting && header.column.getCanSort())
|
|
185
|
+
return 'pointer';
|
|
186
|
+
return 'default';
|
|
187
|
+
};
|
|
188
|
+
if (!draggable && !enableSorting) {
|
|
189
|
+
return (0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext());
|
|
190
|
+
}
|
|
191
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ref: headerElementRef, sx: {
|
|
192
|
+
display: 'flex',
|
|
193
|
+
alignItems: 'center',
|
|
194
|
+
gap: 1,
|
|
195
|
+
cursor: getCursor(),
|
|
196
|
+
userSelect: 'none',
|
|
197
|
+
opacity: isDragging ? 0.5 : 1,
|
|
198
|
+
backgroundColor: dragOver ? 'rgba(25, 118, 210, 0.08)' : 'transparent',
|
|
199
|
+
borderLeft: dragOver ? '2px solid #1976d2' : 'none',
|
|
200
|
+
padding: dragOver ? '0 0 0 -2px' : '0',
|
|
201
|
+
width: '100%',
|
|
202
|
+
height: '100%',
|
|
203
|
+
'&:active': {
|
|
204
|
+
cursor: draggable ? 'grabbing' : 'pointer',
|
|
205
|
+
},
|
|
206
|
+
}, draggable: draggable, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onClick: enableSorting ? handleSort : undefined, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
207
|
+
flex: 1,
|
|
208
|
+
display: 'flex',
|
|
209
|
+
alignItems: 'center',
|
|
210
|
+
gap: 1,
|
|
211
|
+
}, children: [(0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext()), getSortIcon()] }) }));
|
|
212
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface TableHeaderProps {
|
|
2
|
+
draggable?: boolean;
|
|
3
|
+
enableColumnResizing?: boolean;
|
|
4
|
+
enableStickyHeader?: boolean;
|
|
5
|
+
fitToScreen?: boolean;
|
|
6
|
+
onColumnReorder?: (draggedColumnId: string, targetColumnId: string) => void;
|
|
7
|
+
slots?: Record<string, any>;
|
|
8
|
+
slotProps?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export declare function TableHeader<T>({ draggable, enableColumnResizing, enableStickyHeader, fitToScreen, onColumnReorder, slots, slotProps, }: TableHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableHeader = TableHeader;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const draggable_header_1 = require("./draggable-header");
|
|
7
|
+
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
10
|
+
function TableHeader({ draggable = false, enableColumnResizing = false, enableStickyHeader = false, fitToScreen = true, onColumnReorder, slots, slotProps, }) {
|
|
11
|
+
const theme = (0, material_1.useTheme)();
|
|
12
|
+
const { table } = (0, data_table_context_1.useDataTableContext)();
|
|
13
|
+
const HeaderCellSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'headerCell', material_1.TableCell);
|
|
14
|
+
const HeaderRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'headerRow', material_1.TableRow);
|
|
15
|
+
const HeaderSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'header', material_1.TableHead);
|
|
16
|
+
const renderHeaderCell = (header) => {
|
|
17
|
+
const isPinned = header.column.getIsPinned();
|
|
18
|
+
const pinnedPosition = isPinned ? header.column.getStart('left') : undefined;
|
|
19
|
+
const pinnedRightPosition = isPinned === 'right' ? header.column.getAfter('right') : undefined;
|
|
20
|
+
const alignment = (0, utils_1.getColumnAlignment)(header.column.columnDef);
|
|
21
|
+
const enableSorting = header.column.getCanSort();
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(HeaderCellSlot, Object.assign({ align: alignment, sx: Object.assign({}, (0, utils_1.getPinnedColumnStyle)({
|
|
23
|
+
width: (fitToScreen && !enableColumnResizing) ? 'auto' : header.getSize(),
|
|
24
|
+
isPinned,
|
|
25
|
+
pinnedPosition,
|
|
26
|
+
isLastLeftPinnedColumn: isPinned === 'left' && header.column.getIsLastColumn('left'),
|
|
27
|
+
isFirstRightPinnedColumn: isPinned === 'right' && header.column.getIsFirstColumn('right'),
|
|
28
|
+
pinnedRightPosition,
|
|
29
|
+
zIndex: isPinned ? 10 : 1,
|
|
30
|
+
disableStickyHeader: enableStickyHeader,
|
|
31
|
+
})) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.headerCell, { children: [(0, jsx_runtime_1.jsx)(draggable_header_1.DraggableHeader, { header: header, enableSorting: enableSorting, draggable: !!(draggable && !isPinned), onColumnReorder: onColumnReorder, slots: slots, slotProps: slotProps }), enableColumnResizing && header.column.getCanResize() ? ((0, jsx_runtime_1.jsx)(material_1.Box, { onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), sx: {
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
right: 0,
|
|
34
|
+
top: '25%',
|
|
35
|
+
height: '50%',
|
|
36
|
+
width: '3px',
|
|
37
|
+
cursor: 'col-resize',
|
|
38
|
+
userSelect: 'none',
|
|
39
|
+
touchAction: 'none',
|
|
40
|
+
borderRadius: '4px',
|
|
41
|
+
backgroundColor: header.column.getIsResizing() ? 'primary.main' : theme.palette.grey[300],
|
|
42
|
+
'&:hover': {
|
|
43
|
+
backgroundColor: theme.palette.primary.main,
|
|
44
|
+
},
|
|
45
|
+
} })) : null] }), header.id));
|
|
46
|
+
};
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(HeaderSlot, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.header, { children: table.getHeaderGroups().map(headerGroup => ((0, jsx_runtime_1.jsx)(HeaderRowSlot, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.headerRow, { children: headerGroup.headers.map(renderHeaderCell) }), headerGroup.id))) })));
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./table"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./headers"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./rows"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./toolbar"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./filters"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./pagination"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./droupdown/menu-dropdown"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TablePaginationProps } from '@mui/material';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export interface DataTablePaginationProps extends Omit<TablePaginationProps, 'count' | 'rowsPerPage' | 'page' | 'onPageChange' | 'onRowsPerPageChange'> {
|
|
4
|
+
totalRow: number;
|
|
5
|
+
footerFilter?: ReactNode | null;
|
|
6
|
+
pagination: {
|
|
7
|
+
pageIndex: number;
|
|
8
|
+
pageSize: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const DataTablePagination: import("react").MemoExoticComponent<({ footerFilter, pagination, totalRow, ...props }: DataTablePaginationProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataTablePagination = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
9
|
+
exports.DataTablePagination = (0, react_1.memo)((_a) => {
|
|
10
|
+
var { footerFilter = null, pagination, totalRow } = _a, props = tslib_1.__rest(_a, ["footerFilter", "pagination", "totalRow"]);
|
|
11
|
+
const { table } = (0, data_table_context_1.useDataTableContext)();
|
|
12
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
gap: 1,
|
|
16
|
+
justifyContent: 'space-between',
|
|
17
|
+
px: 2,
|
|
18
|
+
}, children: [footerFilter, (0, jsx_runtime_1.jsx)(material_1.TablePagination, Object.assign({ component: "div", count: totalRow, rowsPerPage: pagination === null || pagination === void 0 ? void 0 : pagination.pageSize, page: pagination === null || pagination === void 0 ? void 0 : pagination.pageIndex, onPageChange: (_, page) => {
|
|
19
|
+
table.setPageIndex(page);
|
|
20
|
+
}, onRowsPerPageChange: e => {
|
|
21
|
+
const newPageSize = Number(e.target.value);
|
|
22
|
+
table.setPageIndex(0);
|
|
23
|
+
table.setPageSize(newPageSize);
|
|
24
|
+
}, showFirstButton: true, showLastButton: true, labelRowsPerPage: "Rows per page:", labelDisplayedRows: ({ from, to, count }) => `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}` }, props))] }));
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './data-table-pagination';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Row } from '@tanstack/react-table';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export interface DataTableRowProps<T> {
|
|
4
|
+
row: Row<T>;
|
|
5
|
+
enableHover?: boolean;
|
|
6
|
+
enableStripes?: boolean;
|
|
7
|
+
isOdd?: boolean;
|
|
8
|
+
renderSubComponent?: (row: Row<T>) => ReactNode;
|
|
9
|
+
disableStickyHeader?: boolean;
|
|
10
|
+
slots?: Record<string, any>;
|
|
11
|
+
slotProps?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export declare function DataTableRow<T>({ row, enableHover, enableStripes, isOdd, renderSubComponent, disableStickyHeader, slots, slotProps, }: DataTableRowProps<T>): import("react/jsx-runtime").JSX.Element;
|