@itwin/itwinui-react 1.38.1 → 1.39.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 (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/cjs/core/Carousel/Carousel.js +21 -12
  3. package/cjs/core/Carousel/CarouselContext.d.ts +4 -2
  4. package/cjs/core/Carousel/CarouselDotsList.js +1 -0
  5. package/cjs/core/Carousel/CarouselNavigation.js +8 -10
  6. package/cjs/core/Carousel/CarouselSlide.js +3 -7
  7. package/cjs/core/Carousel/CarouselSlider.js +23 -28
  8. package/cjs/core/ColorPicker/ColorPickerContext.d.ts +2 -2
  9. package/cjs/core/ComboBox/ComboBox.js +9 -7
  10. package/cjs/core/ComboBox/ComboBoxDropdown.d.ts +5 -6
  11. package/cjs/core/ComboBox/ComboBoxInput.js +27 -9
  12. package/cjs/core/ComboBox/ComboBoxMenu.js +10 -2
  13. package/cjs/core/ComboBox/helpers.d.ts +1 -1
  14. package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
  15. package/cjs/core/Table/Table.js +32 -22
  16. package/cjs/core/Table/TablePaginator.js +1 -1
  17. package/cjs/core/Table/filters/tableFilters.d.ts +3 -3
  18. package/cjs/core/Table/hooks/useExpanderCell.js +11 -1
  19. package/cjs/core/Toast/Toaster.js +97 -18
  20. package/cjs/core/utils/components/Popover.d.ts +1 -18
  21. package/cjs/core/utils/components/WithCSSTransition.d.ts +1 -2
  22. package/cjs/core/utils/components/icons.d.ts +4 -4
  23. package/cjs/core/utils/hooks/useOverflow.js +4 -2
  24. package/cjs/core/utils/hooks/useTheme.d.ts +1 -1
  25. package/esm/core/Carousel/Carousel.js +21 -12
  26. package/esm/core/Carousel/CarouselContext.d.ts +4 -2
  27. package/esm/core/Carousel/CarouselDotsList.js +1 -0
  28. package/esm/core/Carousel/CarouselNavigation.js +8 -10
  29. package/esm/core/Carousel/CarouselSlide.js +3 -7
  30. package/esm/core/Carousel/CarouselSlider.js +24 -29
  31. package/esm/core/ColorPicker/ColorPickerContext.d.ts +2 -2
  32. package/esm/core/ComboBox/ComboBox.js +9 -7
  33. package/esm/core/ComboBox/ComboBoxDropdown.d.ts +5 -6
  34. package/esm/core/ComboBox/ComboBoxInput.js +27 -9
  35. package/esm/core/ComboBox/ComboBoxMenu.js +10 -2
  36. package/esm/core/ComboBox/helpers.d.ts +1 -1
  37. package/esm/core/DatePicker/DatePicker.d.ts +1 -1
  38. package/esm/core/Table/Table.js +32 -22
  39. package/esm/core/Table/TablePaginator.js +1 -1
  40. package/esm/core/Table/filters/tableFilters.d.ts +3 -3
  41. package/esm/core/Table/hooks/useExpanderCell.js +8 -1
  42. package/esm/core/Toast/Toaster.js +75 -19
  43. package/esm/core/utils/components/Popover.d.ts +1 -18
  44. package/esm/core/utils/components/WithCSSTransition.d.ts +1 -2
  45. package/esm/core/utils/components/icons.d.ts +4 -4
  46. package/esm/core/utils/hooks/useOverflow.js +4 -2
  47. package/esm/core/utils/hooks/useTheme.d.ts +1 -1
  48. package/package.json +24 -39
@@ -10,6 +10,65 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (_) try {
52
+ 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;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
13
72
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
73
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
74
  if (ar || !(i in from)) {
@@ -28,7 +87,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
87
  * See LICENSE.md in the project root for license terms and full copyright notice.
29
88
  *--------------------------------------------------------------------------------------------*/
30
89
  var react_1 = __importDefault(require("react"));
31
- var react_dom_1 = __importDefault(require("react-dom"));
90
+ var ReactDOM = __importStar(require("react-dom"));
32
91
  var utils_1 = require("../utils");
33
92
  var ToastWrapper_1 = require("./ToastWrapper");
34
93
  var TOASTS_CONTAINER_ID = 'iui-toasts-container';
@@ -45,21 +104,41 @@ var Toaster = /** @class */ (function () {
45
104
  this.isInitialized = false;
46
105
  // Create container on demand.
47
106
  // 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
- });
107
+ this.asyncInit = function () { return __awaiter(_this, void 0, void 0, function () {
108
+ var container, toastWrapper, _ReactDOM, _ReactDOMInternals, root;
109
+ var _a, _b;
110
+ return __generator(this, function (_c) {
111
+ if (this.isInitialized) {
112
+ return [2 /*return*/];
113
+ }
114
+ container = (_a = (0, utils_1.getContainer)(TOASTS_CONTAINER_ID)) !== null && _a !== void 0 ? _a : (_b = (0, utils_1.getDocument)()) === null || _b === void 0 ? void 0 : _b.body;
115
+ if (!container) {
116
+ return [2 /*return*/];
117
+ }
118
+ this.isInitialized = true;
119
+ toastWrapper = react_1.default.createElement(ToastWrapper_1.ToastWrapper, { ref: this.toastsRef });
120
+ _ReactDOM = ReactDOM;
121
+ // v18 mode
122
+ if (_ReactDOM.createRoot) {
123
+ _ReactDOMInternals = _ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
124
+ // suppress warning about importing createRoot from react-dom/client
125
+ if (_ReactDOMInternals) {
126
+ _ReactDOMInternals.usingClientEntryPoint = true;
127
+ }
128
+ root = _ReactDOM.createRoot(container);
129
+ root.render(toastWrapper);
130
+ // revert suppression, not to influence users app
131
+ if (_ReactDOMInternals) {
132
+ _ReactDOMInternals.usingClientEntryPoint = false;
133
+ }
134
+ }
135
+ else {
136
+ // v17 and before
137
+ ReactDOM.render(toastWrapper, container);
138
+ }
139
+ return [2 /*return*/];
140
+ });
141
+ }); };
63
142
  }
64
143
  /**
65
144
  * Set global Toaster settings for toasts order and placement.
@@ -73,7 +152,7 @@ var Toaster = /** @class */ (function () {
73
152
  ? 'ascending'
74
153
  : 'descending');
75
154
  this.settings = newSettings;
76
- this.asyncInit.then(function () {
155
+ this.asyncInit().then(function () {
77
156
  var _a, _b;
78
157
  (_a = _this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setPlacement((_b = _this.settings.placement) !== null && _b !== void 0 ? _b : 'top');
79
158
  });
@@ -110,7 +189,7 @@ var Toaster = /** @class */ (function () {
110
189
  };
111
190
  Toaster.prototype.updateView = function () {
112
191
  var _this = this;
113
- this.asyncInit.then(function () {
192
+ this.asyncInit().then(function () {
114
193
  var _a;
115
194
  (_a = _this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setToasts(_this.toasts);
116
195
  });
@@ -26,24 +26,7 @@ export declare type PopoverProps = {
26
26
  * with pre-configured props and plugins (e.g. lazy mounting, focus, etc).
27
27
  * @private
28
28
  */
29
- export declare const Popover: React.ForwardRefExoticComponent<Pick<{
30
- /**
31
- * Controlled flag for whether the popover is visible.
32
- */
33
- visible?: boolean | undefined;
34
- /**
35
- * Determines the events that cause the popover to show.
36
- * Should not be used when `visible` is set.
37
- * @see [tippy.js trigger prop](https://atomiks.github.io/tippyjs/v6/all-props/#trigger)
38
- */
39
- trigger?: string | undefined;
40
- /**
41
- * Placement of the popover content.
42
- * @default 'bottom-start'
43
- * @see [tippy.js placement prop](https://atomiks.github.io/tippyjs/v6/all-props/#placement).
44
- */
45
- placement?: import("@popperjs/core").Placement | undefined;
46
- } & Omit<TippyProps, "placement" | "trigger" | "visible">, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<unknown>>;
29
+ export declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverProps, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<unknown>>;
47
30
  /**
48
31
  * Plugin to hide Popover when either Esc key is pressed,
49
32
  * or when the content inside is not tabbable and Tab key is pressed.
@@ -1,7 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { CSSTransition } from 'react-transition-group';
3
2
  import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
4
- export declare const WithCSSTransition: (props: Partial<CSSTransition.CSSTransitionProps> & {
3
+ export declare const WithCSSTransition: (props: Partial<CSSTransitionProps<undefined>> & {
5
4
  children: JSX.Element;
6
5
  dimension?: "width" | "height" | undefined;
7
6
  }) => JSX.Element;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { CommonProps } from '../props';
3
3
  export declare const StatusIconMap: {
4
- negative: (args?: CommonProps | undefined) => JSX.Element;
5
- positive: (args?: CommonProps | undefined) => JSX.Element;
6
- warning: (args?: CommonProps | undefined) => JSX.Element;
7
- informational: (args?: CommonProps | undefined) => JSX.Element;
4
+ negative: (args?: CommonProps) => JSX.Element;
5
+ positive: (args?: CommonProps) => JSX.Element;
6
+ warning: (args?: CommonProps) => JSX.Element;
7
+ informational: (args?: CommonProps) => JSX.Element;
8
8
  };
@@ -78,8 +78,10 @@ var useOverflow = function (items, disabled, orientation) {
78
78
  var childrenSize = Array.from(containerRef.current.children).reduce(function (sum, child) { return sum + child["offset".concat(dimension)]; }, 0);
79
79
  var avgItemSize = childrenSize / visibleCount;
80
80
  var visibleItems = Math.floor(availableSize / avgItemSize);
81
- // Doubling the visible items to overflow the container. Just to be safe.
82
- setVisibleCount(Math.min(items.length, visibleItems * 2));
81
+ if (!isNaN(visibleItems)) {
82
+ // Doubling the visible items to overflow the container. Just to be safe.
83
+ setVisibleCount(Math.min(items.length, visibleItems * 2));
84
+ }
83
85
  }
84
86
  needsFullRerender.current = false;
85
87
  }, [containerSize, visibleCount, disabled, items.length, orientation]);
@@ -19,4 +19,4 @@ export declare type ThemeType = 'light' | 'dark' | 'os';
19
19
  * @param theme Light, dark, or based on OS setting.
20
20
  * @param themeOptions Options that override default theming behavior.
21
21
  */
22
- export declare const useTheme: (theme?: ThemeType | undefined, themeOptions?: ThemeOptions | undefined) => void;
22
+ export declare const useTheme: (theme?: ThemeType, themeOptions?: ThemeOptions) => void;
@@ -58,19 +58,24 @@ export var Carousel = Object.assign(React.forwardRef(function (props, ref) {
58
58
  var id = React.useState(function () { var _a; return (_a = props.id) !== null && _a !== void 0 ? _a : "iui-carousel-".concat(getRandomValue(10)); })[0];
59
59
  useTheme();
60
60
  var isManuallyUpdating = React.useRef(false);
61
- var scrollInstantly = React.useRef(false);
62
61
  var carouselRef = React.useRef(null);
63
62
  var refs = useMergedRefs(carouselRef, ref);
64
- var _b = React.useState(userActiveIndex), currentIndex = _b[0], _setCurrentIndex = _b[1];
63
+ var _b = React.useState(userActiveIndex), currentIndex = _b[0], setCurrentIndex = _b[1];
64
+ var scrollToSlide = React.useRef(function () { }); // stub function populated in CarouselSlider
65
+ var justMounted = React.useRef(true);
65
66
  React.useEffect(function () {
66
- _setCurrentIndex(userActiveIndex);
67
- }, [userActiveIndex]);
68
- var setCurrentIndex = React.useCallback(function (index) {
69
67
  var _a;
70
- _setCurrentIndex(index);
71
- isManuallyUpdating.current = true;
72
- (_a = carouselRef.current) === null || _a === void 0 ? void 0 : _a.focus();
73
- }, []);
68
+ setCurrentIndex(userActiveIndex);
69
+ scrollToSlide.current(userActiveIndex, {
70
+ instant: justMounted.current,
71
+ });
72
+ // re-focus the carousel for keyboard nav, but not on first mount
73
+ // because it shows outline and might interfere with other components
74
+ if (!justMounted.current) {
75
+ (_a = carouselRef.current) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
76
+ }
77
+ justMounted.current = false;
78
+ }, [userActiveIndex]);
74
79
  var _c = React.useState(0), slideCount = _c[0], setSlideCount = _c[1];
75
80
  var _d = React.useState({}), keysPressed = _d[0], setKeysPressed = _d[1];
76
81
  var handleKeyDown = function (event) {
@@ -88,12 +93,16 @@ export var Carousel = Object.assign(React.forwardRef(function (props, ref) {
88
93
  switch (event.key) {
89
94
  case 'ArrowLeft': {
90
95
  setKeysPressed(function (old) { return (__assign(__assign({}, old), { ArrowLeft: false })); });
91
- setCurrentIndex(function (old) { return (slideCount + old - 1) % slideCount; });
96
+ var prevIndex = (slideCount + currentIndex - 1) % slideCount;
97
+ scrollToSlide.current(prevIndex);
98
+ setCurrentIndex(prevIndex);
92
99
  break;
93
100
  }
94
101
  case 'ArrowRight': {
95
102
  setKeysPressed(function (old) { return (__assign(__assign({}, old), { ArrowRight: false })); });
96
- setCurrentIndex(function (old) { return (slideCount + old + 1) % slideCount; });
103
+ var nextIndex = (slideCount + currentIndex + 1) % slideCount;
104
+ scrollToSlide.current(nextIndex);
105
+ setCurrentIndex(nextIndex);
97
106
  break;
98
107
  }
99
108
  }
@@ -112,7 +121,7 @@ export var Carousel = Object.assign(React.forwardRef(function (props, ref) {
112
121
  keysPressed: keysPressed,
113
122
  idPrefix: id,
114
123
  isManuallyUpdating: isManuallyUpdating,
115
- scrollInstantly: scrollInstantly,
124
+ scrollToSlide: scrollToSlide,
116
125
  } }, children)));
117
126
  }), {
118
127
  Slider: CarouselSlider,
@@ -31,7 +31,9 @@ export declare const CarouselContext: React.Context<{
31
31
  */
32
32
  isManuallyUpdating: React.MutableRefObject<boolean>;
33
33
  /**
34
- * Ref object used to skip smooth scrolling when button is clicked too many times.
34
+ * Function that scrolls to the current slide. Should be called on all managed events (clicks and keydowns).
35
35
  */
36
- scrollInstantly: React.MutableRefObject<boolean>;
36
+ scrollToSlide: React.MutableRefObject<(slideIndex: number, options?: {
37
+ instant?: boolean;
38
+ }) => void>;
37
39
  } | undefined>;
@@ -63,6 +63,7 @@ export var CarouselDotsList = React.forwardRef(function (props, ref) {
63
63
  var handleSlideChange = React.useCallback(function (index) {
64
64
  if (context) {
65
65
  context.setCurrentIndex(index);
66
+ context.scrollToSlide.current(index);
66
67
  }
67
68
  onSlideChange === null || onSlideChange === void 0 ? void 0 : onSlideChange(index);
68
69
  }, [context, onSlideChange]);
@@ -37,13 +37,12 @@ var PreviousButton = React.forwardRef(function (props, ref) {
37
37
  if (!context) {
38
38
  throw new Error('CarouselNavigation should be used inside Carousel');
39
39
  }
40
- var slideCount = context.slideCount, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollInstantly = context.scrollInstantly;
40
+ var slideCount = context.slideCount, currentIndex = context.currentIndex, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollToSlide = context.scrollToSlide;
41
41
  return (React.createElement(IconButton, __assign({ styleType: 'borderless', size: 'small', tabIndex: -1, "data-pressed": keysPressed['ArrowLeft'] || undefined, ref: ref }, props, { onClick: function (e) {
42
42
  var _a;
43
- if (e.detail > 3) {
44
- scrollInstantly.current = true;
45
- }
46
- setCurrentIndex(function (old) { return (slideCount + old - 1) % slideCount; });
43
+ var prevIndex = (slideCount + currentIndex - 1) % slideCount;
44
+ setCurrentIndex(prevIndex);
45
+ scrollToSlide.current(prevIndex, { instant: e.detail > 3 });
47
46
  (_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
48
47
  } }),
49
48
  React.createElement(SvgChevronLeft, null)));
@@ -54,13 +53,12 @@ var NextButton = React.forwardRef(function (props, ref) {
54
53
  if (!context) {
55
54
  throw new Error('CarouselNavigation should be used inside Carousel');
56
55
  }
57
- var slideCount = context.slideCount, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollInstantly = context.scrollInstantly;
56
+ var slideCount = context.slideCount, currentIndex = context.currentIndex, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollToSlide = context.scrollToSlide;
58
57
  return (React.createElement(IconButton, __assign({ styleType: 'borderless', size: 'small', tabIndex: -1, "data-pressed": keysPressed['ArrowRight'] || undefined, ref: ref }, props, { onClick: function (e) {
59
58
  var _a;
60
- if (e.detail > 3) {
61
- scrollInstantly.current = true;
62
- }
63
- setCurrentIndex(function (old) { return (slideCount + old + 1) % slideCount; });
59
+ var nextIndex = (slideCount + currentIndex + 1) % slideCount;
60
+ setCurrentIndex(nextIndex);
61
+ scrollToSlide.current(nextIndex, { instant: e.detail > 3 });
64
62
  (_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
65
63
  } }),
66
64
  React.createElement(SvgChevronRight, null)));
@@ -40,17 +40,13 @@ export var CarouselSlide = React.forwardRef(function (props, ref) {
40
40
  if (!context || index == null) {
41
41
  throw new Error('CarouselSlide must be used within Carousel');
42
42
  }
43
- var currentIndex = context.currentIndex, isManuallyUpdating = context.isManuallyUpdating, setCurrentIndex = context.setCurrentIndex;
43
+ var isManuallyUpdating = context.isManuallyUpdating, setCurrentIndex = context.setCurrentIndex;
44
44
  var updateActiveIndexOnScroll = React.useCallback(function () {
45
45
  // only update index if scroll was triggered by browser
46
- if (!isManuallyUpdating.current && currentIndex !== index) {
46
+ if (!isManuallyUpdating.current) {
47
47
  setCurrentIndex(index);
48
48
  }
49
- // when manual scroll completes, reset the state of `isManuallyUpdating` so that it's ready for future actions
50
- if (currentIndex === index) {
51
- isManuallyUpdating.current = false;
52
- }
53
- }, [currentIndex, index, isManuallyUpdating, setCurrentIndex]);
49
+ }, [index, isManuallyUpdating, setCurrentIndex]);
54
50
  var intersectionRef = useIntersection(updateActiveIndexOnScroll, { threshold: 0.5 }, false);
55
51
  var refs = useMergedRefs(intersectionRef, ref);
56
52
  return (React.createElement("li", __assign({ className: cx('iui-carousel-slider-item', className), role: 'tabpanel', "aria-roledescription": 'slide', ref: refs }, rest), children));
@@ -27,7 +27,7 @@ var __rest = (this && this.__rest) || function (s, e) {
27
27
  import React from 'react';
28
28
  import cx from 'classnames';
29
29
  import { CarouselContext } from './CarouselContext';
30
- import { getWindow, useMergedRefs, useResizeObserver } from '../utils';
30
+ import { getWindow, useMergedRefs } from '../utils';
31
31
  /**
32
32
  * `CarouselSlider` is the scrollable list that should consist of `CarouselSlide` components.
33
33
  */
@@ -37,7 +37,7 @@ export var CarouselSlider = React.forwardRef(function (props, ref) {
37
37
  if (!context) {
38
38
  throw new Error('CarouselSlider must be used within Carousel');
39
39
  }
40
- var currentIndex = context.currentIndex, setSlideCount = context.setSlideCount, idPrefix = context.idPrefix, isManuallyUpdating = context.isManuallyUpdating, scrollInstantly = context.scrollInstantly;
40
+ var setSlideCount = context.setSlideCount, idPrefix = context.idPrefix, scrollToSlide = context.scrollToSlide, isManuallyUpdating = context.isManuallyUpdating;
41
41
  var items = React.useMemo(function () {
42
42
  var _a;
43
43
  return (_a = React.Children.map(children, function (child, index) {
@@ -52,37 +52,32 @@ export var CarouselSlider = React.forwardRef(function (props, ref) {
52
52
  React.useLayoutEffect(function () {
53
53
  setSlideCount(items.length);
54
54
  }, [items.length, setSlideCount]);
55
- var _a = React.useState(), width = _a[0], setWidth = _a[1];
56
- var resizeRef = useResizeObserver(function (_a) {
57
- var width = _a.width;
58
- return setWidth(width);
59
- })[0];
60
55
  var sliderRef = React.useRef(null);
61
- var refs = useMergedRefs(sliderRef, resizeRef, ref);
62
- var justMounted = React.useRef(true);
63
- var previousWidth = React.useRef();
64
- React.useLayoutEffect(function () {
65
- var _a, _b, _c;
66
- var slideToShow = (_a = sliderRef.current) === null || _a === void 0 ? void 0 : _a.children.item(currentIndex);
67
- if (!sliderRef.current ||
68
- !slideToShow ||
69
- (!isManuallyUpdating.current && previousWidth.current === width)) {
56
+ var refs = useMergedRefs(sliderRef, ref);
57
+ scrollToSlide.current = function (slideIndex, _a) {
58
+ var _b, _c, _d;
59
+ var _e = _a === void 0 ? {} : _a, instant = _e.instant;
60
+ isManuallyUpdating.current = true; // start manual update
61
+ var slideToShow = (_b = sliderRef.current) === null || _b === void 0 ? void 0 : _b.children.item(slideIndex);
62
+ if (!sliderRef.current || !slideToShow) {
70
63
  return;
71
64
  }
72
- // instant scroll on first mount
73
- if (justMounted.current) {
74
- scrollInstantly.current = true;
75
- justMounted.current = false;
76
- }
77
- var motionOk = (_c = (_b = getWindow()) === null || _b === void 0 ? void 0 : _b.matchMedia('(prefers-reduced-motion: no-preference)')) === null || _c === void 0 ? void 0 : _c.matches;
65
+ var motionOk = (_d = (_c = getWindow()) === null || _c === void 0 ? void 0 : _c.matchMedia('(prefers-reduced-motion: no-preference)')) === null || _d === void 0 ? void 0 : _d.matches;
78
66
  sliderRef.current.scrollTo({
79
67
  left: slideToShow.offsetLeft - sliderRef.current.offsetLeft,
80
- behavior: (scrollInstantly.current || !motionOk
81
- ? 'instant'
82
- : 'smooth'), // scrollTo accepts 'instant' but ScrollBehavior type is wrong
68
+ behavior: (instant || !motionOk ? 'instant' : 'smooth'), // scrollTo accepts 'instant' but ScrollBehavior type is wrong
83
69
  });
84
- scrollInstantly.current = false;
85
- previousWidth.current = width;
86
- }, [currentIndex, isManuallyUpdating, scrollInstantly, width]);
87
- return (React.createElement("ol", __assign({ "aria-live": 'polite', className: cx('iui-carousel-slider', className), ref: refs }, rest), items));
70
+ };
71
+ var scrollTimeout = React.useRef();
72
+ // reset isManuallyUpdating.current to false after the last scroll event
73
+ var handleOnScroll = React.useCallback(function () {
74
+ var _a, _b;
75
+ if (scrollTimeout.current) {
76
+ (_a = getWindow()) === null || _a === void 0 ? void 0 : _a.clearTimeout(scrollTimeout.current);
77
+ }
78
+ scrollTimeout.current = (_b = getWindow()) === null || _b === void 0 ? void 0 : _b.setTimeout(function () {
79
+ isManuallyUpdating.current = false;
80
+ }, 100);
81
+ }, [isManuallyUpdating]);
82
+ return (React.createElement("ol", __assign({ "aria-live": 'polite', className: cx('iui-carousel-slider', className), ref: refs, onScroll: handleOnScroll }, rest), items));
88
83
  });
@@ -5,7 +5,7 @@ export declare const ColorPickerContext: React.Context<{
5
5
  setActiveColor: (color: ColorValue | ((prevColor: ColorValue) => ColorValue)) => void;
6
6
  hsvColor: HsvColor;
7
7
  onChangeComplete?: ((color: ColorValue) => void) | undefined;
8
- applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean, newColorValue?: ColorValue | undefined) => void;
8
+ applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean, newColorValue?: ColorValue) => void;
9
9
  showAlpha: boolean;
10
10
  } | undefined>;
11
11
  export declare const useColorPickerContext: () => {
@@ -13,6 +13,6 @@ export declare const useColorPickerContext: () => {
13
13
  setActiveColor: (color: ColorValue | ((prevColor: ColorValue) => ColorValue)) => void;
14
14
  hsvColor: HsvColor;
15
15
  onChangeComplete?: ((color: ColorValue) => void) | undefined;
16
- applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean, newColorValue?: ColorValue | undefined) => void;
16
+ applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean, newColorValue?: ColorValue) => void;
17
17
  showAlpha: boolean;
18
18
  };
@@ -100,6 +100,7 @@ export var ComboBox = function (props) {
100
100
  if (isOpen) {
101
101
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); // Focus the input
102
102
  setFilteredOptions(options); // Reset the filtered list
103
+ dispatch(['focus']);
103
104
  }
104
105
  // When the dropdown closes
105
106
  else {
@@ -122,6 +123,7 @@ export var ComboBox = function (props) {
122
123
  var _g = React.useState(options), filteredOptions = _g[0], setFilteredOptions = _g[1];
123
124
  React.useEffect(function () {
124
125
  setFilteredOptions(options);
126
+ dispatch(['focus']);
125
127
  }, [options]);
126
128
  // Filter options based on input value
127
129
  var _h = React.useState((_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.value) !== null && _a !== void 0 ? _a : ''), inputValue = _h[0], setInputValue = _h[1];
@@ -133,12 +135,11 @@ export var ComboBox = function (props) {
133
135
  setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, value)) !== null && _a !== void 0 ? _a : options.filter(function (option) {
134
136
  return option.label.toLowerCase().includes(value.toLowerCase());
135
137
  }));
138
+ if (focusedIndex != -1) {
139
+ dispatch(['focus', -1]);
140
+ }
136
141
  (_b = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _b === void 0 ? void 0 : _b.call(inputProps, event);
137
- }, [filterFunction, inputProps, options]);
138
- // Reset focused item when filteredOptions change
139
- React.useEffect(function () {
140
- dispatch(['focus']);
141
- }, [filteredOptions]);
142
+ }, [filterFunction, focusedIndex, inputProps, options]);
142
143
  // When the value prop changes, update the selectedIndex
143
144
  React.useEffect(function () {
144
145
  dispatch([
@@ -157,7 +158,7 @@ export var ComboBox = function (props) {
157
158
  (_b = onChangeProp.current) === null || _b === void 0 ? void 0 : _b.call(onChangeProp, value);
158
159
  }
159
160
  }, [options, selectedIndex, valueProp]);
160
- var getMenuItem = React.useCallback(function (option) {
161
+ var getMenuItem = React.useCallback(function (option, filteredIndex) {
161
162
  var optionId = getOptionId(option, id);
162
163
  var __originalIndex = optionsExtraInfoRef.current[optionId].__originalIndex;
163
164
  var customItem = itemRenderer
@@ -180,12 +181,13 @@ export var ComboBox = function (props) {
180
181
  'iui-focused': focusedIndex === __originalIndex,
181
182
  }),
182
183
  'data-iui-index': __originalIndex,
184
+ 'data-iui-filtered-index': filteredIndex,
183
185
  ref: mergeRefs(customItem.props.ref, function (el) {
184
186
  if (!enableVirtualization && focusedIndex === __originalIndex) {
185
187
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
186
188
  }
187
189
  }),
188
- })) : (React.createElement(ComboBoxMenuItem, __assign({ key: optionId, id: optionId }, option, { isSelected: selectedIndex === __originalIndex, onClick: function () { return dispatch(['select', __originalIndex]); }, index: __originalIndex }), option.label));
190
+ })) : (React.createElement(ComboBoxMenuItem, __assign({ key: optionId, id: optionId }, option, { isSelected: selectedIndex === __originalIndex, onClick: function () { return dispatch(['select', __originalIndex]); }, index: __originalIndex, "data-iui-filtered-index": filteredIndex }), option.label));
189
191
  }, [enableVirtualization, focusedIndex, id, itemRenderer, selectedIndex]);
190
192
  return (React.createElement(ComboBoxRefsContext.Provider, { value: { inputRef: inputRef, menuRef: menuRef, toggleButtonRef: toggleButtonRef, optionsExtraInfoRef: optionsExtraInfoRef } },
191
193
  React.createElement(ComboBoxActionContext.Provider, { value: dispatch },
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
- export declare const ComboBoxDropdown: React.ForwardRefExoticComponent<Pick<{
3
- visible?: boolean | undefined;
4
- trigger?: string | undefined;
5
- placement?: import("@popperjs/core").Placement | undefined;
6
- } & Omit<import("@tippyjs/react").TippyProps, "placement" | "trigger" | "visible"> & {
2
+ import { PopoverProps } from '../utils';
3
+ declare type ComboBoxDropdownProps = PopoverProps & {
7
4
  children: JSX.Element;
8
- }, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<Element>>;
5
+ };
6
+ export declare const ComboBoxDropdown: React.ForwardRefExoticComponent<Pick<ComboBoxDropdownProps, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<Element>>;
7
+ export {};
@@ -30,7 +30,7 @@ import { useSafeContext, useMergedRefs } from '../utils';
30
30
  import { ComboBoxStateContext, ComboBoxActionContext, ComboBoxRefsContext, } from './helpers';
31
31
  export var ComboBoxInput = React.forwardRef(function (props, forwardedRef) {
32
32
  var onKeyDownProp = props.onKeyDown, onFocusProp = props.onFocus, rest = __rest(props, ["onKeyDown", "onFocus"]);
33
- var _a = useSafeContext(ComboBoxStateContext), isOpen = _a.isOpen, id = _a.id, focusedIndex = _a.focusedIndex;
33
+ var _a = useSafeContext(ComboBoxStateContext), isOpen = _a.isOpen, id = _a.id, focusedIndex = _a.focusedIndex, enableVirtualization = _a.enableVirtualization;
34
34
  var dispatch = useSafeContext(ComboBoxActionContext);
35
35
  var _b = useSafeContext(ComboBoxRefsContext), inputRef = _b.inputRef, menuRef = _b.menuRef, optionsExtraInfoRef = _b.optionsExtraInfoRef;
36
36
  var refs = useMergedRefs(inputRef, forwardedRef);
@@ -43,7 +43,7 @@ export var ComboBoxInput = React.forwardRef(function (props, forwardedRef) {
43
43
  return ((_c = (_b = (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("[data-iui-index=\"".concat(index, "\"]"))) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '');
44
44
  };
45
45
  var handleKeyDown = React.useCallback(function (event) {
46
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
46
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
47
47
  onKeyDownProp === null || onKeyDownProp === void 0 ? void 0 : onKeyDownProp(event);
48
48
  var length = (_a = Object.keys(optionsExtraInfoRef.current).length) !== null && _a !== void 0 ? _a : 0;
49
49
  switch (event.key) {
@@ -56,15 +56,21 @@ export var ComboBoxInput = React.forwardRef(function (props, forwardedRef) {
56
56
  return;
57
57
  }
58
58
  if (focusedIndexRef.current === -1) {
59
+ var currentElement = (_b = menuRef.current) === null || _b === void 0 ? void 0 : _b.querySelector('[data-iui-index]');
59
60
  return dispatch([
60
61
  'focus',
61
- (_c = (_b = Object.values(optionsExtraInfoRef.current)) === null || _b === void 0 ? void 0 : _b[0].__originalIndex) !== null && _c !== void 0 ? _c : -1,
62
+ Number((_c = currentElement === null || currentElement === void 0 ? void 0 : currentElement.getAttribute('data-iui-index')) !== null && _c !== void 0 ? _c : 0),
62
63
  ]);
63
64
  }
65
+ // If virtualization is enabled, dont let round scrolling
66
+ if (enableVirtualization &&
67
+ !((_e = (_d = menuRef.current) === null || _d === void 0 ? void 0 : _d.querySelector("[data-iui-index=\"".concat(focusedIndexRef.current, "\"]"))) === null || _e === void 0 ? void 0 : _e.nextElementSibling)) {
68
+ return;
69
+ }
64
70
  var nextIndex = focusedIndexRef.current;
65
71
  do {
66
- var currentElement = (_d = menuRef.current) === null || _d === void 0 ? void 0 : _d.querySelector("[data-iui-index=\"".concat(nextIndex, "\"]"));
67
- var nextElement = (_e = currentElement === null || currentElement === void 0 ? void 0 : currentElement.nextElementSibling) !== null && _e !== void 0 ? _e : (_f = menuRef.current) === null || _f === void 0 ? void 0 : _f.querySelector('[data-iui-index]');
72
+ var currentElement = (_f = menuRef.current) === null || _f === void 0 ? void 0 : _f.querySelector("[data-iui-index=\"".concat(nextIndex, "\"]"));
73
+ var nextElement = (_g = currentElement === null || currentElement === void 0 ? void 0 : currentElement.nextElementSibling) !== null && _g !== void 0 ? _g : (_h = menuRef.current) === null || _h === void 0 ? void 0 : _h.querySelector('[data-iui-index]');
68
74
  nextIndex = Number(nextElement === null || nextElement === void 0 ? void 0 : nextElement.getAttribute('data-iui-index'));
69
75
  if ((nextElement === null || nextElement === void 0 ? void 0 : nextElement.ariaDisabled) !== 'true') {
70
76
  return dispatch(['focus', nextIndex]);
@@ -80,16 +86,21 @@ export var ComboBoxInput = React.forwardRef(function (props, forwardedRef) {
80
86
  if (length === 0) {
81
87
  return;
82
88
  }
89
+ // If virtualization is enabled, dont let round scrolling
90
+ if (enableVirtualization &&
91
+ !((_k = (_j = menuRef.current) === null || _j === void 0 ? void 0 : _j.querySelector("[data-iui-index=\"".concat(focusedIndexRef.current, "\"]"))) === null || _k === void 0 ? void 0 : _k.previousElementSibling)) {
92
+ return;
93
+ }
83
94
  if (focusedIndexRef.current === -1) {
84
95
  return dispatch([
85
96
  'focus',
86
- (_h = (_g = Object.values(optionsExtraInfoRef.current)) === null || _g === void 0 ? void 0 : _g[length - 1].__originalIndex) !== null && _h !== void 0 ? _h : -1,
97
+ (_m = (_l = Object.values(optionsExtraInfoRef.current)) === null || _l === void 0 ? void 0 : _l[length - 1].__originalIndex) !== null && _m !== void 0 ? _m : -1,
87
98
  ]);
88
99
  }
89
100
  var prevIndex = focusedIndexRef.current;
90
101
  do {
91
- var currentElement = (_j = menuRef.current) === null || _j === void 0 ? void 0 : _j.querySelector("[data-iui-index=\"".concat(prevIndex, "\"]"));
92
- var prevElement = (_k = currentElement === null || currentElement === void 0 ? void 0 : currentElement.previousElementSibling) !== null && _k !== void 0 ? _k : (_l = menuRef.current) === null || _l === void 0 ? void 0 : _l.querySelector('[data-iui-index]:last-of-type');
102
+ var currentElement = (_o = menuRef.current) === null || _o === void 0 ? void 0 : _o.querySelector("[data-iui-index=\"".concat(prevIndex, "\"]"));
103
+ var prevElement = (_p = currentElement === null || currentElement === void 0 ? void 0 : currentElement.previousElementSibling) !== null && _p !== void 0 ? _p : (_q = menuRef.current) === null || _q === void 0 ? void 0 : _q.querySelector('[data-iui-index]:last-of-type');
93
104
  prevIndex = Number(prevElement === null || prevElement === void 0 ? void 0 : prevElement.getAttribute('data-iui-index'));
94
105
  if ((prevElement === null || prevElement === void 0 ? void 0 : prevElement.ariaDisabled) !== 'true') {
95
106
  return dispatch(['focus', prevIndex]);
@@ -116,7 +127,14 @@ export var ComboBoxInput = React.forwardRef(function (props, forwardedRef) {
116
127
  dispatch(['close']);
117
128
  break;
118
129
  }
119
- }, [dispatch, isOpen, menuRef, onKeyDownProp, optionsExtraInfoRef]);
130
+ }, [
131
+ dispatch,
132
+ enableVirtualization,
133
+ isOpen,
134
+ menuRef,
135
+ onKeyDownProp,
136
+ optionsExtraInfoRef,
137
+ ]);
120
138
  var handleFocus = React.useCallback(function (event) {
121
139
  dispatch(['open']);
122
140
  onFocusProp === null || onFocusProp === void 0 ? void 0 : onFocusProp(event);