@itwin/itwinui-react 1.34.0 → 1.35.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 (74) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/cjs/core/ButtonGroup/ButtonGroup.js +1 -0
  3. package/cjs/core/Carousel/Carousel.d.ts +68 -0
  4. package/cjs/core/Carousel/Carousel.js +130 -0
  5. package/cjs/core/Carousel/CarouselContext.d.ts +37 -0
  6. package/cjs/core/Carousel/CarouselContext.js +12 -0
  7. package/cjs/core/Carousel/CarouselDot.d.ts +13 -0
  8. package/cjs/core/Carousel/CarouselDot.js +46 -0
  9. package/cjs/core/Carousel/CarouselDotsList.d.ts +32 -0
  10. package/cjs/core/Carousel/CarouselDotsList.js +132 -0
  11. package/cjs/core/Carousel/CarouselNavigation.d.ts +15 -0
  12. package/cjs/core/Carousel/CarouselNavigation.js +88 -0
  13. package/cjs/core/Carousel/CarouselSlide.d.ts +14 -0
  14. package/cjs/core/Carousel/CarouselSlide.js +63 -0
  15. package/cjs/core/Carousel/CarouselSlider.d.ts +5 -0
  16. package/cjs/core/Carousel/CarouselSlider.js +94 -0
  17. package/cjs/core/Carousel/index.d.ts +4 -0
  18. package/cjs/core/Carousel/index.js +10 -0
  19. package/cjs/core/ComboBox/ComboBox.js +2 -2
  20. package/cjs/core/DatePicker/DatePicker.d.ts +5 -0
  21. package/cjs/core/DatePicker/DatePicker.js +38 -13
  22. package/cjs/core/Modal/Modal.d.ts +5 -0
  23. package/cjs/core/Modal/Modal.js +11 -9
  24. package/cjs/core/Modal/ModalContent.d.ts +14 -0
  25. package/cjs/core/Modal/ModalContent.js +46 -0
  26. package/cjs/core/Modal/index.d.ts +2 -0
  27. package/cjs/core/Modal/index.js +3 -1
  28. package/cjs/core/Table/Table.js +8 -7
  29. package/cjs/core/Table/filters/DateRangeFilter/DateRangeFilter.js +18 -2
  30. package/cjs/core/index.d.ts +4 -2
  31. package/cjs/core/index.js +6 -2
  32. package/cjs/core/utils/hooks/index.d.ts +1 -0
  33. package/cjs/core/utils/hooks/index.js +1 -0
  34. package/cjs/core/utils/hooks/useMediaQuery.d.ts +2 -0
  35. package/cjs/core/utils/hooks/useMediaQuery.js +46 -0
  36. package/cjs/core/utils/hooks/useTheme.d.ts +5 -0
  37. package/cjs/core/utils/hooks/useTheme.js +20 -14
  38. package/esm/core/ButtonGroup/ButtonGroup.js +1 -0
  39. package/esm/core/Carousel/Carousel.d.ts +68 -0
  40. package/esm/core/Carousel/Carousel.js +124 -0
  41. package/esm/core/Carousel/CarouselContext.d.ts +37 -0
  42. package/esm/core/Carousel/CarouselContext.js +6 -0
  43. package/esm/core/Carousel/CarouselDot.d.ts +13 -0
  44. package/esm/core/Carousel/CarouselDot.js +40 -0
  45. package/esm/core/Carousel/CarouselDotsList.d.ts +32 -0
  46. package/esm/core/Carousel/CarouselDotsList.js +126 -0
  47. package/esm/core/Carousel/CarouselNavigation.d.ts +15 -0
  48. package/esm/core/Carousel/CarouselNavigation.js +82 -0
  49. package/esm/core/Carousel/CarouselSlide.d.ts +14 -0
  50. package/esm/core/Carousel/CarouselSlide.js +57 -0
  51. package/esm/core/Carousel/CarouselSlider.d.ts +5 -0
  52. package/esm/core/Carousel/CarouselSlider.js +88 -0
  53. package/esm/core/Carousel/index.d.ts +4 -0
  54. package/esm/core/Carousel/index.js +6 -0
  55. package/esm/core/ComboBox/ComboBox.js +2 -2
  56. package/esm/core/DatePicker/DatePicker.d.ts +5 -0
  57. package/esm/core/DatePicker/DatePicker.js +38 -13
  58. package/esm/core/Modal/Modal.d.ts +5 -0
  59. package/esm/core/Modal/Modal.js +11 -9
  60. package/esm/core/Modal/ModalContent.d.ts +14 -0
  61. package/esm/core/Modal/ModalContent.js +39 -0
  62. package/esm/core/Modal/index.d.ts +2 -0
  63. package/esm/core/Modal/index.js +1 -0
  64. package/esm/core/Table/Table.js +8 -7
  65. package/esm/core/Table/filters/DateRangeFilter/DateRangeFilter.js +18 -2
  66. package/esm/core/index.d.ts +4 -2
  67. package/esm/core/index.js +2 -1
  68. package/esm/core/utils/hooks/index.d.ts +1 -0
  69. package/esm/core/utils/hooks/index.js +1 -0
  70. package/esm/core/utils/hooks/useMediaQuery.d.ts +2 -0
  71. package/esm/core/utils/hooks/useMediaQuery.js +39 -0
  72. package/esm/core/utils/hooks/useTheme.d.ts +5 -0
  73. package/esm/core/utils/hooks/useTheme.js +20 -14
  74. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.35.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.34.2...v1.35.0) (2022-04-05)
4
+
5
+ ### What's new
6
+
7
+ * **Carousel:** Add new Carousel Component ([#569](https://www.github.com/iTwin/iTwinUI-react/issues/569)) ([fc7040c](https://www.github.com/iTwin/iTwinUI-react/commit/fc7040c712011bdf40a6d5b3e9c4bad78a532523))
8
+ * **DatePicker:** Add year selection ([#604](https://www.github.com/iTwin/iTwinUI-react/issues/604)) ([2f57da6](https://www.github.com/iTwin/iTwinUI-react/commit/2f57da6ef07202290e4f6d214a0581dae1528007))
9
+ * **Modal:** Add full page modal ([#588](https://www.github.com/iTwin/iTwinUI-react/issues/588)) ([711a55b](https://www.github.com/iTwin/iTwinUI-react/commit/711a55b2b4373ce4bd99d770a3edc5f9aae516bc))
10
+ - Add `ModalContent` component for better scroll experience.
11
+ * **Theme:** Add support for high contrast themes ([#610](https://www.github.com/iTwin/iTwinUI-react/issues/610)) ([b1b6d95](https://www.github.com/iTwin/iTwinUI-react/commit/b1b6d9519ec0290bd6759a31fc4cc4a7c8ab03e3))
12
+ - High contrast themes are automatically used if user's OS prefers it. It can also be specified manually using `themeOptions.highContrast`.
13
+
14
+ ### Fixes
15
+
16
+ * **Table:** `onBottomReached` was triggered on filtered Table ([#607](https://www.github.com/iTwin/iTwinUI-react/issues/607)) ([2f9cf24](https://www.github.com/iTwin/iTwinUI-react/commit/2f9cf24fd0eecee1bff27cbf8d69281062e3e33d))
17
+
18
+ ### [1.34.2](https://www.github.com/iTwin/iTwinUI-react/compare/v1.34.1...v1.34.2) (2022-03-29)
19
+
20
+ ### Fixes
21
+
22
+ * **Table:** Date filter makes range from the begigging to the end of the day ([#601](https://www.github.com/iTwin/iTwinUI-react/issues/601)) ([ae978b7](https://www.github.com/iTwin/iTwinUI-react/commit/ae978b7df3a59f9cd18474346d88083d888e36e3))
23
+
24
+ ### [1.34.1](https://www.github.com/iTwin/iTwinUI-react/compare/v1.34.0...v1.34.1) (2022-03-24)
25
+
26
+ ### Fixes
27
+
28
+ * **ComboBox:** Combine internal input onChange with `inputProps.onChange` ([#597](https://www.github.com/iTwin/iTwinUI-react/issues/597)) ([e033753](https://www.github.com/iTwin/iTwinUI-react/commit/e033753c81f3b9298df6eb198581c75344f96c00))
29
+
3
30
  ## [1.34.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.33.1...v1.34.0) (2022-03-22)
4
31
 
5
32
  ### What's new
@@ -71,6 +71,7 @@ exports.ButtonGroup = react_1.default.forwardRef(function (props, ref) {
71
71
  return (react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)({
72
72
  'iui-button-group': orientation === 'horizontal',
73
73
  'iui-button-group-vertical': orientation === 'vertical',
74
+ 'iui-button-group-overflow-x': !!overflowButton && orientation === 'horizontal',
74
75
  }, className), "aria-orientation": orientation, ref: refs }, rest), !!overflowButton && visibleCount < items.length ? (react_1.default.createElement(react_1.default.Fragment, null,
75
76
  overflowButton && overflowPlacement === 'start' && (react_1.default.createElement("div", null, overflowButton(visibleCount))),
76
77
  items.slice(0, visibleCount - 1),
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+ import '@itwin/itwinui-css/css/carousel.css';
3
+ export declare type CarouselProps = {
4
+ /**
5
+ * Index of the currently shown slide.
6
+ * Can be used to set the default index or control the active slide programmatically.
7
+ * @default 0
8
+ */
9
+ activeSlideIndex?: number;
10
+ /**
11
+ * Callback fired when the current slide changes.
12
+ */
13
+ onSlideChange?: (index: number) => void;
14
+ } & React.ComponentPropsWithoutRef<'div'>;
15
+ /**
16
+ * The Carousel component consists of a set of slides, normally displayed one at a time. A navigation section is
17
+ * located below the slides, consisting of "dots" and "previous"/"next" buttons, used for changing slides.
18
+ *
19
+ * The currently shown slide can also be changed using the left/right arrow keys or by dragging on a touch device.
20
+ *
21
+ * This component uses a composition approach so it should be used with the provided subcomponents.
22
+ *
23
+ * @example
24
+ * <Carousel>
25
+ * <Carousel.Slider>
26
+ * <Carousel.Slide>...</Carousel.Slide>
27
+ * <Carousel.Slide>...</Carousel.Slide>
28
+ * <Carousel.Slide>...</Carousel.Slide>
29
+ * </Carousel.Slider>
30
+ * <Carousel.Navigation />
31
+ * </Carousel>
32
+ */
33
+ export declare const Carousel: React.ForwardRefExoticComponent<{
34
+ /**
35
+ * Index of the currently shown slide.
36
+ * Can be used to set the default index or control the active slide programmatically.
37
+ * @default 0
38
+ */
39
+ activeSlideIndex?: number | undefined;
40
+ /**
41
+ * Callback fired when the current slide changes.
42
+ */
43
+ onSlideChange?: ((index: number) => void) | undefined;
44
+ } & Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLElement>> & {
45
+ Slider: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>, "key" | keyof React.OlHTMLAttributes<HTMLOListElement>> & React.RefAttributes<HTMLOListElement>>;
46
+ Slide: React.ForwardRefExoticComponent<{
47
+ index?: number | undefined;
48
+ } & Pick<React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "key" | keyof React.LiHTMLAttributes<HTMLLIElement>> & React.RefAttributes<HTMLLIElement>>;
49
+ Navigation: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "key" | keyof React.HTMLAttributes<HTMLElement>> & React.RefAttributes<HTMLElement>> & {
50
+ PreviousButton: React.ForwardRefExoticComponent<{
51
+ isActive?: boolean | undefined;
52
+ } & Omit<import("..").ButtonProps<"button">, "startIcon" | "endIcon"> & React.RefAttributes<HTMLButtonElement>>;
53
+ NextButton: React.ForwardRefExoticComponent<{
54
+ isActive?: boolean | undefined;
55
+ } & Omit<import("..").ButtonProps<"button">, "startIcon" | "endIcon"> & React.RefAttributes<HTMLButtonElement>>;
56
+ };
57
+ DotsList: React.ForwardRefExoticComponent<{
58
+ length?: number | undefined;
59
+ currentIndex?: number | undefined;
60
+ onSlideChange?: ((index: number) => void) | undefined;
61
+ } & Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
62
+ Dot: React.ForwardRefExoticComponent<{
63
+ isActive?: boolean | undefined;
64
+ isSmall?: boolean | undefined;
65
+ isSmaller?: boolean | undefined;
66
+ } & Pick<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "key" | keyof React.ButtonHTMLAttributes<HTMLButtonElement>> & React.RefAttributes<HTMLButtonElement>>;
67
+ };
68
+ export default Carousel;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.Carousel = void 0;
29
+ /*---------------------------------------------------------------------------------------------
30
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
31
+ * See LICENSE.md in the project root for license terms and full copyright notice.
32
+ *--------------------------------------------------------------------------------------------*/
33
+ var react_1 = __importDefault(require("react"));
34
+ var classnames_1 = __importDefault(require("classnames"));
35
+ var utils_1 = require("../utils");
36
+ require("@itwin/itwinui-css/css/carousel.css");
37
+ var CarouselContext_1 = require("./CarouselContext");
38
+ var CarouselSlider_1 = require("./CarouselSlider");
39
+ var CarouselSlide_1 = require("./CarouselSlide");
40
+ var CarouselDotsList_1 = require("./CarouselDotsList");
41
+ var CarouselDot_1 = require("./CarouselDot");
42
+ var CarouselNavigation_1 = require("./CarouselNavigation");
43
+ /**
44
+ * The Carousel component consists of a set of slides, normally displayed one at a time. A navigation section is
45
+ * located below the slides, consisting of "dots" and "previous"/"next" buttons, used for changing slides.
46
+ *
47
+ * The currently shown slide can also be changed using the left/right arrow keys or by dragging on a touch device.
48
+ *
49
+ * This component uses a composition approach so it should be used with the provided subcomponents.
50
+ *
51
+ * @example
52
+ * <Carousel>
53
+ * <Carousel.Slider>
54
+ * <Carousel.Slide>...</Carousel.Slide>
55
+ * <Carousel.Slide>...</Carousel.Slide>
56
+ * <Carousel.Slide>...</Carousel.Slide>
57
+ * </Carousel.Slider>
58
+ * <Carousel.Navigation />
59
+ * </Carousel>
60
+ */
61
+ exports.Carousel = Object.assign(react_1.default.forwardRef(function (props, ref) {
62
+ var _a = props.activeSlideIndex, userActiveIndex = _a === void 0 ? 0 : _a, onSlideChange = props.onSlideChange, className = props.className, children = props.children, rest = __rest(props, ["activeSlideIndex", "onSlideChange", "className", "children"]);
63
+ // Generate a stateful random id if not specified
64
+ var id = react_1.default.useState(function () { var _a; return (_a = props.id) !== null && _a !== void 0 ? _a : "iui-carousel-" + (0, utils_1.getRandomValue)(10); })[0];
65
+ (0, utils_1.useTheme)();
66
+ var isManuallyUpdating = react_1.default.useRef(false);
67
+ var scrollInstantly = react_1.default.useRef(false);
68
+ var carouselRef = react_1.default.useRef(null);
69
+ var refs = (0, utils_1.useMergedRefs)(carouselRef, ref);
70
+ var _b = react_1.default.useState(userActiveIndex), currentIndex = _b[0], _setCurrentIndex = _b[1];
71
+ react_1.default.useEffect(function () {
72
+ _setCurrentIndex(userActiveIndex);
73
+ }, [userActiveIndex]);
74
+ var setCurrentIndex = react_1.default.useCallback(function (index) {
75
+ var _a;
76
+ _setCurrentIndex(index);
77
+ isManuallyUpdating.current = true;
78
+ (_a = carouselRef.current) === null || _a === void 0 ? void 0 : _a.focus();
79
+ }, []);
80
+ var _c = react_1.default.useState(0), slideCount = _c[0], setSlideCount = _c[1];
81
+ var _d = react_1.default.useState({}), keysPressed = _d[0], setKeysPressed = _d[1];
82
+ var handleKeyDown = function (event) {
83
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
84
+ return;
85
+ }
86
+ if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
87
+ setKeysPressed(function (old) {
88
+ var _a;
89
+ return (__assign(__assign({}, old), (_a = {}, _a[event.key] = true, _a)));
90
+ });
91
+ }
92
+ };
93
+ var handleKeyUp = function (event) {
94
+ switch (event.key) {
95
+ case 'ArrowLeft': {
96
+ setKeysPressed(function (old) { return (__assign(__assign({}, old), { ArrowLeft: false })); });
97
+ setCurrentIndex(function (old) { return (slideCount + old - 1) % slideCount; });
98
+ break;
99
+ }
100
+ case 'ArrowRight': {
101
+ setKeysPressed(function (old) { return (__assign(__assign({}, old), { ArrowRight: false })); });
102
+ setCurrentIndex(function (old) { return (slideCount + old + 1) % slideCount; });
103
+ break;
104
+ }
105
+ }
106
+ };
107
+ var userOnSlideChange = react_1.default.useRef(onSlideChange);
108
+ react_1.default.useEffect(function () {
109
+ var _a;
110
+ (_a = userOnSlideChange.current) === null || _a === void 0 ? void 0 : _a.call(userOnSlideChange, currentIndex);
111
+ }, [currentIndex]);
112
+ return (react_1.default.createElement("section", __assign({ "aria-roledescription": 'carousel', tabIndex: 0, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, ref: refs, className: (0, classnames_1.default)('iui-carousel', className) }, rest, { id: id }),
113
+ react_1.default.createElement(CarouselContext_1.CarouselContext.Provider, { value: {
114
+ currentIndex: currentIndex,
115
+ setCurrentIndex: setCurrentIndex,
116
+ slideCount: slideCount,
117
+ setSlideCount: setSlideCount,
118
+ keysPressed: keysPressed,
119
+ idPrefix: id,
120
+ isManuallyUpdating: isManuallyUpdating,
121
+ scrollInstantly: scrollInstantly,
122
+ } }, children)));
123
+ }), {
124
+ Slider: CarouselSlider_1.CarouselSlider,
125
+ Slide: CarouselSlide_1.CarouselSlide,
126
+ Navigation: CarouselNavigation_1.CarouselNavigation,
127
+ DotsList: CarouselDotsList_1.CarouselDotsList,
128
+ Dot: CarouselDot_1.CarouselDot,
129
+ });
130
+ exports.default = exports.Carousel;
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ export declare const CarouselContext: React.Context<{
3
+ /**
4
+ * Stateful index of currently active slide.
5
+ */
6
+ currentIndex: number;
7
+ /**
8
+ * State updater for currentIndex.
9
+ */
10
+ setCurrentIndex: (index: number | ((old: number) => void)) => void;
11
+ /**
12
+ * Number of slides in the carousel. Gets set in `CarouselSlider` for reading in `CarouselDotsList`.
13
+ */
14
+ slideCount: number;
15
+ /**
16
+ * State updater for slideCount.
17
+ */
18
+ setSlideCount: (length: number | ((old: number) => void)) => void;
19
+ /**
20
+ * Stateful value of the left/right arrow keys currently pressed.
21
+ */
22
+ keysPressed: Record<string, boolean>;
23
+ /**
24
+ * Prefix used for setting id for internal carousel components.
25
+ */
26
+ idPrefix: string;
27
+ /**
28
+ * Ref object used for preventing intersection observer callback from interfering with manual slide updates.
29
+ *
30
+ * Should be set to true when updating slides using any manual actions (e.g. clicking buttons), and should be set to false when the slide update completes.
31
+ */
32
+ isManuallyUpdating: React.MutableRefObject<boolean>;
33
+ /**
34
+ * Ref object used to skip smooth scrolling when button is clicked too many times.
35
+ */
36
+ scrollInstantly: React.MutableRefObject<boolean>;
37
+ } | undefined>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CarouselContext = void 0;
7
+ /*---------------------------------------------------------------------------------------------
8
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
9
+ * See LICENSE.md in the project root for license terms and full copyright notice.
10
+ *--------------------------------------------------------------------------------------------*/
11
+ var react_1 = __importDefault(require("react"));
12
+ exports.CarouselContext = react_1.default.createContext(undefined);
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ /**
3
+ * `CarouselDot` is the actual "dot" component used to activate a slide on clicking.
4
+ * It should be used as a child of `CarouselDotsList`.
5
+ */
6
+ export declare const CarouselDot: React.ForwardRefExoticComponent<{
7
+ /** Is this dot currently active? */
8
+ isActive?: boolean | undefined;
9
+ /** Should be set to true for dots that are one spot from the edge of truncation. The dot size becomes small. */
10
+ isSmall?: boolean | undefined;
11
+ /** Should be set to true for dots that are at the edge of truncation. The dot size becomes even smaller. */
12
+ isSmaller?: boolean | undefined;
13
+ } & Pick<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "key" | keyof React.ButtonHTMLAttributes<HTMLButtonElement>> & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.CarouselDot = void 0;
29
+ /*---------------------------------------------------------------------------------------------
30
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
31
+ * See LICENSE.md in the project root for license terms and full copyright notice.
32
+ *--------------------------------------------------------------------------------------------*/
33
+ var react_1 = __importDefault(require("react"));
34
+ var classnames_1 = __importDefault(require("classnames"));
35
+ /**
36
+ * `CarouselDot` is the actual "dot" component used to activate a slide on clicking.
37
+ * It should be used as a child of `CarouselDotsList`.
38
+ */
39
+ exports.CarouselDot = react_1.default.forwardRef(function (props, ref) {
40
+ var isActive = props.isActive, isSmaller = props.isSmaller, isSmall = props.isSmall, className = props.className, rest = __rest(props, ["isActive", "isSmaller", "isSmall", "className"]);
41
+ return (react_1.default.createElement("button", __assign({ type: 'button', role: 'tab', tabIndex: -1, className: (0, classnames_1.default)('iui-carousel-navigation-dot', {
42
+ 'iui-active': isActive,
43
+ 'iui-first': isSmaller,
44
+ 'iui-second': isSmall,
45
+ }, className), "aria-selected": isActive, ref: ref }, rest)));
46
+ });
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import '@itwin/itwinui-css/css/carousel.css';
3
+ /**
4
+ * The `CarouselDots` component shows a list of `CarouselDot` components which can be used to
5
+ * choose a specific slide. If used as a descendant of `Carousel`, then this component does not need
6
+ * any props or `children`.
7
+ *
8
+ * The props can be specified if this component is being used outside `Carousel`. `children` can be specified
9
+ * to override the individual dots that are shown.
10
+ *
11
+ * @example
12
+ * <Carousel>
13
+ * // ...
14
+ * <Carousel.Dots />
15
+ * </Carousel>
16
+ *
17
+ * @example
18
+ * <Carousel.Dots
19
+ * length={10}
20
+ * maxCount={3}
21
+ * currentIndex={current}
22
+ * onSlideChange={(i) => setCurrent(i)}
23
+ * />
24
+ */
25
+ export declare const CarouselDotsList: React.ForwardRefExoticComponent<{
26
+ /** Number of total dots/slides in the carousel. Will be inferred from Carousel context or children. Otherwise, it is required to be passed. */
27
+ length?: number | undefined;
28
+ /** Index of currently active dot. Will be inferred from Carousel context, or else default to 0. */
29
+ currentIndex?: number | undefined;
30
+ /** Callback fired when any of the dots are clicked. */
31
+ onSlideChange?: ((index: number) => void) | undefined;
32
+ } & Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.CarouselDotsList = void 0;
29
+ /*---------------------------------------------------------------------------------------------
30
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
31
+ * See LICENSE.md in the project root for license terms and full copyright notice.
32
+ *--------------------------------------------------------------------------------------------*/
33
+ var react_1 = __importDefault(require("react"));
34
+ var classnames_1 = __importDefault(require("classnames"));
35
+ var CarouselContext_1 = require("./CarouselContext");
36
+ var utils_1 = require("../utils");
37
+ var CarouselDot_1 = require("./CarouselDot");
38
+ require("@itwin/itwinui-css/css/carousel.css");
39
+ /**
40
+ * The `CarouselDots` component shows a list of `CarouselDot` components which can be used to
41
+ * choose a specific slide. If used as a descendant of `Carousel`, then this component does not need
42
+ * any props or `children`.
43
+ *
44
+ * The props can be specified if this component is being used outside `Carousel`. `children` can be specified
45
+ * to override the individual dots that are shown.
46
+ *
47
+ * @example
48
+ * <Carousel>
49
+ * // ...
50
+ * <Carousel.Dots />
51
+ * </Carousel>
52
+ *
53
+ * @example
54
+ * <Carousel.Dots
55
+ * length={10}
56
+ * maxCount={3}
57
+ * currentIndex={current}
58
+ * onSlideChange={(i) => setCurrent(i)}
59
+ * />
60
+ */
61
+ exports.CarouselDotsList = react_1.default.forwardRef(function (props, ref) {
62
+ var _a, _b, _c;
63
+ var userCurrentIndex = props.currentIndex, length = props.length, className = props.className, onSlideChange = props.onSlideChange, children = props.children, rest = __rest(props, ["currentIndex", "length", "className", "onSlideChange", "children"]);
64
+ (0, utils_1.useTheme)();
65
+ var context = react_1.default.useContext(CarouselContext_1.CarouselContext);
66
+ var slideCount = (_a = length !== null && length !== void 0 ? length : context === null || context === void 0 ? void 0 : context.slideCount) !== null && _a !== void 0 ? _a : react_1.default.Children.count(children);
67
+ var currentIndex = (_b = userCurrentIndex !== null && userCurrentIndex !== void 0 ? userCurrentIndex : context === null || context === void 0 ? void 0 : context.currentIndex) !== null && _b !== void 0 ? _b : 0;
68
+ var idPrefix = (_c = props.id) !== null && _c !== void 0 ? _c : context === null || context === void 0 ? void 0 : context.idPrefix;
69
+ var handleSlideChange = react_1.default.useCallback(function (index) {
70
+ if (context) {
71
+ context.setCurrentIndex(index);
72
+ }
73
+ onSlideChange === null || onSlideChange === void 0 ? void 0 : onSlideChange(index);
74
+ }, [context, onSlideChange]);
75
+ var justMounted = react_1.default.useRef(true);
76
+ var _d = react_1.default.useState(slideCount), visibleCount = _d[0], setVisibleCount = _d[1];
77
+ var listRef = react_1.default.useRef(null);
78
+ var _e = react_1.default.useState(), width = _e[0], setWidth = _e[1];
79
+ var _f = (0, utils_1.useResizeObserver)(function (_a) {
80
+ var width = _a.width;
81
+ if (!listRef.current) {
82
+ return;
83
+ }
84
+ setWidth(width);
85
+ var dotWidth = listRef.current.children[0].offsetWidth;
86
+ setVisibleCount(Math.floor(width / dotWidth));
87
+ }), resizeRef = _f[0], resizeObserver = _f[1];
88
+ react_1.default.useEffect(function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); }, [resizeObserver]);
89
+ var refs = (0, utils_1.useMergedRefs)(ref, resizeRef, listRef);
90
+ var firstVisibleDotIndex = react_1.default.useMemo(function () {
91
+ return (0, utils_1.getBoundedValue)(currentIndex - Math.ceil(visibleCount / 2) + 1, 0, slideCount - visibleCount);
92
+ }, [currentIndex, slideCount, visibleCount]);
93
+ var lastVisibleDotIndex = react_1.default.useMemo(function () {
94
+ return (0, utils_1.getBoundedValue)(currentIndex + Math.floor(visibleCount / 2), visibleCount - 1, slideCount - 1);
95
+ }, [currentIndex, slideCount, visibleCount]);
96
+ var dots = react_1.default.useMemo(function () {
97
+ return Array(slideCount)
98
+ .fill(null)
99
+ .map(function (_, index) {
100
+ var isFirstSmallDot = (index === firstVisibleDotIndex && index !== 0) ||
101
+ (index === lastVisibleDotIndex && index !== slideCount - 1);
102
+ var isSecondSmallDot = (index === firstVisibleDotIndex + 1 && index !== 1) ||
103
+ (index === lastVisibleDotIndex - 1 && index !== slideCount - 2);
104
+ var isClipped = index < firstVisibleDotIndex || index > lastVisibleDotIndex;
105
+ return (react_1.default.createElement(CarouselDot_1.CarouselDot, { key: index, "aria-label": "Slide " + index, isActive: index === currentIndex, onClick: function () { return handleSlideChange(index); }, isSmall: isSecondSmallDot, isSmaller: isFirstSmallDot || isClipped, id: idPrefix && idPrefix + "--dot-" + index, "aria-controls": idPrefix && idPrefix + "--slide-" + index }));
106
+ });
107
+ }, [
108
+ slideCount,
109
+ firstVisibleDotIndex,
110
+ lastVisibleDotIndex,
111
+ currentIndex,
112
+ idPrefix,
113
+ handleSlideChange,
114
+ ]);
115
+ react_1.default.useEffect(function () {
116
+ var _a, _b, _c;
117
+ var firstDot = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children[firstVisibleDotIndex];
118
+ if (!listRef.current || !firstDot) {
119
+ return;
120
+ }
121
+ var motionOk = (_c = (_b = (0, utils_1.getWindow)()) === null || _b === void 0 ? void 0 : _b.matchMedia('(prefers-reduced-motion: no-preference)')) === null || _c === void 0 ? void 0 : _c.matches;
122
+ listRef.current.scrollTo({
123
+ left: firstDot.offsetLeft - listRef.current.offsetLeft,
124
+ behavior: motionOk && !justMounted.current ? 'smooth' : 'auto',
125
+ });
126
+ if (justMounted.current) {
127
+ justMounted.current = false;
128
+ }
129
+ }, [currentIndex, firstVisibleDotIndex, slideCount, visibleCount, width]);
130
+ return (react_1.default.createElement(react_1.default.Fragment, null,
131
+ react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)('iui-carousel-navigation-dots', className), role: 'tablist', "aria-label": 'Slides', ref: refs }, rest), children !== null && children !== void 0 ? children : dots)));
132
+ });
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ /**
3
+ * The `CarouselNavigation` component by default consists of the `PreviousButton` and `NextButton`
4
+ * shown on the left and right, and the `CarouselDotsList` component shown in the middle.
5
+ *
6
+ * `children` can be specified to override what is shown in this navigation section.
7
+ */
8
+ export declare const CarouselNavigation: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "key" | keyof React.HTMLAttributes<HTMLElement>> & React.RefAttributes<HTMLElement>> & {
9
+ PreviousButton: React.ForwardRefExoticComponent<{
10
+ isActive?: boolean | undefined;
11
+ } & Omit<import("../Buttons").ButtonProps<"button">, "startIcon" | "endIcon"> & React.RefAttributes<HTMLButtonElement>>;
12
+ NextButton: React.ForwardRefExoticComponent<{
13
+ isActive?: boolean | undefined;
14
+ } & Omit<import("../Buttons").ButtonProps<"button">, "startIcon" | "endIcon"> & React.RefAttributes<HTMLButtonElement>>;
15
+ };
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.CarouselNavigation = void 0;
29
+ /*---------------------------------------------------------------------------------------------
30
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
31
+ * See LICENSE.md in the project root for license terms and full copyright notice.
32
+ *--------------------------------------------------------------------------------------------*/
33
+ var react_1 = __importDefault(require("react"));
34
+ var classnames_1 = __importDefault(require("classnames"));
35
+ var CarouselContext_1 = require("./CarouselContext");
36
+ var Buttons_1 = require("../Buttons");
37
+ var CarouselDotsList_1 = require("./CarouselDotsList");
38
+ var ChevronLeft_1 = __importDefault(require("@itwin/itwinui-icons-react/cjs/icons/ChevronLeft"));
39
+ var ChevronRight_1 = __importDefault(require("@itwin/itwinui-icons-react/cjs/icons/ChevronRight"));
40
+ /** Button for switching to previous slide */
41
+ var PreviousButton = react_1.default.forwardRef(function (props, ref) {
42
+ var context = react_1.default.useContext(CarouselContext_1.CarouselContext);
43
+ if (!context) {
44
+ throw new Error('CarouselNavigation should be used inside Carousel');
45
+ }
46
+ var slideCount = context.slideCount, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollInstantly = context.scrollInstantly;
47
+ return (react_1.default.createElement(Buttons_1.IconButton, __assign({ styleType: 'borderless', size: 'small', tabIndex: -1, "data-pressed": keysPressed['ArrowLeft'] || undefined, ref: ref }, props, { onClick: function (e) {
48
+ var _a;
49
+ if (e.detail > 3) {
50
+ scrollInstantly.current = true;
51
+ }
52
+ setCurrentIndex(function (old) { return (slideCount + old - 1) % slideCount; });
53
+ (_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
54
+ } }),
55
+ react_1.default.createElement(ChevronLeft_1.default, null)));
56
+ });
57
+ /** Button for switching to next slide */
58
+ var NextButton = react_1.default.forwardRef(function (props, ref) {
59
+ var context = react_1.default.useContext(CarouselContext_1.CarouselContext);
60
+ if (!context) {
61
+ throw new Error('CarouselNavigation should be used inside Carousel');
62
+ }
63
+ var slideCount = context.slideCount, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollInstantly = context.scrollInstantly;
64
+ return (react_1.default.createElement(Buttons_1.IconButton, __assign({ styleType: 'borderless', size: 'small', tabIndex: -1, "data-pressed": keysPressed['ArrowRight'] || undefined, ref: ref }, props, { onClick: function (e) {
65
+ var _a;
66
+ if (e.detail > 3) {
67
+ scrollInstantly.current = true;
68
+ }
69
+ setCurrentIndex(function (old) { return (slideCount + old + 1) % slideCount; });
70
+ (_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
71
+ } }),
72
+ react_1.default.createElement(ChevronRight_1.default, null)));
73
+ });
74
+ /**
75
+ * The `CarouselNavigation` component by default consists of the `PreviousButton` and `NextButton`
76
+ * shown on the left and right, and the `CarouselDotsList` component shown in the middle.
77
+ *
78
+ * `children` can be specified to override what is shown in this navigation section.
79
+ */
80
+ exports.CarouselNavigation = Object.assign(react_1.default.forwardRef(function (props, ref) {
81
+ var className = props.className, children = props.children, rest = __rest(props, ["className", "children"]);
82
+ return (react_1.default.createElement("nav", __assign({ className: (0, classnames_1.default)('iui-carousel-navigation', className), ref: ref }, rest), children !== null && children !== void 0 ? children : (react_1.default.createElement(react_1.default.Fragment, null,
83
+ react_1.default.createElement("div", { className: 'iui-carousel-navigation-left' },
84
+ react_1.default.createElement(PreviousButton, null)),
85
+ react_1.default.createElement(CarouselDotsList_1.CarouselDotsList, null),
86
+ react_1.default.createElement("div", { className: 'iui-carousel-navigation-right' },
87
+ react_1.default.createElement(NextButton, null))))));
88
+ }), { PreviousButton: PreviousButton, NextButton: NextButton });
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ /**
3
+ * `CarouselSlide` is used for the actual slide content. The content can be specified through `children`.
4
+ *
5
+ * It is recommended that the slide content bring its own dimensions (esp. height) and that
6
+ * the dimensions should be the same for all slides.
7
+ */
8
+ export declare const CarouselSlide: React.ForwardRefExoticComponent<{
9
+ /**
10
+ * Index of the current slide.
11
+ * Does not need to be manually specified because it will be set in parent (`CarouselSlider`).
12
+ */
13
+ index?: number | undefined;
14
+ } & Pick<React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "key" | keyof React.LiHTMLAttributes<HTMLLIElement>> & React.RefAttributes<HTMLLIElement>>;