@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.
Files changed (81) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/DEV-cjs/core/Breadcrumbs/Breadcrumbs.js +85 -65
  3. package/DEV-cjs/core/ButtonGroup/ButtonGroup.js +32 -27
  4. package/DEV-cjs/core/ComboBox/ComboBox.js +9 -6
  5. package/DEV-cjs/core/DatePicker/DatePicker.js +14 -4
  6. package/DEV-cjs/core/Popover/Popover.js +44 -16
  7. package/DEV-cjs/core/Select/SelectTagContainer.js +27 -13
  8. package/DEV-cjs/core/Table/ColumnHeader.js +21 -28
  9. package/DEV-cjs/core/Table/Table.js +78 -53
  10. package/DEV-cjs/core/Table/TablePaginator.js +111 -88
  11. package/DEV-cjs/core/Table/cells/DefaultCell.js +3 -3
  12. package/DEV-cjs/core/Table/utils.js +3 -3
  13. package/DEV-cjs/styles.js +1 -1
  14. package/DEV-cjs/utils/components/MiddleTextTruncation.js +19 -14
  15. package/DEV-cjs/utils/components/OverflowContainer.js +63 -0
  16. package/DEV-cjs/utils/components/index.js +1 -0
  17. package/DEV-cjs/utils/hooks/useOverflow.js +12 -8
  18. package/DEV-esm/core/Breadcrumbs/Breadcrumbs.js +86 -67
  19. package/DEV-esm/core/ButtonGroup/ButtonGroup.js +33 -28
  20. package/DEV-esm/core/ComboBox/ComboBox.js +9 -6
  21. package/DEV-esm/core/DatePicker/DatePicker.js +12 -4
  22. package/DEV-esm/core/Popover/Popover.js +45 -17
  23. package/DEV-esm/core/Select/SelectTagContainer.js +24 -13
  24. package/DEV-esm/core/Table/ColumnHeader.js +28 -29
  25. package/DEV-esm/core/Table/Table.js +79 -54
  26. package/DEV-esm/core/Table/TablePaginator.js +112 -89
  27. package/DEV-esm/core/Table/cells/DefaultCell.js +4 -4
  28. package/DEV-esm/core/Table/utils.js +1 -1
  29. package/DEV-esm/styles.js +1 -1
  30. package/DEV-esm/utils/components/MiddleTextTruncation.js +19 -14
  31. package/DEV-esm/utils/components/OverflowContainer.js +50 -0
  32. package/DEV-esm/utils/components/index.js +1 -0
  33. package/DEV-esm/utils/hooks/useOverflow.js +8 -8
  34. package/cjs/core/Breadcrumbs/Breadcrumbs.js +84 -64
  35. package/cjs/core/ButtonGroup/ButtonGroup.js +32 -27
  36. package/cjs/core/ComboBox/ComboBox.js +9 -6
  37. package/cjs/core/DatePicker/DatePicker.js +14 -4
  38. package/cjs/core/NonIdealState/NonIdealState.d.ts +15 -11
  39. package/cjs/core/Popover/Popover.d.ts +10 -0
  40. package/cjs/core/Popover/Popover.js +44 -16
  41. package/cjs/core/Select/SelectTagContainer.js +27 -13
  42. package/cjs/core/Table/ColumnHeader.d.ts +8 -12
  43. package/cjs/core/Table/ColumnHeader.js +21 -28
  44. package/cjs/core/Table/Table.js +74 -53
  45. package/cjs/core/Table/TablePaginator.js +111 -88
  46. package/cjs/core/Table/cells/DefaultCell.js +3 -3
  47. package/cjs/core/Table/utils.d.ts +2 -2
  48. package/cjs/core/Table/utils.js +3 -3
  49. package/cjs/styles.js +1 -1
  50. package/cjs/utils/components/MiddleTextTruncation.js +19 -14
  51. package/cjs/utils/components/OverflowContainer.d.ts +37 -0
  52. package/cjs/utils/components/OverflowContainer.js +62 -0
  53. package/cjs/utils/components/index.d.ts +1 -0
  54. package/cjs/utils/components/index.js +1 -0
  55. package/cjs/utils/hooks/useOverflow.d.ts +2 -3
  56. package/cjs/utils/hooks/useOverflow.js +12 -8
  57. package/esm/core/Breadcrumbs/Breadcrumbs.js +85 -66
  58. package/esm/core/ButtonGroup/ButtonGroup.js +33 -28
  59. package/esm/core/ComboBox/ComboBox.js +9 -6
  60. package/esm/core/DatePicker/DatePicker.js +12 -4
  61. package/esm/core/NonIdealState/NonIdealState.d.ts +15 -11
  62. package/esm/core/Popover/Popover.d.ts +10 -0
  63. package/esm/core/Popover/Popover.js +45 -17
  64. package/esm/core/Select/SelectTagContainer.js +24 -13
  65. package/esm/core/Table/ColumnHeader.d.ts +8 -12
  66. package/esm/core/Table/ColumnHeader.js +28 -29
  67. package/esm/core/Table/Table.js +75 -54
  68. package/esm/core/Table/TablePaginator.js +112 -89
  69. package/esm/core/Table/cells/DefaultCell.js +4 -4
  70. package/esm/core/Table/utils.d.ts +2 -2
  71. package/esm/core/Table/utils.js +1 -1
  72. package/esm/styles.js +1 -1
  73. package/esm/utils/components/MiddleTextTruncation.js +19 -14
  74. package/esm/utils/components/OverflowContainer.d.ts +37 -0
  75. package/esm/utils/components/OverflowContainer.js +49 -0
  76. package/esm/utils/components/index.d.ts +1 -0
  77. package/esm/utils/components/index.js +1 -0
  78. package/esm/utils/hooks/useOverflow.d.ts +2 -3
  79. package/esm/utils/hooks/useOverflow.js +8 -8
  80. package/package.json +1 -1
  81. package/styles.css +8 -8
@@ -12,39 +12,32 @@ const _interop_require_default = require('@swc/helpers/_/_interop_require_defaul
12
12
  const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
13
13
  const _react = _interop_require_wildcard._(require('react'));
14
14
  const _index = require('../../utils/index.js');
15
- const _index1 = require('./columns/index.js');
16
15
  const _FilterToggle = require('./filters/FilterToggle.js');
17
16
  const _utils = require('./utils.js');
18
17
  const _classnames = _interop_require_default._(require('classnames'));
19
- const ColumnHeader = (props) => {
18
+ const ColumnHeader = _react.forwardRef((props, forwardedRef) => {
20
19
  let {
21
- columnRefs,
22
20
  column,
23
- index,
24
21
  areFiltersSet,
25
- hasAnySubRows,
26
- headers,
27
- state,
28
- data,
29
22
  isResizable,
30
23
  columnResizeMode,
31
24
  enableColumnReordering,
32
25
  density,
33
- visibleColumns,
26
+ columnHasExpanders,
27
+ isLast,
28
+ isTableEmpty,
34
29
  ...rest
35
30
  } = props;
36
31
  let isHeaderDirectClick = _react.useRef(false);
32
+ let instance = _react.useContext(_utils.TableInstanceContext);
37
33
  let COLUMN_MIN_WIDTHS = {
38
34
  default: 72,
39
35
  withExpander: 108,
40
36
  };
41
37
  let showFilterButton = (column) =>
42
- (0 !== data.length || areFiltersSet) && column.canFilter && !!column.Filter;
43
- let showSortButton = (column) => 0 !== data.length && column.canSort;
38
+ (!isTableEmpty || areFiltersSet) && column.canFilter && !!column.Filter;
39
+ let showSortButton = (column) => !isTableEmpty && column.canSort;
44
40
  let { onClick, ...restSortProps } = column.getSortByToggleProps();
45
- let columnHasExpanders =
46
- hasAnySubRows &&
47
- index === headers.findIndex((c) => c.id !== _index1.SELECTION_CELL_ID);
48
41
  if ([void 0, 0].includes(column.minWidth)) {
49
42
  column.minWidth = columnHasExpanders
50
43
  ? COLUMN_MIN_WIDTHS.withExpander
@@ -64,12 +57,12 @@ const ColumnHeader = (props) => {
64
57
  column.columnClassName,
65
58
  ),
66
59
  style: {
67
- ...(0, _utils.getCellStyle)(column, !!state.isTableResizing),
60
+ ...(0, _utils.getCellStyle)(column, !!instance?.state.isTableResizing),
68
61
  ...(columnHasExpanders &&
69
62
  (0, _utils.getSubRowStyle)({
70
63
  density,
71
64
  })),
72
- ...(0, _utils.getStickyStyle)(column, visibleColumns),
65
+ ...(0, _utils.getStickyStyle)(column, instance?.visibleColumns ?? []),
73
66
  flexWrap: 'wrap',
74
67
  columnGap: 'var(--iui-size-xs)',
75
68
  },
@@ -81,14 +74,14 @@ const ColumnHeader = (props) => {
81
74
  ...rest,
82
75
  key: columnProps.key,
83
76
  title: void 0,
84
- ref: _react.useCallback(
85
- (el) => {
86
- if (el) {
87
- columnRefs.current[column.id] = el;
88
- column.resizeWidth = el.getBoundingClientRect().width;
89
- }
90
- },
91
- [column, columnRefs],
77
+ ref: (0, _index.useMergedRefs)(
78
+ _react.useCallback(
79
+ (el) => {
80
+ if (el) column.resizeWidth = el.getBoundingClientRect().width;
81
+ },
82
+ [column],
83
+ ),
84
+ forwardedRef,
92
85
  ),
93
86
  onMouseDown: () => {
94
87
  isHeaderDirectClick.current = true;
@@ -159,7 +152,7 @@ const ColumnHeader = (props) => {
159
152
  ),
160
153
  isResizable &&
161
154
  column.isResizerVisible &&
162
- (index !== headers.length - 1 || 'expand' === columnResizeMode) &&
155
+ (!isLast || 'expand' === columnResizeMode) &&
163
156
  _react.createElement(
164
157
  _index.Box,
165
158
  {
@@ -178,17 +171,17 @@ const ColumnHeader = (props) => {
178
171
  slot: 'resizers',
179
172
  }),
180
173
  'left' === column.sticky &&
181
- state.sticky.isScrolledToRight &&
174
+ instance?.state.sticky.isScrolledToRight &&
182
175
  _react.createElement(_index.Box, {
183
176
  className: 'iui-table-cell-shadow-right',
184
177
  slot: 'shadows',
185
178
  }),
186
179
  'right' === column.sticky &&
187
- state.sticky.isScrolledToLeft &&
180
+ instance?.state.sticky.isScrolledToLeft &&
188
181
  _react.createElement(_index.Box, {
189
182
  className: 'iui-table-cell-shadow-left',
190
183
  slot: 'shadows',
191
184
  }),
192
185
  ),
193
186
  );
194
- };
187
+ });
@@ -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 (!rowHasParent.has(originalRow)) {
232
- rowHasParent.add(originalRow);
233
- return [originalRow];
234
- }
235
- return originalRow.subRows || [];
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
+ ];
236
240
  },
237
- [rowHasParent],
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;
252
+ },
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;
@@ -452,51 +468,52 @@ const Table = (props) => {
452
468
  (index, virtualItem, virtualizer) => {
453
469
  let row = page[index];
454
470
  prepareRow(row);
455
- if (row.subRows.length > 0 || !subComponent)
456
- return _react.createElement(_TableRowMemoized.TableRowMemoized, {
457
- row: row,
458
- rowProps: rowProps,
459
- isLast: index === page.length - 1,
460
- onRowInViewport: onRowInViewportRef,
461
- onBottomReached: onBottomReachedRef,
462
- intersectionMargin: intersectionMargin,
463
- state: state,
464
- key: row.getRowProps().key,
465
- onClick: onRowClickHandler,
466
- subComponent: subComponent,
467
- isDisabled: !!isRowDisabled?.(row.original),
468
- tableHasSubRows: hasAnySubRows,
469
- tableInstance: instance,
470
- expanderCell: expanderCell,
471
- scrollContainerRef: tableRef.current,
472
- tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
473
- density: density,
474
- virtualItem: virtualItem,
475
- virtualizer: virtualizer,
476
- });
477
- return _react.createElement(
478
- _TableExpandableContentMemoized.TableExpandableContentMemoized,
479
- {
480
- key: row.getRowProps().key,
481
- virtualItem: virtualItem,
482
- ref: enableVirtualization
483
- ? virtualizer?.measureElement
484
- : tableRowRef(row),
485
- isDisabled: !!isRowDisabled?.(row.original),
486
- },
487
- subComponent(row),
488
- );
471
+ let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
472
+ if (isRowASubComponent)
473
+ return _react.createElement(
474
+ _TableExpandableContentMemoized.TableExpandableContentMemoized,
475
+ {
476
+ key: row.getRowProps().key,
477
+ virtualItem: virtualItem,
478
+ ref: enableVirtualization
479
+ ? virtualizer?.measureElement
480
+ : tableRowRef(row),
481
+ isDisabled: !!isRowDisabled?.(row.original),
482
+ },
483
+ subComponent(row),
484
+ );
485
+ return _react.createElement(_TableRowMemoized.TableRowMemoized, {
486
+ row: row,
487
+ rowProps: rowProps,
488
+ isLast: index === page.length - 1,
489
+ onRowInViewport: onRowInViewportRef,
490
+ onBottomReached: onBottomReachedRef,
491
+ intersectionMargin: intersectionMargin,
492
+ state: state,
493
+ key: row.getRowProps().key,
494
+ onClick: onRowClickHandler,
495
+ subComponent: subComponent,
496
+ isDisabled: !!isRowDisabled?.(row.original),
497
+ tableHasSubRows: hasAnySubRows,
498
+ tableInstance: instance,
499
+ expanderCell: expanderCell,
500
+ scrollContainerRef: tableRef.current,
501
+ tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
502
+ density: density,
503
+ virtualItem: virtualItem,
504
+ virtualizer: virtualizer,
505
+ });
489
506
  },
490
507
  [
491
508
  page,
492
509
  prepareRow,
510
+ subComponent,
493
511
  rowProps,
494
512
  onRowInViewportRef,
495
513
  onBottomReachedRef,
496
514
  intersectionMargin,
497
515
  state,
498
516
  onRowClickHandler,
499
- subComponent,
500
517
  isRowDisabled,
501
518
  hasAnySubRows,
502
519
  instance,
@@ -533,9 +550,9 @@ const Table = (props) => {
533
550
  updateStickyState();
534
551
  }, []);
535
552
  return _react.createElement(
536
- _utils.TableColumnsContext.Provider,
553
+ _utils.TableInstanceContext.Provider,
537
554
  {
538
- value: instance.columns,
555
+ value: instance,
539
556
  },
540
557
  _react.createElement(
541
558
  _index.Box,
@@ -597,19 +614,23 @@ const Table = (props) => {
597
614
  return _react.createElement(_ColumnHeader.ColumnHeader, {
598
615
  ...dragAndDropProps,
599
616
  key: dragAndDropProps.key || column.id || index,
600
- columnRefs: columnRefs,
601
617
  column: column,
602
- index: index,
603
618
  areFiltersSet: areFiltersSet,
604
- hasAnySubRows: hasAnySubRows,
605
- headers: headerGroup.headers,
606
- state: state,
607
- data: data,
619
+ columnHasExpanders:
620
+ hasAnySubRows &&
621
+ index ===
622
+ headerGroup.headers.findIndex(
623
+ (c) => c.id !== _index3.SELECTION_CELL_ID,
624
+ ),
625
+ isLast: index === headerGroup.headers.length - 1,
626
+ isTableEmpty: 0 === data.length,
608
627
  isResizable: isResizable,
609
628
  columnResizeMode: columnResizeMode,
610
629
  enableColumnReordering: enableColumnReordering,
611
630
  density: density,
612
- visibleColumns: visibleColumns,
631
+ ref: (el) => {
632
+ if (el) columnRefs.current[column.id] = el;
633
+ },
613
634
  });
614
635
  }),
615
636
  ),
@@ -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.useEffect(() => {
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
- '.iui-table-paginator-page-button',
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 halfVisibleCount = Math.floor(visibleCount / 2);
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 ellipsis = _react.createElement(
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.Box,
156
+ _index.OverflowContainer,
204
157
  {
205
158
  className: 'iui-center',
206
- ref: overflowRef,
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
- if (hasNoRows) return noRowsContent;
229
- if (1 === visibleCount) return pageButton(focusedIndex);
230
- return _react.createElement(
231
- _react.Fragment,
232
- null,
233
- 0 !== startPage &&
234
- _react.createElement(
235
- _react.Fragment,
236
- null,
237
- pageButton(0, 0),
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 instanceColumns = _react.useContext(_utils.TableColumnsContext);
19
+ let instance = _react.useContext(_utils.TableInstanceContext);
20
20
  let isCustomCell = _react.useMemo(
21
21
  () =>
22
- instanceColumns.find(({ id }) => props.cellProps.column.id === id)
22
+ instance?.columns.find(({ id }) => props.cellProps.column.id === id)
23
23
  ?.Cell !== _reacttable.defaultColumn.Cell,
24
- [instanceColumns, props.cellProps.column.id],
24
+ [instance, props.cellProps.column.id],
25
25
  );
26
26
  let {
27
27
  cellElementProps: {
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { ColumnInstance } from '../../react-table/react-table.js';
2
+ import type { ColumnInstance, TableInstance } from '../../react-table/react-table.js';
3
3
  export declare const getCellStyle: <T extends Record<string, unknown>>(column: ColumnInstance<T>, isTableResizing: boolean) => React.CSSProperties | undefined;
4
4
  export declare const getStickyStyle: <T extends Record<string, unknown>>(column: ColumnInstance<T>, columnList: ColumnInstance<T>[]) => React.CSSProperties;
5
5
  export declare const getSubRowStyle: ({ density, depth }: {
@@ -8,4 +8,4 @@ export declare const getSubRowStyle: ({ density, depth }: {
8
8
  }) => {
9
9
  paddingInlineStart: number;
10
10
  };
11
- export declare const TableColumnsContext: React.Context<ColumnInstance<{}>[]>;
11
+ export declare const TableInstanceContext: React.Context<TableInstance<Record<string, unknown>> | undefined>;
@@ -10,8 +10,8 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- TableColumnsContext: function () {
14
- return TableColumnsContext;
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 TableColumnsContext = _react.createContext([]);
76
+ const TableInstanceContext = _react.createContext(void 0);
package/cjs/styles.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const e = '3.15.3';
3
+ const e = '3.15.5';
4
4
  const u = new Proxy(
5
5
  {},
6
6
  {
@@ -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 _useOverflow = require('../hooks/useOverflow.js');
13
+ const _OverflowContainer = require('./OverflowContainer.js');
14
14
  const ELLIPSIS_CHAR = '…';
15
15
  const MiddleTextTruncation = (props) => {
16
- let { text, endCharsCount = 6, textRenderer, style, ...rest } = props;
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
- 'span',
18
+ _OverflowContainer.OverflowContainer,
28
19
  {
20
+ as: 'span',
29
21
  style: {
30
22
  display: 'flex',
31
23
  minWidth: 0,
@@ -33,9 +25,22 @@ const MiddleTextTruncation = (props) => {
33
25
  whiteSpace: 'nowrap',
34
26
  ...style,
35
27
  },
36
- ref: ref,
28
+ itemsCount: text.length,
37
29
  ...rest,
38
30
  },
39
- textRenderer?.(truncatedText, text) ?? truncatedText,
31
+ _react.createElement(MiddleTextTruncationContent, props),
40
32
  );
41
33
  };
34
+ const MiddleTextTruncationContent = (props) => {
35
+ let { text, endCharsCount = 6, textRenderer } = props;
36
+ let { visibleCount } = _OverflowContainer.OverflowContainer.useContext();
37
+ let truncatedText = _react.useMemo(() => {
38
+ if (visibleCount < text.length)
39
+ return `${text.substring(
40
+ 0,
41
+ visibleCount - endCharsCount - ELLIPSIS_CHAR.length,
42
+ )}${ELLIPSIS_CHAR}${text.substring(text.length - endCharsCount)}`;
43
+ return text;
44
+ }, [endCharsCount, text, visibleCount]);
45
+ return textRenderer?.(truncatedText, text) ?? truncatedText;
46
+ };