@itwin/itwinui-react 1.29.0 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/cjs/core/ButtonGroup/ButtonGroup.d.ts +10 -3
  3. package/cjs/core/ButtonGroup/ButtonGroup.js +4 -3
  4. package/cjs/core/ColorPicker/ColorBuilder.js +12 -3
  5. package/cjs/core/Modal/Modal.js +4 -1
  6. package/cjs/core/Radio/Radio.js +1 -1
  7. package/cjs/core/Slider/Slider.js +8 -2
  8. package/cjs/core/Table/Table.d.ts +10 -0
  9. package/cjs/core/Table/Table.js +23 -8
  10. package/cjs/core/Tile/Tile.js +13 -17
  11. package/cjs/core/utils/components/Popover.d.ts +2 -1
  12. package/cjs/core/utils/components/Popover.js +9 -6
  13. package/cjs/core/utils/components/VirtualScroll.d.ts +42 -0
  14. package/cjs/core/utils/components/VirtualScroll.js +174 -0
  15. package/cjs/core/utils/components/index.d.ts +1 -0
  16. package/cjs/core/utils/components/index.js +1 -0
  17. package/cjs/core/utils/props.d.ts +2 -4
  18. package/esm/core/ButtonGroup/ButtonGroup.d.ts +10 -3
  19. package/esm/core/ButtonGroup/ButtonGroup.js +4 -3
  20. package/esm/core/ColorPicker/ColorBuilder.js +12 -3
  21. package/esm/core/Modal/Modal.js +4 -1
  22. package/esm/core/Radio/Radio.js +1 -1
  23. package/esm/core/Slider/Slider.js +8 -2
  24. package/esm/core/Table/Table.d.ts +10 -0
  25. package/esm/core/Table/Table.js +23 -8
  26. package/esm/core/Tile/Tile.js +13 -17
  27. package/esm/core/utils/components/Popover.d.ts +2 -1
  28. package/esm/core/utils/components/Popover.js +9 -6
  29. package/esm/core/utils/components/VirtualScroll.d.ts +42 -0
  30. package/esm/core/utils/components/VirtualScroll.js +168 -0
  31. package/esm/core/utils/components/index.d.ts +1 -0
  32. package/esm/core/utils/components/index.js +1 -0
  33. package/esm/core/utils/props.d.ts +2 -4
  34. package/package.json +4 -3
@@ -41,11 +41,9 @@ export declare type PolymorphicComponentProps<T extends React.ElementType, Props
41
41
  export interface PolymorphicForwardRefComponent<T, OwnProps = Record<string, unknown>> extends React.ForwardRefExoticComponent<Merge<T extends React.ElementType ? React.ComponentPropsWithRef<T> : never, OwnProps & {
42
42
  as?: T;
43
43
  }>> {
44
- <As = T>(props: As extends '' ? {
45
- as: keyof JSX.IntrinsicElements;
46
- } : As extends React.ComponentType<infer P> ? Merge<P, OwnProps & {
44
+ <As = T>(props: As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & {
47
45
  as: As;
48
- }> : As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & {
46
+ }> : As extends React.ComponentType<infer P> ? Merge<P, OwnProps & {
49
47
  as: As;
50
48
  }> : never): React.ReactElement | null;
51
49
  }
@@ -6,13 +6,20 @@ export declare type ButtonGroupProps = {
6
6
  */
7
7
  children: React.ReactNode;
8
8
  /**
9
- * If specified, this prop will be used to show a custom button as the last button
10
- * when overflow happens, i.e. when there is not enough space to fit all the buttons.
9
+ * If specified, this prop will be used to show a custom button when overflow happens,
10
+ * i.e. when there is not enough space to fit all the buttons.
11
11
  *
12
12
  * Expects a function that takes the index of the first button that is overflowing (i.e. hidden)
13
13
  * and returns the `ReactNode` to render.
14
+ *
15
+ * The placement of this button can be controlled using the `overflowPlacement` prop.
14
16
  */
15
17
  overflowButton?: (firstOverflowingIndex: number) => React.ReactNode;
18
+ /**
19
+ * If `overflowButton` is specified, should it placed at the start or the end?
20
+ * @default 'end'
21
+ */
22
+ overflowPlacement?: 'start' | 'end';
16
23
  } & React.ComponentPropsWithRef<'div'>;
17
24
  /**
18
25
  * Group buttons together for common actions.
@@ -42,5 +49,5 @@ export declare type ButtonGroupProps = {
42
49
  * {buttons}
43
50
  * </ButtonGroup>
44
51
  */
45
- export declare const ButtonGroup: React.ForwardRefExoticComponent<Pick<ButtonGroupProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "overflowButton"> & React.RefAttributes<HTMLDivElement>>;
52
+ export declare const ButtonGroup: React.ForwardRefExoticComponent<Pick<ButtonGroupProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "overflowButton" | "overflowPlacement"> & React.RefAttributes<HTMLDivElement>>;
46
53
  export default ButtonGroup;
@@ -57,13 +57,14 @@ import '@itwin/itwinui-css/css/button.css';
57
57
  * </ButtonGroup>
58
58
  */
59
59
  export var ButtonGroup = React.forwardRef(function (props, ref) {
60
- var children = props.children, className = props.className, style = props.style, overflowButton = props.overflowButton, rest = __rest(props, ["children", "className", "style", "overflowButton"]);
60
+ var children = props.children, className = props.className, style = props.style, overflowButton = props.overflowButton, _a = props.overflowPlacement, overflowPlacement = _a === void 0 ? 'end' : _a, rest = __rest(props, ["children", "className", "style", "overflowButton", "overflowPlacement"]);
61
61
  var items = React.useMemo(function () { var _a; return (_a = React.Children.map(children, function (child) { return React.createElement("div", null, child); })) !== null && _a !== void 0 ? _a : []; }, [children]);
62
62
  useTheme();
63
- var _a = useOverflow(items, !overflowButton), overflowRef = _a[0], visibleCount = _a[1];
63
+ var _b = useOverflow(items, !overflowButton), overflowRef = _b[0], visibleCount = _b[1];
64
64
  var refs = useMergedRefs(overflowRef, ref);
65
65
  return (React.createElement("div", __assign({ className: cx('iui-button-group', className), style: __assign(__assign({}, (!!overflowButton && { width: '100%' })), style), ref: refs }, rest), !!overflowButton && visibleCount < items.length ? (React.createElement(React.Fragment, null,
66
+ overflowButton && overflowPlacement === 'start' && (React.createElement("div", null, overflowButton(visibleCount))),
66
67
  items.slice(0, visibleCount - 1),
67
- overflowButton(visibleCount))) : (items)));
68
+ overflowButton && overflowPlacement === 'end' && (React.createElement("div", null, overflowButton(visibleCount))))) : (items)));
68
69
  });
69
70
  export default ButtonGroup;
@@ -132,22 +132,31 @@ export var ColorBuilder = React.forwardRef(function (props, ref) {
132
132
  }
133
133
  }, [colorDotActive, updateColorDot]);
134
134
  var handleSquarePointerUp = React.useCallback(function (event) {
135
+ if (!colorDotActive) {
136
+ return;
137
+ }
135
138
  updateSquareValue(event, 'onChange');
136
139
  setColorDotActive(false);
137
140
  event.preventDefault();
138
141
  event.stopPropagation();
139
- }, [updateSquareValue]);
142
+ }, [colorDotActive, updateSquareValue]);
140
143
  useEventListener('pointerup', handleSquarePointerUp, (_k = builderRef.current) === null || _k === void 0 ? void 0 : _k.ownerDocument);
141
144
  var handleSquarePointerMove = React.useCallback(function (event) {
145
+ if (!colorDotActive) {
146
+ return;
147
+ }
142
148
  event.preventDefault();
143
149
  event.stopPropagation();
144
150
  updateSquareValue(event, 'onUpdate');
145
- }, [updateSquareValue]);
151
+ }, [colorDotActive, updateSquareValue]);
146
152
  useEventListener('pointermove', handleSquarePointerMove, (_l = builderRef.current) === null || _l === void 0 ? void 0 : _l.ownerDocument);
147
153
  var handleSquarePointerLeave = React.useCallback(function (event) {
154
+ if (!colorDotActive) {
155
+ return;
156
+ }
148
157
  updateSquareValue(event, 'onChange');
149
158
  setColorDotActive(false);
150
- }, [updateSquareValue]);
159
+ }, [colorDotActive, updateSquareValue]);
151
160
  useEventListener('pointerleave', handleSquarePointerLeave, (_m = builderRef.current) === null || _m === void 0 ? void 0 : _m.ownerDocument);
152
161
  var keysPressed = React.useRef({}); // keep track of which keys are currently pressed
153
162
  // Arrow key navigation for color dot
@@ -104,13 +104,16 @@ export var Modal = function (props) {
104
104
  var handleMouseDown = function (event) {
105
105
  // Prevents React from resetting its properties
106
106
  event.persist();
107
+ if (event.target !== overlayRef.current) {
108
+ return;
109
+ }
107
110
  if (isDismissible && closeOnExternalClick && onClose) {
108
111
  onClose(event);
109
112
  }
110
113
  };
111
114
  return !!container ? (ReactDOM.createPortal(isOpen && (React.createElement(FocusTrap, null,
112
115
  React.createElement("div", __assign({ className: cx('iui-modal', 'iui-modal-visible', className), tabIndex: -1, onKeyDown: handleKeyDown, ref: overlayRef, onMouseDown: handleMouseDown }, rest),
113
- React.createElement("div", { className: 'iui-modal-dialog', id: id, style: style, role: 'dialog', "aria-modal": 'true', onMouseDown: function (event) { return event.stopPropagation(); } },
116
+ React.createElement("div", { className: 'iui-modal-dialog', id: id, style: style, role: 'dialog', "aria-modal": 'true' },
114
117
  React.createElement("div", { className: 'iui-title-bar' },
115
118
  React.createElement("div", { className: 'iui-title' }, title),
116
119
  isDismissible && (React.createElement(IconButton, { size: 'small', styleType: 'borderless', onClick: onClose, "aria-label": 'Close' },
@@ -52,7 +52,7 @@ export var Radio = React.forwardRef(function (props, ref) {
52
52
  React.createElement("input", __assign({ disabled: disabled, type: 'radio', ref: refs }, rest)),
53
53
  React.createElement("span", { className: cx('iui-radio-dot', checkmarkClassName), style: checkmarkStyle },
54
54
  React.createElement("svg", { viewBox: '0 0 16 16', "aria-hidden": 'true', focusable: 'false' },
55
- React.createElement("circle", { cx: '8', cy: '8', r: '6' }))),
55
+ React.createElement("circle", { cx: '8', cy: '8', r: '4' }))),
56
56
  label && React.createElement("span", { className: 'iui-label' }, label)));
57
57
  });
58
58
  export default Radio;
@@ -158,10 +158,13 @@ export var Slider = React.forwardRef(function (props, ref) {
158
158
  onChange,
159
159
  ]);
160
160
  var handlePointerMove = React.useCallback(function (event) {
161
+ if (activeThumbIndex === undefined) {
162
+ return;
163
+ }
161
164
  event.preventDefault();
162
165
  event.stopPropagation();
163
166
  updateThumbValue(event, 'onUpdate');
164
- }, [updateThumbValue]);
167
+ }, [activeThumbIndex, updateThumbValue]);
165
168
  // function called by Thumb keyboard processing
166
169
  var onThumbValueChanged = React.useCallback(function (index, value) {
167
170
  if (currentValues[index] === value) {
@@ -176,11 +179,14 @@ export var Slider = React.forwardRef(function (props, ref) {
176
179
  setActiveThumbIndex(index);
177
180
  }, []);
178
181
  var handlePointerUp = React.useCallback(function (event) {
182
+ if (activeThumbIndex === undefined) {
183
+ return;
184
+ }
179
185
  updateThumbValue(event, 'onChange');
180
186
  setActiveThumbIndex(undefined);
181
187
  event.preventDefault();
182
188
  event.stopPropagation();
183
- }, [updateThumbValue]);
189
+ }, [activeThumbIndex, updateThumbValue]);
184
190
  var handlePointerDownOnSlider = React.useCallback(function (event) {
185
191
  if (containerRef.current) {
186
192
  var percent = getPercentageOfRectangle(containerRef.current.getBoundingClientRect(), event.clientX);
@@ -56,6 +56,7 @@ export declare type TableProps<T extends Record<string, unknown> = Record<string
56
56
  isSelectable?: boolean;
57
57
  /**
58
58
  * Handler for rows selection. Must be memoized.
59
+ * This is triggered only by user initiated actions (i.e. data change will not call it).
59
60
  */
60
61
  onSelect?: (selectedData: T[] | undefined, tableState?: TableState<T>) => void;
61
62
  /**
@@ -160,6 +161,15 @@ export declare type TableProps<T extends Record<string, unknown> = Record<string
160
161
  * @default 'default'
161
162
  */
162
163
  styleType?: 'default' | 'zebra-rows';
164
+ /**
165
+ * Virtualization is used for the scrollable table body.
166
+ * Height on the table is required for virtualization to work.
167
+ * @example
168
+ * <Table enableVirtualization style={{height: 400}} {...} />
169
+ * @default false
170
+ * @beta
171
+ */
172
+ enableVirtualization?: boolean;
163
173
  } & Omit<CommonProps, 'title'>;
164
174
  /**
165
175
  * Table based on [react-table](https://react-table.tanstack.com/docs/api/overview).
@@ -40,6 +40,7 @@ import { useExpanderCell, useSelectionCell, useSubRowFiltering, useSubRowSelecti
40
40
  import { onExpandHandler, onFilterHandler, onSelectHandler, } from './actionHandlers';
41
41
  import { onSingleSelectHandler } from './actionHandlers/selectHandler';
42
42
  import { onTableResizeEnd, onTableResizeStart, } from './actionHandlers/resizeHandler';
43
+ import VirtualScroll from '../utils/components/VirtualScroll';
43
44
  var singleRowSelectedAction = 'singleRowSelected';
44
45
  var tableResizeStartAction = 'tableResizeStart';
45
46
  var tableResizeEndAction = 'tableResizeEnd';
@@ -87,9 +88,9 @@ var tableResizeEndAction = 'tableResizeEnd';
87
88
  */
88
89
  export var Table = function (props) {
89
90
  var _a;
90
- var data = props.data, columns = props.columns, _b = props.isLoading, isLoading = _b === void 0 ? false : _b, emptyTableContent = props.emptyTableContent, className = props.className, style = props.style, id = props.id, _c = props.isSelectable, isSelectable = _c === void 0 ? false : _c, onSelect = props.onSelect, onRowClick = props.onRowClick, _d = props.isSortable, isSortable = _d === void 0 ? false : _d, onSort = props.onSort, stateReducer = props.stateReducer, onBottomReached = props.onBottomReached, onRowInViewport = props.onRowInViewport, _e = props.intersectionMargin, intersectionMargin = _e === void 0 ? 300 : _e, subComponent = props.subComponent, onExpand = props.onExpand, onFilter = props.onFilter, emptyFilteredTableContent = props.emptyFilteredTableContent, filterFunctions = props.filterTypes, expanderCell = props.expanderCell, isRowDisabled = props.isRowDisabled, rowProps = props.rowProps, _f = props.density, density = _f === void 0 ? 'default' : _f, _g = props.selectSubRows, selectSubRows = _g === void 0 ? true : _g, getSubRows = props.getSubRows, _h = props.selectRowOnClick, selectRowOnClick = _h === void 0 ? true : _h, paginatorRenderer = props.paginatorRenderer, _j = props.pageSize, pageSize = _j === void 0 ? 25 : _j, _k = props.isResizable, isResizable = _k === void 0 ? false : _k, _l = props.styleType, styleType = _l === void 0 ? 'default' : _l, rest = __rest(props, ["data", "columns", "isLoading", "emptyTableContent", "className", "style", "id", "isSelectable", "onSelect", "onRowClick", "isSortable", "onSort", "stateReducer", "onBottomReached", "onRowInViewport", "intersectionMargin", "subComponent", "onExpand", "onFilter", "emptyFilteredTableContent", "filterTypes", "expanderCell", "isRowDisabled", "rowProps", "density", "selectSubRows", "getSubRows", "selectRowOnClick", "paginatorRenderer", "pageSize", "isResizable", "styleType"]);
91
+ var data = props.data, columns = props.columns, _b = props.isLoading, isLoading = _b === void 0 ? false : _b, emptyTableContent = props.emptyTableContent, className = props.className, style = props.style, id = props.id, _c = props.isSelectable, isSelectable = _c === void 0 ? false : _c, onSelect = props.onSelect, onRowClick = props.onRowClick, _d = props.isSortable, isSortable = _d === void 0 ? false : _d, onSort = props.onSort, stateReducer = props.stateReducer, onBottomReached = props.onBottomReached, onRowInViewport = props.onRowInViewport, _e = props.intersectionMargin, intersectionMargin = _e === void 0 ? 300 : _e, subComponent = props.subComponent, onExpand = props.onExpand, onFilter = props.onFilter, emptyFilteredTableContent = props.emptyFilteredTableContent, filterFunctions = props.filterTypes, expanderCell = props.expanderCell, isRowDisabled = props.isRowDisabled, rowProps = props.rowProps, _f = props.density, density = _f === void 0 ? 'default' : _f, _g = props.selectSubRows, selectSubRows = _g === void 0 ? true : _g, getSubRows = props.getSubRows, _h = props.selectRowOnClick, selectRowOnClick = _h === void 0 ? true : _h, paginatorRenderer = props.paginatorRenderer, _j = props.pageSize, pageSize = _j === void 0 ? 25 : _j, _k = props.isResizable, isResizable = _k === void 0 ? false : _k, _l = props.styleType, styleType = _l === void 0 ? 'default' : _l, _m = props.enableVirtualization, enableVirtualization = _m === void 0 ? false : _m, rest = __rest(props, ["data", "columns", "isLoading", "emptyTableContent", "className", "style", "id", "isSelectable", "onSelect", "onRowClick", "isSortable", "onSort", "stateReducer", "onBottomReached", "onRowInViewport", "intersectionMargin", "subComponent", "onExpand", "onFilter", "emptyFilteredTableContent", "filterTypes", "expanderCell", "isRowDisabled", "rowProps", "density", "selectSubRows", "getSubRows", "selectRowOnClick", "paginatorRenderer", "pageSize", "isResizable", "styleType", "enableVirtualization"]);
91
92
  useTheme();
92
- var _m = React.useState(), ownerDocument = _m[0], setOwnerDocument = _m[1];
93
+ var _o = React.useState(), ownerDocument = _o[0], setOwnerDocument = _o[1];
93
94
  var defaultColumn = React.useMemo(function () { return ({
94
95
  maxWidth: 0,
95
96
  minWidth: 0,
@@ -227,6 +228,23 @@ export var Table = function (props) {
227
228
  });
228
229
  var headerRef = React.useRef(null);
229
230
  var bodyRef = React.useRef(null);
231
+ var getPreparedRow = React.useCallback(function (row) {
232
+ prepareRow(row);
233
+ return (React.createElement(TableRowMemoized, { row: row, rowProps: rowProps, isLast: row.index === data.length - 1, onRowInViewport: onRowInViewportRef, onBottomReached: onBottomReachedRef, intersectionMargin: intersectionMargin, state: state, key: row.getRowProps().key, onClick: onRowClickHandler, subComponent: subComponent, isDisabled: !!(isRowDisabled === null || isRowDisabled === void 0 ? void 0 : isRowDisabled(row.original)), tableHasSubRows: hasAnySubRows, tableInstance: instance, expanderCell: expanderCell }));
234
+ }, [
235
+ data.length,
236
+ expanderCell,
237
+ hasAnySubRows,
238
+ instance,
239
+ intersectionMargin,
240
+ isRowDisabled,
241
+ onRowClickHandler,
242
+ prepareRow,
243
+ rowProps,
244
+ state,
245
+ subComponent,
246
+ ]);
247
+ var virtualizedItemRenderer = React.useCallback(function (index) { return getPreparedRow(page[index]); }, [getPreparedRow, page]);
230
248
  return (React.createElement(React.Fragment, null,
231
249
  React.createElement("div", __assign({ ref: function (element) {
232
250
  setOwnerDocument(element === null || element === void 0 ? void 0 : element.ownerDocument);
@@ -263,16 +281,13 @@ export var Table = function (props) {
263
281
  className: cx('iui-table-body', {
264
282
  'iui-zebra-striping': styleType === 'zebra-rows',
265
283
  }),
284
+ style: { outline: 0 },
266
285
  }), { ref: bodyRef, onScroll: function () {
267
286
  if (headerRef.current && bodyRef.current) {
268
287
  headerRef.current.scrollLeft = bodyRef.current.scrollLeft;
269
288
  }
270
- } }),
271
- data.length !== 0 &&
272
- page.map(function (row) {
273
- prepareRow(row);
274
- return (React.createElement(TableRowMemoized, { row: row, rowProps: rowProps, isLast: row.index === data.length - 1, onRowInViewport: onRowInViewportRef, onBottomReached: onBottomReachedRef, intersectionMargin: intersectionMargin, state: state, key: row.getRowProps().key, onClick: onRowClickHandler, subComponent: subComponent, isDisabled: !!(isRowDisabled === null || isRowDisabled === void 0 ? void 0 : isRowDisabled(row.original)), tableHasSubRows: hasAnySubRows, tableInstance: instance, expanderCell: expanderCell }));
275
- }),
289
+ }, tabIndex: -1 }),
290
+ data.length !== 0 && (React.createElement(React.Fragment, null, enableVirtualization ? (React.createElement(VirtualScroll, { itemsLength: page.length, itemRenderer: virtualizedItemRenderer })) : (page.map(function (row) { return getPreparedRow(row); })))),
276
291
  isLoading && data.length === 0 && (React.createElement("div", { className: 'iui-table-empty' },
277
292
  React.createElement(ProgressRadial, { indeterminate: true }))),
278
293
  isLoading && data.length !== 0 && (React.createElement("div", { className: 'iui-row' },
@@ -57,28 +57,28 @@ export var Tile = function (props) {
57
57
  var showMenu = React.useCallback(function () { return setIsMenuVisible(true); }, []);
58
58
  var hideMenu = React.useCallback(function () { return setIsMenuVisible(false); }, []);
59
59
  return (React.createElement("div", __assign({ className: cx('iui-tile', { 'iui-folder': variant === 'folder' }, { 'iui-new': isNew }, { 'iui-selected': isSelected }, className) }, rest),
60
- thumbnail && (React.createElement("div", { className: 'iui-thumbnail' },
61
- typeof thumbnail === 'string' ? (React.createElement("div", { className: 'iui-picture', style: { backgroundImage: "url(" + thumbnail + ")" } })) : thumbnail && thumbnail.type === 'img' ? (React.cloneElement(thumbnail, {
62
- className: 'iui-picture',
60
+ thumbnail && (React.createElement("div", { className: 'iui-tile-thumbnail' },
61
+ typeof thumbnail === 'string' ? (React.createElement("div", { className: 'iui-tile-thumbnail-picture', style: { backgroundImage: "url(" + thumbnail + ")" } })) : thumbnail && thumbnail.type === 'img' ? (React.cloneElement(thumbnail, {
62
+ className: 'iui-tile-thumbnail-picture',
63
63
  })) : React.isValidElement(thumbnail) ? (React.cloneElement(thumbnail, {
64
64
  className: cx('iui-thumbnail-icon', thumbnail.props.className),
65
65
  })) : (thumbnail),
66
66
  leftIcon &&
67
67
  React.cloneElement(leftIcon, {
68
- className: 'iui-small iui-type-indicator',
68
+ className: 'iui-small iui-tile-thumbnail-type-indicator',
69
69
  }),
70
70
  rightIcon &&
71
71
  React.cloneElement(rightIcon, {
72
- className: 'iui-small iui-quick-action',
72
+ className: 'iui-small iui-tile-thumbnail-quick-action',
73
73
  }),
74
- badge && React.createElement("div", { className: 'iui-badge-container' }, badge))),
75
- React.createElement("div", { className: 'iui-content' },
76
- React.createElement("div", { className: 'iui-name' },
74
+ badge && (React.createElement("div", { className: 'iui-tile-thumbnail-badge-container' }, badge)))),
75
+ React.createElement("div", { className: 'iui-tile-content' },
76
+ React.createElement("div", { className: 'iui-tile-name' },
77
77
  isSelected && (React.createElement(SvgCheckmark, { className: cx('iui-tile-status-icon', 'iui-informational'), "aria-hidden": true })),
78
78
  isNew && (React.createElement(SvgNew, { className: cx('iui-tile-status-icon', 'iui-positive'), "aria-hidden": true })),
79
- React.createElement("span", { className: 'iui-name-label' }, name)),
80
- description != undefined && (React.createElement("div", { className: 'iui-description' }, description)),
81
- metadata != undefined && (React.createElement("div", { className: 'iui-metadata' }, metadata)),
79
+ React.createElement("span", { className: 'iui-tile-name-label' }, name)),
80
+ description != undefined && (React.createElement("div", { className: 'iui-tile-description' }, description)),
81
+ metadata != undefined && (React.createElement("div", { className: 'iui-tile-metadata' }, metadata)),
82
82
  moreOptions && (React.createElement(DropdownMenu, { onShow: showMenu, onHide: hideMenu, menuItems: function (close) {
83
83
  return moreOptions.map(function (option) {
84
84
  return React.cloneElement(option, {
@@ -91,15 +91,11 @@ export var Tile = function (props) {
91
91
  });
92
92
  });
93
93
  } },
94
- React.createElement(IconButton, { styleType: 'borderless', size: 'small', className: cx('iui-more-options', {
94
+ React.createElement(IconButton, { styleType: 'borderless', size: 'small', className: cx('iui-tile-more-options', {
95
95
  'iui-visible': isMenuVisible,
96
96
  }), "aria-label": 'More options' },
97
97
  React.createElement(SvgMore, null)))),
98
98
  children),
99
- buttons && (React.createElement("div", { className: 'iui-tile-buttons' }, buttons.map(function (button) {
100
- return React.cloneElement(button, {
101
- className: cx('iui-tile-button', button.props.className),
102
- });
103
- })))));
99
+ buttons && React.createElement("div", { className: 'iui-tile-buttons' }, buttons)));
104
100
  };
105
101
  export default Tile;
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { TippyProps } from '@tippyjs/react';
3
- import { Placement, Instance } from 'tippy.js';
3
+ import type { Placement, Instance } from 'tippy.js';
4
4
  export declare type PopoverInstance = Instance;
5
+ import '@itwin/itwinui-css/css/popover.css';
5
6
  export declare type PopoverProps = {
6
7
  /**
7
8
  * Controlled flag for whether the popover is visible.
@@ -23,15 +23,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
23
23
  return to.concat(ar || Array.prototype.slice.call(from));
24
24
  };
25
25
  import React from 'react';
26
+ import cx from 'classnames';
26
27
  import Tippy from '@tippyjs/react';
27
28
  import { useMergedRefs } from '../hooks/useMergedRefs';
29
+ import '@itwin/itwinui-css/css/popover.css';
28
30
  /**
29
31
  * Wrapper around [tippy.js](https://atomiks.github.io/tippyjs)
30
32
  * with pre-configured props and plugins (e.g. lazy mounting, focus, etc).
31
33
  * @private
32
34
  */
33
35
  export var Popover = React.forwardRef(function (props, ref) {
34
- var _a = React.useState(false), mounted = _a[0], setMounted = _a[1];
36
+ var _a;
37
+ var _b = React.useState(false), mounted = _b[0], setMounted = _b[1];
35
38
  var tippyRef = React.useRef(null);
36
39
  var refs = useMergedRefs(tippyRef, ref);
37
40
  // Plugin to allow lazy mounting. See https://github.com/atomiks/tippyjs-react#lazy-mounting
@@ -50,14 +53,14 @@ export var Popover = React.forwardRef(function (props, ref) {
50
53
  },
51
54
  }); },
52
55
  };
53
- var computedProps = __assign(__assign({ allowHTML: true, animation: false, appendTo: 'parent', arrow: false, duration: 0, interactive: true, popperOptions: {
54
- strategy: 'fixed',
55
- modifiers: [{ name: 'flip' }],
56
- }, role: undefined, offset: [0, 0], maxWidth: '' }, props), { plugins: __spreadArray([
56
+ var computedProps = __assign(__assign({ allowHTML: true, animation: false, appendTo: 'parent', arrow: false, duration: 0, interactive: true, role: undefined, offset: [0, 0], maxWidth: '' }, props), { className: cx('iui-popover', props.className), plugins: __spreadArray([
57
57
  lazyLoad,
58
58
  removeTabIndex,
59
59
  hideOnEscOrTab
60
- ], (props.plugins || []), true) });
60
+ ], (props.plugins || []), true), popperOptions: __assign(__assign({ strategy: 'fixed' }, props.popperOptions), { modifiers: __spreadArray([
61
+ { name: 'flip' },
62
+ { name: 'preventOverflow', options: { padding: 0 } }
63
+ ], (((_a = props.popperOptions) === null || _a === void 0 ? void 0 : _a.modifiers) || []), true) }) });
61
64
  if (props.render) {
62
65
  var render_1 = props.render;
63
66
  computedProps.render = function () {
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ export declare type VirtualScrollProps = {
3
+ /**
4
+ * Length of the items to virtualize.
5
+ */
6
+ itemsLength: number;
7
+ /**
8
+ * Single item render function, which gives index of the item (0 based) in the data array
9
+ * and expects to get the JSX of that element to render.
10
+ * Recommended to memoize the reference of the function.
11
+ */
12
+ itemRenderer: (index: number) => JSX.Element;
13
+ /**
14
+ * Number of items to be rendered at the start and the end.
15
+ * Not recommended to go lower than the visible items in viewport.
16
+ * @default 10
17
+ */
18
+ bufferSize?: number;
19
+ } & React.ComponentPropsWithRef<'div'>;
20
+ /**
21
+ * `VirtualScroll` component is used to render a huge amount of items in the DOM. It renders only the ones which are visible
22
+ * and the amount provided through `bufferSize` prop at the start and the end. Can be used inside other components like `Table`.
23
+ *
24
+ * It has two wrapper elements, so DOM will be changed. One is used for setting full expected height in the scrollable container
25
+ * and other is for transformation (translateY) to show the correct part of the list.
26
+ *
27
+ * Currently it works only with the direct vertically scrollable parent element. It does not work with body scroll.
28
+ * It supports only static (same) height rows virtualization. Expect some issues, if list consists of different height elements.
29
+ * @example
30
+ * const itemRenderer = React.useCallback(() => (
31
+ * <div key={index}>
32
+ * This is my item #{index}
33
+ * </div>
34
+ * ), [])
35
+ * <VirtualScroll
36
+ * itemsLength={1000}
37
+ * itemRenderer={itemRenderer}
38
+ * />
39
+ * @private
40
+ */
41
+ export declare const VirtualScroll: React.ForwardRefExoticComponent<Pick<VirtualScrollProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "itemsLength" | "itemRenderer" | "bufferSize"> & React.RefAttributes<HTMLDivElement>>;
42
+ export default VirtualScroll;
@@ -0,0 +1,168 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import { useResizeObserver } from '../hooks/useResizeObserver';
29
+ var getScrollableParent = function (element, ownerDocument) {
30
+ if (ownerDocument === void 0) { ownerDocument = document; }
31
+ if (!element || element === ownerDocument.body) {
32
+ return ownerDocument.body;
33
+ }
34
+ return isElementScrollable(element)
35
+ ? element
36
+ : getScrollableParent(element.parentElement, ownerDocument);
37
+ };
38
+ var isElementScrollable = function (element) {
39
+ return /(auto|scroll|overlay)/.test(getElementStyle(element, 'overflow') +
40
+ getElementStyle(element, 'overflow-y'));
41
+ };
42
+ var getElementStyle = function (element, prop) {
43
+ return getComputedStyle(element, null).getPropertyValue(prop);
44
+ };
45
+ var getElementHeight = function (element) {
46
+ var _a;
47
+ return (_a = element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height) !== null && _a !== void 0 ? _a : 0;
48
+ };
49
+ var getNumberOfNodesInHeight = function (childHeight, totalHeight) {
50
+ if (!childHeight) {
51
+ return 0;
52
+ }
53
+ return Math.floor(totalHeight / childHeight);
54
+ };
55
+ var getTranslateValue = function (childHeight, startIndex) {
56
+ return childHeight * startIndex;
57
+ };
58
+ var getVisibleNodeCount = function (childHeight, startIndex, childrenLength, scrollContainer) {
59
+ return Math.min(childrenLength - startIndex, getNumberOfNodesInHeight(childHeight, getElementHeight(scrollContainer)));
60
+ };
61
+ /**
62
+ * `VirtualScroll` component is used to render a huge amount of items in the DOM. It renders only the ones which are visible
63
+ * and the amount provided through `bufferSize` prop at the start and the end. Can be used inside other components like `Table`.
64
+ *
65
+ * It has two wrapper elements, so DOM will be changed. One is used for setting full expected height in the scrollable container
66
+ * and other is for transformation (translateY) to show the correct part of the list.
67
+ *
68
+ * Currently it works only with the direct vertically scrollable parent element. It does not work with body scroll.
69
+ * It supports only static (same) height rows virtualization. Expect some issues, if list consists of different height elements.
70
+ * @example
71
+ * const itemRenderer = React.useCallback(() => (
72
+ * <div key={index}>
73
+ * This is my item #{index}
74
+ * </div>
75
+ * ), [])
76
+ * <VirtualScroll
77
+ * itemsLength={1000}
78
+ * itemRenderer={itemRenderer}
79
+ * />
80
+ * @private
81
+ */
82
+ export var VirtualScroll = React.forwardRef(function (_a, ref) {
83
+ var itemsLength = _a.itemsLength, itemRenderer = _a.itemRenderer, _b = _a.bufferSize, bufferSize = _b === void 0 ? 10 : _b, style = _a.style, rest = __rest(_a, ["itemsLength", "itemRenderer", "bufferSize", "style"]);
84
+ var _c = React.useState(0), startNode = _c[0], setStartNode = _c[1];
85
+ var _d = React.useState(0), visibleNodeCount = _d[0], setVisibleNodeCount = _d[1];
86
+ var scrollContainer = React.useRef();
87
+ var parentRef = React.useRef(null);
88
+ var childHeight = React.useRef(0);
89
+ var onScrollRef = React.useRef();
90
+ // Used only to recalculate on resize
91
+ var _e = React.useState(0), scrollContainerHeight = _e[0], setScrollContainerHeight = _e[1];
92
+ var onResize = React.useCallback(function (_a) {
93
+ var height = _a.height;
94
+ setScrollContainerHeight(height);
95
+ }, []);
96
+ var resizeRef = useResizeObserver(onResize)[0];
97
+ // Find scrollable parent
98
+ // Needed only on init
99
+ React.useLayoutEffect(function () {
100
+ var _a;
101
+ var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
102
+ scrollContainer.current = scrollableParent;
103
+ resizeRef(scrollableParent);
104
+ }, [resizeRef]);
105
+ var visibleChildren = React.useMemo(function () {
106
+ var arr = [];
107
+ var endIndex = Math.min(itemsLength, startNode + visibleNodeCount + bufferSize * 2);
108
+ for (var i = startNode; i < endIndex; i++) {
109
+ arr.push(itemRenderer(i));
110
+ }
111
+ return arr;
112
+ }, [itemsLength, itemRenderer, bufferSize, startNode, visibleNodeCount]);
113
+ // Get child height when children available
114
+ React.useLayoutEffect(function () {
115
+ if (!parentRef.current || !visibleChildren.length) {
116
+ return;
117
+ }
118
+ var firstChild = parentRef.current.children.item(0);
119
+ childHeight.current = Number(getElementHeight(firstChild).toFixed(2));
120
+ }, [visibleChildren.length]);
121
+ var updateVirtualScroll = React.useCallback(function () {
122
+ var _a, _b;
123
+ var scrollableContainer = (_a = scrollContainer.current) !== null && _a !== void 0 ? _a : (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.scrollingElement;
124
+ if (!scrollableContainer) {
125
+ return;
126
+ }
127
+ var start = getNumberOfNodesInHeight(childHeight.current, scrollableContainer.scrollTop);
128
+ var startIndex = Math.max(0, start - bufferSize);
129
+ setStartNode(startIndex);
130
+ setVisibleNodeCount(getVisibleNodeCount(childHeight.current, start, itemsLength, scrollableContainer));
131
+ if (!parentRef.current) {
132
+ return;
133
+ }
134
+ parentRef.current.style.transform = "translateY(" + getTranslateValue(childHeight.current, startIndex) + "px)";
135
+ }, [bufferSize, itemsLength]);
136
+ var removeScrollListener = React.useCallback(function () {
137
+ var _a, _b;
138
+ if (!onScrollRef.current) {
139
+ return;
140
+ }
141
+ !scrollContainer.current ||
142
+ scrollContainer.current === ((_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.body)
143
+ ? (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.removeEventListener('scroll', onScrollRef.current)
144
+ : scrollContainer.current.removeEventListener('scroll', onScrollRef.current);
145
+ }, []);
146
+ // Add event listener to the scrollable container.
147
+ React.useLayoutEffect(function () {
148
+ var _a, _b;
149
+ removeScrollListener();
150
+ onScrollRef.current = updateVirtualScroll;
151
+ if (!scrollContainer.current ||
152
+ scrollContainer.current === ((_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.body)) {
153
+ (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.addEventListener('scroll', updateVirtualScroll);
154
+ }
155
+ else {
156
+ scrollContainer.current.addEventListener('scroll', updateVirtualScroll);
157
+ }
158
+ return removeScrollListener;
159
+ }, [updateVirtualScroll, removeScrollListener]);
160
+ React.useLayoutEffect(function () {
161
+ updateVirtualScroll();
162
+ }, [scrollContainerHeight, itemsLength, updateVirtualScroll]);
163
+ return (React.createElement("div", __assign({ style: __assign({ overflow: 'hidden', minHeight: itemsLength * childHeight.current, width: '100%' }, style), ref: ref }, rest),
164
+ React.createElement("div", { style: {
165
+ willChange: 'transform',
166
+ }, ref: parentRef }, visibleChildren)));
167
+ });
168
+ export default VirtualScroll;
@@ -4,3 +4,4 @@ export * from './InputContainer';
4
4
  export * from './icons';
5
5
  export * from './WithCSSTransition';
6
6
  export * from './MiddleTextTruncation';
7
+ export * from './VirtualScroll';
@@ -8,3 +8,4 @@ export * from './InputContainer';
8
8
  export * from './icons';
9
9
  export * from './WithCSSTransition';
10
10
  export * from './MiddleTextTruncation';
11
+ export * from './VirtualScroll';
@@ -41,11 +41,9 @@ export declare type PolymorphicComponentProps<T extends React.ElementType, Props
41
41
  export interface PolymorphicForwardRefComponent<T, OwnProps = Record<string, unknown>> extends React.ForwardRefExoticComponent<Merge<T extends React.ElementType ? React.ComponentPropsWithRef<T> : never, OwnProps & {
42
42
  as?: T;
43
43
  }>> {
44
- <As = T>(props: As extends '' ? {
45
- as: keyof JSX.IntrinsicElements;
46
- } : As extends React.ComponentType<infer P> ? Merge<P, OwnProps & {
44
+ <As = T>(props: As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & {
47
45
  as: As;
48
- }> : As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & {
46
+ }> : As extends React.ComponentType<infer P> ? Merge<P, OwnProps & {
49
47
  as: As;
50
48
  }> : never): React.ReactElement | null;
51
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "1.29.0",
3
+ "version": "1.30.0",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "main": "cjs/index.js",
@@ -40,7 +40,7 @@
40
40
  "build-storybook": "build-storybook"
41
41
  },
42
42
  "dependencies": {
43
- "@itwin/itwinui-css": "^0.44.0",
43
+ "@itwin/itwinui-css": "^0.45.0",
44
44
  "@itwin/itwinui-icons-react": "^1.5.0",
45
45
  "@itwin/itwinui-illustrations-react": "^1.0.1",
46
46
  "@tippyjs/react": "^4.2.5",
@@ -121,7 +121,8 @@
121
121
  "nth-check": "^2.0.1",
122
122
  "ansi-regex": "^5.0.1",
123
123
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
124
- "postcss": "8"
124
+ "postcss": "8",
125
+ "nanoid": "^3.1.31"
125
126
  },
126
127
  "husky": {
127
128
  "hooks": {