@mezzanine-ui/react 1.0.0-beta.3 → 1.0.0-beta.4
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/AutoComplete/AutoComplete.d.ts +23 -0
- package/AutoComplete/AutoComplete.js +23 -9
- package/Breadcrumb/Breadcrumb.js +16 -21
- package/Breadcrumb/BreadcrumbDropdown.d.ts +11 -0
- package/Breadcrumb/BreadcrumbDropdown.js +22 -0
- package/Breadcrumb/BreadcrumbItem.d.ts +2 -3
- package/Breadcrumb/BreadcrumbItem.js +13 -31
- package/Breadcrumb/BreadcrumbOverflowMenu.d.ts +7 -0
- package/Breadcrumb/BreadcrumbOverflowMenu.js +77 -0
- package/Breadcrumb/BreadcrumbOverflowMenuDropdown.d.ts +11 -0
- package/Breadcrumb/BreadcrumbOverflowMenuDropdown.js +21 -0
- package/Breadcrumb/BreadcrumbOverflowMenuItem.d.ts +3 -0
- package/Breadcrumb/BreadcrumbOverflowMenuItem.js +27 -0
- package/Breadcrumb/typings.d.ts +21 -39
- package/Checkbox/index.d.ts +4 -5
- package/Checkbox/index.js +1 -5
- package/ContentHeader/ContentHeader.d.ts +160 -0
- package/ContentHeader/ContentHeader.js +54 -0
- package/ContentHeader/index.d.ts +2 -0
- package/ContentHeader/index.js +1 -0
- package/ContentHeader/utils.d.ts +23 -0
- package/ContentHeader/utils.js +215 -0
- package/Dropdown/Dropdown.d.ts +17 -0
- package/Dropdown/Dropdown.js +6 -2
- package/Dropdown/DropdownItem.d.ts +10 -0
- package/Dropdown/DropdownItem.js +37 -8
- package/Dropdown/DropdownItemCard.d.ts +2 -2
- package/Dropdown/DropdownItemCard.js +11 -8
- package/Empty/Empty.js +2 -1
- package/Empty/icons/EmptyMainNotificationIcon.d.ts +4 -0
- package/Empty/icons/EmptyMainNotificationIcon.js +9 -0
- package/Empty/typings.d.ts +2 -2
- package/FilterArea/Filter.d.ts +32 -0
- package/FilterArea/Filter.js +23 -0
- package/FilterArea/FilterArea.d.ts +58 -0
- package/FilterArea/FilterArea.js +31 -0
- package/FilterArea/FilterLine.d.ts +11 -0
- package/FilterArea/FilterLine.js +13 -0
- package/FilterArea/index.d.ts +6 -0
- package/FilterArea/index.js +3 -0
- package/Input/Input.d.ts +6 -4
- package/Input/Input.js +28 -10
- package/Input/index.d.ts +1 -1
- package/Modal/MediaPreviewModal.d.ts +54 -0
- package/Modal/MediaPreviewModal.js +158 -0
- package/Modal/Modal.js +1 -1
- package/Modal/index.d.ts +2 -0
- package/Modal/index.js +1 -0
- package/Navigation/Navigation.js +6 -5
- package/Navigation/NavigationOption.d.ts +6 -2
- package/Navigation/NavigationOption.js +19 -9
- package/Navigation/NavigationOverflowMenu.d.ts +6 -0
- package/Navigation/NavigationOverflowMenu.js +90 -0
- package/Navigation/NavigationOverflowMenuOption.d.ts +7 -0
- package/Navigation/NavigationOverflowMenuOption.js +68 -0
- package/Navigation/NavigationUserMenu.d.ts +4 -2
- package/Navigation/NavigationUserMenu.js +13 -5
- package/Navigation/context.d.ts +3 -2
- package/NotificationCenter/NotificationCenter.d.ts +1 -1
- package/NotificationCenter/NotificationCenter.js +34 -14
- package/NotificationCenter/NotificationCenterDrawer.d.ts +20 -0
- package/PageHeader/PageHeader.d.ts +32 -25
- package/PageHeader/PageHeader.js +49 -35
- package/ResultState/ResultState.d.ts +9 -0
- package/ResultState/ResultState.js +36 -4
- package/Scrollbar/Scrollbar.d.ts +9 -0
- package/Scrollbar/Scrollbar.js +78 -0
- package/Scrollbar/index.d.ts +2 -0
- package/Scrollbar/index.js +1 -0
- package/Scrollbar/typings.d.ts +47 -0
- package/Select/SelectTrigger.js +5 -4
- package/Select/typings.d.ts +6 -1
- package/Selection/Selection.js +1 -1
- package/Selection/SelectionGroup.d.ts +28 -0
- package/Table/Table.d.ts +2 -120
- package/Table/Table.js +148 -53
- package/Table/TableContext.d.ts +11 -12
- package/Table/components/TableActionsCell.js +12 -4
- package/Table/components/TableBody.js +2 -1
- package/Table/components/TableColGroup.d.ts +1 -4
- package/Table/components/TableColGroup.js +15 -16
- package/Table/components/TableCollectableCell.d.ts +17 -0
- package/Table/components/TableCollectableCell.js +54 -0
- package/Table/components/TableDragOrPinHandleCell.d.ts +20 -0
- package/Table/components/TableDragOrPinHandleCell.js +58 -0
- package/Table/components/TableExpandedRow.js +11 -2
- package/Table/components/TableHeader.js +12 -10
- package/Table/components/TableRow.js +38 -13
- package/Table/components/TableSelectionCell.js +1 -1
- package/Table/components/TableToggleableCell.d.ts +16 -0
- package/Table/components/TableToggleableCell.js +51 -0
- package/Table/components/index.d.ts +4 -1
- package/Table/components/index.js +3 -0
- package/Table/hooks/typings.d.ts +18 -4
- package/Table/hooks/useTableExpansion.d.ts +2 -2
- package/Table/hooks/useTableExpansion.js +5 -5
- package/Table/hooks/useTableFixedOffsets.d.ts +6 -2
- package/Table/hooks/useTableFixedOffsets.js +58 -24
- package/Table/hooks/useTableScroll.d.ts +9 -3
- package/Table/hooks/useTableScroll.js +34 -7
- package/Table/hooks/useTableVirtualization.d.ts +2 -1
- package/Table/hooks/useTableVirtualization.js +2 -8
- package/Table/index.d.ts +4 -3
- package/Table/index.js +3 -0
- package/Table/typings.d.ts +172 -0
- package/Transition/Slide.d.ts +9 -2
- package/Transition/Slide.js +7 -4
- package/Tree/TreeNode.js +1 -1
- package/index.d.ts +4 -2
- package/index.js +6 -3
- package/package.json +6 -4
- package/Navigation/CollapsedMenu.d.ts +0 -6
- package/Navigation/CollapsedMenu.js +0 -16
- package/PageToolbar/PageToolbar.d.ts +0 -110
- package/PageToolbar/PageToolbar.js +0 -23
- package/PageToolbar/index.d.ts +0 -2
- package/PageToolbar/index.js +0 -1
- package/PageToolbar/utils.d.ts +0 -23
- package/PageToolbar/utils.js +0 -157
- package/Table/components/TableDragHandleCell.d.ts +0 -11
- package/Table/components/TableDragHandleCell.js +0 -44
package/Table/Table.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useRef, useMemo, useState, useCallback, useEffect } from 'react';
|
|
4
4
|
import throttle from 'lodash/throttle';
|
|
5
|
-
import { TABLE_ACTIONS_KEY, tableClasses } from '@mezzanine-ui/core/table';
|
|
5
|
+
import { TOGGLEABLE_COLUMN_WIDTH, TOGGLEABLE_KEY, COLLECTABLE_COLUMN_WIDTH, COLLECTABLE_KEY, TABLE_ACTIONS_KEY, tableClasses } from '@mezzanine-ui/core/table';
|
|
6
6
|
import { DragDropContext, Droppable } from '@hello-pangea/dnd';
|
|
7
7
|
import { TableSuperContext, TableContext, TableDataContext } from './TableContext.js';
|
|
8
8
|
import { TableBody } from './components/TableBody.js';
|
|
@@ -19,10 +19,11 @@ import { getNumericCSSVariablePixelValue } from '../utils/get-css-variable-value
|
|
|
19
19
|
import { spacingPrefix } from '@mezzanine-ui/system/spacing';
|
|
20
20
|
import TableBulkActions from './components/TableBulkActions.js';
|
|
21
21
|
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
22
|
+
import Scrollbar from '../Scrollbar/Scrollbar.js';
|
|
22
23
|
import cx from 'clsx';
|
|
23
24
|
|
|
24
25
|
function TableInner(props, ref) {
|
|
25
|
-
const { actions, className, columns, dataSource, draggable, emptyProps, expandable, fullWidth = false, highlight = 'row', loading = false, loadingRowsCount = 10, minHeight, nested = false, pagination, resizable = false, rowHeightPreset = 'base', rowSelection, scroll, showHeader = true, size = 'main', sticky = true, style, transitionState, zebraStriping, separatorAtRowIndexes, ...restProps } = props;
|
|
26
|
+
const { actions, className, columns, dataSource, draggable, emptyProps, expandable, fullWidth = false, highlight = 'row', loading = false, loadingRowsCount = 10, minHeight, nested = false, pagination, pinnable, resizable = false, rowHeightPreset = 'base', rowSelection, scroll, showHeader = true, size = 'main', sticky = true, style, toggleable, collectable, transitionState, zebraStriping, separatorAtRowIndexes, ...restProps } = props;
|
|
26
27
|
const hostRef = useRef(null);
|
|
27
28
|
const composedHostRef = useComposeRefs([ref, hostRef]);
|
|
28
29
|
/** Feature: Loading */
|
|
@@ -71,19 +72,50 @@ function TableInner(props, ref) {
|
|
|
71
72
|
columns,
|
|
72
73
|
});
|
|
73
74
|
/** Feature: Actions column */
|
|
74
|
-
const
|
|
75
|
-
var _a;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
const columnsWithRightControls = useMemo(() => {
|
|
76
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
77
|
+
const result = [...columns];
|
|
78
|
+
// Add toggleable column (rightControl area - after data columns)
|
|
79
|
+
if (toggleable === null || toggleable === void 0 ? void 0 : toggleable.enabled) {
|
|
80
|
+
const toggleableColumn = {
|
|
81
|
+
align: (_a = toggleable.align) !== null && _a !== void 0 ? _a : 'start',
|
|
82
|
+
ellipsis: false,
|
|
83
|
+
fixed: toggleable.fixed ? 'end' : undefined,
|
|
84
|
+
key: TOGGLEABLE_KEY,
|
|
85
|
+
render: () => null, // Placeholder, actual rendering is handled in TableRow
|
|
86
|
+
title: toggleable.title,
|
|
87
|
+
width: (_b = toggleable.minWidth) !== null && _b !== void 0 ? _b : TOGGLEABLE_COLUMN_WIDTH,
|
|
88
|
+
minWidth: (_c = toggleable.minWidth) !== null && _c !== void 0 ? _c : TOGGLEABLE_COLUMN_WIDTH,
|
|
89
|
+
};
|
|
90
|
+
result.push(toggleableColumn);
|
|
91
|
+
}
|
|
92
|
+
// Add collectable column (rightControl area - after toggleable)
|
|
93
|
+
if (collectable === null || collectable === void 0 ? void 0 : collectable.enabled) {
|
|
94
|
+
const collectableColumn = {
|
|
95
|
+
align: (_d = collectable.align) !== null && _d !== void 0 ? _d : 'start',
|
|
96
|
+
ellipsis: false,
|
|
97
|
+
fixed: collectable.fixed ? 'end' : undefined,
|
|
98
|
+
key: COLLECTABLE_KEY,
|
|
99
|
+
render: () => null, // Placeholder, actual rendering is handled in TableRow
|
|
100
|
+
title: collectable.title,
|
|
101
|
+
width: (_e = collectable === null || collectable === void 0 ? void 0 : collectable.minWidth) !== null && _e !== void 0 ? _e : COLLECTABLE_COLUMN_WIDTH,
|
|
102
|
+
minWidth: (_f = collectable === null || collectable === void 0 ? void 0 : collectable.minWidth) !== null && _f !== void 0 ? _f : COLLECTABLE_COLUMN_WIDTH,
|
|
103
|
+
};
|
|
104
|
+
result.push(collectableColumn);
|
|
105
|
+
}
|
|
106
|
+
// Add actions column (rightmost)
|
|
107
|
+
if (actions) {
|
|
108
|
+
const actionsColumn = {
|
|
109
|
+
...actions,
|
|
110
|
+
align: (_g = actions.align) !== null && _g !== void 0 ? _g : 'end',
|
|
111
|
+
ellipsis: false,
|
|
112
|
+
key: TABLE_ACTIONS_KEY,
|
|
113
|
+
render: () => null, // Placeholder, actual rendering is handled in TableRow
|
|
114
|
+
};
|
|
115
|
+
result.push(actionsColumn);
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}, [actions, collectable, columns, toggleable]);
|
|
87
119
|
/** Feature: Row selection */
|
|
88
120
|
const selectionState = useTableSelection({
|
|
89
121
|
dataSource,
|
|
@@ -92,27 +124,54 @@ function TableInner(props, ref) {
|
|
|
92
124
|
/** Feature: Expansion */
|
|
93
125
|
const expansionState = useTableExpansion({
|
|
94
126
|
expandable,
|
|
95
|
-
|
|
127
|
+
hasDragOrPinHandle: !!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled) || !!(pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled),
|
|
96
128
|
});
|
|
97
129
|
/** Feature: Column resized */
|
|
98
130
|
const columnState = useTableResizedColumns();
|
|
99
131
|
/** Feature: Scroll and dimensions calculation */
|
|
100
|
-
const { containerWidth,
|
|
132
|
+
const { containerWidth, handleScrollbarScroll, handleViewportReady, isContainerReady, isScrollingHorizontally, scrollLeft, containerRef: scrollContainerRef, } = useTableScroll({
|
|
101
133
|
enabled: !nested,
|
|
102
134
|
});
|
|
103
135
|
const virtualScrollEnabled = useMemo(() => !!((scroll === null || scroll === void 0 ? void 0 : scroll.virtualized) && (scroll === null || scroll === void 0 ? void 0 : scroll.y)), [scroll === null || scroll === void 0 ? void 0 : scroll.virtualized, scroll === null || scroll === void 0 ? void 0 : scroll.y]);
|
|
104
136
|
/** Feature: Column fixed */
|
|
105
|
-
const actionConfig = useMemo(() =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
const actionConfig = useMemo(() => {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
return ({
|
|
140
|
+
hasDragOrPinHandle: !!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled) || !!(pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled),
|
|
141
|
+
dragOrPinHandleFixed: !!(draggable === null || draggable === void 0 ? void 0 : draggable.fixed) || !!(pinnable === null || pinnable === void 0 ? void 0 : pinnable.fixed),
|
|
142
|
+
dragOrPinHandleType: (draggable === null || draggable === void 0 ? void 0 : draggable.enabled)
|
|
143
|
+
? 'drag'
|
|
144
|
+
: (pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled)
|
|
145
|
+
? 'pin'
|
|
146
|
+
: undefined,
|
|
147
|
+
hasExpansion: !!expandable,
|
|
148
|
+
expansionFixed: !!(expandable === null || expandable === void 0 ? void 0 : expandable.fixed),
|
|
149
|
+
hasSelection: !!rowSelection,
|
|
150
|
+
selectionFixed: !!(rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.fixed),
|
|
151
|
+
hasToggleable: !!(toggleable === null || toggleable === void 0 ? void 0 : toggleable.enabled),
|
|
152
|
+
toggleableMinWidth: (_a = toggleable === null || toggleable === void 0 ? void 0 : toggleable.minWidth) !== null && _a !== void 0 ? _a : TOGGLEABLE_COLUMN_WIDTH,
|
|
153
|
+
toggleableFixed: !!(toggleable === null || toggleable === void 0 ? void 0 : toggleable.fixed),
|
|
154
|
+
hasCollectable: !!(collectable === null || collectable === void 0 ? void 0 : collectable.enabled),
|
|
155
|
+
collectableMinWidth: (_b = collectable === null || collectable === void 0 ? void 0 : collectable.minWidth) !== null && _b !== void 0 ? _b : COLLECTABLE_COLUMN_WIDTH,
|
|
156
|
+
collectableFixed: !!(collectable === null || collectable === void 0 ? void 0 : collectable.fixed),
|
|
157
|
+
});
|
|
158
|
+
}, [
|
|
159
|
+
collectable === null || collectable === void 0 ? void 0 : collectable.enabled,
|
|
160
|
+
collectable === null || collectable === void 0 ? void 0 : collectable.minWidth,
|
|
161
|
+
collectable === null || collectable === void 0 ? void 0 : collectable.fixed,
|
|
162
|
+
draggable === null || draggable === void 0 ? void 0 : draggable.enabled,
|
|
163
|
+
draggable === null || draggable === void 0 ? void 0 : draggable.fixed,
|
|
164
|
+
pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled,
|
|
165
|
+
pinnable === null || pinnable === void 0 ? void 0 : pinnable.fixed,
|
|
166
|
+
expandable,
|
|
167
|
+
rowSelection,
|
|
168
|
+
toggleable === null || toggleable === void 0 ? void 0 : toggleable.enabled,
|
|
169
|
+
toggleable === null || toggleable === void 0 ? void 0 : toggleable.minWidth,
|
|
170
|
+
toggleable === null || toggleable === void 0 ? void 0 : toggleable.fixed,
|
|
171
|
+
]);
|
|
113
172
|
const fixedOffsetsState = useTableFixedOffsets({
|
|
114
173
|
actionConfig,
|
|
115
|
-
columns:
|
|
174
|
+
columns: columnsWithRightControls,
|
|
116
175
|
getResizedColumnWidth: columnState.getResizedColumnWidth,
|
|
117
176
|
});
|
|
118
177
|
/** Feature: Drag n Drop */
|
|
@@ -139,60 +198,96 @@ function TableInner(props, ref) {
|
|
|
139
198
|
fixed: draggable.fixed,
|
|
140
199
|
}
|
|
141
200
|
: undefined, [draggable]);
|
|
201
|
+
const pinnableState = useMemo(() => pinnable
|
|
202
|
+
? {
|
|
203
|
+
enabled: pinnable.enabled,
|
|
204
|
+
fixed: pinnable.fixed,
|
|
205
|
+
pinnedRowKeys: pinnable.pinnedRowKeys,
|
|
206
|
+
onPinChange: pinnable.onPinChange,
|
|
207
|
+
}
|
|
208
|
+
: undefined, [pinnable]);
|
|
209
|
+
const toggleableState = useMemo(() => toggleable
|
|
210
|
+
? {
|
|
211
|
+
enabled: toggleable.enabled,
|
|
212
|
+
fixed: toggleable.fixed,
|
|
213
|
+
isRowDisabled: toggleable.isRowDisabled,
|
|
214
|
+
onToggleChange: toggleable.onToggleChange,
|
|
215
|
+
title: toggleable.title,
|
|
216
|
+
toggledRowKeys: toggleable.toggledRowKeys,
|
|
217
|
+
}
|
|
218
|
+
: undefined, [toggleable]);
|
|
219
|
+
const collectableState = useMemo(() => collectable
|
|
220
|
+
? {
|
|
221
|
+
enabled: collectable.enabled,
|
|
222
|
+
collectedRowKeys: collectable.collectedRowKeys,
|
|
223
|
+
fixed: collectable.fixed,
|
|
224
|
+
isRowDisabled: collectable.isRowDisabled,
|
|
225
|
+
onCollectChange: collectable.onCollectChange,
|
|
226
|
+
title: collectable.title,
|
|
227
|
+
}
|
|
228
|
+
: undefined, [collectable]);
|
|
142
229
|
/** Context values */
|
|
143
230
|
const contextValue = useMemo(() => ({
|
|
144
231
|
actions: actions,
|
|
232
|
+
collectable: collectableState,
|
|
145
233
|
columnState,
|
|
146
234
|
dataSource: dataSourceForRender,
|
|
147
235
|
draggable: draggableState,
|
|
148
236
|
emptyProps,
|
|
149
237
|
expansion: expansionState,
|
|
150
238
|
fixedOffsets: fixedOffsetsState,
|
|
151
|
-
resizable,
|
|
152
|
-
rowHeight,
|
|
153
239
|
highlight: highlightValue,
|
|
154
|
-
|
|
240
|
+
isContainerReady,
|
|
155
241
|
isInsideExpandedContentArea: nested,
|
|
242
|
+
isScrollingHorizontally: isScrollingHorizontally,
|
|
156
243
|
loading,
|
|
157
244
|
pagination: pagination || undefined,
|
|
245
|
+
pinnable: pinnableState,
|
|
246
|
+
resizable,
|
|
247
|
+
rowHeight,
|
|
158
248
|
scroll,
|
|
159
249
|
scrollContainerRef,
|
|
160
250
|
selection: selectionState,
|
|
161
|
-
size,
|
|
162
251
|
separatorAtRowIndexes,
|
|
252
|
+
size,
|
|
163
253
|
sorting: sortingState,
|
|
254
|
+
toggleable: toggleableState,
|
|
164
255
|
transitionState,
|
|
165
256
|
virtualScrollEnabled,
|
|
166
257
|
zebraStriping,
|
|
167
258
|
}), [
|
|
168
259
|
actions,
|
|
260
|
+
collectableState,
|
|
169
261
|
columnState,
|
|
170
262
|
dataSourceForRender,
|
|
171
263
|
draggableState,
|
|
172
264
|
emptyProps,
|
|
173
265
|
expansionState,
|
|
174
266
|
fixedOffsetsState,
|
|
175
|
-
resizable,
|
|
176
|
-
rowHeight,
|
|
177
267
|
highlightValue,
|
|
268
|
+
isContainerReady,
|
|
269
|
+
isScrollingHorizontally,
|
|
178
270
|
loading,
|
|
271
|
+
nested,
|
|
179
272
|
pagination,
|
|
273
|
+
pinnableState,
|
|
274
|
+
resizable,
|
|
275
|
+
rowHeight,
|
|
180
276
|
scroll,
|
|
181
277
|
scrollContainerRef,
|
|
182
|
-
isScrollingHorizontally,
|
|
183
278
|
selectionState,
|
|
279
|
+
separatorAtRowIndexes,
|
|
184
280
|
size,
|
|
185
281
|
sortingState,
|
|
282
|
+
toggleableState,
|
|
186
283
|
transitionState,
|
|
187
284
|
virtualScrollEnabled,
|
|
188
285
|
zebraStriping,
|
|
189
|
-
separatorAtRowIndexes,
|
|
190
|
-
nested,
|
|
191
286
|
]);
|
|
192
287
|
const dataContextValue = useMemo(() => ({
|
|
193
|
-
columns:
|
|
288
|
+
columns: columnsWithRightControls,
|
|
194
289
|
dataSource,
|
|
195
|
-
}), [
|
|
290
|
+
}), [columnsWithRightControls, dataSource]);
|
|
196
291
|
const superContextValue = useMemo(() => {
|
|
197
292
|
var _a;
|
|
198
293
|
return ({
|
|
@@ -200,7 +295,8 @@ function TableInner(props, ref) {
|
|
|
200
295
|
getResizedColumnWidth: columnState.getResizedColumnWidth,
|
|
201
296
|
scrollLeft: scrollLeft,
|
|
202
297
|
expansionLeftPadding: (_a = expansionState === null || expansionState === void 0 ? void 0 : expansionState.expansionLeftPadding) !== null && _a !== void 0 ? _a : 0,
|
|
203
|
-
|
|
298
|
+
hasDragOrPinHandleFixed: (!!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled) && draggable.fixed) ||
|
|
299
|
+
(!!(pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled) && pinnable.fixed),
|
|
204
300
|
});
|
|
205
301
|
}, [
|
|
206
302
|
scrollLeft,
|
|
@@ -209,22 +305,17 @@ function TableInner(props, ref) {
|
|
|
209
305
|
columnState.getResizedColumnWidth,
|
|
210
306
|
draggable === null || draggable === void 0 ? void 0 : draggable.enabled,
|
|
211
307
|
draggable === null || draggable === void 0 ? void 0 : draggable.fixed,
|
|
308
|
+
pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled,
|
|
309
|
+
pinnable === null || pinnable === void 0 ? void 0 : pinnable.fixed,
|
|
212
310
|
]);
|
|
213
311
|
/** Computed styles */
|
|
214
312
|
const scrollContainerStyle = useMemo(() => {
|
|
215
313
|
const containerStyle = {};
|
|
216
|
-
if (scroll === null || scroll === void 0 ? void 0 : scroll.y) {
|
|
217
|
-
containerStyle.maxHeight = scroll.y;
|
|
218
|
-
}
|
|
219
|
-
if (nested) {
|
|
220
|
-
containerStyle.position = 'unset';
|
|
221
|
-
containerStyle.overflow = 'unset';
|
|
222
|
-
}
|
|
223
314
|
if (minHeight) {
|
|
224
315
|
containerStyle.minHeight = minHeight;
|
|
225
316
|
}
|
|
226
317
|
return containerStyle;
|
|
227
|
-
}, [
|
|
318
|
+
}, [minHeight]);
|
|
228
319
|
const tableStyle = useMemo(() => {
|
|
229
320
|
const baseStyle = {};
|
|
230
321
|
if (fullWidth) {
|
|
@@ -234,12 +325,18 @@ function TableInner(props, ref) {
|
|
|
234
325
|
}, [fullWidth]);
|
|
235
326
|
/** Scroll Container Ref */
|
|
236
327
|
const droppableInnerRefSetter = useRef(null);
|
|
237
|
-
|
|
238
|
-
|
|
328
|
+
// Handler for Scrollbar's onViewportReady - composes with handleViewportReady and droppable innerRef
|
|
329
|
+
const handleScrollbarViewportReady = useCallback((viewport, instance) => {
|
|
330
|
+
handleViewportReady(viewport, instance);
|
|
331
|
+
// Also set droppable innerRef to viewport element for DnD
|
|
239
332
|
if (droppableInnerRefSetter.current) {
|
|
240
|
-
droppableInnerRefSetter.current(
|
|
333
|
+
droppableInnerRefSetter.current(viewport);
|
|
241
334
|
}
|
|
242
|
-
}, [
|
|
335
|
+
}, [handleViewportReady]);
|
|
336
|
+
// Scrollbar events for OverlayScrollbars
|
|
337
|
+
const scrollbarEvents = useMemo(() => ({
|
|
338
|
+
scroll: handleScrollbarScroll,
|
|
339
|
+
}), [handleScrollbarScroll]);
|
|
243
340
|
/** Feature: bulk actions */
|
|
244
341
|
const bulkActionsConfig = useMemo(() => {
|
|
245
342
|
if (!selectionState || selectionState.mode !== 'checkbox') {
|
|
@@ -314,9 +411,7 @@ function TableInner(props, ref) {
|
|
|
314
411
|
else {
|
|
315
412
|
droppableInnerRefSetter.current = null;
|
|
316
413
|
}
|
|
317
|
-
return (jsx(TableContext.Provider, { value: contextValue, children: jsx(TableDataContext.Provider, { value: dataContextValue, children: jsxs("div", { className: cx(tableClasses.host, className), ref: composedHostRef, style: style, ...restProps, children: [jsx(
|
|
318
|
-
[tableClasses.sticky]: !!sticky,
|
|
319
|
-
}), onScroll: handleScroll, ref: droppableProvided ? composedScrollContainerRef : setContainerRef, style: scrollContainerStyle, children: jsxs("table", { className: cx(tableClasses.root, size === 'sub' ? tableClasses.sub : tableClasses.main), style: tableStyle, children: [jsx(TableColGroup, {}), showHeader && jsx(TableHeader, {}), jsx(TableBody, {}), (droppableProvided === null || droppableProvided === void 0 ? void 0 : droppableProvided.placeholder) ? (jsx("tbody", { children: droppableProvided.placeholder })) : null] }) }), pagination && (jsx(TablePagination, { ...pagination, ref: paginationRef })), (bulkActionsConfig === null || bulkActionsConfig === void 0 ? void 0 : bulkActionsConfig.enabled) ? (jsx(TableBulkActions, { bulkActions: bulkActionsConfig.bulkActions, isFixed: isBulkActionsFixed, onClearSelection: bulkActionsConfig.onClearSelection, selectedRowKeys: bulkActionsConfig.selectedRowKeys })) : null] }) }) }));
|
|
414
|
+
return (jsx(TableContext.Provider, { value: contextValue, children: jsx(TableDataContext.Provider, { value: dataContextValue, children: jsxs("div", { className: cx(tableClasses.host, className), ref: composedHostRef, style: style, ...restProps, children: [jsx(Scrollbar, { ...droppableProvided === null || droppableProvided === void 0 ? void 0 : droppableProvided.droppableProps, className: sticky ? tableClasses.sticky : undefined, defer: false, disabled: nested, events: scrollbarEvents, onViewportReady: handleScrollbarViewportReady, style: scrollContainerStyle, maxHeight: scroll === null || scroll === void 0 ? void 0 : scroll.y, children: jsxs("table", { className: cx(tableClasses.root, size === 'sub' ? tableClasses.sub : tableClasses.main), style: tableStyle, children: [jsx(TableColGroup, {}), showHeader && jsx(TableHeader, {}), jsx(TableBody, {}), (droppableProvided === null || droppableProvided === void 0 ? void 0 : droppableProvided.placeholder) ? (jsx("tbody", { children: droppableProvided.placeholder })) : null] }) }), pagination && (jsx(TablePagination, { ...pagination, ref: paginationRef })), (bulkActionsConfig === null || bulkActionsConfig === void 0 ? void 0 : bulkActionsConfig.enabled) ? (jsx(TableBulkActions, { bulkActions: bulkActionsConfig.bulkActions, isFixed: isBulkActionsFixed, onClearSelection: bulkActionsConfig.onClearSelection, selectedRowKeys: bulkActionsConfig.selectedRowKeys })) : null] }) }) }));
|
|
320
415
|
};
|
|
321
416
|
if (nested) {
|
|
322
417
|
return renderMainTable();
|
package/Table/TableContext.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HighlightMode, TableSize, TableActionsBase, TableColumn, TableDataSource, TableExpandable, TableRowSelection, TableScroll, TableSelectionMode } from '@mezzanine-ui/core/table';
|
|
1
|
+
import type { HighlightMode, TableSize, TableActionsBase, TableColumn, TableDataSource, TableExpandable, TableRowSelection, TableScroll, TableSelectionMode, TableCollectable, TableToggleable, TablePinnable, TableDraggable } from '@mezzanine-ui/core/table';
|
|
2
2
|
import type { EmptyProps } from '../Empty';
|
|
3
3
|
import type { PaginationProps } from '../Pagination';
|
|
4
4
|
import type { UseTableFixedOffsetsReturn } from './hooks/useTableFixedOffsets';
|
|
@@ -32,11 +32,6 @@ export interface TableResizedColumnState {
|
|
|
32
32
|
getResizedColumnWidth: (key: string) => number | undefined;
|
|
33
33
|
setResizedColumnWidth: (key: string, width: number) => void;
|
|
34
34
|
}
|
|
35
|
-
/** Draggable state */
|
|
36
|
-
export interface TableDraggableState {
|
|
37
|
-
enabled: boolean;
|
|
38
|
-
fixed?: boolean | 'start';
|
|
39
|
-
}
|
|
40
35
|
/** Highlight state for hover effects */
|
|
41
36
|
export interface TableHighlightState {
|
|
42
37
|
columnIndex: number | null;
|
|
@@ -47,30 +42,34 @@ export interface TableHighlightState {
|
|
|
47
42
|
/** Main table context */
|
|
48
43
|
export interface TableContextValue<T extends TableDataSource = TableDataSource> {
|
|
49
44
|
actions?: TableActionsBase<T>;
|
|
45
|
+
collectable?: TableCollectable<T>;
|
|
50
46
|
columnState?: TableResizedColumnState;
|
|
51
47
|
dataSource: T[];
|
|
52
|
-
draggable?:
|
|
48
|
+
draggable?: Omit<TableDraggable<T>, 'onDragEnd'>;
|
|
53
49
|
emptyProps?: EmptyProps & {
|
|
54
50
|
height?: number | string;
|
|
55
51
|
};
|
|
56
52
|
expansion?: TableExpansionState<T>;
|
|
57
53
|
fixedOffsets?: UseTableFixedOffsetsReturn;
|
|
58
|
-
resizable?: boolean;
|
|
59
|
-
rowHeight: number;
|
|
60
54
|
highlight?: TableHighlightState;
|
|
55
|
+
isContainerReady?: boolean;
|
|
56
|
+
isInsideExpandedContentArea?: boolean;
|
|
61
57
|
isScrollingHorizontally?: boolean;
|
|
62
58
|
loading?: boolean;
|
|
63
59
|
pagination?: PaginationProps;
|
|
64
|
-
|
|
60
|
+
pinnable?: TablePinnable;
|
|
61
|
+
resizable?: boolean;
|
|
62
|
+
rowHeight: number;
|
|
65
63
|
scroll?: TableScroll;
|
|
66
64
|
scrollContainerRef?: React.RefObject<HTMLDivElement | null>;
|
|
67
65
|
selection?: TableSelectionState<T>;
|
|
68
66
|
separatorAtRowIndexes?: number[];
|
|
67
|
+
size?: TableSize;
|
|
69
68
|
sorting?: TableSortingState;
|
|
69
|
+
toggleable?: TableToggleable<T>;
|
|
70
70
|
transitionState?: TableTransitionState;
|
|
71
71
|
virtualScrollEnabled?: boolean;
|
|
72
72
|
zebraStriping?: boolean;
|
|
73
|
-
isInsideExpandedContentArea?: boolean;
|
|
74
73
|
}
|
|
75
74
|
export declare const TableContext: import("react").Context<TableContextValue<TableDataSource> | null>;
|
|
76
75
|
export declare function useTableContext<T extends TableDataSource = TableDataSource>(): TableContextValue<T>;
|
|
@@ -86,7 +85,7 @@ export interface TableSuperContextValue {
|
|
|
86
85
|
getResizedColumnWidth?: (key: string) => number | undefined;
|
|
87
86
|
scrollLeft?: number;
|
|
88
87
|
expansionLeftPadding?: number;
|
|
89
|
-
|
|
88
|
+
hasDragOrPinHandleFixed?: boolean;
|
|
90
89
|
}
|
|
91
90
|
export declare const TableSuperContext: import("react").Context<TableSuperContextValue | null>;
|
|
92
91
|
export declare function useTableSuperContext(): TableSuperContextValue;
|
|
@@ -4,7 +4,8 @@ import { memo, forwardRef, useMemo } from 'react';
|
|
|
4
4
|
import { getCellAlignClass, tableClasses } from '@mezzanine-ui/core/table';
|
|
5
5
|
import { useTableContext } from '../TableContext.js';
|
|
6
6
|
import Button from '../../Button/Button.js';
|
|
7
|
-
import
|
|
7
|
+
import { DotHorizontalIcon } from '@mezzanine-ui/icons';
|
|
8
|
+
import Dropdown from '../../Dropdown/Dropdown.js';
|
|
8
9
|
import cx from 'clsx';
|
|
9
10
|
|
|
10
11
|
const TableActionsCellInner = forwardRef(function TableActionsCell(props, ref) {
|
|
@@ -67,10 +68,17 @@ const TableActionsCellInner = forwardRef(function TableActionsCell(props, ref) {
|
|
|
67
68
|
[tableClasses.cellFixedShadow]: showShadow,
|
|
68
69
|
[tableClasses.cellFixedStart]: fixed === 'start',
|
|
69
70
|
[tableClasses.cellHighlight]: isCellHighlighted,
|
|
70
|
-
}, className), onMouseEnter: handleMouseEnter, ref: ref, style: cellStyle, children: jsx("div", { className: cx(tableClasses.cellContent, alignClass), children: jsx(
|
|
71
|
-
var _a, _b, _c;
|
|
71
|
+
}, className), onMouseEnter: handleMouseEnter, ref: ref, style: cellStyle, children: jsx("div", { className: cx(tableClasses.cellContent, alignClass), children: jsx("div", { className: tableClasses.actionsCell, children: actionItems.map((item, actionIndex) => {
|
|
72
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
72
73
|
const isDisabled = (_b = (_a = item.disabled) === null || _a === void 0 ? void 0 : _a.call(item, record)) !== null && _b !== void 0 ? _b : false;
|
|
73
|
-
|
|
74
|
+
const baseKey = `${item.name || 'name'}-${((_c = item.icon) === null || _c === void 0 ? void 0 : _c.name) || 'icon'}-${rowIndex}-${actionIndex}`;
|
|
75
|
+
if (item.type === 'dropdown') {
|
|
76
|
+
const dropdownItem = item;
|
|
77
|
+
return (jsx(Dropdown, { type: "default", maxHeight: dropdownItem.maxHeight, onSelect: (option) => dropdownItem.onSelect(option, record, rowIndex), options: dropdownItem.options, placement: (_d = dropdownItem.placement) !== null && _d !== void 0 ? _d : 'bottom-end', children: jsx(Button, { iconType: "icon-only", icon: (_e = dropdownItem === null || dropdownItem === void 0 ? void 0 : dropdownItem.icon) !== null && _e !== void 0 ? _e : DotHorizontalIcon, size: "sub", type: "button", variant: (_f = dropdownItem.variant) !== null && _f !== void 0 ? _f : 'base-text-link', children: dropdownItem.name }) }, baseKey));
|
|
78
|
+
}
|
|
79
|
+
// Default to button type
|
|
80
|
+
const buttonItem = item;
|
|
81
|
+
return (jsx(Button, { disabled: isDisabled, icon: buttonItem.icon, iconType: buttonItem.iconType, onClick: () => buttonItem.onClick(record, rowIndex), size: "sub", type: "button", variant: (_g = buttonItem.variant) !== null && _g !== void 0 ? _g : actions.variant, children: buttonItem.name }, baseKey));
|
|
74
82
|
}) }) }) }));
|
|
75
83
|
});
|
|
76
84
|
const TableActionsCell = memo(TableActionsCellInner);
|
|
@@ -13,7 +13,7 @@ import Fade from '../../Transition/Fade.js';
|
|
|
13
13
|
import cx from 'clsx';
|
|
14
14
|
|
|
15
15
|
const TableBodyInner = forwardRef(function TableBody(_, ref) {
|
|
16
|
-
const { dataSource, draggable, emptyProps, expansion, loading, scrollContainerRef, selection, size, virtualScrollEnabled, } = useTableContext();
|
|
16
|
+
const { dataSource, draggable, emptyProps, expansion, isContainerReady, loading, scrollContainerRef, selection, size, virtualScrollEnabled, } = useTableContext();
|
|
17
17
|
const { columns } = useTableDataContext();
|
|
18
18
|
/** Feature: Empty State */
|
|
19
19
|
const isEmpty = useMemo(() => !dataSource.length, [dataSource.length]);
|
|
@@ -21,6 +21,7 @@ const TableBodyInner = forwardRef(function TableBody(_, ref) {
|
|
|
21
21
|
const virtualization = useTableVirtualization({
|
|
22
22
|
dataSource,
|
|
23
23
|
enabled: virtualScrollEnabled,
|
|
24
|
+
isContainerReady,
|
|
24
25
|
isRowExpanded: expansion === null || expansion === void 0 ? void 0 : expansion.isRowExpanded,
|
|
25
26
|
scrollContainerRef: scrollContainerRef,
|
|
26
27
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { DRAG_OR_PIN_HANDLE_COLUMN_WIDTH, SELECTION_COLUMN_WIDTH, EXPANSION_COLUMN_WIDTH, DRAG_OR_PIN_HANDLE_KEY, EXPANSION_KEY, SELECTION_KEY } from '@mezzanine-ui/core/table';
|
|
5
5
|
import { useTableContext, useTableDataContext, useTableSuperContext } from '../TableContext.js';
|
|
6
6
|
import { calculateColumnWidths, shouldCalculateWidths } from '../utils/calculateColumnWidths.js';
|
|
7
7
|
|
|
8
|
-
const TableColGroupInner = memo(function TableColGroup(
|
|
9
|
-
const {
|
|
10
|
-
const { columnState, draggable, expansion, isInsideExpandedContentArea, selection, } = useTableContext();
|
|
8
|
+
const TableColGroupInner = memo(function TableColGroup() {
|
|
9
|
+
const { columnState, draggable, expansion, isInsideExpandedContentArea, pinnable, selection, } = useTableContext();
|
|
11
10
|
const { columns } = useTableDataContext();
|
|
12
11
|
const { containerWidth, getResizedColumnWidth: getParentResizedColumnWidth } = useTableSuperContext();
|
|
13
12
|
// For nested tables, use parent's resized widths; for root tables, use own
|
|
@@ -19,14 +18,14 @@ const TableColGroupInner = memo(function TableColGroup(props) {
|
|
|
19
18
|
// Calculate action columns total width
|
|
20
19
|
const actionColumnsWidth = useMemo(() => {
|
|
21
20
|
let width = 0;
|
|
22
|
-
if (draggable === null || draggable === void 0 ? void 0 : draggable.enabled)
|
|
23
|
-
width +=
|
|
21
|
+
if ((draggable === null || draggable === void 0 ? void 0 : draggable.enabled) || (pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled))
|
|
22
|
+
width += DRAG_OR_PIN_HANDLE_COLUMN_WIDTH;
|
|
24
23
|
if (selection)
|
|
25
24
|
width += SELECTION_COLUMN_WIDTH;
|
|
26
25
|
if (expansion)
|
|
27
26
|
width += EXPANSION_COLUMN_WIDTH;
|
|
28
27
|
return width;
|
|
29
|
-
}, [draggable === null || draggable === void 0 ? void 0 : draggable.enabled, expansion, selection]);
|
|
28
|
+
}, [draggable === null || draggable === void 0 ? void 0 : draggable.enabled, expansion, pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled, selection]);
|
|
30
29
|
// Calculate resolved widths for all columns (only for root tables)
|
|
31
30
|
const resolvedWidths = useMemo(() => {
|
|
32
31
|
if (!enableWidthCalculation) {
|
|
@@ -47,22 +46,22 @@ const TableColGroupInner = memo(function TableColGroup(props) {
|
|
|
47
46
|
]);
|
|
48
47
|
const renderCols = () => {
|
|
49
48
|
const cols = [];
|
|
50
|
-
if (draggable === null || draggable === void 0 ? void 0 : draggable.enabled) {
|
|
51
|
-
cols.push(jsx("col", {
|
|
52
|
-
maxWidth:
|
|
53
|
-
minWidth:
|
|
54
|
-
width:
|
|
55
|
-
} },
|
|
49
|
+
if ((draggable === null || draggable === void 0 ? void 0 : draggable.enabled) || (pinnable === null || pinnable === void 0 ? void 0 : pinnable.enabled)) {
|
|
50
|
+
cols.push(jsx("col", { style: {
|
|
51
|
+
maxWidth: DRAG_OR_PIN_HANDLE_COLUMN_WIDTH,
|
|
52
|
+
minWidth: DRAG_OR_PIN_HANDLE_COLUMN_WIDTH,
|
|
53
|
+
width: DRAG_OR_PIN_HANDLE_COLUMN_WIDTH,
|
|
54
|
+
} }, DRAG_OR_PIN_HANDLE_KEY));
|
|
56
55
|
}
|
|
57
56
|
if (expansion) {
|
|
58
|
-
cols.push(jsx("col", {
|
|
57
|
+
cols.push(jsx("col", { style: {
|
|
59
58
|
maxWidth: EXPANSION_COLUMN_WIDTH,
|
|
60
59
|
minWidth: EXPANSION_COLUMN_WIDTH,
|
|
61
60
|
width: EXPANSION_COLUMN_WIDTH,
|
|
62
61
|
} }, EXPANSION_KEY));
|
|
63
62
|
}
|
|
64
63
|
if (selection) {
|
|
65
|
-
cols.push(jsx("col", {
|
|
64
|
+
cols.push(jsx("col", { style: {
|
|
66
65
|
maxWidth: SELECTION_COLUMN_WIDTH,
|
|
67
66
|
minWidth: SELECTION_COLUMN_WIDTH,
|
|
68
67
|
width: SELECTION_COLUMN_WIDTH,
|
|
@@ -97,7 +96,7 @@ const TableColGroupInner = memo(function TableColGroup(props) {
|
|
|
97
96
|
});
|
|
98
97
|
return cols;
|
|
99
98
|
};
|
|
100
|
-
return jsx("colgroup", {
|
|
99
|
+
return jsx("colgroup", { children: renderCols() });
|
|
101
100
|
});
|
|
102
101
|
const TableColGroup = TableColGroupInner;
|
|
103
102
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type TableDataSource } from '@mezzanine-ui/core/table';
|
|
2
|
+
export interface TableCollectableCellProps<T extends TableDataSource = TableDataSource> {
|
|
3
|
+
className?: string;
|
|
4
|
+
fixed?: boolean;
|
|
5
|
+
fixedOffset?: number;
|
|
6
|
+
isHeader?: boolean;
|
|
7
|
+
/** Row record - required when isHeader is false */
|
|
8
|
+
record?: T;
|
|
9
|
+
showShadow?: boolean;
|
|
10
|
+
/** Explicit width for dragging state */
|
|
11
|
+
width?: number;
|
|
12
|
+
}
|
|
13
|
+
declare const ForwardedTableCollectableCell: <T extends TableDataSource = TableDataSource>(props: TableCollectableCellProps<T> & {
|
|
14
|
+
ref?: React.ForwardedRef<HTMLTableCellElement>;
|
|
15
|
+
}) => React.ReactElement;
|
|
16
|
+
export declare const TableCollectableCell: typeof ForwardedTableCollectableCell;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { memo, forwardRef, useCallback } from 'react';
|
|
4
|
+
import { getRowKey, tableClasses } from '@mezzanine-ui/core/table';
|
|
5
|
+
import { StarFilledIcon, StarOutlineIcon } from '@mezzanine-ui/icons';
|
|
6
|
+
import { useTableContext } from '../TableContext.js';
|
|
7
|
+
import Skeleton from '../../Skeleton/Skeleton.js';
|
|
8
|
+
import Icon from '../../Icon/Icon.js';
|
|
9
|
+
import cx from 'clsx';
|
|
10
|
+
|
|
11
|
+
function TableCollectableCellInner(props, ref) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const { collectable, loading } = useTableContext();
|
|
14
|
+
const { className, fixed = false, fixedOffset = 0, record, showShadow = false, width, } = props;
|
|
15
|
+
const cellStyle = {};
|
|
16
|
+
// Apply explicit width for dragging state
|
|
17
|
+
if (width !== undefined) {
|
|
18
|
+
cellStyle.width = width;
|
|
19
|
+
cellStyle.minWidth = width;
|
|
20
|
+
cellStyle.maxWidth = width;
|
|
21
|
+
cellStyle.flexShrink = 0;
|
|
22
|
+
}
|
|
23
|
+
if (fixed) {
|
|
24
|
+
cellStyle['--fixed-end-offset'] =
|
|
25
|
+
`${fixedOffset}px`;
|
|
26
|
+
}
|
|
27
|
+
const rowKey = record ? getRowKey(record) : '';
|
|
28
|
+
const isCollected = (_a = collectable === null || collectable === void 0 ? void 0 : collectable.collectedRowKeys.includes(rowKey)) !== null && _a !== void 0 ? _a : false;
|
|
29
|
+
const isDisabled = record
|
|
30
|
+
? ((_c = (_b = collectable === null || collectable === void 0 ? void 0 : collectable.isRowDisabled) === null || _b === void 0 ? void 0 : _b.call(collectable, record)) !== null && _c !== void 0 ? _c : false)
|
|
31
|
+
: false;
|
|
32
|
+
const handleCollectClick = useCallback(() => {
|
|
33
|
+
if (!collectable || !record || isDisabled)
|
|
34
|
+
return;
|
|
35
|
+
collectable.onCollectChange(record, !isCollected);
|
|
36
|
+
}, [collectable, isCollected, isDisabled, record]);
|
|
37
|
+
const renderChild = () => {
|
|
38
|
+
if (loading) {
|
|
39
|
+
return jsx(Skeleton, { variant: "body-highlight", width: "100%" });
|
|
40
|
+
}
|
|
41
|
+
return (jsx("button", { "aria-disabled": isDisabled, "aria-label": isCollected ? 'Remove from collection' : 'Add to collection', "aria-pressed": isCollected, className: cx(tableClasses.collectHandleIcon, {
|
|
42
|
+
[`${tableClasses.collectHandleIcon}--disabled`]: isDisabled,
|
|
43
|
+
}), disabled: isDisabled, onClick: handleCollectClick, type: "button", children: jsx(Icon, { color: isCollected ? 'brand' : 'neutral', icon: isCollected ? StarFilledIcon : StarOutlineIcon }) }));
|
|
44
|
+
};
|
|
45
|
+
return (jsx("td", { className: cx(tableClasses.cell, {
|
|
46
|
+
[tableClasses.cellFixed]: fixed,
|
|
47
|
+
[tableClasses.cellFixedEnd]: fixed,
|
|
48
|
+
[tableClasses.cellFixedShadow]: showShadow,
|
|
49
|
+
}, className), ref: ref, style: cellStyle, children: renderChild() }));
|
|
50
|
+
}
|
|
51
|
+
const ForwardedTableCollectableCell = forwardRef(TableCollectableCellInner);
|
|
52
|
+
const TableCollectableCell = memo(ForwardedTableCollectableCell);
|
|
53
|
+
|
|
54
|
+
export { TableCollectableCell };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type TableDataSource } from '@mezzanine-ui/core/table';
|
|
2
|
+
export interface TableDragOrPinHandleCellProps<T extends TableDataSource = TableDataSource> {
|
|
3
|
+
className?: string;
|
|
4
|
+
dragHandleProps?: Record<string, unknown>;
|
|
5
|
+
fixed?: boolean;
|
|
6
|
+
fixedOffset?: number;
|
|
7
|
+
isHeader?: boolean;
|
|
8
|
+
/** The mode of this cell: 'drag' for drag handle, 'pin' for pin handle */
|
|
9
|
+
mode: 'drag' | 'pin';
|
|
10
|
+
/** Row record - required when mode is 'pin' and isHeader is false */
|
|
11
|
+
record?: T;
|
|
12
|
+
showShadow?: boolean;
|
|
13
|
+
/** Explicit width for dragging state */
|
|
14
|
+
width?: number;
|
|
15
|
+
}
|
|
16
|
+
declare const ForwardedTableDragOrPinHandleCell: <T extends TableDataSource = TableDataSource>(props: TableDragOrPinHandleCellProps<T> & {
|
|
17
|
+
ref?: React.ForwardedRef<HTMLTableCellElement>;
|
|
18
|
+
}) => React.ReactElement;
|
|
19
|
+
export declare const TableDragOrPinHandleCell: typeof ForwardedTableDragOrPinHandleCell;
|
|
20
|
+
export {};
|