@itwin/itwinui-react 3.15.2 → 3.15.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/CHANGELOG.md +19 -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/ProgressIndicators/ProgressLinear.js +2 -1
- 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 +17 -10
- 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/core/TransferList/TransferList.js +18 -6
- 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/ProgressIndicators/ProgressLinear.js +2 -1
- 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 +18 -11
- 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/core/TransferList/TransferList.js +14 -2
- 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/Popover/Popover.d.ts +10 -0
- package/cjs/core/Popover/Popover.js +44 -16
- package/cjs/core/ProgressIndicators/ProgressLinear.js +2 -1
- 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 +13 -10
- 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/core/TransferList/TransferList.d.ts +1 -1
- package/cjs/core/TransferList/TransferList.js +18 -6
- 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/Popover/Popover.d.ts +10 -0
- package/esm/core/Popover/Popover.js +45 -17
- package/esm/core/ProgressIndicators/ProgressLinear.js +2 -1
- 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 +14 -11
- 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/core/TransferList/TransferList.d.ts +1 -1
- package/esm/core/TransferList/TransferList.js +14 -2
- 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
package/cjs/core/Table/Table.js
CHANGED
|
@@ -289,7 +289,6 @@ const Table = (props) => {
|
|
|
289
289
|
gotoPage,
|
|
290
290
|
setPageSize,
|
|
291
291
|
flatHeaders,
|
|
292
|
-
visibleColumns,
|
|
293
292
|
setGlobalFilter,
|
|
294
293
|
} = instance;
|
|
295
294
|
let headerGroups = _headerGroups;
|
|
@@ -533,9 +532,9 @@ const Table = (props) => {
|
|
|
533
532
|
updateStickyState();
|
|
534
533
|
}, []);
|
|
535
534
|
return _react.createElement(
|
|
536
|
-
_utils.
|
|
535
|
+
_utils.TableInstanceContext.Provider,
|
|
537
536
|
{
|
|
538
|
-
value: instance
|
|
537
|
+
value: instance,
|
|
539
538
|
},
|
|
540
539
|
_react.createElement(
|
|
541
540
|
_index.Box,
|
|
@@ -597,19 +596,23 @@ const Table = (props) => {
|
|
|
597
596
|
return _react.createElement(_ColumnHeader.ColumnHeader, {
|
|
598
597
|
...dragAndDropProps,
|
|
599
598
|
key: dragAndDropProps.key || column.id || index,
|
|
600
|
-
columnRefs: columnRefs,
|
|
601
599
|
column: column,
|
|
602
|
-
index: index,
|
|
603
600
|
areFiltersSet: areFiltersSet,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
601
|
+
columnHasExpanders:
|
|
602
|
+
hasAnySubRows &&
|
|
603
|
+
index ===
|
|
604
|
+
headerGroup.headers.findIndex(
|
|
605
|
+
(c) => c.id !== _index3.SELECTION_CELL_ID,
|
|
606
|
+
),
|
|
607
|
+
isLast: index === headerGroup.headers.length - 1,
|
|
608
|
+
isTableEmpty: 0 === data.length,
|
|
608
609
|
isResizable: isResizable,
|
|
609
610
|
columnResizeMode: columnResizeMode,
|
|
610
611
|
enableColumnReordering: enableColumnReordering,
|
|
611
612
|
density: density,
|
|
612
|
-
|
|
613
|
+
ref: (el) => {
|
|
614
|
+
if (el) columnRefs.current[column.id] = el;
|
|
615
|
+
},
|
|
613
616
|
});
|
|
614
617
|
}),
|
|
615
618
|
),
|
|
@@ -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: {
|
|
@@ -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
|
|
11
|
+
export declare const TableInstanceContext: React.Context<TableInstance<Record<string, unknown>> | undefined>;
|
package/cjs/core/Table/utils.js
CHANGED
|
@@ -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);
|
|
@@ -54,7 +54,7 @@ export declare const TransferList: PolymorphicForwardRefComponent<"div", {}> & {
|
|
|
54
54
|
/**
|
|
55
55
|
* TransferList toolbar subcomponent
|
|
56
56
|
*/
|
|
57
|
-
Toolbar: PolymorphicForwardRefComponent<"div",
|
|
57
|
+
Toolbar: PolymorphicForwardRefComponent<"div", object>;
|
|
58
58
|
};
|
|
59
59
|
export declare const TransferListContext: React.Context<{
|
|
60
60
|
/**
|
|
@@ -25,6 +25,7 @@ const _index = require('../../utils/index.js');
|
|
|
25
25
|
const _List = require('../List/List.js');
|
|
26
26
|
const _ListItem = require('../List/ListItem.js');
|
|
27
27
|
const _Label = require('../Label/Label.js');
|
|
28
|
+
const _ButtonGroup = require('../ButtonGroup/ButtonGroup.js');
|
|
28
29
|
const TransferListComponent = _index.polymorphic.div(
|
|
29
30
|
'iui-transfer-list-wrapper',
|
|
30
31
|
);
|
|
@@ -169,12 +170,23 @@ const TransferListListboxLabel = _react.forwardRef((props, ref) => {
|
|
|
169
170
|
children,
|
|
170
171
|
);
|
|
171
172
|
});
|
|
172
|
-
const TransferListToolbar =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
const TransferListToolbar = _react.forwardRef((props, ref) => {
|
|
174
|
+
let { className, children, ...rest } = props;
|
|
175
|
+
return _react.createElement(
|
|
176
|
+
_ButtonGroup.ButtonGroup,
|
|
177
|
+
{
|
|
178
|
+
role: 'toolbar',
|
|
179
|
+
ref: ref,
|
|
180
|
+
...rest,
|
|
181
|
+
orientation: 'vertical',
|
|
182
|
+
className: (0, _classnames.default)(
|
|
183
|
+
'iui-transfer-list-toolbar',
|
|
184
|
+
className,
|
|
185
|
+
),
|
|
186
|
+
},
|
|
187
|
+
children,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
178
190
|
const TransferList = Object.assign(TransferListComponent, {
|
|
179
191
|
ListboxWrapper: TransferListListboxWrapper,
|
|
180
192
|
Listbox: TransferListListbox,
|
package/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,9 +25,22 @@ 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
|
};
|
|
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
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PolymorphicForwardRefComponent } from '../props.js';
|
|
3
|
+
type OverflowContainerProps = {
|
|
4
|
+
/**
|
|
5
|
+
* The orientation of the overflow in container.
|
|
6
|
+
* @default 'horizontal'
|
|
7
|
+
*/
|
|
8
|
+
overflowOrientation?: 'horizontal' | 'vertical';
|
|
9
|
+
/**
|
|
10
|
+
* Count of the *original* items (i.e. when sufficient space is available).
|
|
11
|
+
*/
|
|
12
|
+
itemsCount: number;
|
|
13
|
+
};
|
|
14
|
+
type OverflowContainerOverflowNodeProps = {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Wrapper over `useOverflow`.
|
|
19
|
+
*
|
|
20
|
+
* - Use `OverflowContainer.useContext()` to get overflow related properties.
|
|
21
|
+
* - Wrap overflow content in `OverflowContainer.OverflowNode` to conditionally render it when overflowing.
|
|
22
|
+
*/
|
|
23
|
+
export declare const OverflowContainer: PolymorphicForwardRefComponent<"div", OverflowContainerProps> & {
|
|
24
|
+
/**
|
|
25
|
+
* Wrap overflow content in this component to conditionally render it when overflowing.
|
|
26
|
+
*/
|
|
27
|
+
OverflowNode: (props: OverflowContainerOverflowNodeProps) => React.ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* Get overflow related properties of the nearest `OverflowContainer` ancestor.
|
|
30
|
+
*/
|
|
31
|
+
useContext: typeof useOverflowContainerContext;
|
|
32
|
+
};
|
|
33
|
+
declare function useOverflowContainerContext(): {
|
|
34
|
+
visibleCount: number;
|
|
35
|
+
itemsCount: number;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
function useOverflowContainerContext() {
|
|
58
|
+
let overflowContainerContext = (0, _useSafeContext.useSafeContext)(
|
|
59
|
+
OverflowContainerContext,
|
|
60
|
+
);
|
|
61
|
+
return overflowContainerContext;
|
|
62
|
+
}
|
|
@@ -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);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
/**
|
|
3
2
|
* Hook that observes the size of an element and returns the number of items
|
|
4
3
|
* that should be visible based on the size of the container element.
|
|
@@ -6,7 +5,7 @@ import * as React from 'react';
|
|
|
6
5
|
* The returned number should be used to render the element with fewer items.
|
|
7
6
|
*
|
|
8
7
|
* @private
|
|
9
|
-
* @param items
|
|
8
|
+
* @param itemsCount Number of items that this element contains.
|
|
10
9
|
* @param disabled Set to true to disconnect the observer.
|
|
11
10
|
* @param dimension 'horizontal' (default) or 'vertical'
|
|
12
11
|
* @returns [callback ref to set on container, stateful count of visible items]
|
|
@@ -21,4 +20,4 @@ import * as React from 'react';
|
|
|
21
20
|
* </div>
|
|
22
21
|
* );
|
|
23
22
|
*/
|
|
24
|
-
export declare const useOverflow: <T extends HTMLElement>(
|
|
23
|
+
export declare const useOverflow: <T extends HTMLElement>(itemsCount: number, disabled?: boolean, orientation?: "horizontal" | "vertical") => readonly [(instance: T | null | undefined) => void, number];
|
|
@@ -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]);
|