@ackplus/react-tanstack-data-table 1.1.19 → 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.
- package/dist/lib/hooks/use-data-table-engine.d.ts.map +1 -1
- package/dist/lib/hooks/use-data-table-engine.js +54 -15
- package/dist/lib/types/data-table.types.d.ts +2 -1
- package/dist/lib/types/data-table.types.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +0 -75
- package/src/lib/components/data-table-view.tsx +0 -386
- package/src/lib/components/droupdown/menu-dropdown.tsx +0 -103
- package/src/lib/components/filters/filter-value-input.tsx +0 -225
- package/src/lib/components/filters/index.ts +0 -126
- package/src/lib/components/headers/draggable-header.tsx +0 -326
- package/src/lib/components/headers/index.ts +0 -6
- package/src/lib/components/headers/table-header.tsx +0 -175
- package/src/lib/components/index.ts +0 -21
- package/src/lib/components/pagination/data-table-pagination.tsx +0 -111
- package/src/lib/components/pagination/index.ts +0 -5
- package/src/lib/components/rows/data-table-row.tsx +0 -218
- package/src/lib/components/rows/empty-data-row.tsx +0 -69
- package/src/lib/components/rows/index.ts +0 -7
- package/src/lib/components/rows/loading-rows.tsx +0 -164
- package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +0 -125
- package/src/lib/components/toolbar/column-filter-control.tsx +0 -432
- package/src/lib/components/toolbar/column-pinning-control.tsx +0 -275
- package/src/lib/components/toolbar/column-reset-control.tsx +0 -74
- package/src/lib/components/toolbar/column-visibility-control.tsx +0 -105
- package/src/lib/components/toolbar/data-table-toolbar.tsx +0 -257
- package/src/lib/components/toolbar/index.ts +0 -17
- package/src/lib/components/toolbar/table-export-control.tsx +0 -233
- package/src/lib/components/toolbar/table-refresh-control.tsx +0 -62
- package/src/lib/components/toolbar/table-search-control.tsx +0 -155
- package/src/lib/components/toolbar/table-size-control.tsx +0 -102
- package/src/lib/contexts/data-table-context.tsx +0 -126
- package/src/lib/data-table.tsx +0 -29
- package/src/lib/features/README.md +0 -161
- package/src/lib/features/column-filter.feature.ts +0 -493
- package/src/lib/features/index.ts +0 -23
- package/src/lib/features/selection.feature.ts +0 -322
- package/src/lib/hooks/index.ts +0 -2
- package/src/lib/hooks/use-data-table-engine.ts +0 -1516
- package/src/lib/icons/add-icon.tsx +0 -23
- package/src/lib/icons/csv-icon.tsx +0 -15
- package/src/lib/icons/delete-icon.tsx +0 -30
- package/src/lib/icons/excel-icon.tsx +0 -15
- package/src/lib/icons/index.ts +0 -7
- package/src/lib/icons/unpin-icon.tsx +0 -18
- package/src/lib/icons/view-comfortable-icon.tsx +0 -45
- package/src/lib/icons/view-compact-icon.tsx +0 -55
- package/src/lib/types/column.types.ts +0 -63
- package/src/lib/types/data-table-api.ts +0 -191
- package/src/lib/types/data-table.types.ts +0 -192
- package/src/lib/types/export.types.ts +0 -223
- package/src/lib/types/index.ts +0 -24
- package/src/lib/types/slots.types.ts +0 -342
- package/src/lib/types/table.types.ts +0 -88
- package/src/lib/utils/column-helpers.ts +0 -72
- package/src/lib/utils/debounced-fetch.utils.ts +0 -131
- package/src/lib/utils/export-utils.ts +0 -712
- package/src/lib/utils/index.ts +0 -27
- package/src/lib/utils/logger.ts +0 -203
- package/src/lib/utils/slot-helpers.tsx +0 -194
- package/src/lib/utils/special-columns.utils.ts +0 -101
- package/src/lib/utils/styling-helpers.ts +0 -126
- package/src/lib/utils/table-helpers.ts +0 -106
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TableHeader Component
|
|
3
|
-
*
|
|
4
|
-
* Unified header component that combines:
|
|
5
|
-
* - Sortable functionality
|
|
6
|
-
* - Draggable column reordering
|
|
7
|
-
* - Column resizing
|
|
8
|
-
* - Pinning support
|
|
9
|
-
*/
|
|
10
|
-
import React, { ReactElement } from 'react';
|
|
11
|
-
import { TableHead, TableRow, TableCell, Box, useTheme, TableHeadProps, TableRowProps, TableCellProps, SxProps } from '@mui/material';
|
|
12
|
-
import { Header } from '@tanstack/react-table';
|
|
13
|
-
|
|
14
|
-
import { DraggableHeader } from './draggable-header';
|
|
15
|
-
import { useDataTableContext } from '../../contexts/data-table-context';
|
|
16
|
-
import { getPinnedColumnStyle, getColumnAlignment } from '../../utils';
|
|
17
|
-
import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
|
|
18
|
-
|
|
19
|
-
export interface TableHeaderProps extends TableHeadProps {
|
|
20
|
-
draggable?: boolean;
|
|
21
|
-
enableColumnResizing?: boolean;
|
|
22
|
-
enableStickyHeader?: boolean;
|
|
23
|
-
onColumnReorder?: (draggedColumnId: string, targetColumnId: string) => void;
|
|
24
|
-
// Enhanced customization props
|
|
25
|
-
headerRowProps?: TableRowProps;
|
|
26
|
-
headerCellProps?: TableCellProps;
|
|
27
|
-
containerSx?: SxProps;
|
|
28
|
-
resizeHandleSx?: SxProps;
|
|
29
|
-
slots?: Record<string, any>;
|
|
30
|
-
slotProps?: Record<string, any>;
|
|
31
|
-
[key: string]: any;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Renders table headers with sorting, dragging, and resizing capabilities
|
|
36
|
-
*/
|
|
37
|
-
export function TableHeader<T>(props: TableHeaderProps): ReactElement {
|
|
38
|
-
const {
|
|
39
|
-
draggable = false,
|
|
40
|
-
enableColumnResizing = false,
|
|
41
|
-
enableStickyHeader = false,
|
|
42
|
-
onColumnReorder,
|
|
43
|
-
headerRowProps,
|
|
44
|
-
headerCellProps,
|
|
45
|
-
containerSx,
|
|
46
|
-
resizeHandleSx,
|
|
47
|
-
slots,
|
|
48
|
-
slotProps,
|
|
49
|
-
...otherProps
|
|
50
|
-
} = props;
|
|
51
|
-
|
|
52
|
-
const theme = useTheme();
|
|
53
|
-
const { table } = useDataTableContext();
|
|
54
|
-
|
|
55
|
-
// Extract slot-specific props with enhanced merging
|
|
56
|
-
const headerCellSlotProps = extractSlotProps(slotProps, 'headerCell');
|
|
57
|
-
const headerRowSlotProps = extractSlotProps(slotProps, 'headerRow');
|
|
58
|
-
const headerSlotProps = extractSlotProps(slotProps, 'header');
|
|
59
|
-
|
|
60
|
-
const HeaderCellSlot = getSlotComponent(slots, 'headerCell', TableCell);
|
|
61
|
-
const HeaderRowSlot = getSlotComponent(slots, 'headerRow', TableRow);
|
|
62
|
-
const HeaderSlot = getSlotComponent(slots, 'header', TableHead);
|
|
63
|
-
|
|
64
|
-
// Merge all props for maximum flexibility
|
|
65
|
-
const mergedHeaderProps = mergeSlotProps(
|
|
66
|
-
{
|
|
67
|
-
sx: containerSx,
|
|
68
|
-
},
|
|
69
|
-
headerSlotProps,
|
|
70
|
-
otherProps
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const mergedHeaderRowProps = mergeSlotProps(
|
|
74
|
-
{},
|
|
75
|
-
headerRowSlotProps,
|
|
76
|
-
headerRowProps || {}
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const renderHeaderCell = (header: Header<T, unknown>) => {
|
|
80
|
-
const isPinned = header.column.getIsPinned();
|
|
81
|
-
const pinnedPosition = isPinned ? header.column.getStart('left') : undefined;
|
|
82
|
-
const pinnedRightPosition = isPinned === 'right' ? header.column.getAfter('right') : undefined;
|
|
83
|
-
const alignment = getColumnAlignment(header.column.columnDef);
|
|
84
|
-
const enableSorting = header.column.getCanSort();
|
|
85
|
-
const wrapText = header.column.columnDef.wrapText ?? false;
|
|
86
|
-
const minSize = header.column.columnDef.minSize;
|
|
87
|
-
const maxSize = header.column.columnDef.maxSize;
|
|
88
|
-
const canResize = enableColumnResizing && header.column.getCanResize();
|
|
89
|
-
|
|
90
|
-
const mergedHeaderCellProps = mergeSlotProps(
|
|
91
|
-
{
|
|
92
|
-
align: alignment,
|
|
93
|
-
sx: {
|
|
94
|
-
...getPinnedColumnStyle({
|
|
95
|
-
width: header.getSize(),
|
|
96
|
-
minWidth: minSize !== undefined ? minSize : undefined,
|
|
97
|
-
maxWidth: maxSize !== undefined ? maxSize : undefined,
|
|
98
|
-
isPinned,
|
|
99
|
-
pinnedPosition,
|
|
100
|
-
isLastLeftPinnedColumn: isPinned === 'left' && header.column.getIsLastColumn('left'),
|
|
101
|
-
isFirstRightPinnedColumn: isPinned === 'right' && header.column.getIsFirstColumn('right'),
|
|
102
|
-
pinnedRightPosition,
|
|
103
|
-
zIndex: isPinned ? 10 : 1,
|
|
104
|
-
disableStickyHeader: enableStickyHeader,
|
|
105
|
-
wrapText,
|
|
106
|
-
}),
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
headerCellSlotProps,
|
|
110
|
-
headerCellProps || {}
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const mergedResizeHandleProps = mergeSlotProps(
|
|
114
|
-
{
|
|
115
|
-
onMouseDown: header.getResizeHandler(),
|
|
116
|
-
onTouchStart: header.getResizeHandler(),
|
|
117
|
-
sx: {
|
|
118
|
-
position: 'absolute',
|
|
119
|
-
right: 0,
|
|
120
|
-
top: '25%',
|
|
121
|
-
height: '50%',
|
|
122
|
-
width: '3px',
|
|
123
|
-
cursor: 'col-resize',
|
|
124
|
-
userSelect: 'none',
|
|
125
|
-
touchAction: 'none',
|
|
126
|
-
borderRadius: '4px',
|
|
127
|
-
backgroundColor: header.column.getIsResizing() ? 'primary.main' : theme.palette.grey[300],
|
|
128
|
-
'&:hover': {
|
|
129
|
-
backgroundColor: theme.palette.primary.main,
|
|
130
|
-
},
|
|
131
|
-
...resizeHandleSx,
|
|
132
|
-
},
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<HeaderCellSlot
|
|
138
|
-
key={header.id}
|
|
139
|
-
{...mergedHeaderCellProps}
|
|
140
|
-
>
|
|
141
|
-
<DraggableHeader
|
|
142
|
-
header={header}
|
|
143
|
-
enableSorting={enableSorting}
|
|
144
|
-
draggable={!!(draggable && !isPinned)}
|
|
145
|
-
onColumnReorder={onColumnReorder}
|
|
146
|
-
slots={slots}
|
|
147
|
-
slotProps={slotProps}
|
|
148
|
-
alignment={alignment}
|
|
149
|
-
/>
|
|
150
|
-
|
|
151
|
-
{/* Column resizer */}
|
|
152
|
-
{canResize ? (
|
|
153
|
-
<Box
|
|
154
|
-
{...mergedResizeHandleProps}
|
|
155
|
-
/>
|
|
156
|
-
) : null}
|
|
157
|
-
</HeaderCellSlot>
|
|
158
|
-
);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
<HeaderSlot
|
|
163
|
-
{...mergedHeaderProps}
|
|
164
|
-
>
|
|
165
|
-
{table.getHeaderGroups().map(headerGroup => (
|
|
166
|
-
<HeaderRowSlot
|
|
167
|
-
key={headerGroup.id}
|
|
168
|
-
{...mergedHeaderRowProps}
|
|
169
|
-
>
|
|
170
|
-
{headerGroup.headers.map(renderHeaderCell)}
|
|
171
|
-
</HeaderRowSlot>
|
|
172
|
-
))}
|
|
173
|
-
</HeaderSlot>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataTable Components
|
|
3
|
-
*
|
|
4
|
-
* Organized component exports for the MUI TanStack DataTable
|
|
5
|
-
*/
|
|
6
|
-
// Header components
|
|
7
|
-
export * from './headers';
|
|
8
|
-
|
|
9
|
-
// Row components
|
|
10
|
-
export * from './rows';
|
|
11
|
-
|
|
12
|
-
// Toolbar components
|
|
13
|
-
export * from './toolbar';
|
|
14
|
-
|
|
15
|
-
// Filter components
|
|
16
|
-
export * from './filters';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// Pagination components
|
|
20
|
-
export * from './pagination';
|
|
21
|
-
export * from './droupdown/menu-dropdown';
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// data-table-pagination.tsx
|
|
2
|
-
import { TablePagination, Box, TablePaginationProps, SxProps } from '@mui/material';
|
|
3
|
-
import { memo, ReactNode, useEffect, useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
import { useDataTableContext } from '../../contexts/data-table-context';
|
|
6
|
-
import { mergeSlotProps } from '../../utils/slot-helpers';
|
|
7
|
-
|
|
8
|
-
export interface DataTablePaginationProps extends Omit<TablePaginationProps, 'count' | 'rowsPerPage' | 'page' | 'onPageChange' | 'onRowsPerPageChange'> {
|
|
9
|
-
totalRow: number;
|
|
10
|
-
footerFilter?: ReactNode | null;
|
|
11
|
-
pagination: {
|
|
12
|
-
pageIndex: number;
|
|
13
|
-
pageSize: number;
|
|
14
|
-
};
|
|
15
|
-
// Enhanced customization props
|
|
16
|
-
containerSx?: SxProps;
|
|
17
|
-
paginationProps?: TablePaginationProps;
|
|
18
|
-
footerSx?: SxProps;
|
|
19
|
-
slots?: Record<string, any>;
|
|
20
|
-
slotProps?: Record<string, any>;
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const DataTablePagination = memo((props: DataTablePaginationProps) => {
|
|
25
|
-
const {
|
|
26
|
-
footerFilter = null,
|
|
27
|
-
pagination,
|
|
28
|
-
totalRow,
|
|
29
|
-
containerSx,
|
|
30
|
-
paginationProps,
|
|
31
|
-
footerSx,
|
|
32
|
-
...otherProps
|
|
33
|
-
} = props;
|
|
34
|
-
|
|
35
|
-
const { table, tableSize } = useDataTableContext();
|
|
36
|
-
const pageSize = pagination?.pageSize || 1;
|
|
37
|
-
const maxPageIndex = Math.max(0, Math.ceil(totalRow / pageSize) - 1);
|
|
38
|
-
const safePageIndex = useMemo(
|
|
39
|
-
() => Math.min(Math.max(pagination?.pageIndex ?? 0, 0), maxPageIndex),
|
|
40
|
-
[maxPageIndex, pagination?.pageIndex]
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if ((pagination?.pageIndex ?? 0) !== safePageIndex) {
|
|
45
|
-
table?.setPageIndex(safePageIndex);
|
|
46
|
-
}
|
|
47
|
-
}, [pagination?.pageIndex, safePageIndex, table]);
|
|
48
|
-
|
|
49
|
-
// Extract slot-specific props with enhanced merging
|
|
50
|
-
// const paginationSlotProps = extractSlotProps(slotProps, 'pagination');
|
|
51
|
-
|
|
52
|
-
// Merge all props for maximum flexibility
|
|
53
|
-
const mergedContainerProps = mergeSlotProps(
|
|
54
|
-
{
|
|
55
|
-
sx: {
|
|
56
|
-
display: 'flex',
|
|
57
|
-
alignItems: 'center',
|
|
58
|
-
gap: 1,
|
|
59
|
-
justifyContent: 'space-between',
|
|
60
|
-
px: 2,
|
|
61
|
-
...containerSx,
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const mergedPaginationProps: any = mergeSlotProps(
|
|
69
|
-
{
|
|
70
|
-
component: 'div',
|
|
71
|
-
size: tableSize === 'small' ? 'small' : 'medium',
|
|
72
|
-
count: totalRow,
|
|
73
|
-
rowsPerPage: pagination?.pageSize,
|
|
74
|
-
page: safePageIndex,
|
|
75
|
-
onPageChange: (_, page: number) => {
|
|
76
|
-
// Use TanStack Table's native pagination methods
|
|
77
|
-
table.setPageIndex(page);
|
|
78
|
-
},
|
|
79
|
-
onRowsPerPageChange: (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
80
|
-
const newPageSize = Number(e.target.value);
|
|
81
|
-
// Use TanStack Table's native pagination methods
|
|
82
|
-
table.setPageIndex(0);
|
|
83
|
-
table.setPageSize(newPageSize);
|
|
84
|
-
},
|
|
85
|
-
showFirstButton: true,
|
|
86
|
-
showLastButton: true,
|
|
87
|
-
labelRowsPerPage: 'Rows per page:',
|
|
88
|
-
labelDisplayedRows: ({ from, to, count }: { from: number; to: number; count: number }) =>
|
|
89
|
-
`${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`,
|
|
90
|
-
},
|
|
91
|
-
{ ...paginationProps, ...otherProps }
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<Box
|
|
96
|
-
{...mergedContainerProps}
|
|
97
|
-
>
|
|
98
|
-
{footerFilter && (
|
|
99
|
-
<Box sx={footerSx}>
|
|
100
|
-
{footerFilter as any}
|
|
101
|
-
</Box>
|
|
102
|
-
)}
|
|
103
|
-
|
|
104
|
-
<TablePagination
|
|
105
|
-
{...mergedPaginationProps}
|
|
106
|
-
/>
|
|
107
|
-
</Box>
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
DataTablePagination.displayName = 'DataTablePagination';
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataTableRow Component
|
|
3
|
-
*
|
|
4
|
-
* Renders individual table rows with support for:
|
|
5
|
-
* - Column pinning
|
|
6
|
-
* - Row expansion
|
|
7
|
-
* - Hover effects
|
|
8
|
-
* - Striped styling
|
|
9
|
-
*/
|
|
10
|
-
import { TableRow, TableCell, Collapse, TableRowProps, TableCellProps, SxProps, tableRowClasses } from '@mui/material';
|
|
11
|
-
import { flexRender, Row } from '@tanstack/react-table';
|
|
12
|
-
import { ReactNode, ReactElement } from 'react';
|
|
13
|
-
|
|
14
|
-
import { getPinnedColumnStyle, getColumnAlignment } from '../../utils';
|
|
15
|
-
import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
|
|
16
|
-
import { useDataTableContext } from '../../contexts/data-table-context';
|
|
17
|
-
|
|
18
|
-
export interface DataTableRowProps<T> extends TableRowProps {
|
|
19
|
-
row: Row<T>;
|
|
20
|
-
enableHover?: boolean;
|
|
21
|
-
enableStripes?: boolean;
|
|
22
|
-
isOdd?: boolean;
|
|
23
|
-
renderSubComponent?: (row: Row<T>) => ReactNode;
|
|
24
|
-
disableStickyHeader?: boolean;
|
|
25
|
-
// Row click props
|
|
26
|
-
onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, row: Row<T>) => void;
|
|
27
|
-
selectOnRowClick?: boolean; // If true, row click will toggle selection (default: false)
|
|
28
|
-
// Enhanced customization props
|
|
29
|
-
cellProps?: TableCellProps;
|
|
30
|
-
expandedRowProps?: TableRowProps;
|
|
31
|
-
expandedCellProps?: TableCellProps;
|
|
32
|
-
containerSx?: SxProps;
|
|
33
|
-
expandedContainerSx?: SxProps;
|
|
34
|
-
// Cell slot management
|
|
35
|
-
slots?: Record<string, any>;
|
|
36
|
-
slotProps?: Record<string, any>;
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Individual table row component with cell rendering and expansion support
|
|
42
|
-
*/
|
|
43
|
-
export function DataTableRow<T>(props: DataTableRowProps<T>): ReactElement {
|
|
44
|
-
const {
|
|
45
|
-
row,
|
|
46
|
-
enableHover = true,
|
|
47
|
-
enableStripes = false,
|
|
48
|
-
isOdd = false,
|
|
49
|
-
renderSubComponent,
|
|
50
|
-
disableStickyHeader = false,
|
|
51
|
-
onRowClick,
|
|
52
|
-
selectOnRowClick = false,
|
|
53
|
-
cellProps,
|
|
54
|
-
expandedRowProps,
|
|
55
|
-
expandedCellProps,
|
|
56
|
-
containerSx,
|
|
57
|
-
expandedContainerSx,
|
|
58
|
-
slots,
|
|
59
|
-
slotProps,
|
|
60
|
-
...otherProps
|
|
61
|
-
} = props;
|
|
62
|
-
const { table } = useDataTableContext();
|
|
63
|
-
|
|
64
|
-
// Extract slot-specific props with enhanced merging
|
|
65
|
-
const cellSlotProps = extractSlotProps(slotProps, 'cell');
|
|
66
|
-
const expandedRowSlotProps = extractSlotProps(slotProps, 'expandedRow');
|
|
67
|
-
const rowSlotProps = extractSlotProps(slotProps, 'row');
|
|
68
|
-
|
|
69
|
-
const CellSlot = getSlotComponent(slots, 'cell', TableCell);
|
|
70
|
-
const ExpandedRowSlot = getSlotComponent(slots, 'expandedRow', TableRow);
|
|
71
|
-
const TableRowSlot = getSlotComponent(slots, 'row', TableRow);
|
|
72
|
-
|
|
73
|
-
// Handle row click
|
|
74
|
-
const handleRowClick = (event: React.MouseEvent<HTMLTableRowElement>) => {
|
|
75
|
-
// Check if click target is a checkbox, button, or interactive element
|
|
76
|
-
const target = event.target as HTMLElement;
|
|
77
|
-
|
|
78
|
-
// Check for various interactive elements
|
|
79
|
-
const isCheckboxClick = target.closest('input[type="checkbox"]') !== null;
|
|
80
|
-
const isButtonClick = target.closest('button') !== null;
|
|
81
|
-
const isLinkClick = target.closest('a') !== null;
|
|
82
|
-
// Check for elements with interactive roles (button, checkbox, switch, etc.)
|
|
83
|
-
const isInteractiveRole = target.closest('[role="button"]') !== null ||
|
|
84
|
-
target.closest('[role="checkbox"]') !== null ||
|
|
85
|
-
target.closest('[role="switch"]') !== null ||
|
|
86
|
-
target.closest('[role="menuitem"]') !== null;
|
|
87
|
-
|
|
88
|
-
// Determine if this is an interactive element click
|
|
89
|
-
const isInteractiveClick = isCheckboxClick || isButtonClick || isLinkClick || isInteractiveRole;
|
|
90
|
-
|
|
91
|
-
// If selectOnRowClick is enabled and it's not an interactive element click, toggle selection
|
|
92
|
-
if (selectOnRowClick && !isInteractiveClick && table?.toggleRowSelected) {
|
|
93
|
-
table.toggleRowSelected(row.id);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Only call onRowClick if it's not an interactive element click
|
|
97
|
-
if (onRowClick && !isInteractiveClick) {
|
|
98
|
-
onRowClick(event, row);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// Merge all props for maximum flexibility
|
|
103
|
-
const mergedRowProps = mergeSlotProps(
|
|
104
|
-
{
|
|
105
|
-
hover: enableHover,
|
|
106
|
-
selected: !!table?.getIsRowSelected?.(row.id),
|
|
107
|
-
onClick: (onRowClick || selectOnRowClick) ? handleRowClick : undefined,
|
|
108
|
-
sx: (theme) => ({
|
|
109
|
-
// set the row background as a variable
|
|
110
|
-
'--row-bg': enableStripes && isOdd
|
|
111
|
-
? theme.palette.action.hover
|
|
112
|
-
: theme.palette.background.paper,
|
|
113
|
-
backgroundColor: 'var(--row-bg)',
|
|
114
|
-
// keep the variable in sync for hover/selected
|
|
115
|
-
...(enableHover && {
|
|
116
|
-
'&:hover': { '--row-bg': theme.palette.action.hover },
|
|
117
|
-
}),
|
|
118
|
-
[`&.${tableRowClasses.selected}`]: {
|
|
119
|
-
'--row-bg': theme.palette.action.selected,
|
|
120
|
-
backgroundColor: 'var(--row-bg)',
|
|
121
|
-
},
|
|
122
|
-
// Add cursor pointer if row is clickable
|
|
123
|
-
...((onRowClick || selectOnRowClick) && {
|
|
124
|
-
cursor: 'pointer',
|
|
125
|
-
}),
|
|
126
|
-
...containerSx,
|
|
127
|
-
}),
|
|
128
|
-
},
|
|
129
|
-
rowSlotProps,
|
|
130
|
-
otherProps
|
|
131
|
-
);
|
|
132
|
-
const mergedExpandedRowProps = mergeSlotProps(
|
|
133
|
-
{
|
|
134
|
-
sx: expandedContainerSx,
|
|
135
|
-
},
|
|
136
|
-
expandedRowSlotProps,
|
|
137
|
-
expandedRowProps || {}
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
<>
|
|
142
|
-
<TableRowSlot
|
|
143
|
-
{...mergedRowProps}
|
|
144
|
-
>
|
|
145
|
-
{row.getVisibleCells().map(cell => {
|
|
146
|
-
const isPinned = cell.column.getIsPinned();
|
|
147
|
-
const pinnedPosition = isPinned ? cell.column.getStart('left') : undefined;
|
|
148
|
-
const pinnedRightPosition = isPinned === 'right' ? cell.column.getAfter('right') : undefined;
|
|
149
|
-
const alignment = getColumnAlignment(cell.column.columnDef);
|
|
150
|
-
|
|
151
|
-
// Get minSize and maxSize from column definition
|
|
152
|
-
const minSize = cell.column.columnDef?.minSize;
|
|
153
|
-
const maxSize = cell.column.columnDef.maxSize;
|
|
154
|
-
const wrapText = cell.column.columnDef.wrapText ?? false;
|
|
155
|
-
|
|
156
|
-
const mergedCellProps = mergeSlotProps(
|
|
157
|
-
{
|
|
158
|
-
align: alignment,
|
|
159
|
-
sx: {
|
|
160
|
-
...getPinnedColumnStyle({
|
|
161
|
-
width: cell.column.getSize(),
|
|
162
|
-
minWidth: minSize !== undefined ? minSize : undefined,
|
|
163
|
-
maxWidth: maxSize !== undefined ? maxSize : undefined,
|
|
164
|
-
isPinned,
|
|
165
|
-
pinnedPosition,
|
|
166
|
-
pinnedRightPosition,
|
|
167
|
-
zIndex: isPinned ? 9 : 1,
|
|
168
|
-
disableStickyHeader,
|
|
169
|
-
isLastLeftPinnedColumn: isPinned === 'left' && cell.column.getIsLastColumn('left'),
|
|
170
|
-
isFirstRightPinnedColumn: isPinned === 'right' && cell.column.getIsFirstColumn('right'),
|
|
171
|
-
wrapText,
|
|
172
|
-
}),
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
cellSlotProps,
|
|
176
|
-
cellProps || {}
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
return (
|
|
180
|
-
<CellSlot
|
|
181
|
-
key={cell.id}
|
|
182
|
-
{...mergedCellProps}
|
|
183
|
-
>
|
|
184
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
185
|
-
</CellSlot>
|
|
186
|
-
);
|
|
187
|
-
})}
|
|
188
|
-
</TableRowSlot>
|
|
189
|
-
|
|
190
|
-
{row.getIsExpanded() && renderSubComponent ? (
|
|
191
|
-
<ExpandedRowSlot
|
|
192
|
-
{...mergedExpandedRowProps}
|
|
193
|
-
>
|
|
194
|
-
<CellSlot
|
|
195
|
-
colSpan={row.getVisibleCells().length}
|
|
196
|
-
sx={{
|
|
197
|
-
py: 0,
|
|
198
|
-
...expandedCellProps?.sx,
|
|
199
|
-
}}
|
|
200
|
-
{...mergeSlotProps(
|
|
201
|
-
{},
|
|
202
|
-
cellSlotProps,
|
|
203
|
-
expandedCellProps || {}
|
|
204
|
-
)}
|
|
205
|
-
>
|
|
206
|
-
<Collapse
|
|
207
|
-
in={row.getIsExpanded()}
|
|
208
|
-
timeout="auto"
|
|
209
|
-
unmountOnExit
|
|
210
|
-
>
|
|
211
|
-
{renderSubComponent(row) as any}
|
|
212
|
-
</Collapse>
|
|
213
|
-
</CellSlot>
|
|
214
|
-
</ExpandedRowSlot>
|
|
215
|
-
) : null}
|
|
216
|
-
</>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { TableCell, TableRow, TableRowProps, TableCellProps, SxProps } from '@mui/material';
|
|
2
|
-
import React, { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { getSlotComponent, mergeSlotProps, extractSlotProps } from '../../utils/slot-helpers';
|
|
4
|
-
|
|
5
|
-
export interface EmptyDataRowProps {
|
|
6
|
-
colSpan: number;
|
|
7
|
-
message: string | ReactNode;
|
|
8
|
-
// Enhanced customization props
|
|
9
|
-
rowProps?: TableRowProps;
|
|
10
|
-
cellProps?: TableCellProps;
|
|
11
|
-
containerSx?: SxProps;
|
|
12
|
-
messageSx?: SxProps;
|
|
13
|
-
slots?: Record<string, any>;
|
|
14
|
-
slotProps?: Record<string, any>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function EmptyDataRow(props: EmptyDataRowProps): ReactElement {
|
|
18
|
-
const {
|
|
19
|
-
colSpan,
|
|
20
|
-
message,
|
|
21
|
-
rowProps,
|
|
22
|
-
cellProps,
|
|
23
|
-
containerSx,
|
|
24
|
-
messageSx,
|
|
25
|
-
slots,
|
|
26
|
-
slotProps,
|
|
27
|
-
} = props;
|
|
28
|
-
|
|
29
|
-
// Extract slot-specific props with enhanced merging
|
|
30
|
-
const emptyRowSlotProps = extractSlotProps(slotProps, 'emptyRow');
|
|
31
|
-
const cellSlotProps = extractSlotProps(slotProps, 'cell');
|
|
32
|
-
|
|
33
|
-
const EmptyRowSlot = getSlotComponent(slots, 'emptyRow', TableRow);
|
|
34
|
-
const EmptyCellSlot = getSlotComponent(slots, 'cell', TableCell);
|
|
35
|
-
|
|
36
|
-
// Merge all props for maximum flexibility
|
|
37
|
-
const mergedRowProps = mergeSlotProps(
|
|
38
|
-
{
|
|
39
|
-
sx: containerSx,
|
|
40
|
-
},
|
|
41
|
-
emptyRowSlotProps,
|
|
42
|
-
rowProps || {}
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const mergedCellProps = mergeSlotProps(
|
|
46
|
-
{
|
|
47
|
-
colSpan,
|
|
48
|
-
align: 'center',
|
|
49
|
-
sx: {
|
|
50
|
-
py: 4,
|
|
51
|
-
...messageSx,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
cellSlotProps,
|
|
55
|
-
cellProps || {}
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<EmptyRowSlot
|
|
60
|
-
{...mergedRowProps}
|
|
61
|
-
>
|
|
62
|
-
<EmptyCellSlot
|
|
63
|
-
{...mergedCellProps}
|
|
64
|
-
>
|
|
65
|
-
{message}
|
|
66
|
-
</EmptyCellSlot>
|
|
67
|
-
</EmptyRowSlot>
|
|
68
|
-
);
|
|
69
|
-
}
|