@itwin/itwinui-react 3.0.0-dev.1 → 3.0.0-dev.2

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 (211) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/cjs/core/Alert/Alert.d.ts +47 -28
  3. package/cjs/core/Alert/Alert.js +73 -21
  4. package/cjs/core/Avatar/Avatar.js +1 -1
  5. package/cjs/core/AvatarGroup/AvatarGroup.js +1 -1
  6. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
  7. package/cjs/core/ButtonGroup/ButtonGroup.js +1 -4
  8. package/cjs/core/Buttons/DropdownButton/DropdownButton.js +3 -5
  9. package/cjs/core/Carousel/Carousel.d.ts +2 -2
  10. package/cjs/core/Carousel/Carousel.js +3 -5
  11. package/cjs/core/Carousel/CarouselDotsList.js +8 -10
  12. package/cjs/core/Carousel/CarouselNavigation.d.ts +2 -2
  13. package/cjs/core/Carousel/CarouselNavigation.js +3 -5
  14. package/cjs/core/Carousel/CarouselSlider.js +10 -15
  15. package/cjs/core/ColorPicker/ColorBuilder.js +7 -10
  16. package/cjs/core/ColorPicker/ColorInputPanel.js +12 -15
  17. package/cjs/core/ColorPicker/ColorPalette.js +4 -6
  18. package/cjs/core/ColorPicker/ColorPicker.js +3 -3
  19. package/cjs/core/ComboBox/ComboBox.js +25 -32
  20. package/cjs/core/ComboBox/ComboBoxDropdown.js +1 -2
  21. package/cjs/core/ComboBox/ComboBoxEndIcon.js +1 -1
  22. package/cjs/core/ComboBox/ComboBoxInput.js +21 -20
  23. package/cjs/core/ComboBox/ComboBoxMenu.js +3 -4
  24. package/cjs/core/ComboBox/ComboBoxMenuItem.js +2 -2
  25. package/cjs/core/ComboBox/helpers.js +4 -5
  26. package/cjs/core/DatePicker/DatePicker.js +32 -32
  27. package/cjs/core/Dialog/Dialog.js +11 -4
  28. package/cjs/core/Dialog/DialogBackdrop.js +1 -1
  29. package/cjs/core/Dialog/DialogContext.d.ts +11 -0
  30. package/cjs/core/Dialog/DialogMain.js +16 -22
  31. package/cjs/core/DropdownMenu/DropdownMenu.js +6 -8
  32. package/cjs/core/ExpandableBlock/ExpandableBlock.js +2 -2
  33. package/cjs/core/FileUpload/FileEmptyCard.js +1 -1
  34. package/cjs/core/FileUpload/FileUpload.js +3 -6
  35. package/cjs/core/FileUpload/FileUploadCard.js +9 -10
  36. package/cjs/core/InformationPanel/InformationPanel.js +1 -4
  37. package/cjs/core/LabeledInput/LabeledInput.js +1 -1
  38. package/cjs/core/LabeledTextarea/LabeledTextarea.js +1 -1
  39. package/cjs/core/Menu/Menu.js +3 -4
  40. package/cjs/core/Menu/MenuItem.js +8 -11
  41. package/cjs/core/Modal/Modal.d.ts +8 -9
  42. package/cjs/core/Modal/Modal.js +7 -17
  43. package/cjs/core/SearchBox/SearchBox.js +12 -12
  44. package/cjs/core/Select/Select.js +12 -17
  45. package/cjs/core/SideNavigation/SideNavigation.js +2 -2
  46. package/cjs/core/Slider/Slider.js +16 -19
  47. package/cjs/core/Slider/Thumb.js +1 -1
  48. package/cjs/core/StatusMessage/StatusMessage.js +1 -1
  49. package/cjs/core/Stepper/Stepper.js +1 -1
  50. package/cjs/core/Stepper/StepperStep.js +1 -1
  51. package/cjs/core/Table/Table.js +15 -15
  52. package/cjs/core/Table/TablePaginator.js +2 -3
  53. package/cjs/core/Table/TableRowMemoized.js +38 -45
  54. package/cjs/core/Table/actionHandlers/expandHandler.js +3 -3
  55. package/cjs/core/Table/actionHandlers/filterHandler.js +4 -5
  56. package/cjs/core/Table/actionHandlers/selectHandler.js +6 -6
  57. package/cjs/core/Table/cells/DefaultCell.js +1 -1
  58. package/cjs/core/Table/cells/EditableCell.js +6 -12
  59. package/cjs/core/Table/columns/actionColumn.js +3 -6
  60. package/cjs/core/Table/columns/expanderColumn.js +3 -3
  61. package/cjs/core/Table/columns/selectionColumn.js +4 -4
  62. package/cjs/core/Table/filters/DateRangeFilter/DatePickerInput.js +2 -4
  63. package/cjs/core/Table/filters/DateRangeFilter/DateRangeFilter.js +2 -3
  64. package/cjs/core/Table/filters/NumberRangeFilter/NumberRangeFilter.js +2 -3
  65. package/cjs/core/Table/filters/TextFilter/TextFilter.js +1 -2
  66. package/cjs/core/Table/hooks/useResizeColumns.js +16 -22
  67. package/cjs/core/Table/hooks/useScrollToRow.js +1 -2
  68. package/cjs/core/Table/hooks/useStickyColumns.js +3 -5
  69. package/cjs/core/Table/hooks/useSubRowFiltering.js +2 -4
  70. package/cjs/core/Tabs/Tabs.js +13 -16
  71. package/cjs/core/ThemeProvider/ThemeContext.d.ts +1 -1
  72. package/cjs/core/ThemeProvider/ThemeProvider.d.ts +2 -3
  73. package/cjs/core/ThemeProvider/ThemeProvider.js +11 -13
  74. package/cjs/core/Tile/Tile.js +2 -3
  75. package/cjs/core/TimePicker/TimePicker.js +13 -13
  76. package/cjs/core/Toast/Toast.js +2 -3
  77. package/cjs/core/Toast/Toaster.js +6 -11
  78. package/cjs/core/TransferList/TransferList.js +3 -4
  79. package/cjs/core/Tree/Tree.js +9 -13
  80. package/cjs/core/Tree/TreeNode.js +9 -10
  81. package/cjs/core/utils/color/ColorValue.js +9 -15
  82. package/cjs/core/utils/components/AutoclearingHiddenLiveRegion.js +2 -3
  83. package/cjs/core/utils/components/FocusTrap.js +4 -4
  84. package/cjs/core/utils/components/MiddleTextTruncation.js +1 -2
  85. package/cjs/core/utils/components/Popover.js +5 -8
  86. package/cjs/core/utils/components/Resizer.js +7 -6
  87. package/cjs/core/utils/components/VirtualScroll.js +14 -21
  88. package/cjs/core/utils/functions/dom.js +5 -5
  89. package/cjs/core/utils/functions/polymorphic.js +1 -1
  90. package/cjs/core/utils/functions/supports.js +1 -1
  91. package/cjs/core/utils/hooks/index.d.ts +0 -1
  92. package/cjs/core/utils/hooks/index.js +0 -1
  93. package/cjs/core/utils/hooks/useContainerWidth.js +1 -1
  94. package/cjs/core/utils/hooks/useDragAndDrop.js +8 -10
  95. package/cjs/core/utils/hooks/useEventListener.js +1 -1
  96. package/cjs/core/utils/hooks/useGlobals.d.ts +9 -2
  97. package/cjs/core/utils/hooks/useGlobals.js +6 -4
  98. package/cjs/core/utils/hooks/useId.js +1 -2
  99. package/cjs/core/utils/hooks/useIntersection.js +2 -3
  100. package/cjs/core/utils/hooks/useMediaQuery.js +6 -8
  101. package/cjs/core/utils/hooks/useOverflow.js +1 -2
  102. package/cjs/core/utils/hooks/useResizeObserver.js +3 -4
  103. package/cjs/styles.js +1 -4
  104. package/esm/core/Alert/Alert.d.ts +47 -28
  105. package/esm/core/Alert/Alert.js +74 -22
  106. package/esm/core/Avatar/Avatar.js +1 -1
  107. package/esm/core/AvatarGroup/AvatarGroup.js +1 -1
  108. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
  109. package/esm/core/ButtonGroup/ButtonGroup.js +1 -4
  110. package/esm/core/Buttons/DropdownButton/DropdownButton.js +3 -5
  111. package/esm/core/Carousel/Carousel.d.ts +2 -2
  112. package/esm/core/Carousel/Carousel.js +3 -5
  113. package/esm/core/Carousel/CarouselDotsList.js +8 -10
  114. package/esm/core/Carousel/CarouselNavigation.d.ts +2 -2
  115. package/esm/core/Carousel/CarouselNavigation.js +3 -5
  116. package/esm/core/Carousel/CarouselSlider.js +10 -15
  117. package/esm/core/ColorPicker/ColorBuilder.js +7 -10
  118. package/esm/core/ColorPicker/ColorInputPanel.js +12 -15
  119. package/esm/core/ColorPicker/ColorPalette.js +4 -6
  120. package/esm/core/ColorPicker/ColorPicker.js +3 -3
  121. package/esm/core/ComboBox/ComboBox.js +25 -32
  122. package/esm/core/ComboBox/ComboBoxDropdown.js +1 -2
  123. package/esm/core/ComboBox/ComboBoxEndIcon.js +1 -1
  124. package/esm/core/ComboBox/ComboBoxInput.js +21 -20
  125. package/esm/core/ComboBox/ComboBoxMenu.js +3 -4
  126. package/esm/core/ComboBox/ComboBoxMenuItem.js +2 -2
  127. package/esm/core/ComboBox/helpers.js +4 -5
  128. package/esm/core/DatePicker/DatePicker.js +32 -32
  129. package/esm/core/Dialog/Dialog.js +12 -5
  130. package/esm/core/Dialog/DialogBackdrop.js +1 -1
  131. package/esm/core/Dialog/DialogContext.d.ts +11 -0
  132. package/esm/core/Dialog/DialogMain.js +16 -22
  133. package/esm/core/DropdownMenu/DropdownMenu.js +6 -8
  134. package/esm/core/ExpandableBlock/ExpandableBlock.js +2 -2
  135. package/esm/core/FileUpload/FileEmptyCard.js +1 -1
  136. package/esm/core/FileUpload/FileUpload.js +3 -6
  137. package/esm/core/FileUpload/FileUploadCard.js +9 -10
  138. package/esm/core/InformationPanel/InformationPanel.js +1 -4
  139. package/esm/core/LabeledInput/LabeledInput.js +1 -1
  140. package/esm/core/LabeledTextarea/LabeledTextarea.js +1 -1
  141. package/esm/core/Menu/Menu.js +3 -4
  142. package/esm/core/Menu/MenuItem.js +8 -11
  143. package/esm/core/Modal/Modal.d.ts +8 -9
  144. package/esm/core/Modal/Modal.js +3 -10
  145. package/esm/core/SearchBox/SearchBox.js +12 -12
  146. package/esm/core/Select/Select.js +12 -17
  147. package/esm/core/SideNavigation/SideNavigation.js +2 -2
  148. package/esm/core/Slider/Slider.js +16 -19
  149. package/esm/core/Slider/Thumb.js +1 -1
  150. package/esm/core/StatusMessage/StatusMessage.js +1 -1
  151. package/esm/core/Stepper/Stepper.js +1 -1
  152. package/esm/core/Stepper/StepperStep.js +1 -1
  153. package/esm/core/Table/Table.js +15 -15
  154. package/esm/core/Table/TablePaginator.js +2 -3
  155. package/esm/core/Table/TableRowMemoized.js +38 -45
  156. package/esm/core/Table/actionHandlers/expandHandler.js +3 -3
  157. package/esm/core/Table/actionHandlers/filterHandler.js +4 -5
  158. package/esm/core/Table/actionHandlers/selectHandler.js +6 -6
  159. package/esm/core/Table/cells/DefaultCell.js +1 -1
  160. package/esm/core/Table/cells/EditableCell.js +6 -12
  161. package/esm/core/Table/columns/actionColumn.js +3 -6
  162. package/esm/core/Table/columns/expanderColumn.js +3 -3
  163. package/esm/core/Table/columns/selectionColumn.js +4 -4
  164. package/esm/core/Table/filters/DateRangeFilter/DatePickerInput.js +2 -4
  165. package/esm/core/Table/filters/DateRangeFilter/DateRangeFilter.js +2 -3
  166. package/esm/core/Table/filters/NumberRangeFilter/NumberRangeFilter.js +2 -3
  167. package/esm/core/Table/filters/TextFilter/TextFilter.js +1 -2
  168. package/esm/core/Table/hooks/useResizeColumns.js +16 -22
  169. package/esm/core/Table/hooks/useScrollToRow.js +1 -2
  170. package/esm/core/Table/hooks/useStickyColumns.js +3 -5
  171. package/esm/core/Table/hooks/useSubRowFiltering.js +2 -4
  172. package/esm/core/Tabs/Tabs.js +13 -16
  173. package/esm/core/ThemeProvider/ThemeContext.d.ts +1 -1
  174. package/esm/core/ThemeProvider/ThemeProvider.d.ts +2 -3
  175. package/esm/core/ThemeProvider/ThemeProvider.js +12 -14
  176. package/esm/core/Tile/Tile.js +2 -3
  177. package/esm/core/TimePicker/TimePicker.js +13 -13
  178. package/esm/core/Toast/Toast.js +2 -3
  179. package/esm/core/Toast/Toaster.js +6 -11
  180. package/esm/core/TransferList/TransferList.js +3 -4
  181. package/esm/core/Tree/Tree.js +9 -13
  182. package/esm/core/Tree/TreeNode.js +9 -10
  183. package/esm/core/utils/color/ColorValue.js +9 -15
  184. package/esm/core/utils/components/AutoclearingHiddenLiveRegion.js +2 -3
  185. package/esm/core/utils/components/FocusTrap.js +4 -4
  186. package/esm/core/utils/components/MiddleTextTruncation.js +1 -2
  187. package/esm/core/utils/components/Popover.js +5 -8
  188. package/esm/core/utils/components/Resizer.js +7 -6
  189. package/esm/core/utils/components/VirtualScroll.js +14 -21
  190. package/esm/core/utils/functions/dom.js +5 -5
  191. package/esm/core/utils/functions/polymorphic.js +1 -1
  192. package/esm/core/utils/functions/supports.js +1 -1
  193. package/esm/core/utils/hooks/index.d.ts +0 -1
  194. package/esm/core/utils/hooks/index.js +0 -1
  195. package/esm/core/utils/hooks/useContainerWidth.js +1 -1
  196. package/esm/core/utils/hooks/useDragAndDrop.js +8 -10
  197. package/esm/core/utils/hooks/useEventListener.js +1 -1
  198. package/esm/core/utils/hooks/useGlobals.d.ts +9 -2
  199. package/esm/core/utils/hooks/useGlobals.js +6 -4
  200. package/esm/core/utils/hooks/useId.js +1 -2
  201. package/esm/core/utils/hooks/useIntersection.js +2 -3
  202. package/esm/core/utils/hooks/useMediaQuery.js +6 -8
  203. package/esm/core/utils/hooks/useOverflow.js +1 -2
  204. package/esm/core/utils/hooks/useResizeObserver.js +3 -4
  205. package/esm/styles.js +1 -4
  206. package/package.json +2 -2
  207. package/styles.css +18 -20
  208. package/cjs/core/utils/hooks/useIsThemeAlreadySet.d.ts +0 -7
  209. package/cjs/core/utils/hooks/useIsThemeAlreadySet.js +0 -54
  210. package/esm/core/utils/hooks/useIsThemeAlreadySet.d.ts +0 -7
  211. package/esm/core/utils/hooks/useIsThemeAlreadySet.js +0 -27
@@ -25,9 +25,8 @@ export const ColorPalette = React.forwardRef((props, ref) => {
25
25
  const [focusedIndex, setFocusedIndex] = React.useState();
26
26
  // callback ref to set tabindex=0 on first child if none of the swatches are tabbable
27
27
  const setDefaultTabIndex = (el) => {
28
- var _a;
29
28
  if (el && !el.querySelector('[tabindex="0"]')) {
30
- (_a = el.firstElementChild) === null || _a === void 0 ? void 0 : _a.setAttribute('tabindex', '0');
29
+ el.firstElementChild?.setAttribute('tabindex', '0');
31
30
  }
32
31
  };
33
32
  const paletteRef = React.useRef(null);
@@ -41,7 +40,7 @@ export const ColorPalette = React.forwardRef((props, ref) => {
41
40
  if (!swatches.length) {
42
41
  return;
43
42
  }
44
- const currentIndex = swatches.findIndex((swatch) => { var _a; return swatch === ((_a = paletteRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.activeElement); });
43
+ const currentIndex = swatches.findIndex((swatch) => swatch === paletteRef.current?.ownerDocument.activeElement);
45
44
  if (currentIndex < 0) {
46
45
  return;
47
46
  }
@@ -83,10 +82,9 @@ export const ColorPalette = React.forwardRef((props, ref) => {
83
82
  };
84
83
  // call focus() when focusedIndex changes
85
84
  React.useEffect(() => {
86
- var _a;
87
85
  if (focusedIndex != null) {
88
86
  const swatches = getFocusableElements(paletteRef.current);
89
- (_a = swatches[focusedIndex]) === null || _a === void 0 ? void 0 : _a.focus();
87
+ swatches[focusedIndex]?.focus();
90
88
  }
91
89
  }, [focusedIndex]);
92
90
  return (React.createElement(Box, { className: cx('iui-color-palette-wrapper', className), ref: ref, ...rest },
@@ -98,7 +96,7 @@ export const ColorPalette = React.forwardRef((props, ref) => {
98
96
  const color = getColorValue(_color);
99
97
  return (React.createElement(ColorSwatch, { key: index, color: color, onClick: (event) => {
100
98
  event.preventDefault();
101
- onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(color);
99
+ onChangeComplete?.(color);
102
100
  setActiveColor(color);
103
101
  }, isActive: color.equals(activeColor) }));
104
102
  }))));
@@ -54,13 +54,13 @@ export const ColorPicker = React.forwardRef((props, forwardedRef) => {
54
54
  const applyHsvColorChange = React.useCallback((newColor, selectionChanged, newColorValue) => {
55
55
  // save the HSV values
56
56
  setHsvColor(newColor);
57
- const newActiveColor = newColorValue !== null && newColorValue !== void 0 ? newColorValue : ColorValue.create(newColor);
57
+ const newActiveColor = newColorValue ?? ColorValue.create(newColor);
58
58
  // Only update selected color when dragging is done
59
59
  if (selectionChanged) {
60
- onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newActiveColor);
60
+ onChangeComplete?.(newActiveColor);
61
61
  }
62
62
  else {
63
- onChange === null || onChange === void 0 ? void 0 : onChange(newActiveColor);
63
+ onChange?.(newActiveColor);
64
64
  }
65
65
  activeColorTbgr.current = newActiveColor.toTbgr();
66
66
  // this converts it to store in tbgr
@@ -24,8 +24,7 @@ const isSingleOnChange = (onChange, multiple) => {
24
24
  };
25
25
  /** Returns either `option.id` or derives a stable id using `idPrefix` and `option.label` (without whitespace) */
26
26
  const getOptionId = (option, idPrefix) => {
27
- var _a;
28
- return (_a = option.id) !== null && _a !== void 0 ? _a : `${idPrefix}-option-${option.label.replace(/\s/g, '-')}`;
27
+ return option.id ?? `${idPrefix}-option-${option.label.replace(/\s/g, '-')}`;
29
28
  };
30
29
  /**
31
30
  * ComboBox component that allows typing a value to filter the options in dropdown list.
@@ -41,13 +40,11 @@ const getOptionId = (option, idPrefix) => {
41
40
  * />
42
41
  */
43
42
  export const ComboBox = (props) => {
44
- var _a, _b;
45
43
  const { options, value: valueProp, onChange, filterFunction, inputProps, dropdownMenuProps, emptyStateMessage = 'No options found', itemRenderer, enableVirtualization = false, multiple = false, onShow, onHide, ...rest } = props;
46
44
  // Generate a stateful random id if not specified
47
- const [id] = React.useState(() => {
48
- var _a, _b;
49
- return (_b = (_a = props.id) !== null && _a !== void 0 ? _a : ((inputProps === null || inputProps === void 0 ? void 0 : inputProps.id) && `${inputProps.id}-cb`)) !== null && _b !== void 0 ? _b : `iui-cb-${getRandomValue(10)}`;
50
- });
45
+ const [id] = React.useState(() => props.id ??
46
+ (inputProps?.id && `${inputProps.id}-cb`) ??
47
+ `iui-cb-${getRandomValue(10)}`);
51
48
  // Refs get set in subcomponents
52
49
  const inputRef = React.useRef(null);
53
50
  const menuRef = React.useRef(null);
@@ -73,7 +70,7 @@ export const ComboBox = (props) => {
73
70
  const getSelectedIndexes = React.useCallback(() => {
74
71
  if (isMultipleEnabled(valueProp, multiple)) {
75
72
  const indexArray = [];
76
- valueProp === null || valueProp === void 0 ? void 0 : valueProp.forEach((value) => {
73
+ valueProp?.forEach((value) => {
77
74
  const indexToAdd = options.findIndex((option) => option.value === value);
78
75
  if (indexToAdd > -1) {
79
76
  indexArray.push(indexToAdd);
@@ -92,10 +89,9 @@ export const ComboBox = (props) => {
92
89
  focusedIndex: -1,
93
90
  });
94
91
  useIsomorphicLayoutEffect(() => {
95
- var _a, _b;
96
92
  // When the dropdown opens
97
93
  if (isOpen) {
98
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); // Focus the input
94
+ inputRef.current?.focus(); // Focus the input
99
95
  // Reset the filtered list (does not reset when multiple enabled)
100
96
  if (!multiple) {
101
97
  setFilteredOptions(optionsRef.current);
@@ -109,7 +105,7 @@ export const ComboBox = (props) => {
109
105
  // Reset the input value if not multiple
110
106
  if (!isMultipleEnabled(selected, multiple)) {
111
107
  setInputValue(selected != undefined && selected >= 0
112
- ? (_b = optionsRef.current[selected]) === null || _b === void 0 ? void 0 : _b.label
108
+ ? optionsRef.current[selected]?.label
113
109
  : '');
114
110
  }
115
111
  }
@@ -124,9 +120,9 @@ export const ComboBox = (props) => {
124
120
  // Update filtered options to the latest value options according to input value
125
121
  const [filteredOptions, setFilteredOptions] = React.useState(options);
126
122
  React.useEffect(() => {
127
- var _a;
128
123
  if (inputValue) {
129
- setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, inputValue)) !== null && _a !== void 0 ? _a : options.filter((option) => option.label.toLowerCase().includes(inputValue.toLowerCase())));
124
+ setFilteredOptions(filterFunction?.(options, inputValue) ??
125
+ options.filter((option) => option.label.toLowerCase().includes(inputValue.toLowerCase())));
130
126
  }
131
127
  else {
132
128
  setFilteredOptions(options);
@@ -136,18 +132,18 @@ export const ComboBox = (props) => {
136
132
  // eslint-disable-next-line react-hooks/exhaustive-deps
137
133
  }, [options]);
138
134
  // Filter options based on input value
139
- const [inputValue, setInputValue] = React.useState((_b = (_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.value) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '');
135
+ const [inputValue, setInputValue] = React.useState(inputProps?.value?.toString() ?? '');
140
136
  const [liveRegionSelection, setLiveRegionSelection] = React.useState('');
141
137
  const handleOnInput = React.useCallback((event) => {
142
- var _a, _b;
143
138
  const { value } = event.currentTarget;
144
139
  setInputValue(value);
145
140
  dispatch({ type: 'open' }); // reopen when typing
146
- setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(optionsRef.current, value)) !== null && _a !== void 0 ? _a : optionsRef.current.filter((option) => option.label.toLowerCase().includes(value.toLowerCase())));
141
+ setFilteredOptions(filterFunction?.(optionsRef.current, value) ??
142
+ optionsRef.current.filter((option) => option.label.toLowerCase().includes(value.toLowerCase())));
147
143
  if (focusedIndex != -1) {
148
144
  dispatch({ type: 'focus', value: -1 });
149
145
  }
150
- (_b = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _b === void 0 ? void 0 : _b.call(inputProps, event);
146
+ inputProps?.onChange?.(event);
151
147
  }, [filterFunction, focusedIndex, inputProps, optionsRef]);
152
148
  // When the value prop changes, update the selected index/indices
153
149
  React.useEffect(() => {
@@ -196,23 +192,21 @@ export const ComboBox = (props) => {
196
192
  }, [selected]);
197
193
  // Calls user defined onChange
198
194
  const onChangeHandler = React.useCallback((__originalIndex, actionType, newArray) => {
199
- var _a, _b, _c, _d;
200
195
  if (isSingleOnChange(onChangeProp.current, multiple)) {
201
- (_a = onChangeProp.current) === null || _a === void 0 ? void 0 : _a.call(onChangeProp, (_b = optionsRef.current[__originalIndex]) === null || _b === void 0 ? void 0 : _b.value);
196
+ onChangeProp.current?.(optionsRef.current[__originalIndex]?.value);
202
197
  }
203
198
  else {
204
199
  actionType &&
205
200
  newArray &&
206
- ((_c = onChangeProp.current) === null || _c === void 0 ? void 0 : _c.call(onChangeProp, newArray === null || newArray === void 0 ? void 0 : newArray.map((item) => { var _a; return (_a = optionsRef.current[item]) === null || _a === void 0 ? void 0 : _a.value; }), {
207
- value: (_d = optionsRef.current[__originalIndex]) === null || _d === void 0 ? void 0 : _d.value,
201
+ onChangeProp.current?.(newArray?.map((item) => optionsRef.current[item]?.value), {
202
+ value: optionsRef.current[__originalIndex]?.value,
208
203
  type: actionType,
209
- }));
204
+ });
210
205
  }
211
206
  }, [multiple, onChangeProp, optionsRef]);
212
207
  const onClickHandler = React.useCallback((__originalIndex) => {
213
- var _a, _b;
214
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true }); // return focus to input
215
- if ((_b = optionsRef.current[__originalIndex]) === null || _b === void 0 ? void 0 : _b.disabled) {
208
+ inputRef.current?.focus({ preventScroll: true }); // return focus to input
209
+ if (optionsRef.current[__originalIndex]?.disabled) {
216
210
  return;
217
211
  }
218
212
  if (isMultipleEnabled(selected, multiple)) {
@@ -224,7 +218,7 @@ export const ComboBox = (props) => {
224
218
  onChangeHandler(__originalIndex, actionType, newArray);
225
219
  // update live region
226
220
  setLiveRegionSelection(newArray
227
- .map((item) => { var _a; return (_a = optionsRef.current[item]) === null || _a === void 0 ? void 0 : _a.label; })
221
+ .map((item) => optionsRef.current[item]?.label)
228
222
  .filter(Boolean)
229
223
  .join(', '));
230
224
  }
@@ -245,7 +239,7 @@ export const ComboBox = (props) => {
245
239
  const optionId = getOptionId(option, id);
246
240
  const { __originalIndex } = optionsExtraInfoRef.current[optionId];
247
241
  const { icon, startIcon: startIconProp, ...restOptions } = option;
248
- const startIcon = startIconProp !== null && startIconProp !== void 0 ? startIconProp : icon;
242
+ const startIcon = startIconProp ?? icon;
249
243
  const customItem = itemRenderer
250
244
  ? itemRenderer(option, {
251
245
  isFocused: focusedIndex === __originalIndex,
@@ -256,9 +250,8 @@ export const ComboBox = (props) => {
256
250
  : null;
257
251
  return customItem ? (React.cloneElement(customItem, {
258
252
  onClick: (e) => {
259
- var _a, _b;
260
253
  onClickHandler(__originalIndex);
261
- (_b = (_a = customItem.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
254
+ customItem.props.onClick?.(e);
262
255
  },
263
256
  // ComboBox.MenuItem handles scrollIntoView, data-iui-index and focused through context
264
257
  // but we still need to pass them here for backwards compatibility with MenuItem
@@ -267,7 +260,7 @@ export const ComboBox = (props) => {
267
260
  'data-iui-filtered-index': filteredIndex,
268
261
  ref: mergeRefs(customItem.props.ref, (el) => {
269
262
  if (!enableVirtualization && focusedIndex === __originalIndex) {
270
- el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
263
+ el?.scrollIntoView({ block: 'nearest' });
271
264
  }
272
265
  }),
273
266
  })) : (React.createElement(ComboBoxMenuItem, { key: optionId, id: optionId, startIcon: startIcon, ...restOptions, isSelected: isMenuItemSelected(__originalIndex), onClick: () => {
@@ -297,7 +290,7 @@ export const ComboBox = (props) => {
297
290
  getMenuItem,
298
291
  multiple,
299
292
  } },
300
- React.createElement(ComboBoxInputContainer, { disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled, ...rest },
293
+ React.createElement(ComboBoxInputContainer, { disabled: inputProps?.disabled, ...rest },
301
294
  React.createElement(React.Fragment, null,
302
295
  React.createElement(ComboBoxInput, { value: inputValue, ...inputProps, onChange: handleOnInput, selectTags: isMultipleEnabled(selected, multiple)
303
296
  ? selected.map((index) => {
@@ -305,7 +298,7 @@ export const ComboBox = (props) => {
305
298
  return (React.createElement(SelectTag, { key: item.label, label: item.label }));
306
299
  })
307
300
  : undefined })),
308
- React.createElement(ComboBoxEndIcon, { disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled, isOpen: isOpen }),
301
+ React.createElement(ComboBoxEndIcon, { disabled: inputProps?.disabled, isOpen: isOpen }),
309
302
  multiple ? (React.createElement(AutoclearingHiddenLiveRegion, { text: liveRegionSelection })) : null),
310
303
  React.createElement(ComboBoxDropdown, { ...dropdownMenuProps, onShow: onShow, onHide: onHide },
311
304
  React.createElement(ComboBoxMenu, null, filteredOptions.length > 0 && !enableVirtualization
@@ -17,8 +17,7 @@ export const ComboBoxDropdown = React.forwardRef((props, forwardedRef) => {
17
17
  }
18
18
  }, [dispatch, props.visible]);
19
19
  return (React.createElement(Popover, { placement: 'bottom-start', visible: isOpen, onClickOutside: React.useCallback((_, { target }) => {
20
- var _a;
21
- if (!((_a = toggleButtonRef.current) === null || _a === void 0 ? void 0 : _a.contains(target))) {
20
+ if (!toggleButtonRef.current?.contains(target)) {
22
21
  dispatch({ type: 'close' });
23
22
  }
24
23
  }, [dispatch, toggleButtonRef]), animation: 'shift-away', duration: 200, reference: inputRef, ref: forwardedRef, content: children, ...rest }));
@@ -17,6 +17,6 @@ export const ComboBoxEndIcon = React.forwardRef((props, forwardedRef) => {
17
17
  'iui-open': isOpen,
18
18
  }, className), onClick: mergeEventHandlers(onClickProp, () => {
19
19
  dispatch({ type: isOpen ? 'close' : 'open' });
20
- }), ...rest }, children !== null && children !== void 0 ? children : React.createElement(SvgCaretDownSmall, { "aria-hidden": true })));
20
+ }), ...rest }, children ?? React.createElement(SvgCaretDownSmall, { "aria-hidden": true })));
21
21
  });
22
22
  ComboBoxEndIcon.displayName = 'ComboBoxEndIcon';
@@ -13,18 +13,16 @@ export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
13
13
  const dispatch = useSafeContext(ComboBoxActionContext);
14
14
  const { inputRef, menuRef, optionsExtraInfoRef } = useSafeContext(ComboBoxRefsContext);
15
15
  const refs = useMergedRefs(inputRef, forwardedRef);
16
- const focusedIndexRef = React.useRef(focusedIndex !== null && focusedIndex !== void 0 ? focusedIndex : -1);
16
+ const focusedIndexRef = React.useRef(focusedIndex ?? -1);
17
17
  React.useEffect(() => {
18
- focusedIndexRef.current = focusedIndex !== null && focusedIndex !== void 0 ? focusedIndex : -1;
18
+ focusedIndexRef.current = focusedIndex ?? -1;
19
19
  }, [focusedIndex]);
20
20
  const getIdFromIndex = (index) => {
21
- var _a, _b, _c;
22
- return ((_c = (_b = (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-iui-index="${index}"]`)) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '');
21
+ return (menuRef.current?.querySelector(`[data-iui-index="${index}"]`)?.id ?? '');
23
22
  };
24
23
  const handleKeyDown = React.useCallback((event) => {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
26
- onKeyDownProp === null || onKeyDownProp === void 0 ? void 0 : onKeyDownProp(event);
27
- const length = (_a = Object.keys(optionsExtraInfoRef.current).length) !== null && _a !== void 0 ? _a : 0;
24
+ onKeyDownProp?.(event);
25
+ const length = Object.keys(optionsExtraInfoRef.current).length ?? 0;
28
26
  if (event.altKey) {
29
27
  return;
30
28
  }
@@ -38,22 +36,23 @@ export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
38
36
  return;
39
37
  }
40
38
  if (focusedIndexRef.current === -1) {
41
- const currentElement = (_b = menuRef.current) === null || _b === void 0 ? void 0 : _b.querySelector('[data-iui-index]');
39
+ const currentElement = menuRef.current?.querySelector('[data-iui-index]');
42
40
  return dispatch({
43
41
  type: 'focus',
44
- value: Number((_c = currentElement === null || currentElement === void 0 ? void 0 : currentElement.getAttribute('data-iui-index')) !== null && _c !== void 0 ? _c : 0),
42
+ value: Number(currentElement?.getAttribute('data-iui-index') ?? 0),
45
43
  });
46
44
  }
47
45
  // If virtualization is enabled, dont let round scrolling
48
46
  if (enableVirtualization &&
49
- !((_e = (_d = menuRef.current) === null || _d === void 0 ? void 0 : _d.querySelector(`[data-iui-index="${focusedIndexRef.current}"]`)) === null || _e === void 0 ? void 0 : _e.nextElementSibling)) {
47
+ !menuRef.current?.querySelector(`[data-iui-index="${focusedIndexRef.current}"]`)?.nextElementSibling) {
50
48
  return;
51
49
  }
52
50
  let nextIndex = focusedIndexRef.current;
53
51
  do {
54
- const currentElement = (_f = menuRef.current) === null || _f === void 0 ? void 0 : _f.querySelector(`[data-iui-index="${nextIndex}"]`);
55
- const 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]');
56
- nextIndex = Number(nextElement === null || nextElement === void 0 ? void 0 : nextElement.getAttribute('data-iui-index'));
52
+ const currentElement = menuRef.current?.querySelector(`[data-iui-index="${nextIndex}"]`);
53
+ const nextElement = currentElement?.nextElementSibling ??
54
+ menuRef.current?.querySelector('[data-iui-index]');
55
+ nextIndex = Number(nextElement?.getAttribute('data-iui-index'));
57
56
  if (nextElement) {
58
57
  return dispatch({ type: 'focus', value: nextIndex });
59
58
  }
@@ -70,20 +69,22 @@ export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
70
69
  }
71
70
  // If virtualization is enabled, dont let round scrolling
72
71
  if (enableVirtualization &&
73
- !((_k = (_j = menuRef.current) === null || _j === void 0 ? void 0 : _j.querySelector(`[data-iui-index="${focusedIndexRef.current}"]`)) === null || _k === void 0 ? void 0 : _k.previousElementSibling)) {
72
+ !menuRef.current?.querySelector(`[data-iui-index="${focusedIndexRef.current}"]`)?.previousElementSibling) {
74
73
  return;
75
74
  }
76
75
  if (focusedIndexRef.current === -1) {
77
76
  return dispatch({
78
77
  type: 'focus',
79
- value: (_m = (_l = Object.values(optionsExtraInfoRef.current)) === null || _l === void 0 ? void 0 : _l[length - 1].__originalIndex) !== null && _m !== void 0 ? _m : -1,
78
+ value: Object.values(optionsExtraInfoRef.current)?.[length - 1]
79
+ .__originalIndex ?? -1,
80
80
  });
81
81
  }
82
82
  let prevIndex = focusedIndexRef.current;
83
83
  do {
84
- const currentElement = (_o = menuRef.current) === null || _o === void 0 ? void 0 : _o.querySelector(`[data-iui-index="${prevIndex}"]`);
85
- const 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');
86
- prevIndex = Number(prevElement === null || prevElement === void 0 ? void 0 : prevElement.getAttribute('data-iui-index'));
84
+ const currentElement = menuRef.current?.querySelector(`[data-iui-index="${prevIndex}"]`);
85
+ const prevElement = currentElement?.previousElementSibling ??
86
+ menuRef.current?.querySelector('[data-iui-index]:last-of-type');
87
+ prevIndex = Number(prevElement?.getAttribute('data-iui-index'));
87
88
  if (prevElement) {
88
89
  return dispatch({ type: 'focus', value: prevIndex });
89
90
  }
@@ -94,7 +95,7 @@ export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
94
95
  event.preventDefault();
95
96
  if (isOpen) {
96
97
  if (focusedIndexRef.current > -1) {
97
- onClickHandler === null || onClickHandler === void 0 ? void 0 : onClickHandler(focusedIndexRef.current);
98
+ onClickHandler?.(focusedIndexRef.current);
98
99
  }
99
100
  }
100
101
  else {
@@ -122,7 +123,7 @@ export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
122
123
  ]);
123
124
  const handleFocus = React.useCallback((event) => {
124
125
  dispatch({ type: 'open' });
125
- onFocusProp === null || onFocusProp === void 0 ? void 0 : onFocusProp(event);
126
+ onFocusProp?.(event);
126
127
  }, [dispatch, onFocusProp]);
127
128
  const handleClick = React.useCallback(() => {
128
129
  if (!isOpen) {
@@ -8,7 +8,7 @@ import { Menu } from '../Menu/index.js';
8
8
  import { Surface } from '../Surface/index.js';
9
9
  import { useSafeContext, useMergedRefs, useVirtualization, mergeRefs, getWindow, } from '../utils/index.js';
10
10
  import { ComboBoxStateContext, ComboBoxRefsContext } from './helpers.js';
11
- const isOverflowOverlaySupported = () => { var _a, _b, _c; return (_c = (_b = (_a = getWindow()) === null || _a === void 0 ? void 0 : _a.CSS) === null || _b === void 0 ? void 0 : _b.supports) === null || _c === void 0 ? void 0 : _c.call(_b, 'overflow: overlay'); };
11
+ const isOverflowOverlaySupported = () => getWindow()?.CSS?.supports?.('overflow: overlay');
12
12
  const VirtualizedComboBoxMenu = React.forwardRef(({ children, className, style, ...rest }, forwardedRef) => {
13
13
  const { minWidth, id, filteredOptions, getMenuItem, focusedIndex } = useSafeContext(ComboBoxStateContext);
14
14
  const { menuRef } = useSafeContext(ComboBoxRefsContext);
@@ -17,12 +17,11 @@ const VirtualizedComboBoxMenu = React.forwardRef(({ children, className, style,
17
17
  : children, // Here is expected empty state content
18
18
  [filteredOptions, getMenuItem, children]);
19
19
  const focusedVisibleIndex = React.useMemo(() => {
20
- var _a, _b;
21
- const currentElement = (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-iui-index="${focusedIndex}"]`);
20
+ const currentElement = menuRef.current?.querySelector(`[data-iui-index="${focusedIndex}"]`);
22
21
  if (!currentElement) {
23
22
  return focusedIndex;
24
23
  }
25
- return Number((_b = currentElement.getAttribute('data-iui-filtered-index')) !== null && _b !== void 0 ? _b : focusedIndex);
24
+ return Number(currentElement.getAttribute('data-iui-filtered-index') ?? focusedIndex);
26
25
  }, [focusedIndex, menuRef]);
27
26
  const { outerProps, innerProps, visibleChildren } = useVirtualization({
28
27
  // 'Fool' VirtualScroll by passing length 1
@@ -11,11 +11,11 @@ export const ComboBoxMenuItem = React.memo(React.forwardRef((props, forwardedRef
11
11
  const { focusedIndex, enableVirtualization } = useSafeContext(ComboBoxStateContext);
12
12
  const focusRef = (el) => {
13
13
  if (!enableVirtualization && focusedIndex === index) {
14
- el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
14
+ el?.scrollIntoView({ block: 'nearest' });
15
15
  }
16
16
  };
17
17
  const refs = useMergedRefs(forwardedRef, focusRef);
18
- return (React.createElement(ListItem, { actionable: true, size: size, active: isSelected, disabled: disabled, focused: focusedIndex === index, ref: refs, onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(value), role: role, tabIndex: role === 'presentation' ? undefined : -1, "aria-selected": isSelected, "aria-disabled": disabled, "data-iui-index": index, ...rest },
18
+ return (React.createElement(ListItem, { actionable: true, size: size, active: isSelected, disabled: disabled, focused: focusedIndex === index, ref: refs, onClick: () => onClick?.(value), role: role, tabIndex: role === 'presentation' ? undefined : -1, "aria-selected": isSelected, "aria-disabled": disabled, "data-iui-index": index, ...rest },
19
19
  startIcon && (React.createElement(ListItem.Icon, { as: 'span', "aria-hidden": true }, startIcon)),
20
20
  React.createElement(ListItem.Content, null,
21
21
  children,
@@ -4,7 +4,6 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import * as React from 'react';
6
6
  export const comboBoxReducer = (state, action) => {
7
- var _a, _b, _c, _d, _e;
8
7
  switch (action.type) {
9
8
  case 'open': {
10
9
  return { ...state, isOpen: true };
@@ -18,8 +17,8 @@ export const comboBoxReducer = (state, action) => {
18
17
  }
19
18
  return {
20
19
  ...state,
21
- selected: (_a = action.value) !== null && _a !== void 0 ? _a : state.selected,
22
- focusedIndex: (_b = action.value) !== null && _b !== void 0 ? _b : state.focusedIndex,
20
+ selected: action.value ?? state.selected,
21
+ focusedIndex: action.value ?? state.focusedIndex,
23
22
  };
24
23
  }
25
24
  case 'multiselect': {
@@ -32,12 +31,12 @@ export const comboBoxReducer = (state, action) => {
32
31
  if (Array.isArray(state.selected)) {
33
32
  return {
34
33
  ...state,
35
- focusedIndex: (_c = action.value) !== null && _c !== void 0 ? _c : -1,
34
+ focusedIndex: action.value ?? -1,
36
35
  };
37
36
  }
38
37
  return {
39
38
  ...state,
40
- focusedIndex: (_e = (_d = action.value) !== null && _d !== void 0 ? _d : state.selected) !== null && _e !== void 0 ? _e : -1,
39
+ focusedIndex: action.value ?? state.selected ?? -1,
41
40
  };
42
41
  }
43
42
  default: {
@@ -110,17 +110,20 @@ export const generateLocalizedStrings = (locale) => {
110
110
  * <DatePicker date={new Date()} onChange={(e) => console.log('New date value: ' + e)} />
111
111
  */
112
112
  export const DatePicker = React.forwardRef((props, forwardedRef) => {
113
- var _a, _b, _c, _d, _e, _f, _g, _h;
114
113
  const { date, onChange, localizedNames, className, setFocus = false, showTime = false, use12Hours = false, precision, hourStep, minuteStep, secondStep, useCombinedRenderer, combinedRenderer, hourRenderer, minuteRenderer, secondRenderer, meridiemRenderer, showYearSelection = false, enableRangeSelect = false, startDate, endDate, isDateDisabled, ...rest } = props;
115
- const monthNames = (_a = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.months) !== null && _a !== void 0 ? _a : defaultMonths;
116
- const shortDays = (_b = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.shortDays) !== null && _b !== void 0 ? _b : defaultShortDays;
117
- const longDays = (_c = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.days) !== null && _c !== void 0 ? _c : defaultLongDays;
114
+ const monthNames = localizedNames?.months ?? defaultMonths;
115
+ const shortDays = localizedNames?.shortDays ?? defaultShortDays;
116
+ const longDays = localizedNames?.days ?? defaultLongDays;
118
117
  const [selectedDay, setSelectedDay] = React.useState(date);
119
118
  const [selectedStartDay, setSelectedStartDay] = React.useState(startDate);
120
119
  const [selectedEndDay, setSelectedEndDay] = React.useState(endDate);
121
- const [focusedDay, setFocusedDay] = React.useState((_d = selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : selectedDay) !== null && _d !== void 0 ? _d : new Date());
122
- const [displayedMonthIndex, setDisplayedMonthIndex] = React.useState((_f = (_e = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getMonth()) !== null && _e !== void 0 ? _e : selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getMonth()) !== null && _f !== void 0 ? _f : new Date().getMonth());
123
- const [displayedYear, setDisplayedYear] = React.useState((_h = (_g = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getFullYear()) !== null && _g !== void 0 ? _g : selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getFullYear()) !== null && _h !== void 0 ? _h : new Date().getFullYear());
120
+ const [focusedDay, setFocusedDay] = React.useState(selectedStartDay ?? selectedDay ?? new Date());
121
+ const [displayedMonthIndex, setDisplayedMonthIndex] = React.useState(selectedStartDay?.getMonth() ??
122
+ selectedDay?.getMonth() ??
123
+ new Date().getMonth());
124
+ const [displayedYear, setDisplayedYear] = React.useState(selectedStartDay?.getFullYear() ??
125
+ selectedDay?.getFullYear() ??
126
+ new Date().getFullYear());
124
127
  // boolean that toggles between the user picking the start date and end date for date range
125
128
  const [isSelectingStartDate, setIsSelectingStartDate] = React.useState(true);
126
129
  // Used to focus days only when days are changed
@@ -136,15 +139,16 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
136
139
  setDisplayedYear(newYear);
137
140
  }, []);
138
141
  React.useEffect(() => {
139
- var _a, _b, _c, _d;
140
142
  const currentDate = new Date();
141
143
  setSelectedDay(date);
142
144
  setSelectedStartDay(startDate);
143
145
  setSelectedEndDay(endDate);
144
146
  if (!enableRangeSelect) {
145
- setFocusedDay(date !== null && date !== void 0 ? date : currentDate);
147
+ setFocusedDay(date ?? currentDate);
146
148
  }
147
- setMonthAndYear((_b = (_a = startDate === null || startDate === void 0 ? void 0 : startDate.getMonth()) !== null && _a !== void 0 ? _a : date === null || date === void 0 ? void 0 : date.getMonth()) !== null && _b !== void 0 ? _b : currentDate.getMonth(), (_d = (_c = startDate === null || startDate === void 0 ? void 0 : startDate.getFullYear()) !== null && _c !== void 0 ? _c : date === null || date === void 0 ? void 0 : date.getFullYear()) !== null && _d !== void 0 ? _d : currentDate.getFullYear());
149
+ setMonthAndYear(startDate?.getMonth() ?? date?.getMonth() ?? currentDate.getMonth(), startDate?.getFullYear() ??
150
+ date?.getFullYear() ??
151
+ currentDate.getFullYear());
148
152
  }, [date, setMonthAndYear, startDate, endDate, enableRangeSelect]);
149
153
  const days = React.useMemo(() => {
150
154
  let offsetToFirst = new Date(displayedYear, displayedMonthIndex, 1).getDay();
@@ -169,8 +173,7 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
169
173
  return weeksInMonth;
170
174
  }, [days]);
171
175
  const getNewFocusedDate = (newYear, newMonth) => {
172
- var _a;
173
- const currentDate = (_a = selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : selectedDay) !== null && _a !== void 0 ? _a : new Date();
176
+ const currentDate = selectedStartDay ?? selectedDay ?? new Date();
174
177
  const newDate = new Date(newYear, newMonth, currentDate.getDate(), currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds());
175
178
  return newDate;
176
179
  };
@@ -199,51 +202,51 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
199
202
  const onDayClick = (day) => {
200
203
  // single date selection
201
204
  if (!enableRangeSelect) {
202
- if (day.getMonth() !== (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getMonth())) {
205
+ if (day.getMonth() !== selectedDay?.getMonth()) {
203
206
  setMonthAndYear(day.getMonth(), day.getFullYear());
204
207
  }
205
- const currentDate = selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date();
208
+ const currentDate = selectedDay ?? new Date();
206
209
  const newDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds());
207
210
  setSelectedDay(newDate);
208
211
  setFocusedDay(newDate);
209
- isSingleOnChange(onChange, enableRangeSelect) && (onChange === null || onChange === void 0 ? void 0 : onChange(newDate));
212
+ isSingleOnChange(onChange, enableRangeSelect) && onChange?.(newDate);
210
213
  }
211
214
  // start date selection (date range only)
212
215
  else if (isSelectingStartDate) {
213
- if (day.getMonth() !== (selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getMonth())) {
216
+ if (day.getMonth() !== selectedStartDay?.getMonth()) {
214
217
  setMonthAndYear(day.getMonth(), day.getFullYear());
215
218
  }
216
- const currentStartDate = selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : new Date();
219
+ const currentStartDate = selectedStartDay ?? new Date();
217
220
  const newStartDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentStartDate.getHours(), currentStartDate.getMinutes(), currentStartDate.getSeconds());
218
221
  setSelectedStartDay(newStartDate);
219
222
  setFocusedDay(newStartDate);
220
223
  // if the start date is after the end date or the end date is undefined, reset the end date
221
224
  if (!isBefore(newStartDate, selectedEndDay)) {
222
225
  setSelectedEndDay(newStartDate);
223
- onChange === null || onChange === void 0 ? void 0 : onChange(newStartDate, newStartDate);
226
+ onChange?.(newStartDate, newStartDate);
224
227
  }
225
228
  else {
226
- selectedEndDay && (onChange === null || onChange === void 0 ? void 0 : onChange(newStartDate, selectedEndDay));
229
+ selectedEndDay && onChange?.(newStartDate, selectedEndDay);
227
230
  }
228
231
  setIsSelectingStartDate(false);
229
232
  }
230
233
  // end date selection (date range only)
231
234
  else {
232
- if (day.getMonth() !== (selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getMonth())) {
235
+ if (day.getMonth() !== selectedEndDay?.getMonth()) {
233
236
  setMonthAndYear(day.getMonth(), day.getFullYear());
234
237
  }
235
- const currentEndDate = selectedEndDay !== null && selectedEndDay !== void 0 ? selectedEndDay : new Date();
238
+ const currentEndDate = selectedEndDay ?? new Date();
236
239
  const newEndDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentEndDate.getHours(), currentEndDate.getMinutes(), currentEndDate.getSeconds());
237
240
  setFocusedDay(newEndDate);
238
241
  // if the end date is before the start date, move back the start date and still have user select end date
239
242
  if (!isBefore(newEndDate, selectedStartDay)) {
240
243
  setSelectedEndDay(newEndDate);
241
- selectedStartDay && (onChange === null || onChange === void 0 ? void 0 : onChange(selectedStartDay, newEndDate));
244
+ selectedStartDay && onChange?.(selectedStartDay, newEndDate);
242
245
  setIsSelectingStartDate(true);
243
246
  }
244
247
  else {
245
248
  setSelectedStartDay(newEndDate);
246
- selectedEndDay && (onChange === null || onChange === void 0 ? void 0 : onChange(newEndDate, selectedEndDay));
249
+ selectedEndDay && onChange?.(newEndDate, selectedEndDay);
247
250
  }
248
251
  }
249
252
  };
@@ -295,7 +298,7 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
295
298
  case 'Enter':
296
299
  case ' ':
297
300
  case 'Spacebar':
298
- if (!(isDateDisabled === null || isDateDisabled === void 0 ? void 0 : isDateDisabled(focusedDay))) {
301
+ if (!isDateDisabled?.(focusedDay)) {
299
302
  onDayClick(focusedDay);
300
303
  }
301
304
  event.preventDefault();
@@ -348,17 +351,14 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
348
351
  React.createElement("div", { onKeyDown: handleCalendarKeyDown, role: 'listbox' }, weeks.map((weekDays, weekIndex) => {
349
352
  return (React.createElement(Box, { key: `week-${displayedMonthIndex}-${weekIndex}`, className: 'iui-calendar-week' }, weekDays.map((weekDay, dayIndex) => {
350
353
  const dateValue = weekDay.getDate();
351
- const isDisabled = isDateDisabled === null || isDateDisabled === void 0 ? void 0 : isDateDisabled(weekDay);
354
+ const isDisabled = isDateDisabled?.(weekDay);
352
355
  return (React.createElement(Box, { key: `day-${displayedMonthIndex}-${dayIndex}`, className: getDayClass(weekDay), onClick: () => !isDisabled && onDayClick(weekDay), role: 'option', tabIndex: isSameDay(weekDay, focusedDay) ? 0 : -1, "aria-disabled": isDisabled ? 'true' : undefined, ref: (element) => isSameDay(weekDay, focusedDay) &&
353
356
  needFocus.current &&
354
- (element === null || element === void 0 ? void 0 : element.focus()) }, dateValue));
357
+ element?.focus() }, dateValue));
355
358
  })));
356
359
  }))),
357
- showTime && (React.createElement(TimePicker, { date: selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : selectedDay, use12Hours: use12Hours, precision: precision, hourStep: hourStep, minuteStep: minuteStep, secondStep: secondStep, useCombinedRenderer: useCombinedRenderer, combinedRenderer: combinedRenderer, hourRenderer: hourRenderer, minuteRenderer: minuteRenderer, secondRenderer: secondRenderer, meridiemRenderer: meridiemRenderer, onChange: (date) => {
358
- var _a, _b, _c, _d, _e, _f;
359
- return isSingleOnChange(onChange, enableRangeSelect)
360
- ? onChange === null || onChange === void 0 ? void 0 : onChange(date)
361
- : onChange === null || onChange === void 0 ? void 0 : onChange(new Date((_a = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getFullYear()) !== null && _a !== void 0 ? _a : date.getFullYear(), (_b = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getMonth()) !== null && _b !== void 0 ? _b : date.getMonth(), (_c = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getDate()) !== null && _c !== void 0 ? _c : date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()), new Date((_d = selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getFullYear()) !== null && _d !== void 0 ? _d : date.getFullYear(), (_e = selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getMonth()) !== null && _e !== void 0 ? _e : date.getMonth(), (_f = selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getDate()) !== null && _f !== void 0 ? _f : date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
362
- } }))));
360
+ showTime && (React.createElement(TimePicker, { date: selectedStartDay ?? selectedDay, use12Hours: use12Hours, precision: precision, hourStep: hourStep, minuteStep: minuteStep, secondStep: secondStep, useCombinedRenderer: useCombinedRenderer, combinedRenderer: combinedRenderer, hourRenderer: hourRenderer, minuteRenderer: minuteRenderer, secondRenderer: secondRenderer, meridiemRenderer: meridiemRenderer, onChange: (date) => isSingleOnChange(onChange, enableRangeSelect)
361
+ ? onChange?.(date)
362
+ : onChange?.(new Date(selectedStartDay?.getFullYear() ?? date.getFullYear(), selectedStartDay?.getMonth() ?? date.getMonth(), selectedStartDay?.getDate() ?? date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()), new Date(selectedEndDay?.getFullYear() ?? date.getFullYear(), selectedEndDay?.getMonth() ?? date.getMonth(), selectedEndDay?.getDate() ?? date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())) }))));
363
363
  });
364
364
  export default DatePicker;