@itwin/itwinui-react 1.38.0 → 1.38.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ### [1.38.1](https://www.github.com/iTwin/iTwinUI-react/compare/v1.38.0...v1.38.1) (2022-05-23)
4
+
5
+ ### Fixes
6
+
7
+ * **Toaster:** Fix initial position setting ([#687](https://www.github.com/iTwin/iTwinUI-react/issues/687)) ([c58b747](https://www.github.com/iTwin/iTwinUI-react/commit/c58b74786bf90a165993afb2eec926f74b37a1eb))
8
+
3
9
  ## [1.38.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.37.3...v1.38.0) (2022-05-23)
4
10
 
5
11
  ### What's new
@@ -51,6 +51,13 @@ export declare type ComboBoxProps<T> = {
51
51
  id: string;
52
52
  index: number;
53
53
  }) => JSX.Element;
54
+ /**
55
+ * If enabled, virtualization is used for the scrollable dropdown list.
56
+ * Use it if you expect a very long list of items.
57
+ * @default false
58
+ * @beta
59
+ */
60
+ enableVirtualization?: boolean;
54
61
  } & Pick<InputContainerProps, 'status'> & Omit<CommonProps, 'title'>;
55
62
  /**
56
63
  * ComboBox component that allows typing a value to filter the options in dropdown list.
@@ -63,7 +63,7 @@ var getOptionId = function (option, idPrefix) {
63
63
  */
64
64
  var ComboBox = function (props) {
65
65
  var _a;
66
- var options = props.options, valueProp = props.value, onChange = props.onChange, filterFunction = props.filterFunction, inputProps = props.inputProps, dropdownMenuProps = props.dropdownMenuProps, _b = props.emptyStateMessage, emptyStateMessage = _b === void 0 ? 'No options found' : _b, itemRenderer = props.itemRenderer, rest = __rest(props, ["options", "value", "onChange", "filterFunction", "inputProps", "dropdownMenuProps", "emptyStateMessage", "itemRenderer"]);
66
+ var options = props.options, valueProp = props.value, onChange = props.onChange, filterFunction = props.filterFunction, inputProps = props.inputProps, dropdownMenuProps = props.dropdownMenuProps, _b = props.emptyStateMessage, emptyStateMessage = _b === void 0 ? 'No options found' : _b, itemRenderer = props.itemRenderer, _c = props.enableVirtualization, enableVirtualization = _c === void 0 ? false : _c, rest = __rest(props, ["options", "value", "onChange", "filterFunction", "inputProps", "dropdownMenuProps", "emptyStateMessage", "itemRenderer", "enableVirtualization"]);
67
67
  // Generate a stateful random id if not specified
68
68
  var id = react_1.default.useState(function () {
69
69
  var _a, _b;
@@ -95,11 +95,11 @@ var ComboBox = function (props) {
95
95
  });
96
96
  }
97
97
  // Reducer where all the component-wide state is stored
98
- var _c = react_1.default.useReducer(helpers_1.comboBoxReducer, {
98
+ var _d = react_1.default.useReducer(helpers_1.comboBoxReducer, {
99
99
  isOpen: false,
100
100
  selectedIndex: -1,
101
101
  focusedIndex: -1,
102
- }), _d = _c[0], isOpen = _d.isOpen, selectedIndex = _d.selectedIndex, focusedIndex = _d.focusedIndex, dispatch = _c[1];
102
+ }), _e = _d[0], isOpen = _e.isOpen, selectedIndex = _e.selectedIndex, focusedIndex = _e.focusedIndex, dispatch = _d[1];
103
103
  react_1.default.useEffect(function () {
104
104
  var _a, _b;
105
105
  // When the dropdown opens
@@ -118,19 +118,19 @@ var ComboBox = function (props) {
118
118
  }
119
119
  }, [isOpen, options, selectedIndex]);
120
120
  // Set min-width of menu to be same as input
121
- var _e = react_1.default.useState(0), minWidth = _e[0], setMinWidth = _e[1];
121
+ var _f = react_1.default.useState(0), minWidth = _f[0], setMinWidth = _f[1];
122
122
  react_1.default.useEffect(function () {
123
123
  if (inputRef.current) {
124
124
  setMinWidth(inputRef.current.offsetWidth);
125
125
  }
126
126
  }, [isOpen]);
127
127
  // Initialize filtered options to the latest value options
128
- var _f = react_1.default.useState(options), filteredOptions = _f[0], setFilteredOptions = _f[1];
128
+ var _g = react_1.default.useState(options), filteredOptions = _g[0], setFilteredOptions = _g[1];
129
129
  react_1.default.useEffect(function () {
130
130
  setFilteredOptions(options);
131
131
  }, [options]);
132
132
  // Filter options based on input value
133
- var _g = react_1.default.useState((_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.value) !== null && _a !== void 0 ? _a : ''), inputValue = _g[0], setInputValue = _g[1];
133
+ var _h = react_1.default.useState((_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.value) !== null && _a !== void 0 ? _a : ''), inputValue = _h[0], setInputValue = _h[1];
134
134
  var handleOnInput = react_1.default.useCallback(function (event) {
135
135
  var _a, _b;
136
136
  var value = event.currentTarget.value;
@@ -187,21 +187,28 @@ var ComboBox = function (props) {
187
187
  }),
188
188
  'data-iui-index': __originalIndex,
189
189
  ref: (0, utils_1.mergeRefs)(customItem.props.ref, function (el) {
190
- // will need to check for virtualization here too
191
- if (focusedIndex === __originalIndex) {
190
+ if (!enableVirtualization && focusedIndex === __originalIndex) {
192
191
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
193
192
  }
194
193
  }),
195
194
  })) : (react_1.default.createElement(ComboBoxMenuItem_1.ComboBoxMenuItem, __assign({ key: optionId, id: optionId }, option, { isSelected: selectedIndex === __originalIndex, onClick: function () { return dispatch(['select', __originalIndex]); }, index: __originalIndex }), option.label));
196
- }, [focusedIndex, id, itemRenderer, selectedIndex]);
195
+ }, [enableVirtualization, focusedIndex, id, itemRenderer, selectedIndex]);
197
196
  return (react_1.default.createElement(helpers_1.ComboBoxRefsContext.Provider, { value: { inputRef: inputRef, menuRef: menuRef, toggleButtonRef: toggleButtonRef, optionsExtraInfoRef: optionsExtraInfoRef } },
198
197
  react_1.default.createElement(helpers_1.ComboBoxActionContext.Provider, { value: dispatch },
199
- react_1.default.createElement(helpers_1.ComboBoxStateContext.Provider, { value: { id: id, minWidth: minWidth, isOpen: isOpen, focusedIndex: focusedIndex } },
198
+ react_1.default.createElement(helpers_1.ComboBoxStateContext.Provider, { value: {
199
+ id: id,
200
+ minWidth: minWidth,
201
+ isOpen: isOpen,
202
+ focusedIndex: focusedIndex,
203
+ enableVirtualization: enableVirtualization,
204
+ filteredOptions: filteredOptions,
205
+ getMenuItem: getMenuItem,
206
+ } },
200
207
  react_1.default.createElement(ComboBoxInputContainer_1.ComboBoxInputContainer, __assign({ disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled }, rest),
201
208
  react_1.default.createElement(ComboBoxInput_1.ComboBoxInput, __assign({ value: inputValue }, inputProps, { onChange: handleOnInput })),
202
209
  react_1.default.createElement(ComboBoxEndIcon_1.ComboBoxEndIcon, { disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled, isOpen: isOpen })),
203
210
  react_1.default.createElement(ComboBoxDropdown_1.ComboBoxDropdown, __assign({}, dropdownMenuProps),
204
- react_1.default.createElement(ComboBoxMenu_1.ComboBoxMenu, null, filteredOptions.length > 0 ? (filteredOptions.map(getMenuItem)) : (react_1.default.createElement(Menu_1.MenuExtraContent, null,
211
+ react_1.default.createElement(ComboBoxMenu_1.ComboBoxMenu, null, filteredOptions.length > 0 && !enableVirtualization ? (filteredOptions.map(getMenuItem)) : (react_1.default.createElement(Menu_1.MenuExtraContent, null,
205
212
  react_1.default.createElement(Typography_1.Text, { isMuted: true }, emptyStateMessage)))))))));
206
213
  };
207
214
  exports.ComboBox = ComboBox;
@@ -33,13 +33,49 @@ exports.ComboBoxMenu = void 0;
33
33
  var classnames_1 = __importDefault(require("classnames"));
34
34
  var react_1 = __importDefault(require("react"));
35
35
  var Menu_1 = require("../Menu");
36
+ var Surface_1 = require("../Surface");
36
37
  var utils_1 = require("../utils");
37
38
  var helpers_1 = require("./helpers");
39
+ var VirtualizedComboBoxMenu = react_1.default.forwardRef(function (_a, forwardedRef) {
40
+ var _b, _c, _d;
41
+ var children = _a.children, style = _a.style, rest = __rest(_a, ["children", "style"]);
42
+ var _e = (0, utils_1.useSafeContext)(helpers_1.ComboBoxStateContext), minWidth = _e.minWidth, id = _e.id, filteredOptions = _e.filteredOptions, getMenuItem = _e.getMenuItem, focusedIndex = _e.focusedIndex;
43
+ var menuRef = (0, utils_1.useSafeContext)(helpers_1.ComboBoxRefsContext).menuRef;
44
+ var virtualItemRenderer = react_1.default.useCallback(function (index) {
45
+ return filteredOptions.length > 0
46
+ ? getMenuItem(filteredOptions[index])
47
+ : children;
48
+ }, // Here is expected empty state content
49
+ [filteredOptions, getMenuItem, children]);
50
+ var _f = (0, utils_1.useVirtualization)({
51
+ // 'Fool' VirtualScroll by passing length 1
52
+ // whenever there is no elements, to show empty state message
53
+ itemsLength: filteredOptions.length || 1,
54
+ itemRenderer: virtualItemRenderer,
55
+ scrollToIndex: focusedIndex,
56
+ }), outerProps = _f.outerProps, innerProps = _f.innerProps, visibleChildren = _f.visibleChildren;
57
+ var overflowY = ((_d = (_c = (_b = (0, utils_1.getWindow)()) === null || _b === void 0 ? void 0 : _b.CSS) === null || _c === void 0 ? void 0 : _c.supports) === null || _d === void 0 ? void 0 : _d.call(_c, 'overflow-x: overlay'))
58
+ ? { overflowY: 'overlay' }
59
+ : { overflowY: 'auto' };
60
+ var styles = react_1.default.useMemo(function () { return ({
61
+ minWidth: minWidth,
62
+ maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"),
63
+ maxHeight: 315,
64
+ }); }, [minWidth]);
65
+ return (react_1.default.createElement(Surface_1.Surface, __assign({ elevation: 1, style: __assign(__assign(__assign({}, styles), overflowY), style) }, rest),
66
+ react_1.default.createElement("div", __assign({}, outerProps),
67
+ react_1.default.createElement(Menu_1.Menu, { id: "".concat(id, "-list"), setFocus: false, role: 'listbox', ref: (0, utils_1.mergeRefs)(menuRef, innerProps.ref, forwardedRef), style: innerProps.style }, visibleChildren))));
68
+ });
38
69
  exports.ComboBoxMenu = react_1.default.forwardRef(function (props, forwardedRef) {
39
70
  var className = props.className, style = props.style, rest = __rest(props, ["className", "style"]);
40
- var _a = (0, utils_1.useSafeContext)(helpers_1.ComboBoxStateContext), minWidth = _a.minWidth, id = _a.id;
71
+ var _a = (0, utils_1.useSafeContext)(helpers_1.ComboBoxStateContext), minWidth = _a.minWidth, id = _a.id, enableVirtualization = _a.enableVirtualization;
41
72
  var menuRef = (0, utils_1.useSafeContext)(helpers_1.ComboBoxRefsContext).menuRef;
42
73
  var refs = (0, utils_1.useMergedRefs)(menuRef, forwardedRef);
43
- return (react_1.default.createElement(Menu_1.Menu, __assign({ id: "".concat(id, "-list"), style: react_1.default.useMemo(function () { return (__assign({ minWidth: minWidth, maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"), maxHeight: 300 }, style)); }, [minWidth, style]), setFocus: false, role: 'listbox', ref: refs, className: (0, classnames_1.default)('iui-scroll', className) }, rest)));
74
+ var styles = react_1.default.useMemo(function () { return ({
75
+ minWidth: minWidth,
76
+ maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"),
77
+ maxHeight: 315,
78
+ }); }, [minWidth]);
79
+ return (react_1.default.createElement(react_1.default.Fragment, null, !enableVirtualization ? (react_1.default.createElement(Menu_1.Menu, __assign({ id: "".concat(id, "-list"), style: __assign(__assign({}, styles), style), setFocus: false, role: 'listbox', ref: refs, className: (0, classnames_1.default)('iui-scroll', className) }, rest))) : (react_1.default.createElement(VirtualizedComboBoxMenu, __assign({ ref: forwardedRef }, props)))));
44
80
  });
45
81
  exports.ComboBoxMenu.displayName = 'ComboBoxMenu';
@@ -36,10 +36,9 @@ var utils_1 = require("../utils");
36
36
  var helpers_1 = require("./helpers");
37
37
  exports.ComboBoxMenuItem = react_1.default.memo(react_1.default.forwardRef(function (props, forwardedRef) {
38
38
  var children = props.children, isSelected = props.isSelected, disabled = props.disabled, value = props.value, onClick = props.onClick, sublabel = props.sublabel, _a = props.size, size = _a === void 0 ? !!sublabel ? 'large' : 'default' : _a, icon = props.icon, badge = props.badge, className = props.className, _b = props.role, role = _b === void 0 ? 'menuitem' : _b, index = props.index, rest = __rest(props, ["children", "isSelected", "disabled", "value", "onClick", "sublabel", "size", "icon", "badge", "className", "role", "index"]);
39
- var focusedIndex = (0, utils_1.useSafeContext)(helpers_1.ComboBoxStateContext).focusedIndex;
39
+ var _c = (0, utils_1.useSafeContext)(helpers_1.ComboBoxStateContext), focusedIndex = _c.focusedIndex, enableVirtualization = _c.enableVirtualization;
40
40
  var focusRef = function (el) {
41
- // will need to check for virtualization here too
42
- if (focusedIndex === index) {
41
+ if (!enableVirtualization && focusedIndex === index) {
43
42
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
44
43
  }
45
44
  };
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { SelectOption } from '../Select/Select';
2
3
  declare type ComboBoxAction = 'open' | 'close' | 'select' | 'focus';
3
4
  export declare const comboBoxReducer: (state: {
4
5
  isOpen: boolean;
@@ -17,11 +18,15 @@ export declare const ComboBoxRefsContext: React.Context<{
17
18
  __originalIndex: number;
18
19
  }>>;
19
20
  } | undefined>;
20
- export declare const ComboBoxStateContext: React.Context<{
21
+ declare type ComboBoxStateContextProps<T = unknown> = {
21
22
  isOpen: boolean;
22
23
  id: string;
23
24
  minWidth: number;
24
- focusedIndex?: number | undefined;
25
- } | undefined>;
25
+ enableVirtualization: boolean;
26
+ filteredOptions: SelectOption<T>[];
27
+ getMenuItem: (option: SelectOption<T>) => JSX.Element;
28
+ focusedIndex?: number;
29
+ };
30
+ export declare const ComboBoxStateContext: React.Context<ComboBoxStateContextProps<unknown> | undefined>;
26
31
  export declare const ComboBoxActionContext: React.Context<((x: [ComboBoxAction] | [ComboBoxAction, number]) => void) | undefined>;
27
32
  export {};
@@ -146,7 +146,7 @@ var Select = function (props) {
146
146
  return options.find(function (option) { return option.value === value; });
147
147
  }, [options, value]);
148
148
  return (react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)('iui-input-with-icon', className), "aria-expanded": isOpen, "aria-haspopup": 'listbox', style: style }, rest),
149
- react_1.default.createElement(DropdownMenu_1.DropdownMenu, __assign({ menuItems: menuItems, placement: 'bottom-start', className: (0, classnames_1.default)('iui-scroll', menuClassName), style: __assign({ minWidth: minWidth, maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"), maxHeight: "300px" }, menuStyle), role: 'listbox', onShow: onShowHandler, onHide: onHideHandler, disabled: disabled }, popoverProps, { visible: isOpen, onClickOutside: function (_, _a) {
149
+ react_1.default.createElement(DropdownMenu_1.DropdownMenu, __assign({ menuItems: menuItems, placement: 'bottom-start', className: (0, classnames_1.default)('iui-scroll', menuClassName), style: __assign({ minWidth: minWidth, maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"), maxHeight: 315 }, menuStyle), role: 'listbox', onShow: onShowHandler, onHide: onHideHandler, disabled: disabled }, popoverProps, { visible: isOpen, onClickOutside: function (_, _a) {
150
150
  var _b;
151
151
  var target = _a.target;
152
152
  if (!((_b = toggleButtonRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
@@ -22,6 +22,7 @@ export default class Toaster {
22
22
  private settings;
23
23
  private toastsRef;
24
24
  private isInitialized;
25
+ private asyncInit;
25
26
  /**
26
27
  * Set global Toaster settings for toasts order and placement.
27
28
  * Settings will be applied to new toasts on the page.
@@ -41,7 +42,6 @@ export default class Toaster {
41
42
  };
42
43
  private createToast;
43
44
  private removeToast;
44
- private createContainer;
45
45
  private updateView;
46
46
  private closeToast;
47
47
  closeAll(): void;
@@ -10,42 +10,6 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
13
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
14
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
15
  if (ar || !(i in from)) {
@@ -70,6 +34,7 @@ var ToastWrapper_1 = require("./ToastWrapper");
70
34
  var TOASTS_CONTAINER_ID = 'iui-toasts-container';
71
35
  var Toaster = /** @class */ (function () {
72
36
  function Toaster() {
37
+ var _this = this;
73
38
  this.toasts = [];
74
39
  this.lastId = 0;
75
40
  this.settings = {
@@ -78,19 +43,40 @@ var Toaster = /** @class */ (function () {
78
43
  };
79
44
  this.toastsRef = react_1.default.createRef();
80
45
  this.isInitialized = false;
46
+ // Create container on demand.
47
+ // Cannot do it in constructor, because SSG/SSR apps would fail.
48
+ this.asyncInit = new Promise(function (resolve) {
49
+ if (_this.isInitialized) {
50
+ resolve();
51
+ return;
52
+ }
53
+ var container = (0, utils_1.getContainer)(TOASTS_CONTAINER_ID);
54
+ if (!container) {
55
+ // should never happen
56
+ resolve();
57
+ return;
58
+ }
59
+ _this.isInitialized = true;
60
+ react_dom_1.default.render(react_1.default.createElement(ToastWrapper_1.ToastWrapper, { ref: _this.toastsRef }), container);
61
+ resolve();
62
+ });
81
63
  }
82
64
  /**
83
65
  * Set global Toaster settings for toasts order and placement.
84
66
  * Settings will be applied to new toasts on the page.
85
67
  */
86
68
  Toaster.prototype.setSettings = function (newSettings) {
87
- var _a, _b, _c, _d, _e;
69
+ var _this = this;
70
+ var _a, _b, _c;
88
71
  (_a = newSettings.placement) !== null && _a !== void 0 ? _a : (newSettings.placement = this.settings.placement);
89
72
  (_b = newSettings.order) !== null && _b !== void 0 ? _b : (newSettings.order = ((_c = newSettings.placement) === null || _c === void 0 ? void 0 : _c.startsWith('bottom'))
90
73
  ? 'ascending'
91
74
  : 'descending');
92
75
  this.settings = newSettings;
93
- (_d = this.toastsRef.current) === null || _d === void 0 ? void 0 : _d.setPlacement((_e = this.settings.placement) !== null && _e !== void 0 ? _e : 'top');
76
+ this.asyncInit.then(function () {
77
+ var _a, _b;
78
+ (_a = _this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setPlacement((_b = _this.settings.placement) !== null && _b !== void 0 ? _b : 'top');
79
+ });
94
80
  };
95
81
  Toaster.prototype.positive = function (content, options) {
96
82
  return this.createToast(content, 'positive', options);
@@ -122,34 +108,12 @@ var Toaster = /** @class */ (function () {
122
108
  this.toasts = this.toasts.filter(function (toast) { return toast.id !== id; });
123
109
  this.updateView();
124
110
  };
125
- // Create container on demand.
126
- // Cannot do it in constructor, because SSG/SSR apps would fail.
127
- Toaster.prototype.createContainer = function () {
128
- return __awaiter(this, void 0, void 0, function () {
129
- var container;
130
- return __generator(this, function (_a) {
131
- container = (0, utils_1.getContainer)(TOASTS_CONTAINER_ID);
132
- if (!container) {
133
- return [2 /*return*/];
134
- }
135
- react_dom_1.default.render(react_1.default.createElement(ToastWrapper_1.ToastWrapper, { ref: this.toastsRef }), container);
136
- return [2 /*return*/];
137
- });
138
- });
139
- };
140
111
  Toaster.prototype.updateView = function () {
141
112
  var _this = this;
142
- var _a;
143
- if (!this.isInitialized) {
144
- this.createContainer().then(function () {
145
- var _a;
146
- _this.isInitialized = true;
147
- (_a = _this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setToasts(_this.toasts);
148
- });
149
- }
150
- else {
151
- (_a = this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setToasts(this.toasts);
152
- }
113
+ this.asyncInit.then(function () {
114
+ var _a;
115
+ (_a = _this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setToasts(_this.toasts);
116
+ });
153
117
  };
154
118
  Toaster.prototype.closeToast = function (toastId) {
155
119
  this.toasts = this.toasts.map(function (toast) {
@@ -16,6 +16,10 @@ export declare type VirtualScrollProps = {
16
16
  * @default 10
17
17
  */
18
18
  bufferSize?: number;
19
+ /**
20
+ * Index of the first element on initial render.
21
+ */
22
+ scrollToIndex?: number;
19
23
  } & React.ComponentPropsWithRef<'div'>;
20
24
  /**
21
25
  * `VirtualScroll` component is used to render a huge amount of items in the DOM. It renders only the ones which are visible
@@ -38,5 +42,35 @@ export declare type VirtualScrollProps = {
38
42
  * />
39
43
  * @private
40
44
  */
41
- export declare const VirtualScroll: React.ForwardRefExoticComponent<Pick<VirtualScrollProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "itemsLength" | "itemRenderer" | "bufferSize"> & React.RefAttributes<HTMLDivElement>>;
45
+ export declare const VirtualScroll: React.ForwardRefExoticComponent<Pick<VirtualScrollProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "itemsLength" | "itemRenderer" | "bufferSize" | "scrollToIndex"> & React.RefAttributes<HTMLDivElement>>;
46
+ /**
47
+ * `useVirtualization` is used for efficiently rendering only the visible rows from a large list.
48
+ * It returns `outerProps` and `innerProps`, which need to be applied on 2 container elements and `visibleChildren` which is a list of virtualized items.
49
+ * @example
50
+ * const itemRenderer = React.useCallback((index: number) => (
51
+ * <li key={index}>
52
+ * This is my item #{index}
53
+ * </li>
54
+ * ), [])
55
+ *
56
+ * const { outerProps, innerProps, visibleChildren } = useVirtualization({itemsLength: 1000, itemRenderer: itemRenderer});
57
+ * return (
58
+ * <div {...outerProps}>
59
+ * <ul {...innerProps}>
60
+ * {visibleChildren}
61
+ * </ul>
62
+ * </div>
63
+ * );
64
+ * @private
65
+ */
66
+ export declare const useVirtualization: (props: VirtualScrollProps) => {
67
+ outerProps: React.HTMLAttributes<HTMLElement>;
68
+ innerProps: {
69
+ readonly style: {
70
+ readonly willChange: "transform";
71
+ };
72
+ readonly ref: (instance: HTMLElement | null) => void;
73
+ };
74
+ visibleChildren: JSX.Element[];
75
+ };
42
76
  export default VirtualScroll;