@mezzanine-ui/react 1.0.0-alpha.0 → 1.0.0-beta.0
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/Breadcrumb/Breadcrumb.js +40 -12
- package/Breadcrumb/typings.d.ts +8 -3
- package/Drawer/Drawer.d.ts +47 -6
- package/Drawer/Drawer.js +36 -11
- package/Empty/Empty.js +26 -3
- package/Empty/typings.d.ts +16 -7
- package/PageHeader/PageHeader.d.ts +5 -1
- package/PageHeader/PageHeader.js +8 -3
- package/PageToolbar/PageToolbar.d.ts +73 -26
- package/PageToolbar/PageToolbar.js +10 -101
- package/PageToolbar/utils.d.ts +23 -0
- package/PageToolbar/utils.js +165 -0
- package/Pagination/PaginationItem.js +1 -3
- package/Pagination/usePagination.js +0 -18
- package/Radio/Radio.d.ts +36 -3
- package/Radio/Radio.js +21 -11
- package/Radio/RadioGroup.d.ts +36 -7
- package/Radio/RadioGroup.js +5 -4
- package/Radio/RadioGroupContext.d.ts +2 -1
- package/Radio/index.d.ts +3 -3
- package/Tab/Tab.d.ts +32 -0
- package/Tab/Tab.js +57 -0
- package/Tab/TabItem.d.ts +27 -0
- package/Tab/TabItem.js +18 -0
- package/Tab/index.d.ts +4 -0
- package/Tab/index.js +2 -0
- package/Table/Table.d.ts +75 -94
- package/Table/Table.js +216 -161
- package/Table/TableContext.d.ts +114 -51
- package/Table/TableContext.js +21 -3
- package/Table/components/TableBody.d.ts +5 -0
- package/Table/components/TableBody.js +102 -0
- package/Table/components/TableCell.d.ts +17 -0
- package/Table/components/TableCell.js +74 -0
- package/Table/components/TableColGroup.d.ts +4 -0
- package/Table/components/TableColGroup.js +206 -0
- package/Table/components/TableDragHandleCell.d.ts +9 -0
- package/Table/components/TableDragHandleCell.js +37 -0
- package/Table/components/TableExpandCell.d.ts +11 -0
- package/Table/components/TableExpandCell.js +44 -0
- package/Table/components/TableExpandedRow.d.ts +9 -0
- package/Table/components/TableExpandedRow.js +46 -0
- package/Table/components/TableHeader.d.ts +4 -0
- package/Table/components/TableHeader.js +125 -0
- package/Table/components/TablePagination.d.ts +3 -0
- package/Table/components/TablePagination.js +11 -0
- package/Table/components/TableResizeHandle.d.ts +13 -0
- package/Table/components/TableResizeHandle.js +115 -0
- package/Table/components/TableRow.d.ts +12 -0
- package/Table/components/TableRow.js +126 -0
- package/Table/components/TableSelectionCell.d.ts +13 -0
- package/Table/components/TableSelectionCell.js +35 -0
- package/Table/components/index.d.ts +10 -0
- package/Table/components/index.js +10 -0
- package/Table/hooks/index.d.ts +9 -0
- package/Table/hooks/index.js +8 -0
- package/Table/hooks/typings.d.ts +14 -0
- package/Table/hooks/useTableColumns.d.ts +8 -0
- package/Table/hooks/useTableColumns.js +91 -0
- package/Table/hooks/useTableDataSource.d.ts +57 -0
- package/Table/hooks/useTableDataSource.js +183 -0
- package/Table/hooks/useTableExpansion.d.ts +7 -0
- package/Table/hooks/useTableExpansion.js +52 -0
- package/Table/hooks/useTableFixedOffsets.d.ts +29 -0
- package/Table/hooks/useTableFixedOffsets.js +241 -0
- package/Table/hooks/useTableScroll.d.ts +12 -0
- package/Table/hooks/useTableScroll.js +58 -0
- package/Table/hooks/useTableSelection.d.ts +7 -0
- package/Table/hooks/useTableSelection.js +94 -0
- package/Table/hooks/useTableSorting.d.ts +6 -0
- package/Table/hooks/useTableSorting.js +32 -0
- package/Table/hooks/useTableVirtualization.d.ts +22 -0
- package/Table/hooks/useTableVirtualization.js +115 -0
- package/Table/index.d.ts +7 -10
- package/Table/index.js +22 -6
- package/Table/utils/index.d.ts +2 -0
- package/Table/utils/index.js +1 -0
- package/Table/utils/useTableRowSelection.d.ts +18 -0
- package/Table/utils/useTableRowSelection.js +63 -0
- package/_internal/InputCheck/InputCheck.d.ts +15 -1
- package/_internal/InputCheck/InputCheck.js +6 -2
- package/_internal/InputCheck/InputCheckGroup.d.ts +11 -1
- package/_internal/InputCheck/InputCheckGroup.js +4 -2
- package/_internal/SlideFadeOverlay/SlideFadeOverlay.d.ts +1 -1
- package/_internal/SlideFadeOverlay/SlideFadeOverlay.js +1 -1
- package/index.d.ts +7 -5
- package/index.js +6 -9
- package/package.json +5 -4
- package/utils/flatten-children.d.ts +12 -0
- package/utils/flatten-children.js +37 -0
- package/utils/get-css-variable-value.d.ts +1 -0
- package/utils/get-css-variable-value.js +4 -1
- package/Table/TableBody.d.ts +0 -10
- package/Table/TableBody.js +0 -31
- package/Table/TableBodyRow.d.ts +0 -11
- package/Table/TableBodyRow.js +0 -65
- package/Table/TableCell.d.ts +0 -19
- package/Table/TableCell.js +0 -24
- package/Table/TableExpandedTable.d.ts +0 -11
- package/Table/TableExpandedTable.js +0 -29
- package/Table/TableHeader.d.ts +0 -3
- package/Table/TableHeader.js +0 -36
- package/Table/draggable/useTableDraggable.d.ts +0 -14
- package/Table/draggable/useTableDraggable.js +0 -64
- package/Table/editable/TableEditRenderWrapper.d.ts +0 -7
- package/Table/editable/TableEditRenderWrapper.js +0 -16
- package/Table/expandable/TableExpandable.d.ts +0 -27
- package/Table/expandable/TableExpandable.js +0 -24
- package/Table/pagination/TablePagination.d.ts +0 -10
- package/Table/pagination/TablePagination.js +0 -26
- package/Table/pagination/useTablePagination.d.ts +0 -8
- package/Table/pagination/useTablePagination.js +0 -30
- package/Table/refresh/TableRefresh.d.ts +0 -10
- package/Table/refresh/TableRefresh.js +0 -22
- package/Table/rowSelection/TableRowSelection.d.ts +0 -18
- package/Table/rowSelection/TableRowSelection.js +0 -93
- package/Table/rowSelection/useTableRowSelection.d.ts +0 -6
- package/Table/rowSelection/useTableRowSelection.js +0 -53
- package/Table/sorting/TableSortingIcon.d.ts +0 -10
- package/Table/sorting/TableSortingIcon.js +0 -33
- package/Table/sorting/useTableSorting.d.ts +0 -11
- package/Table/sorting/useTableSorting.js +0 -121
- package/Table/useTableFetchMore.d.ts +0 -10
- package/Table/useTableFetchMore.js +0 -50
- package/Table/useTableLoading.d.ts +0 -5
- package/Table/useTableLoading.js +0 -19
- package/Table/useTableScroll.d.ts +0 -592
- package/Table/useTableScroll.js +0 -296
- package/Tabs/Tab.d.ts +0 -18
- package/Tabs/Tab.js +0 -16
- package/Tabs/TabPane.d.ts +0 -14
- package/Tabs/TabPane.js +0 -19
- package/Tabs/Tabs.d.ts +0 -39
- package/Tabs/Tabs.js +0 -52
- package/Tabs/index.d.ts +0 -6
- package/Tabs/index.js +0 -3
- package/Tabs/useTabsOverflow.d.ts +0 -8
- package/Tabs/useTabsOverflow.js +0 -62
package/Table/Table.d.ts
CHANGED
|
@@ -1,110 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
bodyClassName?: string;
|
|
10
|
-
/**
|
|
11
|
-
* customized body row className
|
|
12
|
-
*/
|
|
13
|
-
bodyRowClassName?: string | ((source: T) => string);
|
|
14
|
-
/**
|
|
15
|
-
* Columns of table <br />
|
|
16
|
-
* `column.render` allowed customizing the column body cell rendering. <br />
|
|
17
|
-
* `column.renderTitle` allowed customizing the column header cell rendering. <br />
|
|
18
|
-
* `column.sorter` is the sorting method that you want to apply to your column. <br />
|
|
19
|
-
* `column.onSorted` is the callback triggered whenever sort icon clicked.
|
|
20
|
-
*/
|
|
1
|
+
import { TableSize, type HighlightMode, type TableColumn, type TableDataSource, type TableDraggable, type TableExpandable, type TableRowSelection, type TableScroll } from '@mezzanine-ui/core/table';
|
|
2
|
+
import type { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
3
|
+
import { type TableTransitionState } from './TableContext';
|
|
4
|
+
import { TablePaginationProps } from './components/TablePagination';
|
|
5
|
+
import type { EmptyProps } from '../Empty';
|
|
6
|
+
export interface TableBaseProps<T extends TableDataSource = TableDataSource> extends Omit<NativeElementPropsWithoutKeyAndRef<'table'>, 'children' | 'draggable' | 'summary' | 'onChange'> {
|
|
7
|
+
/** Column configuration */
|
|
21
8
|
columns: TableColumn<T>[];
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
components?: TableComponents;
|
|
26
|
-
/**
|
|
27
|
-
* Data record array to be displayed. <br />
|
|
28
|
-
* Notice that each source should contain `key` or `id` prop as data primary key.
|
|
29
|
-
*/
|
|
30
|
-
dataSource: TableDataSource[];
|
|
31
|
-
/**
|
|
32
|
-
* Draggable table row. This feature allows sort items by mouse dragging. Not supported when `fetchMore` is enabled and also buggy when use finger touch (mobile device).
|
|
33
|
-
* When `draggable.enabled` is true, draggable will be enabled.
|
|
34
|
-
* `draggable.onDragEnd` return new dataSource for you
|
|
35
|
-
*/
|
|
36
|
-
draggable?: TableDraggable;
|
|
37
|
-
/**
|
|
38
|
-
* props exported from `<Empty />` component.
|
|
39
|
-
*/
|
|
9
|
+
/** Data source */
|
|
10
|
+
dataSource: T[];
|
|
11
|
+
/** Props for Empty component when no data */
|
|
40
12
|
emptyProps?: EmptyProps;
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expandable?: Omit<TableExpandable<T>, 'expandedRowRender'> & {
|
|
46
|
-
expandedRowRender(record: T): ReactNode | ExpandRowBySources;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* customized header className
|
|
50
|
-
*/
|
|
51
|
-
headerClassName?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Whether table is loading or not
|
|
13
|
+
/** Expandable row configuration */
|
|
14
|
+
expandable?: TableExpandable<T>;
|
|
15
|
+
/** Highlight mode for hover effects
|
|
16
|
+
* @default 'row'
|
|
54
17
|
*/
|
|
18
|
+
highlight?: HighlightMode;
|
|
19
|
+
/** Loading state */
|
|
55
20
|
loading?: boolean;
|
|
21
|
+
/** Number of rows to display when loading */
|
|
22
|
+
loadingRowsCount?: number;
|
|
56
23
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @default '資料載入中...'
|
|
24
|
+
* Whether the table is nested inside an expanded row content area
|
|
59
25
|
*/
|
|
60
|
-
|
|
26
|
+
nested?: boolean;
|
|
27
|
+
/** Pagination configuration */
|
|
28
|
+
pagination?: TablePaginationProps;
|
|
61
29
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
30
|
+
* Whether columns are resizable by user interaction
|
|
31
|
+
* @default false
|
|
64
32
|
*/
|
|
65
|
-
|
|
33
|
+
resizable?: boolean;
|
|
66
34
|
/**
|
|
67
|
-
*
|
|
68
|
-
* `rowSelection.selectedRowKey` is the dataSource keys that are currently selected. <br />
|
|
69
|
-
* `rowSelection.onChange` is the callback when selection changed. <br />
|
|
70
|
-
* `rowSelection.actions` are the actions that you want to do for selected data.
|
|
35
|
+
* Row height preset token.
|
|
71
36
|
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
37
|
+
rowHeightPreset?: 'base' | 'condensed' | 'detailed' | 'roomy';
|
|
38
|
+
/** Row selection configuration */
|
|
39
|
+
rowSelection?: TableRowSelection<T>;
|
|
40
|
+
/** Show header row */
|
|
41
|
+
showHeader?: boolean;
|
|
42
|
+
/** Custom size variant
|
|
43
|
+
* @default 'main'
|
|
78
44
|
*/
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
45
|
+
size?: TableSize;
|
|
46
|
+
/** Whether to enable sticky header
|
|
47
|
+
* @default true
|
|
82
48
|
*/
|
|
83
|
-
|
|
49
|
+
sticky?: boolean;
|
|
50
|
+
/** Transition state for row add/remove animations (from useTableDataSource hook) */
|
|
51
|
+
transitionState?: TableTransitionState;
|
|
84
52
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Props when virtualized scrolling is enabled.
|
|
55
|
+
* Draggable is not allowed in this mode.
|
|
56
|
+
*/
|
|
57
|
+
export interface TableVirtualizedProps<T extends TableDataSource = TableDataSource> extends TableBaseProps<T> {
|
|
58
|
+
/** Draggable row configuration - not available when virtualized is enabled */
|
|
59
|
+
draggable?: never;
|
|
60
|
+
/** Scroll configuration with virtualized enabled */
|
|
61
|
+
scroll: TableScroll & {
|
|
62
|
+
virtualized: true;
|
|
63
|
+
y: number | string;
|
|
64
|
+
};
|
|
95
65
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Props when virtualized scrolling is disabled or not specified.
|
|
68
|
+
* Draggable is allowed in this mode.
|
|
69
|
+
*/
|
|
70
|
+
export interface TableNonVirtualizedProps<T extends TableDataSource = TableDataSource> extends TableBaseProps<T> {
|
|
71
|
+
/** Draggable row configuration */
|
|
72
|
+
draggable?: TableDraggable<T>;
|
|
73
|
+
/** Scroll configuration for scrolling (virtualized defaults to false) */
|
|
74
|
+
scroll?: TableScroll & {
|
|
75
|
+
virtualized?: false;
|
|
76
|
+
};
|
|
107
77
|
}
|
|
108
|
-
|
|
109
|
-
|
|
78
|
+
/**
|
|
79
|
+
* TableProps - discriminated union to ensure draggable and virtualized
|
|
80
|
+
* scrolling are mutually exclusive at the type level.
|
|
81
|
+
*/
|
|
82
|
+
export type TableProps<T extends TableDataSource = TableDataSource> = TableVirtualizedProps<T> | TableNonVirtualizedProps<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Table is a high-performance data table component with support for
|
|
85
|
+
* virtual scrolling, column resizing, fixed columns, row selection,
|
|
86
|
+
* sorting, expandable rows, and drag-and-drop row reordering.
|
|
87
|
+
*/
|
|
88
|
+
export declare const Table: <T extends TableDataSource = TableDataSource>(props: TableProps<T> & {
|
|
89
|
+
ref?: React.ForwardedRef<HTMLDivElement>;
|
|
90
|
+
}) => React.ReactElement;
|
|
110
91
|
export default Table;
|
package/Table/Table.js
CHANGED
|
@@ -1,182 +1,237 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useRef, useMemo,
|
|
3
|
-
import { DragDropContext, Droppable } from '@hello-pangea/dnd';
|
|
3
|
+
import { forwardRef, useRef, useMemo, useState, useCallback } from 'react';
|
|
4
4
|
import { tableClasses } from '@mezzanine-ui/core/table';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import TableBody from './TableBody.js';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
5
|
+
import { DragDropContext, Droppable } from '@hello-pangea/dnd';
|
|
6
|
+
import { TableContext, TableDataContext, TableSuperContext } from './TableContext.js';
|
|
7
|
+
import { TableBody } from './components/TableBody.js';
|
|
8
|
+
import { TableColGroup } from './components/TableColGroup.js';
|
|
9
|
+
import { TableHeader } from './components/TableHeader.js';
|
|
10
|
+
import { TablePagination } from './components/TablePagination.js';
|
|
11
|
+
import { useTableColumns } from './hooks/useTableColumns.js';
|
|
12
|
+
import { useTableExpansion } from './hooks/useTableExpansion.js';
|
|
13
|
+
import { useTableFixedOffsets } from './hooks/useTableFixedOffsets.js';
|
|
14
|
+
import { useTableScroll } from './hooks/useTableScroll.js';
|
|
15
|
+
import { useTableSelection } from './hooks/useTableSelection.js';
|
|
16
|
+
import { useTableSorting } from './hooks/useTableSorting.js';
|
|
17
17
|
import { composeRefs } from '../utils/composeRefs.js';
|
|
18
|
-
import
|
|
18
|
+
import { getNumericCSSVariablePixelValue } from '../utils/get-css-variable-value.js';
|
|
19
|
+
import { spacingPrefix } from '@mezzanine-ui/system/spacing';
|
|
19
20
|
import cx from 'clsx';
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
function TableInner(props, ref) {
|
|
23
|
+
const { className, columns, dataSource, draggable, emptyProps, expandable, highlight = 'row', loading = false, loadingRowsCount = 10, nested = false, pagination, resizable = false, rowHeightPreset = 'base', rowSelection, scroll, showHeader = true, size = 'main', sticky = true, style, transitionState, ...restProps } = props;
|
|
24
|
+
const hostRef = useRef(null);
|
|
25
|
+
const scrollContainerRef = useRef(null);
|
|
26
|
+
const tableRef = useRef(null);
|
|
27
|
+
// mock loading dataSource
|
|
28
|
+
const dataSourceForRender = loading
|
|
29
|
+
? Array.from({ length: Math.max(loadingRowsCount, 1) }).map((_, idx) => ({
|
|
30
|
+
key: idx,
|
|
31
|
+
}))
|
|
32
|
+
: dataSource;
|
|
33
|
+
// get row height from preset
|
|
34
|
+
const rowHeight = useMemo(() => {
|
|
35
|
+
switch (rowHeightPreset) {
|
|
36
|
+
case 'condensed':
|
|
37
|
+
return size === 'main'
|
|
38
|
+
? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-condensed`)
|
|
39
|
+
: getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-reduced`);
|
|
40
|
+
case 'detailed':
|
|
41
|
+
return size === 'main'
|
|
42
|
+
? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-tiny`)
|
|
43
|
+
: getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-tightened`);
|
|
44
|
+
case 'roomy':
|
|
45
|
+
return size === 'main'
|
|
46
|
+
? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-small`)
|
|
47
|
+
: getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-medium`);
|
|
48
|
+
case 'base':
|
|
49
|
+
default:
|
|
50
|
+
return size === 'main'
|
|
51
|
+
? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-minimized`)
|
|
52
|
+
: getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-minimal`);
|
|
38
53
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
}, [rowHeightPreset, size]);
|
|
55
|
+
// Highlight state for hover effects
|
|
56
|
+
const [hoveredRowIndex, setHoveredRowIndex] = useState(null);
|
|
57
|
+
const [hoveredColumnIndex, setHoveredColumnIndex] = useState(null);
|
|
58
|
+
const setHoveredCell = useCallback((rowIndex, columnIndex) => {
|
|
59
|
+
setHoveredRowIndex(rowIndex);
|
|
60
|
+
setHoveredColumnIndex(columnIndex);
|
|
61
|
+
}, []);
|
|
62
|
+
// Hooks
|
|
63
|
+
const sortingState = useTableSorting({
|
|
64
|
+
columns,
|
|
47
65
|
});
|
|
48
|
-
|
|
49
|
-
const { fetchMore: onFetchMore, isFetching, isReachEnd, } = useTableFetchMore({
|
|
50
|
-
callback: fetchMoreProp === null || fetchMoreProp === void 0 ? void 0 : fetchMoreProp.callback,
|
|
66
|
+
const selectionState = useTableSelection({
|
|
51
67
|
dataSource,
|
|
52
|
-
|
|
53
|
-
disabled: !!paginationProp,
|
|
54
|
-
isReachEnd: fetchMoreProp === null || fetchMoreProp === void 0 ? void 0 : fetchMoreProp.isReachEnd,
|
|
55
|
-
isFetching: fetchMoreProp === null || fetchMoreProp === void 0 ? void 0 : fetchMoreProp.isFetching,
|
|
68
|
+
rowSelection,
|
|
56
69
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return (_a = refreshProp === null || refreshProp === void 0 ? void 0 : refreshProp.show) !== null && _a !== void 0 ? _a : false; }, [refreshProp === null || refreshProp === void 0 ? void 0 : refreshProp.show]);
|
|
61
|
-
/** Feature Scrolling */
|
|
62
|
-
const [scrollBody, scrollElement, isHorizontalScrolling] = useTableScroll({
|
|
63
|
-
onFetchMore,
|
|
64
|
-
loading,
|
|
65
|
-
scrollBarSize: 4,
|
|
70
|
+
const expansionState = useTableExpansion({
|
|
71
|
+
expandable,
|
|
72
|
+
hasDragHandle: !!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled),
|
|
66
73
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
const actionConfig = useMemo(() => ({
|
|
75
|
+
hasDragHandle: !!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled),
|
|
76
|
+
dragHandleFixed: !!(draggable === null || draggable === void 0 ? void 0 : draggable.fixed),
|
|
77
|
+
hasExpansion: !!expandable,
|
|
78
|
+
expansionFixed: !!(expandable === null || expandable === void 0 ? void 0 : expandable.fixed),
|
|
79
|
+
hasSelection: !!rowSelection,
|
|
80
|
+
selectionFixed: !!(rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.fixed),
|
|
81
|
+
}), [draggable === null || draggable === void 0 ? void 0 : draggable.enabled, draggable === null || draggable === void 0 ? void 0 : draggable.fixed, expandable, rowSelection]);
|
|
82
|
+
const columnState = useTableColumns({
|
|
83
|
+
actionConfig,
|
|
84
|
+
columns,
|
|
72
85
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
siblingCount: (_j = (_h = paginationProp.options) === null || _h === void 0 ? void 0 : _h.siblingCount) !== null && _j !== void 0 ? _j : 1,
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
: undefined,
|
|
110
|
-
scroll: scrollProp,
|
|
111
|
-
draggable: draggableProp
|
|
112
|
-
? {
|
|
113
|
-
...draggableProp,
|
|
114
|
-
draggingId,
|
|
115
|
-
}
|
|
116
|
-
: undefined,
|
|
117
|
-
});
|
|
118
|
-
}, [
|
|
119
|
-
dataSource,
|
|
86
|
+
const scrollState = useTableScroll({
|
|
87
|
+
enabled: !nested,
|
|
88
|
+
});
|
|
89
|
+
// Fixed column offset calculations
|
|
90
|
+
const fixedOffsetsState = useTableFixedOffsets({
|
|
91
|
+
actionConfig,
|
|
92
|
+
columns: columns,
|
|
93
|
+
getResizedColumnWidth: columnState.getResizedColumnWidth,
|
|
94
|
+
});
|
|
95
|
+
// Stabilize draggable object
|
|
96
|
+
const draggableValue = useMemo(() => draggable
|
|
97
|
+
? {
|
|
98
|
+
draggingId: null,
|
|
99
|
+
enabled: true,
|
|
100
|
+
fixed: draggable.fixed,
|
|
101
|
+
}
|
|
102
|
+
: undefined, [draggable]);
|
|
103
|
+
// Stabilize highlight object
|
|
104
|
+
const highlightValue = useMemo(() => ({
|
|
105
|
+
columnIndex: hoveredColumnIndex,
|
|
106
|
+
mode: highlight,
|
|
107
|
+
rowIndex: hoveredRowIndex,
|
|
108
|
+
setHoveredCell,
|
|
109
|
+
}), [highlight, hoveredColumnIndex, hoveredRowIndex, setHoveredCell]);
|
|
110
|
+
// Determine if virtual scrolling should be enabled
|
|
111
|
+
// Requires scroll.virtualized to be true AND scroll.y to be set
|
|
112
|
+
const virtualScrollEnabled = !!((scroll === null || scroll === void 0 ? void 0 : scroll.virtualized) && (scroll === null || scroll === void 0 ? void 0 : scroll.y));
|
|
113
|
+
// Context value - cast to any to avoid complex generic issues
|
|
114
|
+
const contextValue = useMemo(() => ({
|
|
115
|
+
columnState,
|
|
116
|
+
columns: columns,
|
|
117
|
+
dataSource: dataSourceForRender,
|
|
118
|
+
draggable: draggableValue,
|
|
120
119
|
emptyProps,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
expansion: expansionState,
|
|
121
|
+
fixedOffsets: fixedOffsetsState,
|
|
122
|
+
resizable,
|
|
123
|
+
rowHeight,
|
|
124
|
+
highlight: highlightValue,
|
|
125
|
+
isScrollingHorizontally: scrollState.isScrollingHorizontally,
|
|
126
|
+
isInsideExpandedContentArea: nested,
|
|
127
127
|
loading,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const tableDataContextValue = useMemo(() => ({
|
|
128
|
+
pagination: pagination || undefined,
|
|
129
|
+
scroll,
|
|
130
|
+
scrollContainerRef,
|
|
131
|
+
selection: selectionState,
|
|
132
|
+
size,
|
|
133
|
+
sorting: sortingState,
|
|
134
|
+
transitionState,
|
|
135
|
+
virtualScrollEnabled,
|
|
136
|
+
}), [
|
|
137
|
+
columnState,
|
|
139
138
|
columns,
|
|
139
|
+
dataSourceForRender,
|
|
140
|
+
draggableValue,
|
|
141
|
+
emptyProps,
|
|
142
|
+
expansionState,
|
|
143
|
+
fixedOffsetsState,
|
|
144
|
+
resizable,
|
|
145
|
+
rowHeight,
|
|
146
|
+
highlightValue,
|
|
147
|
+
loading,
|
|
148
|
+
pagination,
|
|
149
|
+
scroll,
|
|
150
|
+
scrollContainerRef,
|
|
151
|
+
scrollState.isScrollingHorizontally,
|
|
152
|
+
selectionState,
|
|
153
|
+
size,
|
|
154
|
+
sortingState,
|
|
155
|
+
transitionState,
|
|
156
|
+
virtualScrollEnabled,
|
|
157
|
+
nested,
|
|
158
|
+
]);
|
|
159
|
+
const dataContextValue = useMemo(() => ({
|
|
160
|
+
columns: columns,
|
|
140
161
|
dataSource,
|
|
141
162
|
}), [columns, dataSource]);
|
|
142
|
-
const
|
|
163
|
+
const superContextValue = useMemo(() => {
|
|
143
164
|
var _a;
|
|
144
165
|
return ({
|
|
145
|
-
|
|
166
|
+
containerWidth: scrollState.containerWidth,
|
|
167
|
+
getResizedColumnWidth: columnState.getResizedColumnWidth,
|
|
168
|
+
scrollLeft: scrollState.scrollLeft,
|
|
169
|
+
expansionLeftPadding: (_a = expansionState === null || expansionState === void 0 ? void 0 : expansionState.expansionLeftPadding) !== null && _a !== void 0 ? _a : 0,
|
|
146
170
|
});
|
|
147
|
-
}, [
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
171
|
+
}, [
|
|
172
|
+
scrollState.scrollLeft,
|
|
173
|
+
expansionState === null || expansionState === void 0 ? void 0 : expansionState.expansionLeftPadding,
|
|
174
|
+
scrollState.containerWidth,
|
|
175
|
+
columnState.getResizedColumnWidth,
|
|
176
|
+
]);
|
|
177
|
+
// Drag and drop handler
|
|
178
|
+
const handleDragEnd = useCallback((result) => {
|
|
179
|
+
var _a;
|
|
180
|
+
if (!result.destination || !draggable)
|
|
181
|
+
return;
|
|
182
|
+
const sourceIndex = result.source.index;
|
|
183
|
+
const destIndex = result.destination.index;
|
|
184
|
+
if (sourceIndex === destIndex)
|
|
185
|
+
return;
|
|
186
|
+
const newData = [...dataSource];
|
|
187
|
+
const [removed] = newData.splice(sourceIndex, 1);
|
|
188
|
+
newData.splice(destIndex, 0, removed);
|
|
189
|
+
(_a = draggable.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(draggable, newData);
|
|
190
|
+
}, [dataSource, draggable]);
|
|
191
|
+
const sizeClass = size === 'sub' ? tableClasses.sub : tableClasses.main;
|
|
192
|
+
// Scroll container style
|
|
193
|
+
const scrollContainerStyle = useMemo(() => {
|
|
194
|
+
const containerStyle = {};
|
|
195
|
+
if (scroll === null || scroll === void 0 ? void 0 : scroll.y) {
|
|
196
|
+
containerStyle.maxHeight = scroll.y;
|
|
197
|
+
containerStyle.overflowY = 'auto';
|
|
198
|
+
}
|
|
199
|
+
if (scroll === null || scroll === void 0 ? void 0 : scroll.x) {
|
|
200
|
+
containerStyle.overflowX = 'auto';
|
|
201
|
+
}
|
|
202
|
+
if (nested) {
|
|
203
|
+
containerStyle.position = 'unset';
|
|
204
|
+
containerStyle.overflow = 'unset';
|
|
205
|
+
}
|
|
206
|
+
return containerStyle;
|
|
207
|
+
}, [scroll === null || scroll === void 0 ? void 0 : scroll.x, scroll === null || scroll === void 0 ? void 0 : scroll.y, nested]);
|
|
208
|
+
// Table style with min-width for horizontal scroll
|
|
209
|
+
const tableStyle = useMemo(() => {
|
|
210
|
+
const baseStyle = {};
|
|
211
|
+
if (scroll === null || scroll === void 0 ? void 0 : scroll.x) {
|
|
212
|
+
baseStyle.minWidth = scroll.x;
|
|
213
|
+
baseStyle.width = '100%';
|
|
155
214
|
}
|
|
156
|
-
return
|
|
157
|
-
}, [
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
backgroundColor: '#7d7d7d',
|
|
178
|
-
transition: '0.1s',
|
|
179
|
-
} }) }) }) })] })) }) }) }) }) }) }));
|
|
180
|
-
});
|
|
215
|
+
return baseStyle;
|
|
216
|
+
}, [scroll === null || scroll === void 0 ? void 0 : scroll.x]);
|
|
217
|
+
const { setContainerRef } = scrollState;
|
|
218
|
+
const handleScrollContainerRef = useCallback((element) => {
|
|
219
|
+
scrollContainerRef.current = element;
|
|
220
|
+
setContainerRef(element);
|
|
221
|
+
}, [setContainerRef]);
|
|
222
|
+
const mainTable = (jsx(TableContext.Provider, { value: contextValue, children: jsx(TableDataContext.Provider, { value: dataContextValue, children: jsxs("div", { className: cx(tableClasses.host, className), ref: ref, style: style, ...restProps, children: [jsx("div", { className: cx(tableClasses.scrollContainer, {
|
|
223
|
+
[tableClasses.sticky]: !!sticky,
|
|
224
|
+
}), onScroll: scrollState.handleScroll, ref: handleScrollContainerRef, style: scrollContainerStyle, children: jsxs("table", { className: cx(tableClasses.root, sizeClass), ref: tableRef, style: tableStyle, children: [jsx(TableColGroup, {}), showHeader && jsx(TableHeader, {}), jsx(TableBody, {})] }) }), pagination && jsx(TablePagination, { ...pagination })] }) }) }));
|
|
225
|
+
if (nested) {
|
|
226
|
+
return mainTable;
|
|
227
|
+
}
|
|
228
|
+
return (jsx(DragDropContext, { onDragEnd: handleDragEnd, children: jsx(Droppable, { droppableId: "mzn-table-v2-dnd", children: (provided) => (jsxs("div", { ...provided.droppableProps, ref: composeRefs([hostRef, provided.innerRef]), children: [jsx(TableSuperContext.Provider, { value: superContextValue, children: mainTable }), provided.placeholder] })) }) }));
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Table is a high-performance data table component with support for
|
|
232
|
+
* virtual scrolling, column resizing, fixed columns, row selection,
|
|
233
|
+
* sorting, expandable rows, and drag-and-drop row reordering.
|
|
234
|
+
*/
|
|
235
|
+
const Table = forwardRef(TableInner);
|
|
181
236
|
|
|
182
|
-
export { Table as default };
|
|
237
|
+
export { Table, Table as default };
|