@itwin/itwinui-react 3.15.3 → 3.15.5
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/CHANGELOG.md +17 -0
- package/DEV-cjs/core/Breadcrumbs/Breadcrumbs.js +85 -65
- package/DEV-cjs/core/ButtonGroup/ButtonGroup.js +32 -27
- package/DEV-cjs/core/ComboBox/ComboBox.js +9 -6
- package/DEV-cjs/core/DatePicker/DatePicker.js +14 -4
- package/DEV-cjs/core/Popover/Popover.js +44 -16
- package/DEV-cjs/core/Select/SelectTagContainer.js +27 -13
- package/DEV-cjs/core/Table/ColumnHeader.js +21 -28
- package/DEV-cjs/core/Table/Table.js +78 -53
- package/DEV-cjs/core/Table/TablePaginator.js +111 -88
- package/DEV-cjs/core/Table/cells/DefaultCell.js +3 -3
- package/DEV-cjs/core/Table/utils.js +3 -3
- package/DEV-cjs/styles.js +1 -1
- package/DEV-cjs/utils/components/MiddleTextTruncation.js +19 -14
- package/DEV-cjs/utils/components/OverflowContainer.js +63 -0
- package/DEV-cjs/utils/components/index.js +1 -0
- package/DEV-cjs/utils/hooks/useOverflow.js +12 -8
- package/DEV-esm/core/Breadcrumbs/Breadcrumbs.js +86 -67
- package/DEV-esm/core/ButtonGroup/ButtonGroup.js +33 -28
- package/DEV-esm/core/ComboBox/ComboBox.js +9 -6
- package/DEV-esm/core/DatePicker/DatePicker.js +12 -4
- package/DEV-esm/core/Popover/Popover.js +45 -17
- package/DEV-esm/core/Select/SelectTagContainer.js +24 -13
- package/DEV-esm/core/Table/ColumnHeader.js +28 -29
- package/DEV-esm/core/Table/Table.js +79 -54
- package/DEV-esm/core/Table/TablePaginator.js +112 -89
- package/DEV-esm/core/Table/cells/DefaultCell.js +4 -4
- package/DEV-esm/core/Table/utils.js +1 -1
- package/DEV-esm/styles.js +1 -1
- package/DEV-esm/utils/components/MiddleTextTruncation.js +19 -14
- package/DEV-esm/utils/components/OverflowContainer.js +50 -0
- package/DEV-esm/utils/components/index.js +1 -0
- package/DEV-esm/utils/hooks/useOverflow.js +8 -8
- package/cjs/core/Breadcrumbs/Breadcrumbs.js +84 -64
- package/cjs/core/ButtonGroup/ButtonGroup.js +32 -27
- package/cjs/core/ComboBox/ComboBox.js +9 -6
- package/cjs/core/DatePicker/DatePicker.js +14 -4
- package/cjs/core/NonIdealState/NonIdealState.d.ts +15 -11
- package/cjs/core/Popover/Popover.d.ts +10 -0
- package/cjs/core/Popover/Popover.js +44 -16
- package/cjs/core/Select/SelectTagContainer.js +27 -13
- package/cjs/core/Table/ColumnHeader.d.ts +8 -12
- package/cjs/core/Table/ColumnHeader.js +21 -28
- package/cjs/core/Table/Table.js +74 -53
- package/cjs/core/Table/TablePaginator.js +111 -88
- package/cjs/core/Table/cells/DefaultCell.js +3 -3
- package/cjs/core/Table/utils.d.ts +2 -2
- package/cjs/core/Table/utils.js +3 -3
- package/cjs/styles.js +1 -1
- package/cjs/utils/components/MiddleTextTruncation.js +19 -14
- package/cjs/utils/components/OverflowContainer.d.ts +37 -0
- package/cjs/utils/components/OverflowContainer.js +62 -0
- package/cjs/utils/components/index.d.ts +1 -0
- package/cjs/utils/components/index.js +1 -0
- package/cjs/utils/hooks/useOverflow.d.ts +2 -3
- package/cjs/utils/hooks/useOverflow.js +12 -8
- package/esm/core/Breadcrumbs/Breadcrumbs.js +85 -66
- package/esm/core/ButtonGroup/ButtonGroup.js +33 -28
- package/esm/core/ComboBox/ComboBox.js +9 -6
- package/esm/core/DatePicker/DatePicker.js +12 -4
- package/esm/core/NonIdealState/NonIdealState.d.ts +15 -11
- package/esm/core/Popover/Popover.d.ts +10 -0
- package/esm/core/Popover/Popover.js +45 -17
- package/esm/core/Select/SelectTagContainer.js +24 -13
- package/esm/core/Table/ColumnHeader.d.ts +8 -12
- package/esm/core/Table/ColumnHeader.js +28 -29
- package/esm/core/Table/Table.js +75 -54
- package/esm/core/Table/TablePaginator.js +112 -89
- package/esm/core/Table/cells/DefaultCell.js +4 -4
- package/esm/core/Table/utils.d.ts +2 -2
- package/esm/core/Table/utils.js +1 -1
- package/esm/styles.js +1 -1
- package/esm/utils/components/MiddleTextTruncation.js +19 -14
- package/esm/utils/components/OverflowContainer.d.ts +37 -0
- package/esm/utils/components/OverflowContainer.js +49 -0
- package/esm/utils/components/index.d.ts +1 -0
- package/esm/utils/components/index.js +1 -0
- package/esm/utils/hooks/useOverflow.d.ts +2 -3
- package/esm/utils/hooks/useOverflow.js +8 -8
- package/package.json +1 -1
- package/styles.css +8 -8
|
@@ -36,6 +36,7 @@ const singleRowSelectedAction = 'singleRowSelected';
|
|
|
36
36
|
const shiftRowSelectedAction = 'shiftRowSelected';
|
|
37
37
|
const tableResizeStartAction = 'tableResizeStart';
|
|
38
38
|
const tableResizeEndAction = 'tableResizeEnd';
|
|
39
|
+
const iuiId = Symbol('iui-id');
|
|
39
40
|
const flattenColumns = (columns) => {
|
|
40
41
|
let flatColumns = [];
|
|
41
42
|
columns.forEach((column) => {
|
|
@@ -88,6 +89,7 @@ const Table = (props) => {
|
|
|
88
89
|
headerProps,
|
|
89
90
|
bodyProps,
|
|
90
91
|
emptyTableContentProps,
|
|
92
|
+
getRowId,
|
|
91
93
|
...rest
|
|
92
94
|
} = props;
|
|
93
95
|
(0, _index.useGlobals)();
|
|
@@ -225,16 +227,30 @@ const Table = (props) => {
|
|
|
225
227
|
),
|
|
226
228
|
[data, getSubRows],
|
|
227
229
|
);
|
|
228
|
-
let [rowHasParent] = _react.useState(() => new WeakSet());
|
|
229
230
|
let getSubRowsWithSubComponents = _react.useCallback(
|
|
230
|
-
(originalRow) => {
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
(originalRow, relativeIndex) => {
|
|
232
|
+
if (originalRow[iuiId]) return [];
|
|
233
|
+
if (originalRow.subRows) return originalRow.subRows;
|
|
234
|
+
return [
|
|
235
|
+
{
|
|
236
|
+
[iuiId]: `subcomponent-${relativeIndex}`,
|
|
237
|
+
...originalRow,
|
|
238
|
+
},
|
|
239
|
+
];
|
|
240
|
+
},
|
|
241
|
+
[],
|
|
242
|
+
);
|
|
243
|
+
let getRowIdWithSubComponents = _react.useCallback(
|
|
244
|
+
(originalRow, relativeIndex, parent) => {
|
|
245
|
+
let defaultRowId = parent
|
|
246
|
+
? `${parent.id}.${relativeIndex}`
|
|
247
|
+
: `${relativeIndex}`;
|
|
248
|
+
let rowIdFromUser = getRowId?.(originalRow, relativeIndex, parent);
|
|
249
|
+
if (void 0 !== rowIdFromUser && originalRow[iuiId])
|
|
250
|
+
return `${rowIdFromUser}-${defaultRowId}`;
|
|
251
|
+
return rowIdFromUser ?? defaultRowId;
|
|
236
252
|
},
|
|
237
|
-
[
|
|
253
|
+
[getRowId],
|
|
238
254
|
);
|
|
239
255
|
let instance = (0, _reacttable.useTable)(
|
|
240
256
|
{
|
|
@@ -254,6 +270,7 @@ const Table = (props) => {
|
|
|
254
270
|
...props.initialState,
|
|
255
271
|
},
|
|
256
272
|
columnResizeMode,
|
|
273
|
+
getRowId: subComponent ? getRowIdWithSubComponents : getRowId,
|
|
257
274
|
},
|
|
258
275
|
_reacttable.useFlexLayout,
|
|
259
276
|
(0, _index1.useResizeColumns)(ownerDocument),
|
|
@@ -289,7 +306,6 @@ const Table = (props) => {
|
|
|
289
306
|
gotoPage,
|
|
290
307
|
setPageSize,
|
|
291
308
|
flatHeaders,
|
|
292
|
-
visibleColumns,
|
|
293
309
|
setGlobalFilter,
|
|
294
310
|
} = instance;
|
|
295
311
|
let headerGroups = _headerGroups;
|
|
@@ -300,6 +316,10 @@ const Table = (props) => {
|
|
|
300
316
|
"Table's `columns` prop should not have a top-level `Header` or sub-columns. They are only allowed to be passed for backwards compatibility.\n See https://github.com/iTwin/iTwinUI/wiki/iTwinUI-react-v2-migration-guide#breaking-changes",
|
|
301
317
|
);
|
|
302
318
|
}
|
|
319
|
+
if (subComponent && data.some((item) => !!item.subRows?.length))
|
|
320
|
+
logWarning(
|
|
321
|
+
'Passing both `subComponent` and `data` with `subRows` is not supported. There are features designed for `subRows` that are not compatible with `subComponent` and vice versa.',
|
|
322
|
+
);
|
|
303
323
|
let ariaDataAttributes = Object.entries(rest).reduce(
|
|
304
324
|
(result, [key, value]) => {
|
|
305
325
|
if (key.startsWith('data-') || key.startsWith('aria-'))
|
|
@@ -456,51 +476,52 @@ const Table = (props) => {
|
|
|
456
476
|
(index, virtualItem, virtualizer) => {
|
|
457
477
|
let row = page[index];
|
|
458
478
|
prepareRow(row);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
479
|
+
let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
|
|
480
|
+
if (isRowASubComponent)
|
|
481
|
+
return _react.createElement(
|
|
482
|
+
_TableExpandableContentMemoized.TableExpandableContentMemoized,
|
|
483
|
+
{
|
|
484
|
+
key: row.getRowProps().key,
|
|
485
|
+
virtualItem: virtualItem,
|
|
486
|
+
ref: enableVirtualization
|
|
487
|
+
? virtualizer?.measureElement
|
|
488
|
+
: tableRowRef(row),
|
|
489
|
+
isDisabled: !!isRowDisabled?.(row.original),
|
|
490
|
+
},
|
|
491
|
+
subComponent(row),
|
|
492
|
+
);
|
|
493
|
+
return _react.createElement(_TableRowMemoized.TableRowMemoized, {
|
|
494
|
+
row: row,
|
|
495
|
+
rowProps: rowProps,
|
|
496
|
+
isLast: index === page.length - 1,
|
|
497
|
+
onRowInViewport: onRowInViewportRef,
|
|
498
|
+
onBottomReached: onBottomReachedRef,
|
|
499
|
+
intersectionMargin: intersectionMargin,
|
|
500
|
+
state: state,
|
|
501
|
+
key: row.getRowProps().key,
|
|
502
|
+
onClick: onRowClickHandler,
|
|
503
|
+
subComponent: subComponent,
|
|
504
|
+
isDisabled: !!isRowDisabled?.(row.original),
|
|
505
|
+
tableHasSubRows: hasAnySubRows,
|
|
506
|
+
tableInstance: instance,
|
|
507
|
+
expanderCell: expanderCell,
|
|
508
|
+
scrollContainerRef: tableRef.current,
|
|
509
|
+
tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
|
|
510
|
+
density: density,
|
|
511
|
+
virtualItem: virtualItem,
|
|
512
|
+
virtualizer: virtualizer,
|
|
513
|
+
});
|
|
493
514
|
},
|
|
494
515
|
[
|
|
495
516
|
page,
|
|
496
517
|
prepareRow,
|
|
518
|
+
subComponent,
|
|
497
519
|
rowProps,
|
|
498
520
|
onRowInViewportRef,
|
|
499
521
|
onBottomReachedRef,
|
|
500
522
|
intersectionMargin,
|
|
501
523
|
state,
|
|
502
524
|
onRowClickHandler,
|
|
503
|
-
subComponent,
|
|
504
525
|
isRowDisabled,
|
|
505
526
|
hasAnySubRows,
|
|
506
527
|
instance,
|
|
@@ -537,9 +558,9 @@ const Table = (props) => {
|
|
|
537
558
|
updateStickyState();
|
|
538
559
|
}, []);
|
|
539
560
|
return _react.createElement(
|
|
540
|
-
_utils.
|
|
561
|
+
_utils.TableInstanceContext.Provider,
|
|
541
562
|
{
|
|
542
|
-
value: instance
|
|
563
|
+
value: instance,
|
|
543
564
|
},
|
|
544
565
|
_react.createElement(
|
|
545
566
|
_index.Box,
|
|
@@ -601,19 +622,23 @@ const Table = (props) => {
|
|
|
601
622
|
return _react.createElement(_ColumnHeader.ColumnHeader, {
|
|
602
623
|
...dragAndDropProps,
|
|
603
624
|
key: dragAndDropProps.key || column.id || index,
|
|
604
|
-
columnRefs: columnRefs,
|
|
605
625
|
column: column,
|
|
606
|
-
index: index,
|
|
607
626
|
areFiltersSet: areFiltersSet,
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
627
|
+
columnHasExpanders:
|
|
628
|
+
hasAnySubRows &&
|
|
629
|
+
index ===
|
|
630
|
+
headerGroup.headers.findIndex(
|
|
631
|
+
(c) => c.id !== _index3.SELECTION_CELL_ID,
|
|
632
|
+
),
|
|
633
|
+
isLast: index === headerGroup.headers.length - 1,
|
|
634
|
+
isTableEmpty: 0 === data.length,
|
|
612
635
|
isResizable: isResizable,
|
|
613
636
|
columnResizeMode: columnResizeMode,
|
|
614
637
|
enableColumnReordering: enableColumnReordering,
|
|
615
638
|
density: density,
|
|
616
|
-
|
|
639
|
+
ref: (el) => {
|
|
640
|
+
if (el) columnRefs.current[column.id] = el;
|
|
641
|
+
},
|
|
617
642
|
});
|
|
618
643
|
}),
|
|
619
644
|
),
|
|
@@ -18,6 +18,7 @@ const _DropdownButton = require('../Buttons/DropdownButton.js');
|
|
|
18
18
|
const _ProgressRadial = require('../ProgressIndicators/ProgressRadial.js');
|
|
19
19
|
const _MenuItem = require('../Menu/MenuItem.js');
|
|
20
20
|
const _index = require('../../utils/index.js');
|
|
21
|
+
const _styles = require('../../styles.js');
|
|
21
22
|
const defaultLocalization = {
|
|
22
23
|
pageSizeLabel: (size) => `${size} per page`,
|
|
23
24
|
rangeLabel: (startIndex, endIndex, totalRows, isLoading) =>
|
|
@@ -59,7 +60,7 @@ const TablePaginator = (props) => {
|
|
|
59
60
|
);
|
|
60
61
|
let pageListRef = _react.useRef(null);
|
|
61
62
|
let [focusedIndex, setFocusedIndex] = _react.useState(currentPage);
|
|
62
|
-
_react.
|
|
63
|
+
_react.useLayoutEffect(() => {
|
|
63
64
|
setFocusedIndex(currentPage);
|
|
64
65
|
}, [currentPage]);
|
|
65
66
|
let needFocus = _react.useRef(false);
|
|
@@ -68,7 +69,7 @@ const TablePaginator = (props) => {
|
|
|
68
69
|
if (isMounted.current && needFocus.current) {
|
|
69
70
|
let buttonToFocus = Array.from(
|
|
70
71
|
pageListRef.current?.querySelectorAll(
|
|
71
|
-
'
|
|
72
|
+
`.${_styles.styles['iui-table-paginator-page-button']}`,
|
|
72
73
|
) ?? [],
|
|
73
74
|
).find((el) => el.textContent?.trim() === (focusedIndex + 1).toString());
|
|
74
75
|
buttonToFocus?.focus();
|
|
@@ -77,35 +78,7 @@ const TablePaginator = (props) => {
|
|
|
77
78
|
isMounted.current = true;
|
|
78
79
|
}, [focusedIndex]);
|
|
79
80
|
let buttonSize = 'default' != size ? 'small' : void 0;
|
|
80
|
-
let pageButton = _react.useCallback(
|
|
81
|
-
(index, tabIndex = index === focusedIndex ? 0 : -1) =>
|
|
82
|
-
_react.createElement(
|
|
83
|
-
_Button.Button,
|
|
84
|
-
{
|
|
85
|
-
key: index,
|
|
86
|
-
className: 'iui-table-paginator-page-button',
|
|
87
|
-
styleType: 'borderless',
|
|
88
|
-
size: buttonSize,
|
|
89
|
-
'data-iui-active': index === currentPage,
|
|
90
|
-
onClick: () => onPageChange(index),
|
|
91
|
-
'aria-current': index === currentPage,
|
|
92
|
-
'aria-label': localization.goToPageLabel(index + 1),
|
|
93
|
-
tabIndex: tabIndex,
|
|
94
|
-
},
|
|
95
|
-
index + 1,
|
|
96
|
-
),
|
|
97
|
-
[focusedIndex, currentPage, localization, buttonSize, onPageChange],
|
|
98
|
-
);
|
|
99
81
|
let totalPagesCount = Math.ceil(totalRowsCount / pageSize);
|
|
100
|
-
let pageList = _react.useMemo(
|
|
101
|
-
() =>
|
|
102
|
-
new Array(totalPagesCount)
|
|
103
|
-
.fill(null)
|
|
104
|
-
.map((_, index) => pageButton(index)),
|
|
105
|
-
[pageButton, totalPagesCount],
|
|
106
|
-
);
|
|
107
|
-
let [overflowRef, visibleCount] = (0, _index.useOverflow)(pageList);
|
|
108
|
-
let [paginatorResizeRef, paginatorWidth] = (0, _index.useContainerWidth)();
|
|
109
82
|
let onKeyDown = (event) => {
|
|
110
83
|
if (event.altKey) return;
|
|
111
84
|
let focusPage = (delta) => {
|
|
@@ -136,30 +109,10 @@ const TablePaginator = (props) => {
|
|
|
136
109
|
break;
|
|
137
110
|
}
|
|
138
111
|
};
|
|
139
|
-
let
|
|
140
|
-
let startPage = focusedIndex - halfVisibleCount;
|
|
141
|
-
let endPage = focusedIndex + halfVisibleCount + 1;
|
|
142
|
-
if (startPage < 0) {
|
|
143
|
-
endPage = Math.min(totalPagesCount, endPage + Math.abs(startPage));
|
|
144
|
-
startPage = 0;
|
|
145
|
-
}
|
|
146
|
-
if (endPage > totalPagesCount) {
|
|
147
|
-
startPage = Math.max(0, startPage - (endPage - totalPagesCount));
|
|
148
|
-
endPage = totalPagesCount;
|
|
149
|
-
}
|
|
150
|
-
let hasNoRows = 0 === totalPagesCount;
|
|
112
|
+
let [paginatorResizeRef, paginatorWidth] = (0, _index.useContainerWidth)();
|
|
151
113
|
let showPagesList = totalPagesCount > 1 || isLoading;
|
|
152
114
|
let showPageSizeList = pageSizeList && !!onPageSizeChange && !!totalRowsCount;
|
|
153
|
-
let
|
|
154
|
-
_index.Box,
|
|
155
|
-
{
|
|
156
|
-
as: 'span',
|
|
157
|
-
className: (0, _classnames.default)('iui-table-paginator-ellipsis', {
|
|
158
|
-
'iui-table-paginator-ellipsis-small': 'small' === size,
|
|
159
|
-
}),
|
|
160
|
-
},
|
|
161
|
-
'…',
|
|
162
|
-
);
|
|
115
|
+
let hasNoRows = 0 === totalPagesCount;
|
|
163
116
|
let noRowsContent = _react.createElement(
|
|
164
117
|
_react.Fragment,
|
|
165
118
|
null,
|
|
@@ -200,10 +153,10 @@ const TablePaginator = (props) => {
|
|
|
200
153
|
),
|
|
201
154
|
showPagesList &&
|
|
202
155
|
_react.createElement(
|
|
203
|
-
_index.
|
|
156
|
+
_index.OverflowContainer,
|
|
204
157
|
{
|
|
205
158
|
className: 'iui-center',
|
|
206
|
-
|
|
159
|
+
itemsCount: totalPagesCount,
|
|
207
160
|
},
|
|
208
161
|
_react.createElement(
|
|
209
162
|
_IconButton.IconButton,
|
|
@@ -224,40 +177,17 @@ const TablePaginator = (props) => {
|
|
|
224
177
|
onKeyDown: onKeyDown,
|
|
225
178
|
ref: pageListRef,
|
|
226
179
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
ellipsis,
|
|
239
|
-
),
|
|
240
|
-
pageList.slice(startPage, endPage),
|
|
241
|
-
endPage !== totalPagesCount &&
|
|
242
|
-
!isLoading &&
|
|
243
|
-
_react.createElement(
|
|
244
|
-
_react.Fragment,
|
|
245
|
-
null,
|
|
246
|
-
ellipsis,
|
|
247
|
-
pageButton(totalPagesCount - 1, 0),
|
|
248
|
-
),
|
|
249
|
-
isLoading &&
|
|
250
|
-
_react.createElement(
|
|
251
|
-
_react.Fragment,
|
|
252
|
-
null,
|
|
253
|
-
ellipsis,
|
|
254
|
-
_react.createElement(_ProgressRadial.ProgressRadial, {
|
|
255
|
-
indeterminate: true,
|
|
256
|
-
size: 'small',
|
|
257
|
-
}),
|
|
258
|
-
),
|
|
259
|
-
);
|
|
260
|
-
})(),
|
|
180
|
+
hasNoRows
|
|
181
|
+
? noRowsContent
|
|
182
|
+
: _react.createElement(TablePaginatorPageButtons, {
|
|
183
|
+
size: size,
|
|
184
|
+
focusedIndex: focusedIndex,
|
|
185
|
+
totalPagesCount: totalPagesCount,
|
|
186
|
+
onPageChange: onPageChange,
|
|
187
|
+
currentPage: currentPage,
|
|
188
|
+
localization: localization,
|
|
189
|
+
isLoading: isLoading,
|
|
190
|
+
}),
|
|
261
191
|
),
|
|
262
192
|
_react.createElement(
|
|
263
193
|
_IconButton.IconButton,
|
|
@@ -322,3 +252,96 @@ const TablePaginator = (props) => {
|
|
|
322
252
|
),
|
|
323
253
|
);
|
|
324
254
|
};
|
|
255
|
+
const TablePaginatorPageButtons = (props) => {
|
|
256
|
+
let {
|
|
257
|
+
focusedIndex,
|
|
258
|
+
totalPagesCount,
|
|
259
|
+
onPageChange,
|
|
260
|
+
currentPage,
|
|
261
|
+
localization,
|
|
262
|
+
isLoading,
|
|
263
|
+
size,
|
|
264
|
+
} = props;
|
|
265
|
+
let { visibleCount } = _index.OverflowContainer.useContext();
|
|
266
|
+
let buttonSize = 'default' != size ? 'small' : void 0;
|
|
267
|
+
let pageButton = _react.useCallback(
|
|
268
|
+
(index, tabIndex = index === focusedIndex ? 0 : -1) =>
|
|
269
|
+
_react.createElement(
|
|
270
|
+
_Button.Button,
|
|
271
|
+
{
|
|
272
|
+
key: index,
|
|
273
|
+
className: 'iui-table-paginator-page-button',
|
|
274
|
+
styleType: 'borderless',
|
|
275
|
+
size: buttonSize,
|
|
276
|
+
'data-iui-active': index === currentPage,
|
|
277
|
+
onClick: () => onPageChange(index),
|
|
278
|
+
'aria-current': index === currentPage,
|
|
279
|
+
'aria-label': localization.goToPageLabel?.(index + 1),
|
|
280
|
+
tabIndex: tabIndex,
|
|
281
|
+
},
|
|
282
|
+
index + 1,
|
|
283
|
+
),
|
|
284
|
+
[focusedIndex, currentPage, localization, buttonSize, onPageChange],
|
|
285
|
+
);
|
|
286
|
+
let pageList = _react.useMemo(
|
|
287
|
+
() =>
|
|
288
|
+
new Array(totalPagesCount)
|
|
289
|
+
.fill(null)
|
|
290
|
+
.map((_, index) => pageButton(index)),
|
|
291
|
+
[pageButton, totalPagesCount],
|
|
292
|
+
);
|
|
293
|
+
let halfVisibleCount = Math.floor(visibleCount / 2);
|
|
294
|
+
let startPage = focusedIndex - halfVisibleCount;
|
|
295
|
+
let endPage = focusedIndex + halfVisibleCount + 1;
|
|
296
|
+
if (startPage < 0) {
|
|
297
|
+
endPage = Math.min(totalPagesCount, endPage + Math.abs(startPage));
|
|
298
|
+
startPage = 0;
|
|
299
|
+
}
|
|
300
|
+
if (endPage > totalPagesCount) {
|
|
301
|
+
startPage = Math.max(0, startPage - (endPage - totalPagesCount));
|
|
302
|
+
endPage = totalPagesCount;
|
|
303
|
+
}
|
|
304
|
+
let ellipsis = _react.createElement(
|
|
305
|
+
_index.Box,
|
|
306
|
+
{
|
|
307
|
+
as: 'span',
|
|
308
|
+
className: (0, _classnames.default)('iui-table-paginator-ellipsis', {
|
|
309
|
+
'iui-table-paginator-ellipsis-small': 'small' === size,
|
|
310
|
+
}),
|
|
311
|
+
},
|
|
312
|
+
'…',
|
|
313
|
+
);
|
|
314
|
+
if (1 === visibleCount) return pageButton(focusedIndex);
|
|
315
|
+
let showStartEllipsis = startPage > 1;
|
|
316
|
+
let showEndEllipsis = endPage < totalPagesCount - 1;
|
|
317
|
+
return _react.createElement(
|
|
318
|
+
_react.Fragment,
|
|
319
|
+
null,
|
|
320
|
+
0 !== startPage &&
|
|
321
|
+
_react.createElement(
|
|
322
|
+
_react.Fragment,
|
|
323
|
+
null,
|
|
324
|
+
pageButton(0, 0),
|
|
325
|
+
showStartEllipsis ? ellipsis : null,
|
|
326
|
+
),
|
|
327
|
+
pageList.slice(startPage, endPage),
|
|
328
|
+
endPage !== totalPagesCount &&
|
|
329
|
+
!isLoading &&
|
|
330
|
+
_react.createElement(
|
|
331
|
+
_react.Fragment,
|
|
332
|
+
null,
|
|
333
|
+
showEndEllipsis ? ellipsis : null,
|
|
334
|
+
pageButton(totalPagesCount - 1, 0),
|
|
335
|
+
),
|
|
336
|
+
isLoading &&
|
|
337
|
+
_react.createElement(
|
|
338
|
+
_react.Fragment,
|
|
339
|
+
null,
|
|
340
|
+
ellipsis,
|
|
341
|
+
_react.createElement(_ProgressRadial.ProgressRadial, {
|
|
342
|
+
indeterminate: true,
|
|
343
|
+
size: 'small',
|
|
344
|
+
}),
|
|
345
|
+
),
|
|
346
|
+
);
|
|
347
|
+
};
|
|
@@ -16,12 +16,12 @@ const _classnames = _interop_require_default._(require('classnames'));
|
|
|
16
16
|
const _index = require('../../../utils/index.js');
|
|
17
17
|
const _utils = require('../utils.js');
|
|
18
18
|
const DefaultCell = (props) => {
|
|
19
|
-
let
|
|
19
|
+
let instance = _react.useContext(_utils.TableInstanceContext);
|
|
20
20
|
let isCustomCell = _react.useMemo(
|
|
21
21
|
() =>
|
|
22
|
-
|
|
22
|
+
instance?.columns.find(({ id }) => props.cellProps.column.id === id)
|
|
23
23
|
?.Cell !== _reacttable.defaultColumn.Cell,
|
|
24
|
-
[
|
|
24
|
+
[instance, props.cellProps.column.id],
|
|
25
25
|
);
|
|
26
26
|
let {
|
|
27
27
|
cellElementProps: {
|
|
@@ -10,8 +10,8 @@ function _export(target, all) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
_export(exports, {
|
|
13
|
-
|
|
14
|
-
return
|
|
13
|
+
TableInstanceContext: function () {
|
|
14
|
+
return TableInstanceContext;
|
|
15
15
|
},
|
|
16
16
|
getCellStyle: function () {
|
|
17
17
|
return getCellStyle;
|
|
@@ -73,4 +73,4 @@ const getSubRowStyle = ({ density = 'default', depth = 1 }) => {
|
|
|
73
73
|
paddingInlineStart: cellPadding + depth * multiplier,
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
const
|
|
76
|
+
const TableInstanceContext = _react.createContext(void 0);
|
package/DEV-cjs/styles.js
CHANGED
|
@@ -10,22 +10,14 @@ Object.defineProperty(exports, 'MiddleTextTruncation', {
|
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
|
|
12
12
|
const _react = _interop_require_wildcard._(require('react'));
|
|
13
|
-
const
|
|
13
|
+
const _OverflowContainer = require('./OverflowContainer.js');
|
|
14
14
|
const ELLIPSIS_CHAR = '…';
|
|
15
15
|
const MiddleTextTruncation = (props) => {
|
|
16
|
-
let { text,
|
|
17
|
-
let [ref, visibleCount] = (0, _useOverflow.useOverflow)(text);
|
|
18
|
-
let truncatedText = _react.useMemo(() => {
|
|
19
|
-
if (visibleCount < text.length)
|
|
20
|
-
return `${text.substring(
|
|
21
|
-
0,
|
|
22
|
-
visibleCount - endCharsCount - ELLIPSIS_CHAR.length,
|
|
23
|
-
)}${ELLIPSIS_CHAR}${text.substring(text.length - endCharsCount)}`;
|
|
24
|
-
return text;
|
|
25
|
-
}, [endCharsCount, text, visibleCount]);
|
|
16
|
+
let { text, style, ...rest } = props;
|
|
26
17
|
return _react.createElement(
|
|
27
|
-
|
|
18
|
+
_OverflowContainer.OverflowContainer,
|
|
28
19
|
{
|
|
20
|
+
as: 'span',
|
|
29
21
|
style: {
|
|
30
22
|
display: 'flex',
|
|
31
23
|
minWidth: 0,
|
|
@@ -33,10 +25,23 @@ const MiddleTextTruncation = (props) => {
|
|
|
33
25
|
whiteSpace: 'nowrap',
|
|
34
26
|
...style,
|
|
35
27
|
},
|
|
36
|
-
|
|
28
|
+
itemsCount: text.length,
|
|
37
29
|
...rest,
|
|
38
30
|
},
|
|
39
|
-
|
|
31
|
+
_react.createElement(MiddleTextTruncationContent, props),
|
|
40
32
|
);
|
|
41
33
|
};
|
|
42
34
|
MiddleTextTruncation.displayName = 'MiddleTextTruncation';
|
|
35
|
+
const MiddleTextTruncationContent = (props) => {
|
|
36
|
+
let { text, endCharsCount = 6, textRenderer } = props;
|
|
37
|
+
let { visibleCount } = _OverflowContainer.OverflowContainer.useContext();
|
|
38
|
+
let truncatedText = _react.useMemo(() => {
|
|
39
|
+
if (visibleCount < text.length)
|
|
40
|
+
return `${text.substring(
|
|
41
|
+
0,
|
|
42
|
+
visibleCount - endCharsCount - ELLIPSIS_CHAR.length,
|
|
43
|
+
)}${ELLIPSIS_CHAR}${text.substring(text.length - endCharsCount)}`;
|
|
44
|
+
return text;
|
|
45
|
+
}, [endCharsCount, text, visibleCount]);
|
|
46
|
+
return textRenderer?.(truncatedText, text) ?? truncatedText;
|
|
47
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {
|
|
3
|
+
value: true,
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, 'OverflowContainer', {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function () {
|
|
8
|
+
return OverflowContainer;
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
|
|
12
|
+
const _react = _interop_require_default._(require('react'));
|
|
13
|
+
const _useMergedRefs = require('../hooks/useMergedRefs.js');
|
|
14
|
+
const _Box = require('./Box.js');
|
|
15
|
+
const _useOverflow = require('../hooks/useOverflow.js');
|
|
16
|
+
const _useSafeContext = require('../hooks/useSafeContext.js');
|
|
17
|
+
const OverflowContainerComponent = _react.default.forwardRef((props, ref) => {
|
|
18
|
+
let { itemsCount, children, overflowOrientation, ...rest } = props;
|
|
19
|
+
let [containerRef, visibleCount] = (0, _useOverflow.useOverflow)(
|
|
20
|
+
itemsCount,
|
|
21
|
+
false,
|
|
22
|
+
overflowOrientation,
|
|
23
|
+
);
|
|
24
|
+
let overflowContainerContextValue = _react.default.useMemo(
|
|
25
|
+
() => ({
|
|
26
|
+
visibleCount,
|
|
27
|
+
itemsCount,
|
|
28
|
+
}),
|
|
29
|
+
[itemsCount, visibleCount],
|
|
30
|
+
);
|
|
31
|
+
return _react.default.createElement(
|
|
32
|
+
OverflowContainerContext.Provider,
|
|
33
|
+
{
|
|
34
|
+
value: overflowContainerContextValue,
|
|
35
|
+
},
|
|
36
|
+
_react.default.createElement(
|
|
37
|
+
_Box.Box,
|
|
38
|
+
{
|
|
39
|
+
ref: (0, _useMergedRefs.useMergedRefs)(ref, containerRef),
|
|
40
|
+
...rest,
|
|
41
|
+
},
|
|
42
|
+
children,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
const OverflowContainerOverflowNode = (props) => {
|
|
47
|
+
let { children } = props;
|
|
48
|
+
let { visibleCount, itemsCount } = useOverflowContainerContext();
|
|
49
|
+
let isOverflowing = visibleCount < itemsCount;
|
|
50
|
+
return isOverflowing ? children : null;
|
|
51
|
+
};
|
|
52
|
+
const OverflowContainer = Object.assign(OverflowContainerComponent, {
|
|
53
|
+
OverflowNode: OverflowContainerOverflowNode,
|
|
54
|
+
useContext: useOverflowContainerContext,
|
|
55
|
+
});
|
|
56
|
+
const OverflowContainerContext = _react.default.createContext(void 0);
|
|
57
|
+
OverflowContainerContext.displayName = 'OverflowContainerContext';
|
|
58
|
+
function useOverflowContainerContext() {
|
|
59
|
+
let overflowContainerContext = (0, _useSafeContext.useSafeContext)(
|
|
60
|
+
OverflowContainerContext,
|
|
61
|
+
);
|
|
62
|
+
return overflowContainerContext;
|
|
63
|
+
}
|
|
@@ -17,3 +17,4 @@ _export_star._(require('./Portal.js'), exports);
|
|
|
17
17
|
_export_star._(require('./ShadowRoot.js'), exports);
|
|
18
18
|
_export_star._(require('./LineClamp.js'), exports);
|
|
19
19
|
_export_star._(require('./FieldsetBase.js'), exports);
|
|
20
|
+
_export_star._(require('./OverflowContainer.js'), exports);
|
|
@@ -14,10 +14,14 @@ const _useMergedRefs = require('./useMergedRefs.js');
|
|
|
14
14
|
const _useResizeObserver = require('./useResizeObserver.js');
|
|
15
15
|
const _useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect.js');
|
|
16
16
|
const STARTING_MAX_ITEMS_COUNT = 20;
|
|
17
|
-
const useOverflow = (
|
|
17
|
+
const useOverflow = (
|
|
18
|
+
itemsCount,
|
|
19
|
+
disabled = false,
|
|
20
|
+
orientation = 'horizontal',
|
|
21
|
+
) => {
|
|
18
22
|
let containerRef = _react.useRef(null);
|
|
19
23
|
let [visibleCount, setVisibleCount] = _react.useState(() =>
|
|
20
|
-
disabled ?
|
|
24
|
+
disabled ? itemsCount : Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT),
|
|
21
25
|
);
|
|
22
26
|
let needsFullRerender = _react.useRef(true);
|
|
23
27
|
let [containerSize, setContainerSize] = _react.useState(0);
|
|
@@ -32,12 +36,12 @@ const useOverflow = (items, disabled = false, orientation = 'horizontal') => {
|
|
|
32
36
|
);
|
|
33
37
|
let resizeObserverRef = _react.useRef(observer);
|
|
34
38
|
(0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
|
|
35
|
-
if (disabled) setVisibleCount(
|
|
39
|
+
if (disabled) setVisibleCount(itemsCount);
|
|
36
40
|
else {
|
|
37
|
-
setVisibleCount(Math.min(
|
|
41
|
+
setVisibleCount(Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT));
|
|
38
42
|
needsFullRerender.current = true;
|
|
39
43
|
}
|
|
40
|
-
}, [containerSize, disabled,
|
|
44
|
+
}, [containerSize, disabled, itemsCount]);
|
|
41
45
|
let mergedRefs = (0, _useMergedRefs.useMergedRefs)(containerRef, resizeRef);
|
|
42
46
|
(0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
|
|
43
47
|
if (!containerRef.current || disabled) {
|
|
@@ -57,14 +61,14 @@ const useOverflow = (items, disabled = false, orientation = 'horizontal') => {
|
|
|
57
61
|
0,
|
|
58
62
|
);
|
|
59
63
|
let currentVisibleCount =
|
|
60
|
-
visibleCount || Math.min(
|
|
64
|
+
visibleCount || Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT);
|
|
61
65
|
let avgItemSize = childrenSize / currentVisibleCount;
|
|
62
66
|
let visibleItems = Math.floor(availableSize / avgItemSize);
|
|
63
67
|
if (!isNaN(visibleItems))
|
|
64
|
-
setVisibleCount(Math.min(
|
|
68
|
+
setVisibleCount(Math.min(itemsCount, 2 * visibleItems));
|
|
65
69
|
}
|
|
66
70
|
needsFullRerender.current = false;
|
|
67
|
-
}, [containerSize, visibleCount, disabled,
|
|
71
|
+
}, [containerSize, visibleCount, disabled, itemsCount, orientation]);
|
|
68
72
|
(0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
|
|
69
73
|
previousContainerSize.current = containerSize;
|
|
70
74
|
}, [containerSize]);
|