@itwin/itwinui-react 1.34.2 → 1.37.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 (158) hide show
  1. package/CHANGELOG.md +43 -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/ColorPicker/ColorSwatch.d.ts +1 -1
  20. package/cjs/core/DatePicker/DatePicker.d.ts +5 -0
  21. package/cjs/core/DatePicker/DatePicker.js +38 -13
  22. package/cjs/core/Header/HeaderButton.js +1 -0
  23. package/cjs/core/Menu/Menu.js +8 -3
  24. package/cjs/core/Modal/Modal.d.ts +5 -0
  25. package/cjs/core/Modal/Modal.js +11 -9
  26. package/cjs/core/Modal/ModalContent.d.ts +14 -0
  27. package/cjs/core/Modal/ModalContent.js +46 -0
  28. package/cjs/core/Modal/index.d.ts +2 -0
  29. package/cjs/core/Modal/index.js +3 -1
  30. package/cjs/core/SkipToContentLink/SkipToContentLink.d.ts +33 -0
  31. package/cjs/core/SkipToContentLink/SkipToContentLink.js +50 -0
  32. package/cjs/core/SkipToContentLink/index.d.ts +4 -0
  33. package/cjs/core/SkipToContentLink/index.js +10 -0
  34. package/cjs/core/Surface/Surface.d.ts +32 -0
  35. package/cjs/core/Surface/Surface.js +70 -0
  36. package/cjs/core/Surface/index.d.ts +4 -0
  37. package/cjs/core/Surface/index.js +10 -0
  38. package/cjs/core/Table/Table.d.ts +7 -0
  39. package/cjs/core/Table/Table.js +51 -27
  40. package/cjs/core/Table/TableCell.js +3 -3
  41. package/cjs/core/Table/TableRowMemoized.js +12 -7
  42. package/cjs/core/Table/actionHandlers/index.d.ts +2 -1
  43. package/cjs/core/Table/actionHandlers/index.js +5 -1
  44. package/cjs/core/Table/cells/DefaultCell.d.ts +1 -1
  45. package/cjs/core/Table/cells/DefaultCell.js +5 -2
  46. package/cjs/core/Table/columns/actionColumn.d.ts +35 -0
  47. package/cjs/core/Table/columns/actionColumn.js +91 -0
  48. package/cjs/core/Table/columns/expanderColumn.d.ts +47 -0
  49. package/cjs/core/Table/columns/expanderColumn.js +81 -0
  50. package/cjs/core/Table/columns/index.d.ts +3 -0
  51. package/cjs/core/Table/columns/index.js +15 -0
  52. package/cjs/core/Table/columns/selectionColumn.d.ts +35 -0
  53. package/cjs/core/Table/columns/selectionColumn.js +67 -0
  54. package/cjs/core/Table/hooks/index.d.ts +2 -2
  55. package/cjs/core/Table/hooks/index.js +1 -3
  56. package/cjs/core/Table/hooks/useExpanderCell.d.ts +0 -1
  57. package/cjs/core/Table/hooks/useExpanderCell.js +25 -39
  58. package/cjs/core/Table/hooks/useResizeColumns.js +8 -2
  59. package/cjs/core/Table/hooks/useSelectionCell.d.ts +1 -2
  60. package/cjs/core/Table/hooks/useSelectionCell.js +8 -53
  61. package/cjs/core/Table/index.d.ts +1 -0
  62. package/cjs/core/Table/index.js +5 -1
  63. package/cjs/core/Table/utils.js +1 -1
  64. package/cjs/core/Tag/Tag.js +6 -3
  65. package/cjs/core/Tile/Tile.d.ts +6 -2
  66. package/cjs/core/Tile/Tile.js +7 -2
  67. package/cjs/core/Toast/Toast.js +1 -1
  68. package/cjs/core/Typography/Anchor/Anchor.d.ts +1 -0
  69. package/cjs/core/Typography/Anchor/Anchor.js +1 -0
  70. package/cjs/core/index.d.ts +9 -3
  71. package/cjs/core/index.js +13 -2
  72. package/cjs/core/utils/components/Popover.js +13 -1
  73. package/cjs/core/utils/hooks/index.d.ts +1 -0
  74. package/cjs/core/utils/hooks/index.js +1 -0
  75. package/cjs/core/utils/hooks/useMediaQuery.d.ts +2 -0
  76. package/cjs/core/utils/hooks/useMediaQuery.js +46 -0
  77. package/cjs/core/utils/hooks/useTheme.d.ts +5 -0
  78. package/cjs/core/utils/hooks/useTheme.js +20 -14
  79. package/cjs/types/react-table-config.d.ts +18 -0
  80. package/esm/core/ButtonGroup/ButtonGroup.js +1 -0
  81. package/esm/core/Carousel/Carousel.d.ts +68 -0
  82. package/esm/core/Carousel/Carousel.js +124 -0
  83. package/esm/core/Carousel/CarouselContext.d.ts +37 -0
  84. package/esm/core/Carousel/CarouselContext.js +6 -0
  85. package/esm/core/Carousel/CarouselDot.d.ts +13 -0
  86. package/esm/core/Carousel/CarouselDot.js +40 -0
  87. package/esm/core/Carousel/CarouselDotsList.d.ts +32 -0
  88. package/esm/core/Carousel/CarouselDotsList.js +126 -0
  89. package/esm/core/Carousel/CarouselNavigation.d.ts +15 -0
  90. package/esm/core/Carousel/CarouselNavigation.js +82 -0
  91. package/esm/core/Carousel/CarouselSlide.d.ts +14 -0
  92. package/esm/core/Carousel/CarouselSlide.js +57 -0
  93. package/esm/core/Carousel/CarouselSlider.d.ts +5 -0
  94. package/esm/core/Carousel/CarouselSlider.js +88 -0
  95. package/esm/core/Carousel/index.d.ts +4 -0
  96. package/esm/core/Carousel/index.js +6 -0
  97. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  98. package/esm/core/DatePicker/DatePicker.d.ts +5 -0
  99. package/esm/core/DatePicker/DatePicker.js +38 -13
  100. package/esm/core/Header/HeaderButton.js +1 -0
  101. package/esm/core/Menu/Menu.js +8 -3
  102. package/esm/core/Modal/Modal.d.ts +5 -0
  103. package/esm/core/Modal/Modal.js +11 -9
  104. package/esm/core/Modal/ModalContent.d.ts +14 -0
  105. package/esm/core/Modal/ModalContent.js +39 -0
  106. package/esm/core/Modal/index.d.ts +2 -0
  107. package/esm/core/Modal/index.js +1 -0
  108. package/esm/core/SkipToContentLink/SkipToContentLink.d.ts +33 -0
  109. package/esm/core/SkipToContentLink/SkipToContentLink.js +44 -0
  110. package/esm/core/SkipToContentLink/index.d.ts +4 -0
  111. package/esm/core/SkipToContentLink/index.js +6 -0
  112. package/esm/core/Surface/Surface.d.ts +32 -0
  113. package/esm/core/Surface/Surface.js +64 -0
  114. package/esm/core/Surface/index.d.ts +4 -0
  115. package/esm/core/Surface/index.js +6 -0
  116. package/esm/core/Table/Table.d.ts +7 -0
  117. package/esm/core/Table/Table.js +47 -23
  118. package/esm/core/Table/TableCell.js +2 -2
  119. package/esm/core/Table/TableRowMemoized.js +12 -7
  120. package/esm/core/Table/actionHandlers/index.d.ts +2 -1
  121. package/esm/core/Table/actionHandlers/index.js +2 -1
  122. package/esm/core/Table/cells/DefaultCell.d.ts +1 -1
  123. package/esm/core/Table/cells/DefaultCell.js +5 -2
  124. package/esm/core/Table/columns/actionColumn.d.ts +35 -0
  125. package/esm/core/Table/columns/actionColumn.js +84 -0
  126. package/esm/core/Table/columns/expanderColumn.d.ts +47 -0
  127. package/esm/core/Table/columns/expanderColumn.js +74 -0
  128. package/esm/core/Table/columns/index.d.ts +3 -0
  129. package/esm/core/Table/columns/index.js +7 -0
  130. package/esm/core/Table/columns/selectionColumn.d.ts +35 -0
  131. package/esm/core/Table/columns/selectionColumn.js +60 -0
  132. package/esm/core/Table/hooks/index.d.ts +2 -2
  133. package/esm/core/Table/hooks/index.js +2 -2
  134. package/esm/core/Table/hooks/useExpanderCell.d.ts +0 -1
  135. package/esm/core/Table/hooks/useExpanderCell.js +24 -35
  136. package/esm/core/Table/hooks/useResizeColumns.js +8 -2
  137. package/esm/core/Table/hooks/useSelectionCell.d.ts +1 -2
  138. package/esm/core/Table/hooks/useSelectionCell.js +7 -49
  139. package/esm/core/Table/index.d.ts +1 -0
  140. package/esm/core/Table/index.js +1 -0
  141. package/esm/core/Table/utils.js +1 -1
  142. package/esm/core/Tag/Tag.js +6 -3
  143. package/esm/core/Tile/Tile.d.ts +6 -2
  144. package/esm/core/Tile/Tile.js +7 -2
  145. package/esm/core/Toast/Toast.js +1 -1
  146. package/esm/core/Typography/Anchor/Anchor.d.ts +1 -0
  147. package/esm/core/Typography/Anchor/Anchor.js +1 -0
  148. package/esm/core/index.d.ts +9 -3
  149. package/esm/core/index.js +5 -2
  150. package/esm/core/utils/components/Popover.js +13 -1
  151. package/esm/core/utils/hooks/index.d.ts +1 -0
  152. package/esm/core/utils/hooks/index.js +1 -0
  153. package/esm/core/utils/hooks/useMediaQuery.d.ts +2 -0
  154. package/esm/core/utils/hooks/useMediaQuery.js +39 -0
  155. package/esm/core/utils/hooks/useTheme.d.ts +5 -0
  156. package/esm/core/utils/hooks/useTheme.js +20 -14
  157. package/esm/types/react-table-config.d.ts +18 -0
  158. package/package.json +3 -2
@@ -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,126 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { CarouselContext } from './CarouselContext';
30
+ import { getBoundedValue, getWindow, useMergedRefs, useResizeObserver, useTheme, } from '../utils';
31
+ import { CarouselDot } from './CarouselDot';
32
+ import '@itwin/itwinui-css/css/carousel.css';
33
+ /**
34
+ * The `CarouselDots` component shows a list of `CarouselDot` components which can be used to
35
+ * choose a specific slide. If used as a descendant of `Carousel`, then this component does not need
36
+ * any props or `children`.
37
+ *
38
+ * The props can be specified if this component is being used outside `Carousel`. `children` can be specified
39
+ * to override the individual dots that are shown.
40
+ *
41
+ * @example
42
+ * <Carousel>
43
+ * // ...
44
+ * <Carousel.Dots />
45
+ * </Carousel>
46
+ *
47
+ * @example
48
+ * <Carousel.Dots
49
+ * length={10}
50
+ * maxCount={3}
51
+ * currentIndex={current}
52
+ * onSlideChange={(i) => setCurrent(i)}
53
+ * />
54
+ */
55
+ export var CarouselDotsList = React.forwardRef(function (props, ref) {
56
+ var _a, _b, _c;
57
+ var userCurrentIndex = props.currentIndex, length = props.length, className = props.className, onSlideChange = props.onSlideChange, children = props.children, rest = __rest(props, ["currentIndex", "length", "className", "onSlideChange", "children"]);
58
+ useTheme();
59
+ var context = React.useContext(CarouselContext);
60
+ var slideCount = (_a = length !== null && length !== void 0 ? length : context === null || context === void 0 ? void 0 : context.slideCount) !== null && _a !== void 0 ? _a : React.Children.count(children);
61
+ var currentIndex = (_b = userCurrentIndex !== null && userCurrentIndex !== void 0 ? userCurrentIndex : context === null || context === void 0 ? void 0 : context.currentIndex) !== null && _b !== void 0 ? _b : 0;
62
+ var idPrefix = (_c = props.id) !== null && _c !== void 0 ? _c : context === null || context === void 0 ? void 0 : context.idPrefix;
63
+ var handleSlideChange = React.useCallback(function (index) {
64
+ if (context) {
65
+ context.setCurrentIndex(index);
66
+ }
67
+ onSlideChange === null || onSlideChange === void 0 ? void 0 : onSlideChange(index);
68
+ }, [context, onSlideChange]);
69
+ var justMounted = React.useRef(true);
70
+ var _d = React.useState(slideCount), visibleCount = _d[0], setVisibleCount = _d[1];
71
+ var listRef = React.useRef(null);
72
+ var _e = React.useState(), width = _e[0], setWidth = _e[1];
73
+ var _f = useResizeObserver(function (_a) {
74
+ var width = _a.width;
75
+ if (!listRef.current) {
76
+ return;
77
+ }
78
+ setWidth(width);
79
+ var dotWidth = listRef.current.children[0].offsetWidth;
80
+ setVisibleCount(Math.floor(width / dotWidth));
81
+ }), resizeRef = _f[0], resizeObserver = _f[1];
82
+ React.useEffect(function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); }, [resizeObserver]);
83
+ var refs = useMergedRefs(ref, resizeRef, listRef);
84
+ var firstVisibleDotIndex = React.useMemo(function () {
85
+ return getBoundedValue(currentIndex - Math.ceil(visibleCount / 2) + 1, 0, slideCount - visibleCount);
86
+ }, [currentIndex, slideCount, visibleCount]);
87
+ var lastVisibleDotIndex = React.useMemo(function () {
88
+ return getBoundedValue(currentIndex + Math.floor(visibleCount / 2), visibleCount - 1, slideCount - 1);
89
+ }, [currentIndex, slideCount, visibleCount]);
90
+ var dots = React.useMemo(function () {
91
+ return Array(slideCount)
92
+ .fill(null)
93
+ .map(function (_, index) {
94
+ var isFirstSmallDot = (index === firstVisibleDotIndex && index !== 0) ||
95
+ (index === lastVisibleDotIndex && index !== slideCount - 1);
96
+ var isSecondSmallDot = (index === firstVisibleDotIndex + 1 && index !== 1) ||
97
+ (index === lastVisibleDotIndex - 1 && index !== slideCount - 2);
98
+ var isClipped = index < firstVisibleDotIndex || index > lastVisibleDotIndex;
99
+ return (React.createElement(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 }));
100
+ });
101
+ }, [
102
+ slideCount,
103
+ firstVisibleDotIndex,
104
+ lastVisibleDotIndex,
105
+ currentIndex,
106
+ idPrefix,
107
+ handleSlideChange,
108
+ ]);
109
+ React.useEffect(function () {
110
+ var _a, _b, _c;
111
+ var firstDot = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children[firstVisibleDotIndex];
112
+ if (!listRef.current || !firstDot) {
113
+ return;
114
+ }
115
+ 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;
116
+ listRef.current.scrollTo({
117
+ left: firstDot.offsetLeft - listRef.current.offsetLeft,
118
+ behavior: motionOk && !justMounted.current ? 'smooth' : 'auto',
119
+ });
120
+ if (justMounted.current) {
121
+ justMounted.current = false;
122
+ }
123
+ }, [currentIndex, firstVisibleDotIndex, slideCount, visibleCount, width]);
124
+ return (React.createElement(React.Fragment, null,
125
+ React.createElement("div", __assign({ className: cx('iui-carousel-navigation-dots', className), role: 'tablist', "aria-label": 'Slides', ref: refs }, rest), children !== null && children !== void 0 ? children : dots)));
126
+ });
@@ -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,82 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { CarouselContext } from './CarouselContext';
30
+ import { IconButton } from '../Buttons';
31
+ import { CarouselDotsList } from './CarouselDotsList';
32
+ import SvgChevronLeft from '@itwin/itwinui-icons-react/cjs/icons/ChevronLeft';
33
+ import SvgChevronRight from '@itwin/itwinui-icons-react/cjs/icons/ChevronRight';
34
+ /** Button for switching to previous slide */
35
+ var PreviousButton = React.forwardRef(function (props, ref) {
36
+ var context = React.useContext(CarouselContext);
37
+ if (!context) {
38
+ throw new Error('CarouselNavigation should be used inside Carousel');
39
+ }
40
+ var slideCount = context.slideCount, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollInstantly = context.scrollInstantly;
41
+ return (React.createElement(IconButton, __assign({ styleType: 'borderless', size: 'small', tabIndex: -1, "data-pressed": keysPressed['ArrowLeft'] || undefined, ref: ref }, props, { onClick: function (e) {
42
+ var _a;
43
+ if (e.detail > 3) {
44
+ scrollInstantly.current = true;
45
+ }
46
+ setCurrentIndex(function (old) { return (slideCount + old - 1) % slideCount; });
47
+ (_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
48
+ } }),
49
+ React.createElement(SvgChevronLeft, null)));
50
+ });
51
+ /** Button for switching to next slide */
52
+ var NextButton = React.forwardRef(function (props, ref) {
53
+ var context = React.useContext(CarouselContext);
54
+ if (!context) {
55
+ throw new Error('CarouselNavigation should be used inside Carousel');
56
+ }
57
+ var slideCount = context.slideCount, setCurrentIndex = context.setCurrentIndex, keysPressed = context.keysPressed, scrollInstantly = context.scrollInstantly;
58
+ return (React.createElement(IconButton, __assign({ styleType: 'borderless', size: 'small', tabIndex: -1, "data-pressed": keysPressed['ArrowRight'] || undefined, ref: ref }, props, { onClick: function (e) {
59
+ var _a;
60
+ if (e.detail > 3) {
61
+ scrollInstantly.current = true;
62
+ }
63
+ setCurrentIndex(function (old) { return (slideCount + old + 1) % slideCount; });
64
+ (_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
65
+ } }),
66
+ React.createElement(SvgChevronRight, null)));
67
+ });
68
+ /**
69
+ * The `CarouselNavigation` component by default consists of the `PreviousButton` and `NextButton`
70
+ * shown on the left and right, and the `CarouselDotsList` component shown in the middle.
71
+ *
72
+ * `children` can be specified to override what is shown in this navigation section.
73
+ */
74
+ export var CarouselNavigation = Object.assign(React.forwardRef(function (props, ref) {
75
+ var className = props.className, children = props.children, rest = __rest(props, ["className", "children"]);
76
+ return (React.createElement("nav", __assign({ className: cx('iui-carousel-navigation', className), ref: ref }, rest), children !== null && children !== void 0 ? children : (React.createElement(React.Fragment, null,
77
+ React.createElement("div", { className: 'iui-carousel-navigation-left' },
78
+ React.createElement(PreviousButton, null)),
79
+ React.createElement(CarouselDotsList, null),
80
+ React.createElement("div", { className: 'iui-carousel-navigation-right' },
81
+ React.createElement(NextButton, null))))));
82
+ }), { 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>>;
@@ -0,0 +1,57 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { useIntersection, useMergedRefs } from '../utils';
30
+ import { CarouselContext } from './CarouselContext';
31
+ /**
32
+ * `CarouselSlide` is used for the actual slide content. The content can be specified through `children`.
33
+ *
34
+ * It is recommended that the slide content bring its own dimensions (esp. height) and that
35
+ * the dimensions should be the same for all slides.
36
+ */
37
+ export var CarouselSlide = React.forwardRef(function (props, ref) {
38
+ var index = props.index, className = props.className, children = props.children, rest = __rest(props, ["index", "className", "children"]);
39
+ var context = React.useContext(CarouselContext);
40
+ if (!context || index == null) {
41
+ throw new Error('CarouselSlide must be used within Carousel');
42
+ }
43
+ var currentIndex = context.currentIndex, isManuallyUpdating = context.isManuallyUpdating, setCurrentIndex = context.setCurrentIndex;
44
+ var updateActiveIndexOnScroll = React.useCallback(function () {
45
+ // only update index if scroll was triggered by browser
46
+ if (!isManuallyUpdating.current && currentIndex !== index) {
47
+ setCurrentIndex(index);
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]);
54
+ var intersectionRef = useIntersection(updateActiveIndexOnScroll, { threshold: 0.5 }, false);
55
+ var refs = useMergedRefs(intersectionRef, ref);
56
+ return (React.createElement("li", __assign({ className: cx('iui-carousel-slider-item', className), role: 'tabpanel', "aria-roledescription": 'slide', ref: refs }, rest), children));
57
+ });
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ /**
3
+ * `CarouselSlider` is the scrollable list that should consist of `CarouselSlide` components.
4
+ */
5
+ export declare const CarouselSlider: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>, "key" | keyof React.OlHTMLAttributes<HTMLOListElement>> & React.RefAttributes<HTMLOListElement>>;
@@ -0,0 +1,88 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { CarouselContext } from './CarouselContext';
30
+ import { getWindow, useMergedRefs, useResizeObserver } from '../utils';
31
+ /**
32
+ * `CarouselSlider` is the scrollable list that should consist of `CarouselSlide` components.
33
+ */
34
+ export var CarouselSlider = React.forwardRef(function (props, ref) {
35
+ var children = props.children, className = props.className, rest = __rest(props, ["children", "className"]);
36
+ var context = React.useContext(CarouselContext);
37
+ if (!context) {
38
+ throw new Error('CarouselSlider must be used within Carousel');
39
+ }
40
+ var currentIndex = context.currentIndex, setSlideCount = context.setSlideCount, idPrefix = context.idPrefix, isManuallyUpdating = context.isManuallyUpdating, scrollInstantly = context.scrollInstantly;
41
+ var items = React.useMemo(function () {
42
+ var _a;
43
+ return (_a = React.Children.map(children, function (child, index) {
44
+ return React.isValidElement(child)
45
+ ? React.cloneElement(child, {
46
+ id: idPrefix + "--slide-" + index,
47
+ index: index,
48
+ })
49
+ : child;
50
+ })) !== null && _a !== void 0 ? _a : [];
51
+ }, [children, idPrefix]);
52
+ React.useLayoutEffect(function () {
53
+ setSlideCount(items.length);
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
+ 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)) {
70
+ return;
71
+ }
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;
78
+ sliderRef.current.scrollTo({
79
+ left: slideToShow.offsetLeft - sliderRef.current.offsetLeft,
80
+ behavior: (scrollInstantly.current || !motionOk
81
+ ? 'instant'
82
+ : 'smooth'), // scrollTo accepts 'instant' but ScrollBehavior type is wrong
83
+ });
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));
88
+ });
@@ -0,0 +1,4 @@
1
+ export { Carousel } from './Carousel';
2
+ export type { CarouselProps } from './Carousel';
3
+ declare const _default: "./Carousel";
4
+ export default _default;
@@ -0,0 +1,6 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ export { Carousel } from './Carousel';
6
+ export default './Carousel';
@@ -17,5 +17,5 @@ export declare type ColorSwatchProps = {
17
17
  * <ColorSwatch color='#23450b' onClick={onClick}/>
18
18
  * <ColorSwatch color={{ r: 255, g: 255, b: 0 }} onClick={onClick}/>
19
19
  */
20
- export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "aria-disabled" | "role" | "children" | "className" | "accessKey" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "isActive"> & React.RefAttributes<HTMLDivElement>>;
20
+ export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "aria-disabled" | "role" | "children" | "className" | "onClick" | "accessKey" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "isActive"> & React.RefAttributes<HTMLDivElement>>;
21
21
  export default ColorSwatch;
@@ -36,6 +36,11 @@ export declare type DatePickerProps = {
36
36
  * @default false
37
37
  */
38
38
  showTime?: boolean;
39
+ /**
40
+ * Show additional buttons to select year.
41
+ * @default false
42
+ */
43
+ showYearSelection?: boolean;
39
44
  } & Omit<TimePickerProps, 'date' | 'onChange' | 'setFocusHour'>;
40
45
  /**
41
46
  * Date picker component
@@ -26,6 +26,8 @@ var __rest = (this && this.__rest) || function (s, e) {
26
26
  *--------------------------------------------------------------------------------------------*/
27
27
  import SvgChevronLeft from '@itwin/itwinui-icons-react/cjs/icons/ChevronLeft';
28
28
  import SvgChevronRight from '@itwin/itwinui-icons-react/cjs/icons/ChevronRight';
29
+ import SvgChevronLeftDouble from '@itwin/itwinui-icons-react/cjs/icons/ChevronLeftDouble';
30
+ import SvgChevronRightDouble from '@itwin/itwinui-icons-react/cjs/icons/ChevronRightDouble';
29
31
  import cx from 'classnames';
30
32
  import React from 'react';
31
33
  import { useTheme } from '../utils';
@@ -120,15 +122,15 @@ export var generateLocalizedStrings = function (locale) {
120
122
  */
121
123
  export var DatePicker = function (props) {
122
124
  var _a, _b, _c;
123
- var date = props.date, onChange = props.onChange, localizedNames = props.localizedNames, className = props.className, style = props.style, _d = props.setFocus, setFocus = _d === void 0 ? false : _d, _e = props.showTime, showTime = _e === void 0 ? false : _e, _f = props.use12Hours, use12Hours = _f === void 0 ? false : _f, precision = props.precision, hourStep = props.hourStep, minuteStep = props.minuteStep, secondStep = props.secondStep, rest = __rest(props, ["date", "onChange", "localizedNames", "className", "style", "setFocus", "showTime", "use12Hours", "precision", "hourStep", "minuteStep", "secondStep"]);
125
+ var date = props.date, onChange = props.onChange, localizedNames = props.localizedNames, className = props.className, style = props.style, _d = props.setFocus, setFocus = _d === void 0 ? false : _d, _e = props.showTime, showTime = _e === void 0 ? false : _e, _f = props.use12Hours, use12Hours = _f === void 0 ? false : _f, precision = props.precision, hourStep = props.hourStep, minuteStep = props.minuteStep, secondStep = props.secondStep, _g = props.showYearSelection, showYearSelection = _g === void 0 ? false : _g, rest = __rest(props, ["date", "onChange", "localizedNames", "className", "style", "setFocus", "showTime", "use12Hours", "precision", "hourStep", "minuteStep", "secondStep", "showYearSelection"]);
124
126
  useTheme();
125
127
  var monthNames = (_a = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.months) !== null && _a !== void 0 ? _a : defaultMonths;
126
128
  var shortDays = (_b = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.shortDays) !== null && _b !== void 0 ? _b : defaultShortDays;
127
129
  var longDays = (_c = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.days) !== null && _c !== void 0 ? _c : defaultLongDays;
128
- var _g = React.useState(date), selectedDay = _g[0], setSelectedDay = _g[1];
129
- var _h = React.useState(selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date()), focusedDay = _h[0], setFocusedDay = _h[1];
130
- var _j = React.useState(selectedDay ? selectedDay.getMonth() : new Date().getMonth()), displayedMonthIndex = _j[0], setDisplayedMonthIndex = _j[1];
131
- var _k = React.useState(selectedDay ? selectedDay.getFullYear() : new Date().getFullYear()), displayedYear = _k[0], setDisplayedYear = _k[1];
130
+ var _h = React.useState(date), selectedDay = _h[0], setSelectedDay = _h[1];
131
+ var _j = React.useState(selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date()), focusedDay = _j[0], setFocusedDay = _j[1];
132
+ var _k = React.useState(selectedDay ? selectedDay.getMonth() : new Date().getMonth()), displayedMonthIndex = _k[0], setDisplayedMonthIndex = _k[1];
133
+ var _l = React.useState(selectedDay ? selectedDay.getFullYear() : new Date().getFullYear()), displayedYear = _l[0], setDisplayedYear = _l[1];
132
134
  // Used to focus days only when days are changed
133
135
  // e.g. without this, when changing months day would be focused
134
136
  var needFocus = React.useRef(setFocus);
@@ -174,6 +176,16 @@ export var DatePicker = function (props) {
174
176
  var newDate = new Date(newYear, newMonth, currentDate.getDate(), currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds());
175
177
  return newDate;
176
178
  };
179
+ var handleMoveToPreviousYear = function () {
180
+ var newYear = displayedYear - 1;
181
+ setMonthAndYear(displayedMonthIndex, newYear);
182
+ setFocusedDay(getNewFocusedDate(newYear, displayedMonthIndex));
183
+ };
184
+ var handleMoveToNextYear = function () {
185
+ var newYear = displayedYear + 1;
186
+ setMonthAndYear(displayedMonthIndex, newYear);
187
+ setFocusedDay(getNewFocusedDate(newYear, displayedMonthIndex));
188
+ };
177
189
  var handleMoveToPreviousMonth = function () {
178
190
  var newMonth = displayedMonthIndex !== 0 ? displayedMonthIndex - 1 : 11;
179
191
  var newYear = displayedMonthIndex !== 0 ? displayedYear : displayedYear - 1;
@@ -246,26 +258,39 @@ export var DatePicker = function (props) {
246
258
  break;
247
259
  }
248
260
  };
261
+ var getDayClass = function (day) {
262
+ if (day.getMonth() !== displayedMonthIndex) {
263
+ return 'iui-calendar-day-outside-month';
264
+ }
265
+ var dayClass = 'iui-calendar-day';
266
+ if (isSameDay(day, selectedDay)) {
267
+ dayClass += '-selected';
268
+ }
269
+ if (isSameDay(day, new Date())) {
270
+ dayClass += '-today';
271
+ }
272
+ return dayClass;
273
+ };
249
274
  return (React.createElement("div", __assign({ className: cx('iui-date-picker', className), style: style }, rest),
250
275
  React.createElement("div", null,
251
276
  React.createElement("div", { className: 'iui-calendar-month-year' },
252
- React.createElement(IconButton, { styleType: 'borderless', onClick: handleMoveToPreviousMonth, "aria-label": 'Previous month' },
277
+ showYearSelection && (React.createElement(IconButton, { styleType: 'borderless', onClick: handleMoveToPreviousYear, "aria-label": 'Previous year', size: 'small' },
278
+ React.createElement(SvgChevronLeftDouble, null))),
279
+ React.createElement(IconButton, { styleType: 'borderless', onClick: handleMoveToPreviousMonth, "aria-label": 'Previous month', size: 'small' },
253
280
  React.createElement(SvgChevronLeft, null)),
254
281
  React.createElement("span", { "aria-live": 'polite' },
255
282
  React.createElement("span", { className: 'iui-calendar-month', title: monthNames[displayedMonthIndex] }, monthNames[displayedMonthIndex]),
256
283
  "\u00A0",
257
284
  displayedYear),
258
- React.createElement(IconButton, { styleType: 'borderless', onClick: handleMoveToNextMonth, "aria-label": 'Next month' },
259
- React.createElement(SvgChevronRight, null))),
285
+ React.createElement(IconButton, { styleType: 'borderless', onClick: handleMoveToNextMonth, "aria-label": 'Next month', size: 'small' },
286
+ React.createElement(SvgChevronRight, null)),
287
+ showYearSelection && (React.createElement(IconButton, { styleType: 'borderless', onClick: handleMoveToNextYear, "aria-label": 'Next year', size: 'small' },
288
+ React.createElement(SvgChevronRightDouble, null)))),
260
289
  React.createElement("div", { className: 'iui-calendar-weekdays' }, shortDays.map(function (day, index) { return (React.createElement("div", { key: day, title: longDays[index] }, day)); })),
261
290
  React.createElement("div", { onKeyDown: handleCalendarKeyDown, role: 'listbox' }, weeks.map(function (weekDays, weekIndex) {
262
291
  return (React.createElement("div", { key: "week-" + displayedMonthIndex + "-" + weekIndex, className: 'iui-calendar-week' }, weekDays.map(function (weekDay, dayIndex) {
263
292
  var dateValue = weekDay.getDate();
264
- return (React.createElement("div", { key: "day-" + displayedMonthIndex + "-" + dayIndex, className: cx('iui-calendar-day', {
265
- 'iui-outside-month': weekDay.getMonth() !== displayedMonthIndex,
266
- 'iui-today': isSameDay(weekDay, new Date()),
267
- 'iui-selected': isSameDay(weekDay, selectedDay),
268
- }), onClick: function () { return onDayClick(weekDay); }, role: 'option', tabIndex: isSameDay(weekDay, focusedDay) ? 0 : -1, ref: function (element) {
293
+ return (React.createElement("div", { key: "day-" + displayedMonthIndex + "-" + dayIndex, className: getDayClass(weekDay), onClick: function () { return onDayClick(weekDay); }, role: 'option', tabIndex: isSameDay(weekDay, focusedDay) ? 0 : -1, ref: function (element) {
269
294
  return isSameDay(weekDay, focusedDay) &&
270
295
  needFocus.current &&
271
296
  (element === null || element === void 0 ? void 0 : element.focus());
@@ -55,6 +55,7 @@ export var HeaderButton = React.forwardRef(function (props, ref) {
55
55
  : undefined, styleType: 'borderless', className: cx({
56
56
  'iui-header-button': !isSplitButton(props),
57
57
  'iui-header-split-button': isSplitButton(props),
58
+ 'iui-header-dropdown-button': !isSplitButton(props) && isDropdownButton(props),
58
59
  'iui-active': isActive,
59
60
  }, className), 'aria-current': isActive ? 'location' : undefined, children: (React.createElement(React.Fragment, null,
60
61
  React.createElement("div", null, name),
@@ -40,9 +40,14 @@ export var Menu = React.forwardRef(function (props, ref) {
40
40
  React.useEffect(function () {
41
41
  setFocusedIndex(null);
42
42
  }, [children]);
43
+ var getFocusableNodes = React.useCallback(function () {
44
+ var focusableItems = getFocusableElements(menuRef.current);
45
+ // Filter out focusable elements that are inside each menu item, e.g. checkbox, anchor
46
+ return focusableItems.filter(function (i) { return !focusableItems.some(function (p) { return p.contains(i.parentElement); }); });
47
+ }, []);
43
48
  React.useEffect(function () {
44
49
  var _a;
45
- var items = getFocusableElements(menuRef.current);
50
+ var items = getFocusableNodes();
46
51
  if (focusedIndex != null) {
47
52
  (_a = items === null || items === void 0 ? void 0 : items[focusedIndex]) === null || _a === void 0 ? void 0 : _a.focus();
48
53
  return;
@@ -51,9 +56,9 @@ export var Menu = React.forwardRef(function (props, ref) {
51
56
  if (setFocus) {
52
57
  setFocusedIndex(selectedIndex > -1 ? selectedIndex : 0);
53
58
  }
54
- }, [setFocus, focusedIndex]);
59
+ }, [setFocus, focusedIndex, getFocusableNodes]);
55
60
  var onKeyDown = function (event) {
56
- var items = getFocusableElements(menuRef.current);
61
+ var items = getFocusableNodes();
57
62
  if (!(items === null || items === void 0 ? void 0 : items.length)) {
58
63
  return;
59
64
  }