@carbon/react 1.103.0 → 1.104.0-rc.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 (769) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +956 -956
  2. package/es/_virtual/_rolldown/runtime.js +25 -0
  3. package/es/components/AILabel/index.d.ts +29 -2
  4. package/es/components/AILabel/index.js +114 -169
  5. package/es/components/AISkeleton/AISkeletonIcon.js +23 -27
  6. package/es/components/AISkeleton/AISkeletonPlaceholder.js +19 -27
  7. package/es/components/AISkeleton/AISkeletonText.js +26 -39
  8. package/es/components/Accordion/Accordion.Skeleton.js +55 -79
  9. package/es/components/Accordion/Accordion.js +43 -61
  10. package/es/components/Accordion/AccordionItem.js +102 -156
  11. package/es/components/Accordion/AccordionProvider.js +18 -15
  12. package/es/components/AspectRatio/AspectRatio.js +41 -47
  13. package/es/components/BadgeIndicator/index.js +28 -33
  14. package/es/components/Breadcrumb/Breadcrumb.Skeleton.js +39 -50
  15. package/es/components/Breadcrumb/Breadcrumb.js +39 -51
  16. package/es/components/Breadcrumb/BreadcrumbItem.js +80 -83
  17. package/es/components/Button/Button.Skeleton.js +49 -58
  18. package/es/components/Button/Button.d.ts +1 -1
  19. package/es/components/Button/Button.js +146 -240
  20. package/es/components/Button/ButtonBase.js +82 -104
  21. package/es/components/Button/index.js +13 -6
  22. package/es/components/ButtonSet/ButtonSet.js +74 -98
  23. package/es/components/ButtonSet/index.js +12 -4
  24. package/es/components/ChatButton/ChatButton.Skeleton.js +27 -27
  25. package/es/components/ChatButton/ChatButton.js +64 -79
  26. package/es/components/Checkbox/Checkbox.Skeleton.js +26 -25
  27. package/es/components/Checkbox/Checkbox.js +116 -195
  28. package/es/components/Checkbox/index.js +13 -5
  29. package/es/components/CheckboxGroup/CheckboxGroup.js +100 -148
  30. package/es/components/ClassPrefix/index.js +21 -17
  31. package/es/components/CodeSnippet/CodeSnippet.Skeleton.js +45 -42
  32. package/es/components/CodeSnippet/CodeSnippet.js +210 -299
  33. package/es/components/ComboBox/ComboBox.js +621 -970
  34. package/es/components/ComboBox/index.js +12 -4
  35. package/es/components/ComboButton/index.js +172 -208
  36. package/es/components/ComposedModal/ComposedModal.js +311 -450
  37. package/es/components/ComposedModal/ComposedModalPresence.js +47 -42
  38. package/es/components/ComposedModal/ModalFooter.js +127 -207
  39. package/es/components/ComposedModal/ModalHeader.js +71 -101
  40. package/es/components/ComposedModal/useComposedModalState.js +21 -15
  41. package/es/components/ContainedList/ContainedList.js +67 -102
  42. package/es/components/ContainedList/ContainedListItem/ContainedListItem.js +49 -67
  43. package/es/components/ContainedList/ContainedListItem/index.js +12 -4
  44. package/es/components/ContainedList/index.js +15 -12
  45. package/es/components/ContentSwitcher/ContentSwitcher.js +108 -140
  46. package/es/components/ContextMenu/useContextMenu.js +41 -36
  47. package/es/components/Copy/Copy.js +97 -117
  48. package/es/components/Copy/index.js +12 -4
  49. package/es/components/CopyButton/CopyButton.js +81 -94
  50. package/es/components/CopyButton/index.js +12 -4
  51. package/es/components/DangerButton/DangerButton.js +11 -9
  52. package/es/components/DataTable/DataTable.d.ts +11 -11
  53. package/es/components/DataTable/DataTable.js +448 -630
  54. package/es/components/DataTable/Table.js +111 -156
  55. package/es/components/DataTable/TableActionList.js +14 -6
  56. package/es/components/DataTable/TableBatchAction.js +25 -34
  57. package/es/components/DataTable/TableBatchActions.js +78 -113
  58. package/es/components/DataTable/TableBody.js +26 -19
  59. package/es/components/DataTable/TableCell.js +31 -46
  60. package/es/components/DataTable/TableContainer.js +75 -82
  61. package/es/components/DataTable/TableContext.js +14 -6
  62. package/es/components/DataTable/TableDecoratorRow.js +30 -36
  63. package/es/components/DataTable/TableExpandHeader.js +53 -90
  64. package/es/components/DataTable/TableExpandRow.js +82 -119
  65. package/es/components/DataTable/TableExpandedRow.js +45 -51
  66. package/es/components/DataTable/TableHead.js +7 -5
  67. package/es/components/DataTable/TableHeader.js +138 -181
  68. package/es/components/DataTable/TableRow.d.ts +1 -1
  69. package/es/components/DataTable/TableRow.js +42 -76
  70. package/es/components/DataTable/TableSelectAll.js +42 -70
  71. package/es/components/DataTable/TableSelectRow.js +63 -98
  72. package/es/components/DataTable/TableSlugRow.js +35 -43
  73. package/es/components/DataTable/TableToolbar.js +33 -45
  74. package/es/components/DataTable/TableToolbarAction.js +25 -20
  75. package/es/components/DataTable/TableToolbarContent.js +14 -6
  76. package/es/components/DataTable/TableToolbarMenu.js +35 -46
  77. package/es/components/DataTable/TableToolbarSearch.js +97 -187
  78. package/es/components/DataTable/state/getDerivedStateFromProps.js +38 -43
  79. package/es/components/DataTable/state/sortStates.js +11 -9
  80. package/es/components/DataTable/state/sorting.js +53 -72
  81. package/es/components/DataTable/tools/cells.js +15 -7
  82. package/es/components/DataTable/tools/denormalize.js +27 -19
  83. package/es/components/DataTable/tools/filter.js +21 -22
  84. package/es/components/DataTable/tools/normalize.js +57 -72
  85. package/es/components/DataTable/tools/sorting.js +50 -71
  86. package/es/components/DataTableSkeleton/DataTableSkeleton.js +66 -94
  87. package/es/components/DatePicker/DatePicker.Skeleton.js +44 -51
  88. package/es/components/DatePicker/DatePicker.js +485 -752
  89. package/es/components/DatePicker/DatePickerLocales.js +75 -126
  90. package/es/components/DatePicker/index.js +13 -5
  91. package/es/components/DatePicker/plugins/appendToPlugin.js +31 -45
  92. package/es/components/DatePicker/plugins/fixEventsPlugin.js +127 -171
  93. package/es/components/DatePicker/plugins/rangePlugin.js +40 -48
  94. package/es/components/DatePicker/utils.js +11 -3
  95. package/es/components/DatePickerInput/DatePickerInput.js +179 -289
  96. package/es/components/DatePickerInput/index.js +12 -4
  97. package/es/components/Dialog/Dialog.js +303 -574
  98. package/es/components/Dialog/index.js +18 -2
  99. package/es/components/Dropdown/Dropdown.Skeleton.js +26 -38
  100. package/es/components/Dropdown/Dropdown.js +344 -535
  101. package/es/components/Dropdown/index.js +13 -5
  102. package/es/components/ErrorBoundary/ErrorBoundary.js +36 -58
  103. package/es/components/ErrorBoundary/ErrorBoundaryContext.js +14 -9
  104. package/es/components/ExpandableSearch/ExpandableSearch.js +60 -69
  105. package/es/components/ExpandableSearch/index.js +12 -4
  106. package/es/components/FeatureFlags/index.d.ts +11 -2
  107. package/es/components/FeatureFlags/index.js +79 -77
  108. package/es/components/FileUploader/FileUploader.Skeleton.js +35 -30
  109. package/es/components/FileUploader/FileUploader.js +269 -343
  110. package/es/components/FileUploader/FileUploaderButton.js +110 -160
  111. package/es/components/FileUploader/FileUploaderDropContainer.js +144 -221
  112. package/es/components/FileUploader/FileUploaderItem.js +138 -157
  113. package/es/components/FileUploader/Filename.d.ts +1 -1
  114. package/es/components/FileUploader/Filename.js +53 -72
  115. package/es/components/FluidComboBox/FluidComboBox.Skeleton.js +26 -28
  116. package/es/components/FluidComboBox/FluidComboBox.js +54 -105
  117. package/es/components/FluidDatePicker/FluidDatePicker.Skeleton.js +56 -53
  118. package/es/components/FluidDatePicker/FluidDatePicker.js +46 -68
  119. package/es/components/FluidDatePickerInput/FluidDatePickerInput.js +23 -16
  120. package/es/components/FluidDropdown/FluidDropdown.Skeleton.js +26 -28
  121. package/es/components/FluidDropdown/FluidDropdown.js +55 -111
  122. package/es/components/FluidForm/FluidForm.js +29 -31
  123. package/es/components/FluidForm/FormContext.js +12 -6
  124. package/es/components/FluidMultiSelect/FluidMultiSelect.Skeleton.js +26 -28
  125. package/es/components/FluidMultiSelect/FluidMultiSelect.js +67 -197
  126. package/es/components/FluidNumberInput/FluidNumberInput.Skeleton.js +27 -30
  127. package/es/components/FluidNumberInput/FluidNumberInput.js +63 -147
  128. package/es/components/FluidSearch/FluidSearch.Skeleton.js +27 -30
  129. package/es/components/FluidSearch/FluidSearch.js +41 -84
  130. package/es/components/FluidSelect/FluidSelect.Skeleton.js +26 -28
  131. package/es/components/FluidSelect/FluidSelect.js +40 -76
  132. package/es/components/FluidSelect/index.js +13 -5
  133. package/es/components/FluidTextArea/FluidTextArea.Skeleton.js +27 -30
  134. package/es/components/FluidTextArea/FluidTextArea.js +48 -112
  135. package/es/components/FluidTextInput/FluidPasswordInput.js +44 -99
  136. package/es/components/FluidTextInput/FluidTextInput.Skeleton.js +27 -30
  137. package/es/components/FluidTextInput/FluidTextInput.js +49 -104
  138. package/es/components/FluidTextInput/index.js +14 -6
  139. package/es/components/FluidTimePicker/FluidTimePicker.Skeleton.js +30 -33
  140. package/es/components/FluidTimePicker/FluidTimePicker.js +68 -115
  141. package/es/components/FluidTimePickerSelect/FluidTimePickerSelect.js +28 -47
  142. package/es/components/Form/Form.js +23 -25
  143. package/es/components/FormGroup/FormGroup.js +45 -67
  144. package/es/components/FormItem/FormItem.js +23 -25
  145. package/es/components/FormLabel/FormLabel.js +28 -34
  146. package/es/components/Grid/CSSGrid.d.ts +1 -1
  147. package/es/components/Grid/CSSGrid.js +85 -127
  148. package/es/components/Grid/Column.js +192 -324
  149. package/es/components/Grid/ColumnHang.js +28 -36
  150. package/es/components/Grid/FlexGrid.js +40 -60
  151. package/es/components/Grid/Grid.js +29 -42
  152. package/es/components/Grid/GridContext.js +36 -42
  153. package/es/components/Grid/Row.js +31 -49
  154. package/es/components/Heading/index.js +36 -51
  155. package/es/components/Icon/Icon.Skeleton.js +21 -21
  156. package/es/components/IconButton/index.js +117 -178
  157. package/es/components/IconIndicator/index.d.ts +1 -1
  158. package/es/components/IconIndicator/index.js +59 -60
  159. package/es/components/IdPrefix/index.js +21 -17
  160. package/es/components/InlineCheckbox/InlineCheckbox.js +69 -113
  161. package/es/components/InlineCheckbox/index.js +12 -4
  162. package/es/components/InlineLoading/InlineLoading.js +83 -100
  163. package/es/components/InlineLoading/index.js +12 -4
  164. package/es/components/Layer/LayerContext.js +12 -4
  165. package/es/components/Layer/LayerLevel.js +20 -4
  166. package/es/components/Layer/index.js +54 -66
  167. package/es/components/Layout/index.js +77 -109
  168. package/es/components/LayoutDirection/LayoutDirection.d.ts +1 -1
  169. package/es/components/LayoutDirection/LayoutDirection.js +33 -37
  170. package/es/components/LayoutDirection/LayoutDirectionContext.js +12 -6
  171. package/es/components/LayoutDirection/useLayoutDirection.js +15 -7
  172. package/es/components/Link/Link.js +63 -108
  173. package/es/components/Link/index.js +12 -4
  174. package/es/components/ListBox/ListBox.js +78 -126
  175. package/es/components/ListBox/ListBoxField.js +24 -43
  176. package/es/components/ListBox/ListBoxMenu.js +36 -42
  177. package/es/components/ListBox/ListBoxMenuIcon.js +39 -40
  178. package/es/components/ListBox/ListBoxMenuItem.js +67 -88
  179. package/es/components/ListBox/ListBoxPropTypes.js +17 -5
  180. package/es/components/ListBox/ListBoxSelection.js +71 -96
  181. package/es/components/ListBox/index.js +16 -14
  182. package/es/components/ListBox/next/ListBoxSelection.js +79 -117
  183. package/es/components/ListBox/next/ListBoxTrigger.js +44 -48
  184. package/es/components/ListItem/ListItem.js +25 -28
  185. package/es/components/Loading/Loading.js +64 -73
  186. package/es/components/Loading/index.js +12 -4
  187. package/es/components/Menu/Menu.js +220 -363
  188. package/es/components/Menu/MenuContext.d.ts +1 -1
  189. package/es/components/Menu/MenuContext.js +41 -38
  190. package/es/components/Menu/MenuItem.js +282 -413
  191. package/es/components/MenuButton/index.js +134 -195
  192. package/es/components/Modal/Modal.js +500 -660
  193. package/es/components/Modal/ModalPresence.js +39 -37
  194. package/es/components/Modal/index.js +13 -5
  195. package/es/components/ModalWrapper/ModalWrapper.d.ts +2 -2
  196. package/es/components/ModalWrapper/ModalWrapper.js +106 -130
  197. package/es/components/MultiSelect/FilterableMultiSelect.js +605 -918
  198. package/es/components/MultiSelect/MultiSelect.js +454 -716
  199. package/es/components/MultiSelect/MultiSelectPropTypes.js +13 -30
  200. package/es/components/MultiSelect/filter.js +14 -9
  201. package/es/components/MultiSelect/tools/sorting.js +21 -34
  202. package/es/components/Notification/Notification.js +508 -785
  203. package/es/components/NumberInput/NumberFormatPropTypes.js +69 -30
  204. package/es/components/NumberInput/NumberInput.Skeleton.js +29 -33
  205. package/es/components/NumberInput/NumberInput.js +567 -947
  206. package/es/components/OrderedList/OrderedList.js +31 -44
  207. package/es/components/OverflowMenu/OverflowMenu.js +335 -450
  208. package/es/components/OverflowMenu/index.js +25 -16
  209. package/es/components/OverflowMenu/next/index.js +154 -186
  210. package/es/components/OverflowMenuItem/OverflowMenuItem.js +100 -160
  211. package/es/components/OverflowMenuItem/index.js +12 -4
  212. package/es/components/OverflowMenuV2/index.js +15 -13
  213. package/es/components/PageHeader/PageHeader.js +297 -442
  214. package/es/components/PageHeader/index.js +24 -2
  215. package/es/components/Pagination/Pagination.Skeleton.js +34 -35
  216. package/es/components/Pagination/Pagination.d.ts +1 -1
  217. package/es/components/Pagination/Pagination.js +251 -356
  218. package/es/components/Pagination/experimental/PageSelector.js +38 -54
  219. package/es/components/Pagination/experimental/Pagination-story.d.ts +114 -0
  220. package/es/components/Pagination/experimental/Pagination.js +144 -196
  221. package/es/components/PaginationNav/PaginationNav.js +320 -426
  222. package/es/components/Popover/index.js +318 -437
  223. package/es/components/PrimaryButton/PrimaryButton.js +11 -9
  224. package/es/components/ProgressBar/ProgressBar.js +117 -143
  225. package/es/components/ProgressIndicator/ProgressIndicator.Skeleton.js +42 -38
  226. package/es/components/ProgressIndicator/ProgressIndicator.js +146 -243
  227. package/es/components/RadioButton/RadioButton.Skeleton.js +23 -25
  228. package/es/components/RadioButton/RadioButton.js +101 -174
  229. package/es/components/RadioButton/index.js +12 -4
  230. package/es/components/RadioButtonGroup/RadioButtonGroup.js +135 -207
  231. package/es/components/RadioTile/RadioTile.js +104 -168
  232. package/es/components/RadioTile/index.js +12 -4
  233. package/es/components/Search/Search.Skeleton.js +28 -33
  234. package/es/components/Search/Search.js +182 -278
  235. package/es/components/Search/index.js +13 -5
  236. package/es/components/Search/utils.js +11 -3
  237. package/es/components/SecondaryButton/SecondaryButton.js +11 -9
  238. package/es/components/Select/Select.Skeleton.js +27 -30
  239. package/es/components/Select/Select.js +178 -257
  240. package/es/components/Select/index.js +13 -5
  241. package/es/components/SelectItem/SelectItem.js +33 -48
  242. package/es/components/SelectItem/index.js +12 -4
  243. package/es/components/SelectItemGroup/SelectItemGroup.js +27 -37
  244. package/es/components/ShapeIndicator/index.d.ts +1 -1
  245. package/es/components/ShapeIndicator/index.js +74 -80
  246. package/es/components/SkeletonIcon/SkeletonIcon.js +21 -24
  247. package/es/components/SkeletonPlaceholder/SkeletonPlaceholder.js +15 -24
  248. package/es/components/SkeletonText/SkeletonText.js +67 -81
  249. package/es/components/SkeletonText/index.js +12 -4
  250. package/es/components/Slider/Slider.Skeleton.js +68 -91
  251. package/es/components/Slider/Slider.js +864 -1315
  252. package/es/components/Slider/SliderHandles.js +73 -66
  253. package/es/components/Stack/HStack.js +19 -11
  254. package/es/components/Stack/Stack.js +56 -80
  255. package/es/components/Stack/VStack.js +19 -11
  256. package/es/components/StructuredList/StructuredList.Skeleton.js +55 -48
  257. package/es/components/StructuredList/StructuredList.js +178 -317
  258. package/es/components/Switch/IconSwitch.js +99 -145
  259. package/es/components/Switch/Switch.js +66 -99
  260. package/es/components/TabContent/TabContent.js +28 -34
  261. package/es/components/Tabs/Tabs.Skeleton.js +41 -36
  262. package/es/components/Tabs/Tabs.js +732 -1149
  263. package/es/components/Tabs/usePressable.js +97 -112
  264. package/es/components/Tag/DismissibleTag.js +119 -156
  265. package/es/components/Tag/OperationalTag.js +91 -111
  266. package/es/components/Tag/SelectableTag.js +94 -129
  267. package/es/components/Tag/Tag.Skeleton.js +26 -30
  268. package/es/components/Tag/Tag.js +152 -200
  269. package/es/components/Tag/isEllipsisActive.js +13 -8
  270. package/es/components/Text/Text.js +66 -79
  271. package/es/components/Text/TextDirection.js +36 -37
  272. package/es/components/Text/TextDirectionContext.js +14 -8
  273. package/es/components/Text/createTextComponent.js +21 -20
  274. package/es/components/TextArea/TextArea.Skeleton.js +25 -29
  275. package/es/components/TextArea/TextArea.js +315 -422
  276. package/es/components/TextArea/index.js +13 -5
  277. package/es/components/TextInput/ControlledPasswordInput.js +133 -198
  278. package/es/components/TextInput/PasswordInput.js +196 -303
  279. package/es/components/TextInput/TextInput.Skeleton.js +24 -28
  280. package/es/components/TextInput/TextInput.js +219 -317
  281. package/es/components/TextInput/index.js +13 -5
  282. package/es/components/TextInput/util.js +21 -25
  283. package/es/components/Theme/index.js +79 -95
  284. package/es/components/Tile/Tile.js +394 -593
  285. package/es/components/TileGroup/TileGroup.js +70 -111
  286. package/es/components/TimePicker/TimePicker.d.ts +1 -1
  287. package/es/components/TimePicker/TimePicker.js +148 -247
  288. package/es/components/TimePickerSelect/TimePickerSelect.js +43 -58
  289. package/es/components/Toggle/Toggle.Skeleton.js +24 -22
  290. package/es/components/Toggle/Toggle.js +102 -171
  291. package/es/components/ToggleSmall/ToggleSmall.Skeleton.js +46 -51
  292. package/es/components/Toggletip/index.d.ts +2 -2
  293. package/es/components/Toggletip/index.js +170 -256
  294. package/es/components/Tooltip/DefinitionTooltip.js +98 -138
  295. package/es/components/Tooltip/Tooltip.js +188 -263
  296. package/es/components/TreeView/TreeContext.js +13 -5
  297. package/es/components/TreeView/TreeNode.js +361 -500
  298. package/es/components/TreeView/TreeView.js +164 -237
  299. package/es/components/UIShell/Content.js +23 -30
  300. package/es/components/UIShell/Header.js +25 -29
  301. package/es/components/UIShell/HeaderContainer.js +31 -40
  302. package/es/components/UIShell/HeaderGlobalAction.js +65 -90
  303. package/es/components/UIShell/HeaderGlobalBar.js +16 -9
  304. package/es/components/UIShell/HeaderMenu.js +141 -215
  305. package/es/components/UIShell/HeaderMenuButton.js +43 -66
  306. package/es/components/UIShell/HeaderMenuItem.js +49 -76
  307. package/es/components/UIShell/HeaderName.js +32 -44
  308. package/es/components/UIShell/HeaderNavigation.js +32 -37
  309. package/es/components/UIShell/HeaderPanel.js +74 -97
  310. package/es/components/UIShell/HeaderSideNavItems.js +27 -33
  311. package/es/components/UIShell/Link.js +29 -50
  312. package/es/components/UIShell/SideNav.js +132 -241
  313. package/es/components/UIShell/SideNavContext.js +21 -15
  314. package/es/components/UIShell/SideNavDetails.js +29 -34
  315. package/es/components/UIShell/SideNavDivider.js +21 -21
  316. package/es/components/UIShell/SideNavFooter.js +43 -52
  317. package/es/components/UIShell/SideNavHeader.js +26 -35
  318. package/es/components/UIShell/SideNavIcon.js +28 -33
  319. package/es/components/UIShell/SideNavItem.js +28 -33
  320. package/es/components/UIShell/SideNavItems.js +31 -40
  321. package/es/components/UIShell/SideNavLink.js +52 -79
  322. package/es/components/UIShell/SideNavLinkText.js +24 -25
  323. package/es/components/UIShell/SideNavMenu.js +102 -143
  324. package/es/components/UIShell/SideNavMenuItem.js +40 -52
  325. package/es/components/UIShell/SideNavSwitcher.js +59 -68
  326. package/es/components/UIShell/SkipToContent.js +28 -36
  327. package/es/components/UIShell/Switcher.js +69 -99
  328. package/es/components/UIShell/SwitcherDivider.js +16 -24
  329. package/es/components/UIShell/SwitcherItem.js +74 -114
  330. package/es/components/UnorderedList/UnorderedList.js +28 -37
  331. package/es/feature-flags.js +19 -10
  332. package/es/index.js +249 -242
  333. package/es/internal/FloatingMenu.js +246 -292
  334. package/es/internal/OptimizedResize.js +35 -46
  335. package/es/internal/Selection.js +99 -132
  336. package/es/internal/clamp.js +12 -4
  337. package/es/internal/defaultItemToString.js +15 -9
  338. package/es/internal/deprecateFieldOnObject.js +22 -14
  339. package/es/internal/environment.js +15 -7
  340. package/es/internal/getAnnouncement.js +16 -13
  341. package/es/internal/keyboard/keys.js +48 -48
  342. package/es/internal/keyboard/match.js +25 -42
  343. package/es/internal/keyboard/navigation.js +22 -27
  344. package/es/internal/noopFn.js +10 -2
  345. package/es/internal/useAttachedMenu.js +43 -51
  346. package/es/internal/useControllableState.js +43 -48
  347. package/es/internal/useDelayedState.js +30 -35
  348. package/es/internal/useEvent.js +39 -35
  349. package/es/internal/useId.js +51 -87
  350. package/es/internal/useIdPrefix.js +13 -5
  351. package/es/internal/useIsomorphicEffect.js +12 -4
  352. package/es/internal/useMatchMedia.js +29 -21
  353. package/es/internal/useMergedRefs.js +26 -22
  354. package/es/internal/useNoInteractiveChildren.js +70 -99
  355. package/es/internal/useNormalizedInputProps.js +47 -51
  356. package/es/internal/useOutsideClick.js +21 -24
  357. package/es/internal/useOverflowItems.js +89 -90
  358. package/es/internal/usePrefix.js +13 -5
  359. package/es/internal/usePresence.js +51 -54
  360. package/es/internal/usePresenceContext.js +35 -35
  361. package/es/internal/usePreviousValue.js +26 -18
  362. package/es/internal/useResizeObserver.js +57 -66
  363. package/es/internal/useSavedCallback.js +24 -17
  364. package/es/internal/utils.js +17 -9
  365. package/es/internal/warning.js +17 -22
  366. package/es/internal/wrapFocus.js +77 -98
  367. package/es/prop-types/AriaPropTypes.js +14 -6
  368. package/es/prop-types/deprecate.js +30 -27
  369. package/es/prop-types/deprecateComponent.js +17 -8
  370. package/es/prop-types/deprecateValuesWithin.js +18 -21
  371. package/es/prop-types/isRequiredOneOf.js +21 -24
  372. package/es/prop-types/requiredIfGivenPropIsTruthy.js +14 -14
  373. package/es/tools/events.js +17 -21
  374. package/es/tools/mapPopoverAlign.js +19 -18
  375. package/es/tools/mergeRefs.js +14 -17
  376. package/es/tools/setupGetInstanceId.js +16 -8
  377. package/es/tools/toggleClass.js +17 -9
  378. package/es/tools/wrapComponent.js +34 -39
  379. package/icons/index.d.ts +2 -1
  380. package/icons/index.esm.js +2 -2
  381. package/icons/index.js +7 -10
  382. package/lib/_virtual/_rolldown/runtime.js +50 -0
  383. package/lib/components/AILabel/index.d.ts +29 -2
  384. package/lib/components/AILabel/index.js +118 -171
  385. package/lib/components/AISkeleton/AISkeletonIcon.js +27 -31
  386. package/lib/components/AISkeleton/AISkeletonPlaceholder.js +29 -31
  387. package/lib/components/AISkeleton/AISkeletonText.js +30 -43
  388. package/lib/components/Accordion/Accordion.Skeleton.js +59 -84
  389. package/lib/components/Accordion/Accordion.js +47 -65
  390. package/lib/components/Accordion/AccordionItem.js +106 -160
  391. package/lib/components/Accordion/AccordionProvider.js +20 -17
  392. package/lib/components/AspectRatio/AspectRatio.js +45 -51
  393. package/lib/components/BadgeIndicator/index.js +33 -39
  394. package/lib/components/Breadcrumb/Breadcrumb.Skeleton.js +43 -55
  395. package/lib/components/Breadcrumb/Breadcrumb.js +43 -55
  396. package/lib/components/Breadcrumb/BreadcrumbItem.js +84 -87
  397. package/lib/components/Button/Button.Skeleton.js +53 -63
  398. package/lib/components/Button/Button.d.ts +1 -1
  399. package/lib/components/Button/Button.js +149 -244
  400. package/lib/components/Button/ButtonBase.js +85 -108
  401. package/lib/components/Button/index.js +13 -15
  402. package/lib/components/ButtonSet/ButtonSet.js +78 -102
  403. package/lib/components/ButtonSet/index.js +12 -9
  404. package/lib/components/ChatButton/ChatButton.Skeleton.js +31 -31
  405. package/lib/components/ChatButton/ChatButton.js +68 -83
  406. package/lib/components/Checkbox/Checkbox.Skeleton.js +30 -30
  407. package/lib/components/Checkbox/Checkbox.js +119 -198
  408. package/lib/components/Checkbox/index.js +13 -11
  409. package/lib/components/CheckboxGroup/CheckboxGroup.js +104 -152
  410. package/lib/components/ClassPrefix/index.js +24 -19
  411. package/lib/components/CodeSnippet/CodeSnippet.Skeleton.js +49 -47
  412. package/lib/components/CodeSnippet/CodeSnippet.js +215 -303
  413. package/lib/components/ComboBox/ComboBox.js +626 -974
  414. package/lib/components/ComboBox/index.js +12 -9
  415. package/lib/components/ComboButton/index.js +176 -210
  416. package/lib/components/ComposedModal/ComposedModal.js +315 -454
  417. package/lib/components/ComposedModal/ComposedModalPresence.js +49 -44
  418. package/lib/components/ComposedModal/ModalFooter.js +131 -209
  419. package/lib/components/ComposedModal/ModalHeader.js +75 -103
  420. package/lib/components/ComposedModal/useComposedModalState.js +22 -17
  421. package/lib/components/ContainedList/ContainedList.js +77 -106
  422. package/lib/components/ContainedList/ContainedListItem/ContainedListItem.js +59 -71
  423. package/lib/components/ContainedList/ContainedListItem/index.js +12 -9
  424. package/lib/components/ContainedList/index.js +18 -15
  425. package/lib/components/ContentSwitcher/ContentSwitcher.js +112 -142
  426. package/lib/components/ContextMenu/useContextMenu.js +42 -40
  427. package/lib/components/Copy/Copy.js +101 -121
  428. package/lib/components/Copy/index.js +12 -9
  429. package/lib/components/CopyButton/CopyButton.js +85 -98
  430. package/lib/components/CopyButton/index.js +12 -9
  431. package/lib/components/DangerButton/DangerButton.js +19 -13
  432. package/lib/components/DataTable/DataTable.d.ts +11 -11
  433. package/lib/components/DataTable/DataTable.js +474 -655
  434. package/lib/components/DataTable/Table.js +115 -161
  435. package/lib/components/DataTable/TableActionList.js +15 -11
  436. package/lib/components/DataTable/TableBatchAction.js +28 -38
  437. package/lib/components/DataTable/TableBatchActions.js +82 -117
  438. package/lib/components/DataTable/TableBody.js +29 -23
  439. package/lib/components/DataTable/TableCell.js +35 -50
  440. package/lib/components/DataTable/TableContainer.js +79 -86
  441. package/lib/components/DataTable/TableContext.js +15 -8
  442. package/lib/components/DataTable/TableDecoratorRow.js +34 -40
  443. package/lib/components/DataTable/TableExpandHeader.js +57 -94
  444. package/lib/components/DataTable/TableExpandRow.js +86 -123
  445. package/lib/components/DataTable/TableExpandedRow.js +49 -55
  446. package/lib/components/DataTable/TableHead.js +8 -10
  447. package/lib/components/DataTable/TableHeader.js +142 -185
  448. package/lib/components/DataTable/TableRow.d.ts +1 -1
  449. package/lib/components/DataTable/TableRow.js +46 -80
  450. package/lib/components/DataTable/TableSelectAll.js +46 -74
  451. package/lib/components/DataTable/TableSelectRow.js +67 -102
  452. package/lib/components/DataTable/TableSlugRow.js +39 -47
  453. package/lib/components/DataTable/TableToolbar.js +37 -49
  454. package/lib/components/DataTable/TableToolbarAction.js +28 -24
  455. package/lib/components/DataTable/TableToolbarContent.js +15 -11
  456. package/lib/components/DataTable/TableToolbarMenu.js +39 -50
  457. package/lib/components/DataTable/TableToolbarSearch.js +101 -191
  458. package/lib/components/DataTable/state/getDerivedStateFromProps.js +38 -47
  459. package/lib/components/DataTable/state/sortStates.js +11 -10
  460. package/lib/components/DataTable/state/sorting.js +54 -76
  461. package/lib/components/DataTable/tools/cells.js +15 -8
  462. package/lib/components/DataTable/tools/denormalize.js +27 -22
  463. package/lib/components/DataTable/tools/filter.js +21 -23
  464. package/lib/components/DataTable/tools/normalize.js +57 -76
  465. package/lib/components/DataTable/tools/sorting.js +50 -75
  466. package/lib/components/DataTableSkeleton/DataTableSkeleton.js +70 -98
  467. package/lib/components/DatePicker/DatePicker.Skeleton.js +48 -56
  468. package/lib/components/DatePicker/DatePicker.js +491 -756
  469. package/lib/components/DatePicker/DatePickerLocales.js +75 -127
  470. package/lib/components/DatePicker/index.js +13 -11
  471. package/lib/components/DatePicker/plugins/appendToPlugin.js +31 -46
  472. package/lib/components/DatePicker/plugins/fixEventsPlugin.js +127 -175
  473. package/lib/components/DatePicker/plugins/rangePlugin.js +42 -50
  474. package/lib/components/DatePicker/utils.js +11 -4
  475. package/lib/components/DatePickerInput/DatePickerInput.js +183 -293
  476. package/lib/components/DatePickerInput/index.js +12 -9
  477. package/lib/components/Dialog/Dialog.js +307 -576
  478. package/lib/components/Dialog/index.js +21 -13
  479. package/lib/components/Dropdown/Dropdown.Skeleton.js +30 -43
  480. package/lib/components/Dropdown/Dropdown.js +348 -539
  481. package/lib/components/Dropdown/index.js +13 -11
  482. package/lib/components/ErrorBoundary/ErrorBoundary.js +39 -62
  483. package/lib/components/ErrorBoundary/ErrorBoundaryContext.js +15 -11
  484. package/lib/components/ExpandableSearch/ExpandableSearch.js +63 -73
  485. package/lib/components/ExpandableSearch/index.js +12 -9
  486. package/lib/components/FeatureFlags/index.d.ts +11 -2
  487. package/lib/components/FeatureFlags/index.js +82 -79
  488. package/lib/components/FileUploader/FileUploader.Skeleton.js +39 -35
  489. package/lib/components/FileUploader/FileUploader.js +273 -347
  490. package/lib/components/FileUploader/FileUploaderButton.js +114 -164
  491. package/lib/components/FileUploader/FileUploaderDropContainer.js +148 -225
  492. package/lib/components/FileUploader/FileUploaderItem.js +142 -161
  493. package/lib/components/FileUploader/Filename.d.ts +1 -1
  494. package/lib/components/FileUploader/Filename.js +56 -76
  495. package/lib/components/FluidComboBox/FluidComboBox.Skeleton.js +30 -32
  496. package/lib/components/FluidComboBox/FluidComboBox.js +58 -109
  497. package/lib/components/FluidDatePicker/FluidDatePicker.Skeleton.js +60 -57
  498. package/lib/components/FluidDatePicker/FluidDatePicker.js +50 -72
  499. package/lib/components/FluidDatePickerInput/FluidDatePickerInput.js +25 -20
  500. package/lib/components/FluidDropdown/FluidDropdown.Skeleton.js +30 -32
  501. package/lib/components/FluidDropdown/FluidDropdown.js +59 -115
  502. package/lib/components/FluidForm/FluidForm.js +33 -35
  503. package/lib/components/FluidForm/FormContext.js +13 -8
  504. package/lib/components/FluidMultiSelect/FluidMultiSelect.Skeleton.js +30 -32
  505. package/lib/components/FluidMultiSelect/FluidMultiSelect.js +71 -201
  506. package/lib/components/FluidNumberInput/FluidNumberInput.Skeleton.js +31 -34
  507. package/lib/components/FluidNumberInput/FluidNumberInput.js +67 -151
  508. package/lib/components/FluidSearch/FluidSearch.Skeleton.js +31 -34
  509. package/lib/components/FluidSearch/FluidSearch.js +45 -88
  510. package/lib/components/FluidSelect/FluidSelect.Skeleton.js +30 -32
  511. package/lib/components/FluidSelect/FluidSelect.js +44 -80
  512. package/lib/components/FluidSelect/index.js +13 -11
  513. package/lib/components/FluidTextArea/FluidTextArea.Skeleton.js +31 -34
  514. package/lib/components/FluidTextArea/FluidTextArea.js +52 -116
  515. package/lib/components/FluidTextInput/FluidPasswordInput.js +48 -103
  516. package/lib/components/FluidTextInput/FluidTextInput.Skeleton.js +31 -34
  517. package/lib/components/FluidTextInput/FluidTextInput.js +53 -108
  518. package/lib/components/FluidTextInput/index.js +14 -13
  519. package/lib/components/FluidTimePicker/FluidTimePicker.Skeleton.js +34 -37
  520. package/lib/components/FluidTimePicker/FluidTimePicker.js +72 -119
  521. package/lib/components/FluidTimePickerSelect/FluidTimePickerSelect.js +31 -51
  522. package/lib/components/Form/Form.js +27 -29
  523. package/lib/components/FormGroup/FormGroup.js +49 -71
  524. package/lib/components/FormItem/FormItem.js +27 -29
  525. package/lib/components/FormLabel/FormLabel.js +32 -38
  526. package/lib/components/Grid/CSSGrid.d.ts +1 -1
  527. package/lib/components/Grid/CSSGrid.js +89 -129
  528. package/lib/components/Grid/Column.js +196 -328
  529. package/lib/components/Grid/ColumnHang.js +32 -38
  530. package/lib/components/Grid/FlexGrid.js +44 -62
  531. package/lib/components/Grid/Grid.js +32 -44
  532. package/lib/components/Grid/GridContext.js +39 -44
  533. package/lib/components/Grid/Row.js +35 -53
  534. package/lib/components/Heading/index.js +39 -53
  535. package/lib/components/Icon/Icon.Skeleton.js +25 -23
  536. package/lib/components/IconButton/index.js +121 -180
  537. package/lib/components/IconIndicator/index.d.ts +1 -1
  538. package/lib/components/IconIndicator/index.js +63 -63
  539. package/lib/components/IdPrefix/index.js +24 -19
  540. package/lib/components/InlineCheckbox/InlineCheckbox.js +72 -117
  541. package/lib/components/InlineCheckbox/index.js +12 -9
  542. package/lib/components/InlineLoading/InlineLoading.js +87 -104
  543. package/lib/components/InlineLoading/index.js +12 -9
  544. package/lib/components/Layer/LayerContext.js +14 -6
  545. package/lib/components/Layer/LayerLevel.js +20 -6
  546. package/lib/components/Layer/index.js +58 -68
  547. package/lib/components/Layout/index.js +81 -111
  548. package/lib/components/LayoutDirection/LayoutDirection.d.ts +1 -1
  549. package/lib/components/LayoutDirection/LayoutDirection.js +36 -40
  550. package/lib/components/LayoutDirection/LayoutDirectionContext.js +14 -8
  551. package/lib/components/LayoutDirection/useLayoutDirection.js +16 -9
  552. package/lib/components/Link/Link.js +67 -112
  553. package/lib/components/Link/index.js +12 -9
  554. package/lib/components/ListBox/ListBox.js +82 -130
  555. package/lib/components/ListBox/ListBoxField.js +33 -47
  556. package/lib/components/ListBox/ListBoxMenu.js +39 -46
  557. package/lib/components/ListBox/ListBoxMenuIcon.js +43 -44
  558. package/lib/components/ListBox/ListBoxMenuItem.js +71 -92
  559. package/lib/components/ListBox/ListBoxPropTypes.js +21 -9
  560. package/lib/components/ListBox/ListBoxSelection.js +75 -100
  561. package/lib/components/ListBox/index.js +17 -21
  562. package/lib/components/ListBox/next/ListBoxSelection.js +83 -121
  563. package/lib/components/ListBox/next/ListBoxTrigger.js +48 -52
  564. package/lib/components/ListItem/ListItem.js +29 -32
  565. package/lib/components/Loading/Loading.js +68 -77
  566. package/lib/components/Loading/index.js +12 -9
  567. package/lib/components/Menu/Menu.js +224 -365
  568. package/lib/components/Menu/MenuContext.d.ts +1 -1
  569. package/lib/components/Menu/MenuContext.js +42 -40
  570. package/lib/components/Menu/MenuItem.js +286 -415
  571. package/lib/components/MenuButton/index.js +138 -197
  572. package/lib/components/Modal/Modal.js +504 -665
  573. package/lib/components/Modal/ModalPresence.js +41 -39
  574. package/lib/components/Modal/index.js +13 -10
  575. package/lib/components/ModalWrapper/ModalWrapper.d.ts +2 -2
  576. package/lib/components/ModalWrapper/ModalWrapper.js +112 -134
  577. package/lib/components/MultiSelect/FilterableMultiSelect.js +611 -920
  578. package/lib/components/MultiSelect/MultiSelect.js +459 -718
  579. package/lib/components/MultiSelect/MultiSelectPropTypes.js +15 -32
  580. package/lib/components/MultiSelect/filter.js +14 -10
  581. package/lib/components/MultiSelect/tools/sorting.js +21 -35
  582. package/lib/components/Notification/Notification.js +514 -787
  583. package/lib/components/NumberInput/NumberFormatPropTypes.js +72 -33
  584. package/lib/components/NumberInput/NumberInput.Skeleton.js +33 -37
  585. package/lib/components/NumberInput/NumberInput.js +571 -950
  586. package/lib/components/OrderedList/OrderedList.js +35 -48
  587. package/lib/components/OverflowMenu/OverflowMenu.js +341 -454
  588. package/lib/components/OverflowMenu/index.js +27 -21
  589. package/lib/components/OverflowMenu/next/index.js +158 -188
  590. package/lib/components/OverflowMenuItem/OverflowMenuItem.js +104 -164
  591. package/lib/components/OverflowMenuItem/index.js +12 -9
  592. package/lib/components/OverflowMenuV2/index.js +25 -15
  593. package/lib/components/PageHeader/PageHeader.js +301 -444
  594. package/lib/components/PageHeader/index.js +27 -19
  595. package/lib/components/Pagination/Pagination.Skeleton.js +38 -37
  596. package/lib/components/Pagination/Pagination.d.ts +1 -1
  597. package/lib/components/Pagination/Pagination.js +256 -360
  598. package/lib/components/Pagination/experimental/PageSelector.js +48 -58
  599. package/lib/components/Pagination/experimental/Pagination-story.d.ts +114 -0
  600. package/lib/components/Pagination/experimental/Pagination.js +148 -200
  601. package/lib/components/PaginationNav/PaginationNav.js +324 -430
  602. package/lib/components/Popover/index.js +323 -440
  603. package/lib/components/PrimaryButton/PrimaryButton.js +19 -13
  604. package/lib/components/ProgressBar/ProgressBar.js +121 -147
  605. package/lib/components/ProgressIndicator/ProgressIndicator.Skeleton.js +46 -43
  606. package/lib/components/ProgressIndicator/ProgressIndicator.js +150 -245
  607. package/lib/components/RadioButton/RadioButton.Skeleton.js +27 -27
  608. package/lib/components/RadioButton/RadioButton.js +105 -178
  609. package/lib/components/RadioButton/index.js +12 -9
  610. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +139 -211
  611. package/lib/components/RadioTile/RadioTile.js +108 -172
  612. package/lib/components/RadioTile/index.js +12 -9
  613. package/lib/components/Search/Search.Skeleton.js +32 -38
  614. package/lib/components/Search/Search.js +185 -281
  615. package/lib/components/Search/index.js +13 -11
  616. package/lib/components/Search/utils.js +11 -4
  617. package/lib/components/SecondaryButton/SecondaryButton.js +19 -13
  618. package/lib/components/Select/Select.Skeleton.js +31 -35
  619. package/lib/components/Select/Select.js +182 -261
  620. package/lib/components/Select/index.js +13 -11
  621. package/lib/components/SelectItem/SelectItem.js +37 -52
  622. package/lib/components/SelectItem/index.js +12 -9
  623. package/lib/components/SelectItemGroup/SelectItemGroup.js +31 -41
  624. package/lib/components/ShapeIndicator/index.d.ts +1 -1
  625. package/lib/components/ShapeIndicator/index.js +78 -83
  626. package/lib/components/SkeletonIcon/SkeletonIcon.js +25 -28
  627. package/lib/components/SkeletonPlaceholder/SkeletonPlaceholder.js +25 -28
  628. package/lib/components/SkeletonText/SkeletonText.js +71 -85
  629. package/lib/components/SkeletonText/index.js +12 -9
  630. package/lib/components/Slider/Slider.Skeleton.js +72 -95
  631. package/lib/components/Slider/Slider.js +868 -1319
  632. package/lib/components/Slider/SliderHandles.js +75 -68
  633. package/lib/components/Stack/HStack.js +22 -14
  634. package/lib/components/Stack/Stack.js +60 -82
  635. package/lib/components/Stack/VStack.js +22 -14
  636. package/lib/components/StructuredList/StructuredList.Skeleton.js +59 -52
  637. package/lib/components/StructuredList/StructuredList.js +182 -319
  638. package/lib/components/Switch/IconSwitch.js +103 -149
  639. package/lib/components/Switch/Switch.js +70 -103
  640. package/lib/components/TabContent/TabContent.js +32 -38
  641. package/lib/components/Tabs/Tabs.Skeleton.js +45 -41
  642. package/lib/components/Tabs/Tabs.js +738 -1153
  643. package/lib/components/Tabs/usePressable.js +98 -114
  644. package/lib/components/Tag/DismissibleTag.js +123 -160
  645. package/lib/components/Tag/OperationalTag.js +95 -115
  646. package/lib/components/Tag/SelectableTag.js +98 -133
  647. package/lib/components/Tag/Tag.Skeleton.js +30 -32
  648. package/lib/components/Tag/Tag.js +156 -204
  649. package/lib/components/Tag/isEllipsisActive.js +13 -9
  650. package/lib/components/Text/Text.js +69 -81
  651. package/lib/components/Text/TextDirection.js +39 -39
  652. package/lib/components/Text/TextDirectionContext.js +15 -10
  653. package/lib/components/Text/createTextComponent.js +29 -22
  654. package/lib/components/TextArea/TextArea.Skeleton.js +29 -34
  655. package/lib/components/TextArea/TextArea.js +319 -426
  656. package/lib/components/TextArea/index.js +13 -11
  657. package/lib/components/TextInput/ControlledPasswordInput.js +137 -202
  658. package/lib/components/TextInput/PasswordInput.js +200 -307
  659. package/lib/components/TextInput/TextInput.Skeleton.js +28 -33
  660. package/lib/components/TextInput/TextInput.js +223 -321
  661. package/lib/components/TextInput/index.js +13 -11
  662. package/lib/components/TextInput/util.js +21 -26
  663. package/lib/components/Theme/index.js +83 -97
  664. package/lib/components/Tile/Tile.js +398 -595
  665. package/lib/components/TileGroup/TileGroup.js +73 -113
  666. package/lib/components/TimePicker/TimePicker.d.ts +1 -1
  667. package/lib/components/TimePicker/TimePicker.js +152 -251
  668. package/lib/components/TimePickerSelect/TimePickerSelect.js +47 -62
  669. package/lib/components/Toggle/Toggle.Skeleton.js +28 -24
  670. package/lib/components/Toggle/Toggle.js +106 -176
  671. package/lib/components/ToggleSmall/ToggleSmall.Skeleton.js +50 -53
  672. package/lib/components/Toggletip/index.d.ts +2 -2
  673. package/lib/components/Toggletip/index.js +174 -258
  674. package/lib/components/Tooltip/DefinitionTooltip.js +102 -140
  675. package/lib/components/Tooltip/Tooltip.js +192 -265
  676. package/lib/components/TreeView/TreeContext.js +14 -7
  677. package/lib/components/TreeView/TreeNode.js +365 -504
  678. package/lib/components/TreeView/TreeView.js +169 -242
  679. package/lib/components/UIShell/Content.js +27 -34
  680. package/lib/components/UIShell/Header.js +29 -33
  681. package/lib/components/UIShell/HeaderContainer.js +34 -44
  682. package/lib/components/UIShell/HeaderGlobalAction.js +69 -94
  683. package/lib/components/UIShell/HeaderGlobalBar.js +17 -14
  684. package/lib/components/UIShell/HeaderMenu.js +146 -221
  685. package/lib/components/UIShell/HeaderMenuButton.js +47 -70
  686. package/lib/components/UIShell/HeaderMenuItem.js +53 -80
  687. package/lib/components/UIShell/HeaderName.js +36 -48
  688. package/lib/components/UIShell/HeaderNavigation.js +36 -41
  689. package/lib/components/UIShell/HeaderPanel.js +78 -101
  690. package/lib/components/UIShell/HeaderSideNavItems.js +31 -37
  691. package/lib/components/UIShell/Link.js +32 -54
  692. package/lib/components/UIShell/SideNav.js +136 -245
  693. package/lib/components/UIShell/SideNavContext.js +23 -17
  694. package/lib/components/UIShell/SideNavDetails.js +33 -38
  695. package/lib/components/UIShell/SideNavDivider.js +25 -25
  696. package/lib/components/UIShell/SideNavFooter.js +47 -56
  697. package/lib/components/UIShell/SideNavHeader.js +30 -39
  698. package/lib/components/UIShell/SideNavIcon.js +32 -37
  699. package/lib/components/UIShell/SideNavItem.js +32 -37
  700. package/lib/components/UIShell/SideNavItems.js +35 -44
  701. package/lib/components/UIShell/SideNavLink.js +56 -83
  702. package/lib/components/UIShell/SideNavLinkText.js +28 -29
  703. package/lib/components/UIShell/SideNavMenu.js +106 -148
  704. package/lib/components/UIShell/SideNavMenuItem.js +44 -56
  705. package/lib/components/UIShell/SideNavSwitcher.js +63 -72
  706. package/lib/components/UIShell/SkipToContent.js +32 -40
  707. package/lib/components/UIShell/Switcher.js +73 -103
  708. package/lib/components/UIShell/SwitcherDivider.js +26 -28
  709. package/lib/components/UIShell/SwitcherItem.js +78 -118
  710. package/lib/components/UnorderedList/UnorderedList.js +32 -41
  711. package/lib/feature-flags.js +21 -13
  712. package/lib/index.js +622 -602
  713. package/lib/internal/FloatingMenu.js +249 -296
  714. package/lib/internal/OptimizedResize.js +35 -47
  715. package/lib/internal/Selection.js +102 -134
  716. package/lib/internal/clamp.js +12 -5
  717. package/lib/internal/defaultItemToString.js +15 -10
  718. package/lib/internal/deprecateFieldOnObject.js +23 -16
  719. package/lib/internal/environment.js +15 -8
  720. package/lib/internal/getAnnouncement.js +16 -14
  721. package/lib/internal/keyboard/keys.js +48 -49
  722. package/lib/internal/keyboard/match.js +25 -43
  723. package/lib/internal/keyboard/navigation.js +22 -29
  724. package/lib/internal/noopFn.js +10 -3
  725. package/lib/internal/useAttachedMenu.js +44 -53
  726. package/lib/internal/useControllableState.js +44 -50
  727. package/lib/internal/useDelayedState.js +31 -37
  728. package/lib/internal/useEvent.js +40 -37
  729. package/lib/internal/useId.js +54 -91
  730. package/lib/internal/useIdPrefix.js +15 -7
  731. package/lib/internal/useIsomorphicEffect.js +13 -8
  732. package/lib/internal/useMatchMedia.js +30 -23
  733. package/lib/internal/useMergedRefs.js +27 -24
  734. package/lib/internal/useNoInteractiveChildren.js +73 -101
  735. package/lib/internal/useNormalizedInputProps.js +55 -53
  736. package/lib/internal/useOutsideClick.js +22 -26
  737. package/lib/internal/useOverflowItems.js +90 -94
  738. package/lib/internal/usePrefix.js +15 -7
  739. package/lib/internal/usePresence.js +52 -56
  740. package/lib/internal/usePresenceContext.js +36 -37
  741. package/lib/internal/usePreviousValue.js +27 -20
  742. package/lib/internal/useResizeObserver.js +58 -68
  743. package/lib/internal/useSavedCallback.js +25 -19
  744. package/lib/internal/utils.js +18 -11
  745. package/lib/internal/warning.js +24 -23
  746. package/lib/internal/wrapFocus.js +78 -100
  747. package/lib/prop-types/AriaPropTypes.js +17 -9
  748. package/lib/prop-types/deprecate.js +30 -29
  749. package/lib/prop-types/deprecateComponent.js +17 -10
  750. package/lib/prop-types/deprecateValuesWithin.js +18 -23
  751. package/lib/prop-types/isRequiredOneOf.js +21 -25
  752. package/lib/prop-types/requiredIfGivenPropIsTruthy.js +14 -15
  753. package/lib/tools/events.js +17 -22
  754. package/lib/tools/mapPopoverAlign.js +19 -19
  755. package/lib/tools/mergeRefs.js +14 -18
  756. package/lib/tools/setupGetInstanceId.js +16 -9
  757. package/lib/tools/toggleClass.js +17 -10
  758. package/lib/tools/wrapComponent.js +38 -43
  759. package/package.json +10 -16
  760. package/es/_virtual/_rollupPluginBabelHelpers.js +0 -40
  761. package/es/components/DataTable/stories/examples/TableToolbarFilter.d.ts +0 -54
  762. package/es/node_modules/es-toolkit/dist/compat/function/debounce.js +0 -55
  763. package/es/node_modules/es-toolkit/dist/compat/function/throttle.js +0 -23
  764. package/es/node_modules/es-toolkit/dist/function/debounce.js +0 -70
  765. package/lib/_virtual/_rollupPluginBabelHelpers.js +0 -45
  766. package/lib/components/DataTable/stories/examples/TableToolbarFilter.d.ts +0 -54
  767. package/lib/node_modules/es-toolkit/dist/compat/function/debounce.js +0 -57
  768. package/lib/node_modules/es-toolkit/dist/compat/function/throttle.js +0 -25
  769. package/lib/node_modules/es-toolkit/dist/function/debounce.js +0 -72
@@ -1,1332 +1,881 @@
1
1
  /**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2026
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React, { useReducer, useRef, useEffect, useMemo } from 'react';
10
- import PropTypes from 'prop-types';
11
- import cx from 'classnames';
12
- import { Enter, ArrowDown, ArrowLeft, ArrowUp, ArrowRight } from '../../internal/keyboard/keys.js';
13
- import { matches } from '../../internal/keyboard/match.js';
14
- import { usePrefix } from '../../internal/usePrefix.js';
15
- import { deprecate } from '../../prop-types/deprecate.js';
16
- import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
17
- import { Text } from '../Text/Text.js';
18
- import '../Text/TextDirection.js';
19
- import '../Tooltip/DefinitionTooltip.js';
20
- import { Tooltip } from '../Tooltip/Tooltip.js';
21
- import { LowerHandle, LowerHandleFocus, UpperHandle, UpperHandleFocus } from './SliderHandles.js';
22
- import { clamp } from '../../internal/clamp.js';
23
- import { useNormalizedInputProps } from '../../internal/useNormalizedInputProps.js';
24
- import { useId } from '../../internal/useId.js';
25
- import { throttle } from '../../node_modules/es-toolkit/dist/compat/function/throttle.js';
26
-
27
- const ThumbWrapper = ({
28
- hasTooltip,
29
- className,
30
- style,
31
- children,
32
- ...rest
33
- }) => {
34
- if (hasTooltip) {
35
- return /*#__PURE__*/React.createElement(Tooltip, _extends({
36
- className: className,
37
- style: style
38
- }, rest), children);
39
- } else {
40
- return /*#__PURE__*/React.createElement("div", {
41
- className: className,
42
- style: style
43
- }, children);
44
- }
45
- };
46
- const translationIds = {
47
- 'carbon.slider.auto-correct-announcement': 'carbon.slider.auto-correct-announcement'
48
- };
49
- const defaultTranslations = {
50
- [translationIds['carbon.slider.auto-correct-announcement']]: 'The inputted value "{correctedValue}" was corrected to the nearest allowed digit.'
8
+ import { usePrefix } from "../../internal/usePrefix.js";
9
+ import { Text } from "../Text/Text.js";
10
+ import { ArrowDown, ArrowLeft, ArrowRight as ArrowRight$1, ArrowUp as ArrowUp$1, Enter } from "../../internal/keyboard/keys.js";
11
+ import { matches } from "../../internal/keyboard/match.js";
12
+ import { useId } from "../../internal/useId.js";
13
+ import { deprecate } from "../../prop-types/deprecate.js";
14
+ import { Tooltip } from "../Tooltip/Tooltip.js";
15
+ import { useNormalizedInputProps } from "../../internal/useNormalizedInputProps.js";
16
+ import { clamp } from "../../internal/clamp.js";
17
+ import { LowerHandle, LowerHandleFocus, UpperHandle, UpperHandleFocus } from "./SliderHandles.js";
18
+ import classNames from "classnames";
19
+ import React, { useEffect, useMemo, useReducer, useRef } from "react";
20
+ import PropTypes from "prop-types";
21
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
22
+ import { WarningAltFilled, WarningFilled } from "@carbon/icons-react";
23
+ import { throttle } from "es-toolkit/compat";
24
+
25
+ //#region src/components/Slider/Slider.tsx
26
+ /**
27
+ * Copyright IBM Corp. 2016, 2026
28
+ *
29
+ * This source code is licensed under the Apache-2.0 license found in the
30
+ * LICENSE file in the root directory of this source tree.
31
+ */
32
+ const ThumbWrapper = ({ hasTooltip, className, style, children, ...rest }) => {
33
+ if (hasTooltip) return /* @__PURE__ */ jsx(Tooltip, {
34
+ className,
35
+ style,
36
+ ...rest,
37
+ children
38
+ });
39
+ else return /* @__PURE__ */ jsx("div", {
40
+ className,
41
+ style,
42
+ children
43
+ });
51
44
  };
45
+ const translationIds = { "carbon.slider.auto-correct-announcement": "carbon.slider.auto-correct-announcement" };
46
+ const defaultTranslations = { [translationIds["carbon.slider.auto-correct-announcement"]]: "The inputted value \"{correctedValue}\" was corrected to the nearest allowed digit." };
52
47
  const defaultTranslateWithId = (messageId, args) => {
53
- const template = defaultTranslations[messageId];
54
- if (args?.correctedValue) {
55
- return template.replace('{correctedValue}', args.correctedValue);
56
- }
57
- return template;
48
+ const template = defaultTranslations[messageId];
49
+ if (args?.correctedValue) return template.replace("{correctedValue}", args.correctedValue);
50
+ return template;
58
51
  };
59
52
  const defaultFormatLabel = (value, label) => {
60
- return `${value}${label ?? ''}`;
53
+ return `${value}${label ?? ""}`;
61
54
  };
62
- const hasUpperValue = valueUpper => typeof valueUpper !== 'undefined';
63
-
64
- // TODO: Assuming a 16ms throttle corresponds to 60 FPS, should it be halved,
65
- // since many systems can handle 120 FPS? If it doesn't correspond to 60 FPS,
66
- // what does it correspond to?
55
+ const hasUpperValue = (valueUpper) => typeof valueUpper !== "undefined";
67
56
  /**
68
- * Minimum time between processed "drag" events in milliseconds.
69
- */
57
+ * Minimum time between processed "drag" events in milliseconds.
58
+ */
70
59
  const EVENT_THROTTLE = 16;
71
- const DRAG_EVENT_TYPES = new Set(['mousemove', 'touchmove']);
72
- const DRAG_STOP_EVENT_TYPES = new Set(['mouseup', 'touchend', 'touchcancel']);
73
- var HandlePosition = /*#__PURE__*/function (HandlePosition) {
74
- HandlePosition["LOWER"] = "lower";
75
- HandlePosition["UPPER"] = "upper";
76
- return HandlePosition;
77
- }(HandlePosition || {}); // TODO: Delete this type and directory type the properties in the function.
78
- const Slider = props => {
79
- // TODO: Move destructured `props` from the IIFE to here.
80
-
81
- const initialState = {
82
- value: props.value,
83
- valueUpper: props.unstable_valueUpper,
84
- left: 0,
85
- leftUpper: 0,
86
- needsOnRelease: false,
87
- isValid: true,
88
- isValidUpper: true,
89
- activeHandle: undefined,
90
- correctedValue: null,
91
- correctedPosition: null,
92
- isRtl: false
93
- };
94
-
95
- // TODO: Investigate using generics on the hook.
96
- const [state, setState] = useReducer((prev, args) => ({
97
- ...prev,
98
- ...args
99
- }), initialState);
100
-
101
- // TODO: Investigate getting rid of these references.
102
- const stateRef = useRef(state);
103
- useEffect(() => {
104
- stateRef.current = state;
105
- }, [state]);
106
- const propsRef = useRef(props);
107
- useEffect(() => {
108
- propsRef.current = props;
109
- }, [props]);
110
- const thumbRef = useRef(null);
111
- const thumbRefUpper = useRef(null);
112
- const filledTrackRef = useRef(null);
113
- const elementRef = useRef(null);
114
- const trackRef = useRef(null);
115
- const generatedId = useId();
116
- const prefix = usePrefix();
117
- const twoHandles = hasUpperValue(state.valueUpper);
118
-
119
- /**
120
- * Sets up initial slider position and value in response to component mount.
121
- */
122
- useEffect(() => {
123
- if (elementRef.current) {
124
- const isRtl = document?.dir === 'rtl';
125
- if (twoHandles) {
126
- const {
127
- value,
128
- left
129
- } = calcValue({
130
- value: stateRef.current.value,
131
- useRawValue: true
132
- });
133
- const {
134
- value: valueUpper,
135
- left: leftUpper
136
- } = calcValue({
137
- value: stateRef.current.valueUpper,
138
- useRawValue: true
139
- });
140
- setState({
141
- isRtl,
142
- value,
143
- left,
144
- valueUpper,
145
- leftUpper
146
- });
147
- } else {
148
- const {
149
- value,
150
- left
151
- } = calcValue({
152
- value: stateRef.current.value,
153
- useRawValue: true
154
- });
155
- setState({
156
- isRtl,
157
- value,
158
- left
159
- });
160
- }
161
- }
162
- return () => {
163
- DRAG_STOP_EVENT_TYPES.forEach(element => elementRef.current?.ownerDocument.removeEventListener(element, onDragStop));
164
- DRAG_EVENT_TYPES.forEach(element => elementRef.current?.ownerDocument.removeEventListener(element, handleDrag));
165
- };
166
- // eslint-disable-next-line react-hooks/exhaustive-deps
167
- }, []);
168
- useEffect(() => {
169
- // TODO: Uncomment this code and delete all of the `filledTrackRef.current`
170
- // checks.
171
- // const el = filledTrackRef.current;
172
- //
173
- // if (!el) return;
174
-
175
- // Fire onChange event handler if present, if there's a usable value, and
176
- // if the value is different from the last one
177
- if (twoHandles) {
178
- if (filledTrackRef.current) {
179
- filledTrackRef.current.style.transform = state.isRtl ? `translate(${100 - state.leftUpper}%, -50%) scaleX(${(state.leftUpper - state.left) / 100})` : `translate(${state.left}%, -50%) scaleX(${(state.leftUpper - state.left) / 100})`;
180
- }
181
- } else {
182
- if (filledTrackRef.current) {
183
- filledTrackRef.current.style.transform = state.isRtl ? `translate(100%, -50%) scaleX(-${state.left / 100})` : `translate(0%, -50%) scaleX(${state.left / 100})`;
184
- }
185
- }
186
- // TODO: Investigate whether the missing dependency should be added.
187
- //
188
- // eslint-disable-next-line react-hooks/exhaustive-deps
189
- }, [state.left, state.leftUpper, state.isRtl]);
190
-
191
- // Fire onChange when value(s) change
192
- const prevValsRef = useRef(null);
193
- useEffect(() => {
194
- const prev = prevValsRef.current;
195
- if (prev && (prev.value !== state.value || prev.valueUpper !== state.valueUpper) && typeof props.onChange === 'function') {
196
- props.onChange({
197
- value: state.value,
198
- valueUpper: state.valueUpper
199
- });
200
- }
201
- prevValsRef.current = {
202
- value: state.value,
203
- valueUpper: state.valueUpper
204
- };
205
- // TODO: Investigate whether the missing dependency should be added.
206
- //
207
- // eslint-disable-next-line react-hooks/exhaustive-deps
208
- }, [state.value, state.valueUpper, props.onChange]);
209
- useEffect(() => {
210
- // Fire onRelease event handler if present and if needed
211
- if (state.needsOnRelease && typeof props.onRelease === 'function') {
212
- props.onRelease({
213
- value: state.value,
214
- valueUpper: state.valueUpper
215
- });
216
- // Reset the flag
217
- setState({
218
- needsOnRelease: false
219
- });
220
- }
221
- // TODO: Investigate whether the missing dependency should be added.
222
- //
223
- // eslint-disable-next-line react-hooks/exhaustive-deps
224
- }, [state.needsOnRelease, state.value, state.valueUpper, props.onRelease]);
225
- const prevSyncKeysRef = useRef(null);
226
- useEffect(() => {
227
- const prev = prevSyncKeysRef.current;
228
- const next = [props.value, props.unstable_valueUpper, props.max, props.min];
229
-
230
- // If value from props does not change, do nothing here.
231
- // Otherwise, do prop -> state sync without "value capping".
232
- if (!prev || prev[0] !== next[0] || prev[1] !== next[1] || prev[2] !== next[2] || prev[3] !== next[3]) {
233
- setState(calcValue({
234
- value: props.value,
235
- useRawValue: true
236
- }));
237
- if (typeof props.unstable_valueUpper !== 'undefined') {
238
- const {
239
- value: valueUpper,
240
- left: leftUpper
241
- } = calcValue({
242
- value: props.unstable_valueUpper,
243
- useRawValue: true
244
- });
245
- setState({
246
- valueUpper,
247
- leftUpper
248
- });
249
- } else {
250
- setState({
251
- valueUpper: undefined,
252
- leftUpper: undefined
253
- });
254
- }
255
- prevSyncKeysRef.current = next;
256
- }
257
- // TODO: Investigate whether the missing dependency should be added.
258
- //
259
- // eslint-disable-next-line react-hooks/exhaustive-deps
260
- }, [props.value, props.unstable_valueUpper, props.max, props.min]);
261
-
262
- /**
263
- * Rounds a given value to the nearest step defined by the slider's `step`
264
- * prop.
265
- *
266
- * @param value - The value to adjust to the nearest step. Defaults to `0`.
267
- * @returns The value rounded to the precision determined by the step.
268
- */
269
- const nearestStepValue = (value = 0) => {
270
- const decimals = (props.step?.toString().split('.')[1] ?? '').length;
271
- return Number(value.toFixed(decimals));
272
- };
273
- const handleDrag = event => {
274
- if (event instanceof globalThis.MouseEvent || event instanceof globalThis.TouchEvent) {
275
- onDrag(event);
276
- }
277
- };
278
-
279
- /**
280
- * Sets up "drag" event handlers and calls `onDrag` in case dragging
281
- * started on somewhere other than the thumb without a corresponding "move"
282
- * event.
283
- */
284
- const onDragStart = evt => {
285
- // Do nothing if component is disabled
286
- if (props.disabled || props.readOnly) {
287
- return;
288
- }
289
-
290
- // We're going to force focus on one of the handles later on here, b/c we're
291
- // firing on a mousedown event, we need to call event.preventDefault() to
292
- // keep the focus from leaving the HTMLElement.
293
- // @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#notes
294
- evt.preventDefault();
295
-
296
- // TODO: Abstract `elementRef.current?.ownerDocument` to a variable that can
297
- // be used here and everywhere else in this file.
298
-
299
- // Add drag stop handlers
300
- DRAG_STOP_EVENT_TYPES.forEach(element => {
301
- elementRef.current?.ownerDocument.addEventListener(element, onDragStop);
302
- });
303
-
304
- // Add drag handlers
305
- DRAG_EVENT_TYPES.forEach(element => {
306
- elementRef.current?.ownerDocument.addEventListener(element, handleDrag);
307
- });
308
- const clientX = getClientXFromEvent(evt.nativeEvent);
309
- let activeHandle;
310
- if (twoHandles) {
311
- if (evt.target == thumbRef.current) {
312
- activeHandle = HandlePosition.LOWER;
313
- } else if (evt.target == thumbRefUpper.current) {
314
- activeHandle = HandlePosition.UPPER;
315
- } else if (clientX) {
316
- const distanceToLower = calcDistanceToHandle(HandlePosition.LOWER, clientX);
317
- const distanceToUpper = calcDistanceToHandle(HandlePosition.UPPER, clientX);
318
- if (distanceToLower <= distanceToUpper) {
319
- activeHandle = HandlePosition.LOWER;
320
- } else {
321
- activeHandle = HandlePosition.UPPER;
322
- }
323
- }
324
- }
325
-
326
- // Force focus to the appropriate handle.
327
- const focusOptions = {
328
- preventScroll: true
329
- };
330
- if (twoHandles) {
331
- if (thumbRef.current && activeHandle === HandlePosition.LOWER) {
332
- thumbRef.current.focus(focusOptions);
333
- } else if (thumbRefUpper.current && activeHandle === HandlePosition.UPPER) {
334
- thumbRefUpper.current.focus(focusOptions);
335
- }
336
- } else if (thumbRef.current) {
337
- thumbRef.current.focus(focusOptions);
338
- }
339
- setState({
340
- activeHandle
341
- });
342
-
343
- // Perform first recalculation since we probably didn't click exactly in the
344
- // middle of the thumb.
345
- onDrag(evt.nativeEvent, activeHandle);
346
- };
347
-
348
- /**
349
- * Removes "drag" and "drag stop" event handlers and calls sets the flag
350
- * indicating that the `onRelease` callback should be called.
351
- */
352
- const onDragStop = () => {
353
- // Do nothing if component is disabled
354
- if (props.disabled || props.readOnly) {
355
- return;
356
- }
357
-
358
- // TODO: Rename parameters in `DRAG_*` loops to `type`.
359
- // Remove drag stop handlers
360
- DRAG_STOP_EVENT_TYPES.forEach(element => {
361
- elementRef.current?.ownerDocument.removeEventListener(element, onDragStop);
362
- });
363
-
364
- // Remove drag handlers
365
- DRAG_EVENT_TYPES.forEach(element => {
366
- elementRef.current?.ownerDocument.removeEventListener(element, handleDrag);
367
- });
368
-
369
- // Set needsOnRelease flag so event fires on next update.
370
- setState({
371
- needsOnRelease: true,
372
- isValid: true,
373
- isValidUpper: true
374
- });
375
- };
376
-
377
- // TODO: Rename this reference.
378
- /**
379
- * Handles a "drag" event by recalculating the value/thumb and setting state
380
- * accordingly.
381
- *
382
- * @param evt The event.
383
- * @param activeHandle The first drag event call, we may have an explicit
384
- * activeHandle value, which is to be used before state is used.
385
- */
386
- const _onDragRef = useRef(null);
387
- _onDragRef.current = (evt, activeHandle) => {
388
- activeHandle = activeHandle ?? stateRef.current.activeHandle;
389
- // Do nothing if component is disabled, or we have no event.
390
- if (propsRef.current.disabled || propsRef.current.readOnly || !evt) {
391
- return;
392
- }
393
- const clientX = getClientXFromEvent(evt);
394
- const {
395
- value,
396
- left
397
- } = calcValue({
398
- clientX,
399
- value: stateRef.current.value
400
- });
401
- // If we're set to two handles, negotiate which drag handle is closest to
402
- // the users' interaction.
403
- if (twoHandles && activeHandle) {
404
- setValueLeftForHandle(activeHandle, {
405
- value: nearestStepValue(value),
406
- left
407
- });
408
- } else {
409
- setState({
410
- value: nearestStepValue(value),
411
- left,
412
- isValid: true
413
- });
414
- }
415
- // TODO: Investigate if it would be better to not call `setState`
416
- // back-to-back here and in other places.
417
- setState({
418
- correctedValue: null,
419
- correctedPosition: null
420
- });
421
- };
422
-
423
- /**
424
- * Throttles calls to `_onDrag` by limiting events to being processed at
425
- * most once every `EVENT_THROTTLE` milliseconds.
426
- */
427
- const onDrag = useMemo(() => throttle((evt, activeHandle) => {
428
- _onDragRef.current?.(evt, activeHandle);
429
- }, EVENT_THROTTLE, {
430
- leading: true,
431
- trailing: false
432
- }), []);
433
-
434
- /**
435
- * Handles a `keydown` event by recalculating the value/thumb and setting
436
- * state accordingly.
437
- */
438
- const onKeyDown = evt => {
439
- // Do nothing if component is disabled, or we don't have a valid event
440
- if (props.disabled || props.readOnly) {
441
- return;
442
- }
443
- const {
444
- step = 1,
445
- stepMultiplier = 4
446
- } = props;
447
- let delta = 0;
448
- if (matches(evt, [ArrowDown, ArrowLeft])) {
449
- delta = -step;
450
- } else if (matches(evt, [ArrowUp, ArrowRight])) {
451
- delta = step;
452
- } else {
453
- // Ignore keys we don't want to handle
454
- return;
455
- }
456
-
457
- // If shift was held, account for the stepMultiplier
458
- if (evt.shiftKey) {
459
- delta *= stepMultiplier;
460
- }
461
- if (twoHandles && state.activeHandle) {
462
- const currentValue = state.activeHandle === HandlePosition.LOWER ? state.value : state.valueUpper;
463
- const {
464
- value,
465
- left
466
- } = calcValue({
467
- value: calcValueForDelta(currentValue ?? props.min, delta, props.step)
468
- });
469
- setValueLeftForHandle(state.activeHandle, {
470
- value: nearestStepValue(value),
471
- left
472
- });
473
- } else {
474
- const {
475
- value,
476
- left
477
- } = calcValue({
478
- // Ensures custom value from `<input>` won't cause skipping next stepping
479
- // point with right arrow key, e.g. Typing 51 in `<input>`, moving focus
480
- // onto the thumb and the hitting right arrow key should yield 52 instead
481
- // of 54.
482
- value: calcValueForDelta(state.value, delta, props.step)
483
- });
484
- setState({
485
- value: nearestStepValue(value),
486
- left,
487
- isValid: true
488
- });
489
- }
490
- setState({
491
- correctedValue: null,
492
- correctedPosition: null
493
- });
494
- };
495
-
496
- /**
497
- * Provides the two-way binding for the input field of the Slider. It also
498
- * Handles a change to the input field by recalculating the value/thumb and
499
- * setting state accordingly.
500
- */
501
- const onChangeInput = evt => {
502
- // Do nothing if component is disabled
503
- if (props.disabled || props.readOnly) {
504
- return;
505
- }
506
-
507
- // Do nothing if we have no valid event, target, or value
508
- if (!evt || !('target' in evt) || typeof evt.target.value !== 'string') {
509
- return;
510
- }
511
-
512
- // Avoid calling calcValue for invalid numbers, but still update the state.
513
- const activeHandle = evt.target.dataset.handlePosition ?? HandlePosition.LOWER;
514
- const targetValue = Number.parseFloat(evt.target.value);
515
- if (twoHandles) {
516
- if (isNaN(targetValue)) {
517
- setValueForHandle(activeHandle, evt.target.value);
518
- } else if (isValidValueForPosition({
519
- handle: activeHandle,
520
- value: targetValue,
521
- min: props.min,
522
- max: props.max
523
- })) {
524
- processNewInputValue(evt.target);
525
- } else {
526
- setValueForHandle(activeHandle, targetValue);
527
- }
528
- } else {
529
- if (isNaN(targetValue)) {
530
- // TODO: Address this error
531
- //
532
- // @ts-expect-error - Passing a string to something that expects a
533
- // number.
534
- setState({
535
- value: evt.target.value
536
- });
537
- } else if (isValidValue({
538
- value: targetValue,
539
- min: props.min,
540
- max: props.max
541
- })) {
542
- processNewInputValue(evt.target);
543
- } else {
544
- setState({
545
- value: targetValue
546
- });
547
- }
548
- }
549
- };
550
-
551
- /**
552
- * Checks for validity of input value after clicking out of the input. It also
553
- * Handles state change to isValid state.
554
- */
555
- const onBlurInput = evt => {
556
- // Do nothing if we have no valid event, target, or value
557
- if (!evt || !('target' in evt) || typeof evt.target.value !== 'string') {
558
- return;
559
- }
560
- const {
561
- value: targetValue
562
- } = evt.target;
563
- processNewInputValue(evt.target);
564
- props.onBlur?.({
565
- value: targetValue,
566
- handlePosition: evt.target.dataset.handlePosition
567
- });
568
- };
569
- const onInputKeyDown = evt => {
570
- // Do nothing if component is disabled, or we don't have a valid event.
571
- if (props.disabled || props.readOnly || !(evt.target instanceof HTMLInputElement)) {
572
- return;
573
- }
574
-
575
- // Do nothing if we have no valid event, target, or value.
576
- if (!evt || !('target' in evt) || typeof evt.target.value !== 'string') {
577
- return;
578
- }
579
- if (matches(evt, [Enter])) {
580
- processNewInputValue(evt.target);
581
- }
582
- };
583
- const processNewInputValue = input => {
584
- setState({
585
- correctedValue: null,
586
- correctedPosition: null
587
- });
588
- const targetValue = Number.parseFloat(input.value);
589
- const validity = !isNaN(targetValue);
590
-
591
- // When there are two handles, we'll also have the data-handle-position
592
- // attribute to consider the other value before settling on the validity to
593
- // set.
594
- const handlePosition = input.dataset.handlePosition;
595
- if (handlePosition === HandlePosition.LOWER) {
596
- setState({
597
- isValid: validity
598
- });
599
- } else if (handlePosition === HandlePosition.UPPER) {
600
- setState({
601
- isValidUpper: validity
602
- });
603
- }
604
- setState({
605
- isValid: validity
606
- });
607
- if (validity) {
608
- const adjustedValue = handlePosition ? getAdjustedValueForPosition({
609
- handle: handlePosition,
610
- value: targetValue,
611
- min: props.min,
612
- max: props.max
613
- }) : getAdjustedValue({
614
- value: targetValue,
615
- min: props.min,
616
- max: props.max
617
- });
618
- if (adjustedValue !== targetValue) {
619
- setState({
620
- correctedValue: targetValue.toString(),
621
- correctedPosition: handlePosition ?? null
622
- });
623
- } else {
624
- setState({
625
- correctedValue: null,
626
- correctedPosition: null
627
- });
628
- }
629
- const {
630
- value,
631
- left
632
- } = calcValue({
633
- value: adjustedValue,
634
- useRawValue: true
635
- });
636
- if (handlePosition) {
637
- setValueLeftForHandle(handlePosition, {
638
- value: nearestStepValue(value),
639
- left
640
- });
641
- } else {
642
- setState({
643
- value,
644
- left
645
- });
646
- }
647
- }
648
- };
649
- const calcLeftPercent = ({
650
- clientX,
651
- value,
652
- range
653
- }) => {
654
- // TODO: Delete the optional chaining operator after `getBoundingClientRect`.
655
- const boundingRect = elementRef.current?.getBoundingClientRect?.();
656
- let width = boundingRect ? boundingRect.right - boundingRect.left : 0;
657
-
658
- // Enforce a minimum width of at least 1 for calculations
659
- if (width <= 0) {
660
- width = 1;
661
- }
662
-
663
- // If a clientX is specified, use it to calculate the leftPercent. If not,
664
- // use the provided value to calculate it instead.
665
- if (clientX) {
666
- const leftOffset = state.isRtl ? (boundingRect?.right ?? 0) - clientX : clientX - (boundingRect?.left ?? 0);
667
- return leftOffset / width;
668
- } else if (value !== null && typeof value !== 'undefined' && range) {
669
- // Prevent NaN calculation if the range is 0.
670
- return range === 0 ? 0 : (value - props.min) / range;
671
- }
672
- // We should never end up in this scenario, but in case we do, and to
673
- // re-assure Typescript, return 0.
674
- return 0;
675
- };
676
-
677
- /**
678
- * Calculates the discrete value (snapped to the nearest step) along
679
- * with the corresponding handle position percentage.
680
- */
681
- const calcDiscreteValueAndPercent = ({
682
- leftPercent
683
- }) => {
684
- const {
685
- step = 1,
686
- min,
687
- max
688
- } = props;
689
- const numSteps = Math.floor((max - min) / step) + 1;
690
- /** Index of the step that corresponds to `leftPercent`. */
691
- const stepIndex = Math.round(leftPercent * (numSteps - 1));
692
- const discreteValue = stepIndex === numSteps - 1 ? max : min + step * stepIndex;
693
- /** Percentage corresponding to the step index. */
694
- const discretePercent = stepIndex / (numSteps - 1);
695
- return {
696
- discreteValue,
697
- discretePercent
698
- };
699
- };
700
-
701
- /**
702
- * Calculates the slider's value and handle position based on either a
703
- * mouse/touch event or an explicit value.
704
- */
705
- const calcValue = ({
706
- clientX,
707
- value,
708
- useRawValue
709
- }) => {
710
- const range = props.max - props.min;
711
- const leftPercentRaw = calcLeftPercent({
712
- clientX,
713
- value,
714
- range
715
- });
716
- /** `leftPercentRaw` clamped between 0 and 1. */
717
- const leftPercent = clamp(leftPercentRaw, 0, 1);
718
- if (useRawValue) {
719
- return {
720
- value,
721
- left: leftPercent * 100
722
- };
723
- }
724
-
725
- // Use the discrete value and percentage for snapping.
726
- const {
727
- discreteValue,
728
- discretePercent
729
- } = calcDiscreteValueAndPercent({
730
- leftPercent
731
- });
732
- return {
733
- value: discreteValue,
734
- left: discretePercent * 100
735
- };
736
- };
737
- const calcDistanceToHandle = (handle, clientX) => {
738
- const handleBoundingRect = getHandleBoundingRect(handle);
739
- /** x-coordinate of the midpoint. */
740
- const handleX = handleBoundingRect.left + handleBoundingRect.width / 2;
741
- return Math.abs(handleX - clientX);
742
- };
743
-
744
- /**
745
- * Calculates a new slider value based on the current value, a change delta,
746
- * and a step.
747
- *
748
- * @param currentValue - The starting value from which the slider is moving.
749
- * @param delta - The amount to adjust the current value by.
750
- * @param step - The step. Defaults to `1`.
751
- * @returns The new slider value, rounded to the same number of decimal places
752
- * as the step.
753
- */
754
- const calcValueForDelta = (currentValue, delta, step = 1) => {
755
- const base = delta > 0 ? Math.round(currentValue / step) * step : currentValue;
756
- const newValue = base + delta;
757
- // TODO: Why is the logical OR needed here?
758
- const decimals = (step.toString().split('.')[1] || '').length;
759
- return Number(newValue.toFixed(decimals));
760
- };
761
-
762
- /**
763
- * Sets state relevant to the given handle position.
764
- *
765
- * Guards against setting either lower or upper values beyond its counterpart.
766
- */
767
- const setValueLeftForHandle = (handle, {
768
- value: newValue,
769
- left: newLeft
770
- }) => {
771
- const {
772
- value,
773
- valueUpper,
774
- left,
775
- leftUpper
776
- } = state;
777
- if (handle === HandlePosition.LOWER) {
778
- // Don't allow higher than the upper handle.
779
- setState({
780
- value: valueUpper && newValue > valueUpper ? valueUpper : newValue,
781
- left: valueUpper && newValue > valueUpper ? leftUpper : newLeft,
782
- isValid: true
783
- });
784
- } else {
785
- setState({
786
- valueUpper: value && newValue < value ? value : newValue,
787
- leftUpper: value && newValue < value ? left : newLeft,
788
- isValidUpper: true
789
- });
790
- }
791
- };
792
- const setValueForHandle = (handle, value) => {
793
- if (handle === HandlePosition.LOWER) {
794
- setState({
795
- // TODO: Address this error
796
- //
797
- // @ts-expect-error - Passing a string to something that expects a
798
- // number.
799
- value,
800
- isValid: true
801
- });
802
- } else {
803
- setState({
804
- // TODO: Address this error
805
- //
806
- // @ts-expect-error - Passing a string to something that expects a
807
- // number.
808
- valueUpper: value,
809
- isValidUpper: true
810
- });
811
- }
812
- };
813
- const isValidValueForPosition = ({
814
- handle,
815
- value: newValue,
816
- min,
817
- max
818
- }) => {
819
- const {
820
- value,
821
- valueUpper
822
- } = state;
823
- if (!isValidValue({
824
- value: newValue,
825
- min,
826
- max
827
- })) {
828
- return false;
829
- }
830
- if (handle === HandlePosition.LOWER) {
831
- return !valueUpper || newValue <= valueUpper;
832
- } else if (handle === HandlePosition.UPPER) {
833
- return !value || newValue >= value;
834
- }
835
- return false;
836
- };
837
- const isValidValue = ({
838
- value,
839
- min,
840
- max
841
- }) => {
842
- return !(value < min || value > max);
843
- };
844
- const getAdjustedValueForPosition = ({
845
- handle,
846
- value: newValueInput,
847
- min,
848
- max
849
- }) => {
850
- const {
851
- value,
852
- valueUpper
853
- } = state;
854
- let newValue = getAdjustedValue({
855
- value: newValueInput,
856
- min,
857
- max
858
- });
859
-
860
- // TODO: Just return the value.
861
- // Next adjust to the opposite handle.
862
- if (handle === HandlePosition.LOWER && valueUpper) {
863
- newValue = newValue > valueUpper ? valueUpper : newValue;
864
- } else if (handle === HandlePosition.UPPER && value) {
865
- newValue = newValue < value ? value : newValue;
866
- }
867
- return newValue;
868
- };
869
- const getAdjustedValue = ({
870
- value,
871
- min,
872
- max
873
- }) => {
874
- // TODO: Just return the value.
875
- if (value < min) {
876
- value = min;
877
- }
878
- if (value > max) {
879
- value = max;
880
- }
881
- return value;
882
- };
883
-
884
- /**
885
- * Get the bounding rect for the requested handles' DOM element.
886
- *
887
- * If the bounding rect is not available, a new, empty DOMRect is returned.
888
- */
889
- const getHandleBoundingRect = handle => {
890
- let boundingRect;
891
- if (handle === HandlePosition.LOWER) {
892
- boundingRect = thumbRef.current?.getBoundingClientRect();
893
- } else {
894
- boundingRect = thumbRefUpper.current?.getBoundingClientRect();
895
- }
896
- return boundingRect ?? new DOMRect();
897
- };
898
- const getClientXFromEvent = event => {
899
- let clientX;
900
- if ('clientX' in event) {
901
- clientX = event.clientX;
902
- } else if ('touches' in event && 0 in event.touches && 'clientX' in event.touches[0]) {
903
- clientX = event.touches[0].clientX;
904
- }
905
- return clientX;
906
- };
907
- useEffect(() => {
908
- const {
909
- isValid,
910
- isValidUpper
911
- } = stateRef.current;
912
- const derivedState = {};
913
-
914
- // Will override state in favor of invalid prop
915
- if (props.invalid === true) {
916
- if (isValid === true) derivedState.isValid = false;
917
- if (isValidUpper === true) derivedState.isValidUpper = false;
918
- } else if (props.invalid === false) {
919
- if (isValid === false) derivedState.isValid = true;
920
- if (isValidUpper === false) derivedState.isValidUpper = true;
921
- }
922
- if (Object.keys(derivedState).length) {
923
- setState(derivedState);
924
- }
925
- }, [props.invalid]);
926
- const {
927
- ariaLabelInput,
928
- unstable_ariaLabelInputUpper: ariaLabelInputUpper,
929
- className,
930
- hideTextInput = false,
931
- id: idProp,
932
- min,
933
- minLabel,
934
- max,
935
- maxLabel,
936
- formatLabel = defaultFormatLabel,
937
- labelText,
938
- hideLabel,
939
- step = 1,
940
- inputType = 'number',
941
- invalidText,
942
- required,
943
- disabled = false,
944
- name,
945
- unstable_nameUpper: nameUpper,
946
- light,
947
- readOnly = false,
948
- warn = false,
949
- warnText,
950
- translateWithId: t = defaultTranslateWithId,
951
- ...other
952
- } = props;
953
- const id = idProp ?? generatedId;
954
- const {
955
- value,
956
- valueUpper,
957
- isValid,
958
- isValidUpper,
959
- correctedValue,
960
- correctedPosition,
961
- isRtl
962
- } = state;
963
- const normalizedProps = useNormalizedInputProps({
964
- id,
965
- disabled,
966
- readOnly,
967
- invalid: !isValid,
968
- warn
969
- });
970
- const normalizedUpperProps = useNormalizedInputProps({
971
- id,
972
- disabled,
973
- readOnly,
974
- invalid: !isValidUpper,
975
- warn
976
- });
977
- delete other.invalid;
978
- delete other.onRelease;
979
- delete other.stepMultiplier;
980
- delete other.unstable_valueUpper;
981
- const showWarning = normalizedProps.warn || correctedPosition === HandlePosition.LOWER && isValid;
982
- const showWarningUpper = normalizedUpperProps.warn || correctedPosition === (twoHandles ? HandlePosition.UPPER : HandlePosition.LOWER) && (twoHandles ? isValidUpper : isValid);
983
- const labelId = `${id}-label`;
984
- const labelClasses = cx(`${prefix}--label`, {
985
- [`${prefix}--visually-hidden`]: hideLabel,
986
- [`${prefix}--label--disabled`]: disabled
987
- });
988
- const containerClasses = cx(`${prefix}--slider-container`, {
989
- [`${prefix}--slider-container--two-handles`]: twoHandles,
990
- [`${prefix}--slider-container--disabled`]: disabled,
991
- [`${prefix}--slider-container--readonly`]: readOnly,
992
- [`${prefix}--slider-container--rtl`]: isRtl
993
- });
994
- const sliderClasses = cx(`${prefix}--slider`, {
995
- [`${prefix}--slider--disabled`]: disabled,
996
- [`${prefix}--slider--readonly`]: readOnly
997
- });
998
- const fixedInputClasses = [`${prefix}--text-input`, `${prefix}--slider-text-input`];
999
- const conditionalInputClasses = {
1000
- [`${prefix}--text-input--light`]: light
1001
- };
1002
- const lowerInputClasses = cx([...fixedInputClasses, `${prefix}--slider-text-input--lower`, conditionalInputClasses, {
1003
- [`${prefix}--text-input--invalid`]: normalizedProps.invalid,
1004
- [`${prefix}--slider-text-input--warn`]: showWarning
1005
- }]);
1006
- const upperInputClasses = cx([...fixedInputClasses, `${prefix}--slider-text-input--upper`, conditionalInputClasses, {
1007
- [`${prefix}--text-input--invalid`]: twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid,
1008
- [`${prefix}--slider-text-input--warn`]: showWarningUpper
1009
- }]);
1010
- const lowerInputWrapperClasses = cx([`${prefix}--text-input-wrapper`, `${prefix}--slider-text-input-wrapper`, `${prefix}--slider-text-input-wrapper--lower`, {
1011
- [`${prefix}--text-input-wrapper--readonly`]: readOnly,
1012
- [`${prefix}--slider-text-input-wrapper--hidden`]: hideTextInput
1013
- }]);
1014
- const upperInputWrapperClasses = cx([`${prefix}--text-input-wrapper`, `${prefix}--slider-text-input-wrapper`, `${prefix}--slider-text-input-wrapper--upper`, {
1015
- [`${prefix}--text-input-wrapper--readonly`]: readOnly,
1016
- [`${prefix}--slider-text-input-wrapper--hidden`]: hideTextInput
1017
- }]);
1018
- const lowerThumbClasses = cx(`${prefix}--slider__thumb`, {
1019
- [`${prefix}--slider__thumb--lower`]: twoHandles
1020
- });
1021
- const upperThumbClasses = cx(`${prefix}--slider__thumb`, {
1022
- [`${prefix}--slider__thumb--upper`]: twoHandles
1023
- });
1024
- const lowerThumbWrapperClasses = cx([`${prefix}--icon-tooltip`, `${prefix}--slider__thumb-wrapper`, {
1025
- [`${prefix}--slider__thumb-wrapper--lower`]: twoHandles
1026
- }]);
1027
- const upperThumbWrapperClasses = cx([`${prefix}--icon-tooltip`, `${prefix}--slider__thumb-wrapper`, {
1028
- [`${prefix}--slider__thumb-wrapper--upper`]: twoHandles
1029
- }]);
1030
- const lowerThumbWrapperProps = {
1031
- style: {
1032
- insetInlineStart: `${state.left}%`
1033
- }
1034
- };
1035
- const upperThumbWrapperProps = {
1036
- style: {
1037
- insetInlineStart: `${state.leftUpper}%`
1038
- }
1039
- };
1040
- return /*#__PURE__*/React.createElement("div", {
1041
- className: cx(`${prefix}--form-item`, className)
1042
- }, /*#__PURE__*/React.createElement(Text, {
1043
- as: "label",
1044
- htmlFor: twoHandles ? undefined : id,
1045
- className: labelClasses,
1046
- id: labelId
1047
- }, labelText), /*#__PURE__*/React.createElement("div", {
1048
- className: containerClasses
1049
- }, twoHandles ? /*#__PURE__*/React.createElement("div", {
1050
- className: lowerInputWrapperClasses
1051
- }, /*#__PURE__*/React.createElement("input", {
1052
- type: hideTextInput ? 'hidden' : inputType,
1053
- id: `${id}-lower-input-for-slider`,
1054
- name: name,
1055
- className: lowerInputClasses,
1056
- value: value,
1057
- "aria-label": ariaLabelInput,
1058
- disabled: disabled,
1059
- required: required,
1060
- min: min,
1061
- max: max,
1062
- step: step,
1063
- onChange: onChangeInput,
1064
- onBlur: onBlurInput,
1065
- onKeyUp: props.onInputKeyUp,
1066
- onKeyDown: onInputKeyDown,
1067
- "data-invalid": normalizedProps.invalid ? true : null,
1068
- "data-handle-position": HandlePosition.LOWER,
1069
- "aria-invalid": normalizedProps.invalid ? true : undefined,
1070
- readOnly: readOnly
1071
- }), normalizedProps.invalid && /*#__PURE__*/React.createElement(WarningFilled, {
1072
- className: `${prefix}--slider__invalid-icon`
1073
- }), showWarning && /*#__PURE__*/React.createElement(WarningAltFilled, {
1074
- className: `${prefix}--slider__invalid-icon ${prefix}--slider__invalid-icon--warning`
1075
- })) : null, /*#__PURE__*/React.createElement(Text, {
1076
- className: `${prefix}--slider__range-label`
1077
- }, formatLabel(min, minLabel)), /*#__PURE__*/React.createElement("div", _extends({
1078
- className: sliderClasses,
1079
- ref: node => {
1080
- elementRef.current = node;
1081
- },
1082
- onMouseDown: onDragStart,
1083
- onTouchStart: onDragStart,
1084
- onKeyDown: onKeyDown,
1085
- role: "presentation",
1086
- tabIndex: -1,
1087
- "data-invalid": (twoHandles ? normalizedProps.invalid || normalizedUpperProps.invalid : normalizedProps.invalid) ? true : null
1088
- }, other), /*#__PURE__*/React.createElement(ThumbWrapper, _extends({
1089
- hasTooltip: hideTextInput,
1090
- className: lowerThumbWrapperClasses,
1091
- label: formatLabel(value, undefined),
1092
- align: "top"
1093
- }, lowerThumbWrapperProps), /*#__PURE__*/React.createElement("div", {
1094
- className: lowerThumbClasses,
1095
- role: "slider",
1096
- id: twoHandles ? undefined : id,
1097
- tabIndex: readOnly || disabled ? undefined : 0,
1098
- "aria-valuetext": formatLabel(value, undefined),
1099
- "aria-valuemax": twoHandles ? valueUpper : max,
1100
- "aria-valuemin": min,
1101
- "aria-valuenow": value,
1102
- "aria-labelledby": twoHandles ? undefined : labelId,
1103
- "aria-label": twoHandles ? ariaLabelInput : undefined,
1104
- ref: thumbRef,
1105
- onFocus: () => setState({
1106
- activeHandle: HandlePosition.LOWER
1107
- })
1108
- }, twoHandles && !isRtl ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LowerHandle, {
1109
- "aria-label": ariaLabelInput
1110
- }), /*#__PURE__*/React.createElement(LowerHandleFocus, {
1111
- "aria-label": ariaLabelInput
1112
- })) : twoHandles && isRtl ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UpperHandle, {
1113
- "aria-label": ariaLabelInputUpper
1114
- }), /*#__PURE__*/React.createElement(UpperHandleFocus, {
1115
- "aria-label": ariaLabelInputUpper
1116
- })) : undefined)), hasUpperValue(valueUpper) ? /*#__PURE__*/React.createElement(ThumbWrapper, _extends({
1117
- hasTooltip: hideTextInput,
1118
- className: upperThumbWrapperClasses,
1119
- label: formatLabel(valueUpper, undefined),
1120
- align: "top"
1121
- }, upperThumbWrapperProps), /*#__PURE__*/React.createElement("div", {
1122
- className: upperThumbClasses,
1123
- role: "slider",
1124
- tabIndex: readOnly || disabled ? undefined : 0,
1125
- "aria-valuemax": max,
1126
- "aria-valuemin": value,
1127
- "aria-valuenow": valueUpper,
1128
- "aria-label": ariaLabelInputUpper,
1129
- ref: thumbRefUpper,
1130
- onFocus: () => setState({
1131
- activeHandle: HandlePosition.UPPER
1132
- })
1133
- }, !isRtl ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UpperHandle, {
1134
- "aria-label": ariaLabelInputUpper
1135
- }), /*#__PURE__*/React.createElement(UpperHandleFocus, {
1136
- "aria-label": ariaLabelInputUpper
1137
- })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LowerHandle, {
1138
- "aria-label": ariaLabelInput
1139
- }), /*#__PURE__*/React.createElement(LowerHandleFocus, {
1140
- "aria-label": ariaLabelInput
1141
- })))) : null, /*#__PURE__*/React.createElement("div", {
1142
- className: `${prefix}--slider__track`,
1143
- ref: node => {
1144
- trackRef.current = node;
1145
- }
1146
- }), /*#__PURE__*/React.createElement("div", {
1147
- className: `${prefix}--slider__filled-track`,
1148
- ref: filledTrackRef
1149
- })), /*#__PURE__*/React.createElement(Text, {
1150
- className: `${prefix}--slider__range-label`
1151
- }, formatLabel(max, maxLabel)), /*#__PURE__*/React.createElement("div", {
1152
- className: upperInputWrapperClasses
1153
- }, /*#__PURE__*/React.createElement("input", {
1154
- type: hideTextInput ? 'hidden' : inputType,
1155
- id: `${id}-${twoHandles ? 'upper-' : ''}input-for-slider`,
1156
- name: twoHandles ? nameUpper : name,
1157
- className: upperInputClasses,
1158
- value: twoHandles ? valueUpper : value,
1159
- "aria-labelledby": !ariaLabelInput && !twoHandles ? labelId : undefined,
1160
- "aria-label": twoHandles ? ariaLabelInputUpper : ariaLabelInput ? ariaLabelInput : undefined,
1161
- disabled: disabled,
1162
- required: required,
1163
- min: min,
1164
- max: max,
1165
- step: step,
1166
- onChange: onChangeInput,
1167
- onBlur: onBlurInput,
1168
- onKeyDown: onInputKeyDown,
1169
- onKeyUp: props.onInputKeyUp,
1170
- "data-invalid": (twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid) ? true : null,
1171
- "data-handle-position": twoHandles ? HandlePosition.UPPER : null,
1172
- "aria-invalid": (twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid) ? true : undefined,
1173
- readOnly: readOnly
1174
- }), (twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid) && /*#__PURE__*/React.createElement(WarningFilled, {
1175
- className: `${prefix}--slider__invalid-icon`
1176
- }), showWarningUpper && /*#__PURE__*/React.createElement(WarningAltFilled, {
1177
- className: `${prefix}--slider__invalid-icon ${prefix}--slider__invalid-icon--warning`
1178
- }))), (normalizedProps.invalid || normalizedUpperProps.invalid) && /*#__PURE__*/React.createElement(Text, {
1179
- as: "div",
1180
- className: cx(`${prefix}--slider__validation-msg`, `${prefix}--slider__validation-msg--invalid`, `${prefix}--form-requirement`)
1181
- }, invalidText), (normalizedProps.warn || normalizedUpperProps.warn) && /*#__PURE__*/React.createElement(Text, {
1182
- as: "div",
1183
- className: cx(`${prefix}--slider__validation-msg`, `${prefix}--form-requirement`)
1184
- }, warnText), correctedValue && /*#__PURE__*/React.createElement(Text, {
1185
- as: "div",
1186
- role: "alert",
1187
- className: cx(`${prefix}--slider__status-msg`, `${prefix}--form-requirement`)
1188
- }, t(translationIds['carbon.slider.auto-correct-announcement'], {
1189
- correctedValue
1190
- })));
60
+ const DRAG_EVENT_TYPES = new Set(["mousemove", "touchmove"]);
61
+ const DRAG_STOP_EVENT_TYPES = new Set([
62
+ "mouseup",
63
+ "touchend",
64
+ "touchcancel"
65
+ ]);
66
+ var HandlePosition = /* @__PURE__ */ function(HandlePosition) {
67
+ HandlePosition["LOWER"] = "lower";
68
+ HandlePosition["UPPER"] = "upper";
69
+ return HandlePosition;
70
+ }(HandlePosition || {});
71
+ const Slider = (props) => {
72
+ const [state, setState] = useReducer((prev, args) => ({
73
+ ...prev,
74
+ ...args
75
+ }), {
76
+ value: props.value,
77
+ valueUpper: props.unstable_valueUpper,
78
+ left: 0,
79
+ leftUpper: 0,
80
+ needsOnRelease: false,
81
+ isValid: true,
82
+ isValidUpper: true,
83
+ activeHandle: void 0,
84
+ correctedValue: null,
85
+ correctedPosition: null,
86
+ isRtl: false
87
+ });
88
+ const stateRef = useRef(state);
89
+ useEffect(() => {
90
+ stateRef.current = state;
91
+ }, [state]);
92
+ const propsRef = useRef(props);
93
+ useEffect(() => {
94
+ propsRef.current = props;
95
+ }, [props]);
96
+ const thumbRef = useRef(null);
97
+ const thumbRefUpper = useRef(null);
98
+ const filledTrackRef = useRef(null);
99
+ const elementRef = useRef(null);
100
+ const trackRef = useRef(null);
101
+ const generatedId = useId();
102
+ const prefix = usePrefix();
103
+ const twoHandles = hasUpperValue(state.valueUpper);
104
+ /**
105
+ * Sets up initial slider position and value in response to component mount.
106
+ */
107
+ useEffect(() => {
108
+ if (elementRef.current) {
109
+ const isRtl = document?.dir === "rtl";
110
+ if (twoHandles) {
111
+ const { value, left } = calcValue({
112
+ value: stateRef.current.value,
113
+ useRawValue: true
114
+ });
115
+ const { value: valueUpper, left: leftUpper } = calcValue({
116
+ value: stateRef.current.valueUpper,
117
+ useRawValue: true
118
+ });
119
+ setState({
120
+ isRtl,
121
+ value,
122
+ left,
123
+ valueUpper,
124
+ leftUpper
125
+ });
126
+ } else {
127
+ const { value, left } = calcValue({
128
+ value: stateRef.current.value,
129
+ useRawValue: true
130
+ });
131
+ setState({
132
+ isRtl,
133
+ value,
134
+ left
135
+ });
136
+ }
137
+ }
138
+ return () => {
139
+ DRAG_STOP_EVENT_TYPES.forEach((element) => elementRef.current?.ownerDocument.removeEventListener(element, onDragStop));
140
+ DRAG_EVENT_TYPES.forEach((element) => elementRef.current?.ownerDocument.removeEventListener(element, handleDrag));
141
+ };
142
+ }, []);
143
+ useEffect(() => {
144
+ if (twoHandles) {
145
+ if (filledTrackRef.current) filledTrackRef.current.style.transform = state.isRtl ? `translate(${100 - state.leftUpper}%, -50%) scaleX(${(state.leftUpper - state.left) / 100})` : `translate(${state.left}%, -50%) scaleX(${(state.leftUpper - state.left) / 100})`;
146
+ } else if (filledTrackRef.current) filledTrackRef.current.style.transform = state.isRtl ? `translate(100%, -50%) scaleX(-${state.left / 100})` : `translate(0%, -50%) scaleX(${state.left / 100})`;
147
+ }, [
148
+ state.left,
149
+ state.leftUpper,
150
+ state.isRtl
151
+ ]);
152
+ const prevValsRef = useRef(null);
153
+ useEffect(() => {
154
+ const prev = prevValsRef.current;
155
+ if (prev && (prev.value !== state.value || prev.valueUpper !== state.valueUpper) && typeof props.onChange === "function") props.onChange({
156
+ value: state.value,
157
+ valueUpper: state.valueUpper
158
+ });
159
+ prevValsRef.current = {
160
+ value: state.value,
161
+ valueUpper: state.valueUpper
162
+ };
163
+ }, [
164
+ state.value,
165
+ state.valueUpper,
166
+ props.onChange
167
+ ]);
168
+ useEffect(() => {
169
+ if (state.needsOnRelease && typeof props.onRelease === "function") {
170
+ props.onRelease({
171
+ value: state.value,
172
+ valueUpper: state.valueUpper
173
+ });
174
+ setState({ needsOnRelease: false });
175
+ }
176
+ }, [
177
+ state.needsOnRelease,
178
+ state.value,
179
+ state.valueUpper,
180
+ props.onRelease
181
+ ]);
182
+ const prevSyncKeysRef = useRef(null);
183
+ useEffect(() => {
184
+ const prev = prevSyncKeysRef.current;
185
+ const next = [
186
+ props.value,
187
+ props.unstable_valueUpper,
188
+ props.max,
189
+ props.min
190
+ ];
191
+ if (!prev || prev[0] !== next[0] || prev[1] !== next[1] || prev[2] !== next[2] || prev[3] !== next[3]) {
192
+ setState(calcValue({
193
+ value: props.value,
194
+ useRawValue: true
195
+ }));
196
+ if (typeof props.unstable_valueUpper !== "undefined") {
197
+ const { value: valueUpper, left: leftUpper } = calcValue({
198
+ value: props.unstable_valueUpper,
199
+ useRawValue: true
200
+ });
201
+ setState({
202
+ valueUpper,
203
+ leftUpper
204
+ });
205
+ } else setState({
206
+ valueUpper: void 0,
207
+ leftUpper: void 0
208
+ });
209
+ prevSyncKeysRef.current = next;
210
+ }
211
+ }, [
212
+ props.value,
213
+ props.unstable_valueUpper,
214
+ props.max,
215
+ props.min
216
+ ]);
217
+ /**
218
+ * Rounds a given value to the nearest step defined by the slider's `step`
219
+ * prop.
220
+ *
221
+ * @param value - The value to adjust to the nearest step. Defaults to `0`.
222
+ * @returns The value rounded to the precision determined by the step.
223
+ */
224
+ const nearestStepValue = (value = 0) => {
225
+ const decimals = (props.step?.toString().split(".")[1] ?? "").length;
226
+ return Number(value.toFixed(decimals));
227
+ };
228
+ const handleDrag = (event) => {
229
+ if (event instanceof globalThis.MouseEvent || event instanceof globalThis.TouchEvent) onDrag(event);
230
+ };
231
+ /**
232
+ * Sets up "drag" event handlers and calls `onDrag` in case dragging
233
+ * started on somewhere other than the thumb without a corresponding "move"
234
+ * event.
235
+ */
236
+ const onDragStart = (evt) => {
237
+ if (props.disabled || props.readOnly) return;
238
+ evt.preventDefault();
239
+ DRAG_STOP_EVENT_TYPES.forEach((element) => {
240
+ elementRef.current?.ownerDocument.addEventListener(element, onDragStop);
241
+ });
242
+ DRAG_EVENT_TYPES.forEach((element) => {
243
+ elementRef.current?.ownerDocument.addEventListener(element, handleDrag);
244
+ });
245
+ const clientX = getClientXFromEvent(evt.nativeEvent);
246
+ let activeHandle;
247
+ if (twoHandles) {
248
+ if (evt.target == thumbRef.current) activeHandle = HandlePosition.LOWER;
249
+ else if (evt.target == thumbRefUpper.current) activeHandle = HandlePosition.UPPER;
250
+ else if (clientX) if (calcDistanceToHandle(HandlePosition.LOWER, clientX) <= calcDistanceToHandle(HandlePosition.UPPER, clientX)) activeHandle = HandlePosition.LOWER;
251
+ else activeHandle = HandlePosition.UPPER;
252
+ }
253
+ const focusOptions = { preventScroll: true };
254
+ if (twoHandles) {
255
+ if (thumbRef.current && activeHandle === HandlePosition.LOWER) thumbRef.current.focus(focusOptions);
256
+ else if (thumbRefUpper.current && activeHandle === HandlePosition.UPPER) thumbRefUpper.current.focus(focusOptions);
257
+ } else if (thumbRef.current) thumbRef.current.focus(focusOptions);
258
+ setState({ activeHandle });
259
+ onDrag(evt.nativeEvent, activeHandle);
260
+ };
261
+ /**
262
+ * Removes "drag" and "drag stop" event handlers and calls sets the flag
263
+ * indicating that the `onRelease` callback should be called.
264
+ */
265
+ const onDragStop = () => {
266
+ if (props.disabled || props.readOnly) return;
267
+ DRAG_STOP_EVENT_TYPES.forEach((element) => {
268
+ elementRef.current?.ownerDocument.removeEventListener(element, onDragStop);
269
+ });
270
+ DRAG_EVENT_TYPES.forEach((element) => {
271
+ elementRef.current?.ownerDocument.removeEventListener(element, handleDrag);
272
+ });
273
+ setState({
274
+ needsOnRelease: true,
275
+ isValid: true,
276
+ isValidUpper: true
277
+ });
278
+ };
279
+ /**
280
+ * Handles a "drag" event by recalculating the value/thumb and setting state
281
+ * accordingly.
282
+ *
283
+ * @param evt The event.
284
+ * @param activeHandle The first drag event call, we may have an explicit
285
+ * activeHandle value, which is to be used before state is used.
286
+ */
287
+ const _onDragRef = useRef(null);
288
+ _onDragRef.current = (evt, activeHandle) => {
289
+ activeHandle = activeHandle ?? stateRef.current.activeHandle;
290
+ if (propsRef.current.disabled || propsRef.current.readOnly || !evt) return;
291
+ const { value, left } = calcValue({
292
+ clientX: getClientXFromEvent(evt),
293
+ value: stateRef.current.value
294
+ });
295
+ if (twoHandles && activeHandle) setValueLeftForHandle(activeHandle, {
296
+ value: nearestStepValue(value),
297
+ left
298
+ });
299
+ else setState({
300
+ value: nearestStepValue(value),
301
+ left,
302
+ isValid: true
303
+ });
304
+ setState({
305
+ correctedValue: null,
306
+ correctedPosition: null
307
+ });
308
+ };
309
+ /**
310
+ * Throttles calls to `_onDrag` by limiting events to being processed at
311
+ * most once every `EVENT_THROTTLE` milliseconds.
312
+ */
313
+ const onDrag = useMemo(() => throttle((evt, activeHandle) => {
314
+ _onDragRef.current?.(evt, activeHandle);
315
+ }, EVENT_THROTTLE, {
316
+ leading: true,
317
+ trailing: false
318
+ }), []);
319
+ /**
320
+ * Handles a `keydown` event by recalculating the value/thumb and setting
321
+ * state accordingly.
322
+ */
323
+ const onKeyDown = (evt) => {
324
+ if (props.disabled || props.readOnly) return;
325
+ const { step = 1, stepMultiplier = 4 } = props;
326
+ let delta = 0;
327
+ if (matches(evt, [ArrowDown, ArrowLeft])) delta = -step;
328
+ else if (matches(evt, [ArrowUp$1, ArrowRight$1])) delta = step;
329
+ else return;
330
+ if (evt.shiftKey) delta *= stepMultiplier;
331
+ if (twoHandles && state.activeHandle) {
332
+ const { value, left } = calcValue({ value: calcValueForDelta((state.activeHandle === HandlePosition.LOWER ? state.value : state.valueUpper) ?? props.min, delta, props.step) });
333
+ setValueLeftForHandle(state.activeHandle, {
334
+ value: nearestStepValue(value),
335
+ left
336
+ });
337
+ } else {
338
+ const { value, left } = calcValue({ value: calcValueForDelta(state.value, delta, props.step) });
339
+ setState({
340
+ value: nearestStepValue(value),
341
+ left,
342
+ isValid: true
343
+ });
344
+ }
345
+ setState({
346
+ correctedValue: null,
347
+ correctedPosition: null
348
+ });
349
+ };
350
+ /**
351
+ * Provides the two-way binding for the input field of the Slider. It also
352
+ * Handles a change to the input field by recalculating the value/thumb and
353
+ * setting state accordingly.
354
+ */
355
+ const onChangeInput = (evt) => {
356
+ if (props.disabled || props.readOnly) return;
357
+ if (!evt || !("target" in evt) || typeof evt.target.value !== "string") return;
358
+ const activeHandle = evt.target.dataset.handlePosition ?? HandlePosition.LOWER;
359
+ const targetValue = Number.parseFloat(evt.target.value);
360
+ if (twoHandles) if (isNaN(targetValue)) setValueForHandle(activeHandle, evt.target.value);
361
+ else if (isValidValueForPosition({
362
+ handle: activeHandle,
363
+ value: targetValue,
364
+ min: props.min,
365
+ max: props.max
366
+ })) processNewInputValue(evt.target);
367
+ else setValueForHandle(activeHandle, targetValue);
368
+ else if (isNaN(targetValue)) setState({ value: evt.target.value });
369
+ else if (isValidValue({
370
+ value: targetValue,
371
+ min: props.min,
372
+ max: props.max
373
+ })) processNewInputValue(evt.target);
374
+ else setState({ value: targetValue });
375
+ };
376
+ /**
377
+ * Checks for validity of input value after clicking out of the input. It also
378
+ * Handles state change to isValid state.
379
+ */
380
+ const onBlurInput = (evt) => {
381
+ if (!evt || !("target" in evt) || typeof evt.target.value !== "string") return;
382
+ const { value: targetValue } = evt.target;
383
+ processNewInputValue(evt.target);
384
+ props.onBlur?.({
385
+ value: targetValue,
386
+ handlePosition: evt.target.dataset.handlePosition
387
+ });
388
+ };
389
+ const onInputKeyDown = (evt) => {
390
+ if (props.disabled || props.readOnly || !(evt.target instanceof HTMLInputElement)) return;
391
+ if (!evt || !("target" in evt) || typeof evt.target.value !== "string") return;
392
+ if (matches(evt, [Enter])) processNewInputValue(evt.target);
393
+ };
394
+ const processNewInputValue = (input) => {
395
+ setState({
396
+ correctedValue: null,
397
+ correctedPosition: null
398
+ });
399
+ const targetValue = Number.parseFloat(input.value);
400
+ const validity = !isNaN(targetValue);
401
+ const handlePosition = input.dataset.handlePosition;
402
+ if (handlePosition === HandlePosition.LOWER) setState({ isValid: validity });
403
+ else if (handlePosition === HandlePosition.UPPER) setState({ isValidUpper: validity });
404
+ setState({ isValid: validity });
405
+ if (validity) {
406
+ const adjustedValue = handlePosition ? getAdjustedValueForPosition({
407
+ handle: handlePosition,
408
+ value: targetValue,
409
+ min: props.min,
410
+ max: props.max
411
+ }) : getAdjustedValue({
412
+ value: targetValue,
413
+ min: props.min,
414
+ max: props.max
415
+ });
416
+ if (adjustedValue !== targetValue) setState({
417
+ correctedValue: targetValue.toString(),
418
+ correctedPosition: handlePosition ?? null
419
+ });
420
+ else setState({
421
+ correctedValue: null,
422
+ correctedPosition: null
423
+ });
424
+ const { value, left } = calcValue({
425
+ value: adjustedValue,
426
+ useRawValue: true
427
+ });
428
+ if (handlePosition) setValueLeftForHandle(handlePosition, {
429
+ value: nearestStepValue(value),
430
+ left
431
+ });
432
+ else setState({
433
+ value,
434
+ left
435
+ });
436
+ }
437
+ };
438
+ const calcLeftPercent = ({ clientX, value, range }) => {
439
+ const boundingRect = elementRef.current?.getBoundingClientRect?.();
440
+ let width = boundingRect ? boundingRect.right - boundingRect.left : 0;
441
+ if (width <= 0) width = 1;
442
+ if (clientX) return (state.isRtl ? (boundingRect?.right ?? 0) - clientX : clientX - (boundingRect?.left ?? 0)) / width;
443
+ else if (value !== null && typeof value !== "undefined" && range) return range === 0 ? 0 : (value - props.min) / range;
444
+ return 0;
445
+ };
446
+ /**
447
+ * Calculates the discrete value (snapped to the nearest step) along
448
+ * with the corresponding handle position percentage.
449
+ */
450
+ const calcDiscreteValueAndPercent = ({ leftPercent }) => {
451
+ const { step = 1, min, max } = props;
452
+ const numSteps = Math.floor((max - min) / step) + 1;
453
+ /** Index of the step that corresponds to `leftPercent`. */
454
+ const stepIndex = Math.round(leftPercent * (numSteps - 1));
455
+ return {
456
+ discreteValue: stepIndex === numSteps - 1 ? max : min + step * stepIndex,
457
+ discretePercent: stepIndex / (numSteps - 1)
458
+ };
459
+ };
460
+ /**
461
+ * Calculates the slider's value and handle position based on either a
462
+ * mouse/touch event or an explicit value.
463
+ */
464
+ const calcValue = ({ clientX, value, useRawValue }) => {
465
+ /** `leftPercentRaw` clamped between 0 and 1. */
466
+ const leftPercent = clamp(calcLeftPercent({
467
+ clientX,
468
+ value,
469
+ range: props.max - props.min
470
+ }), 0, 1);
471
+ if (useRawValue) return {
472
+ value,
473
+ left: leftPercent * 100
474
+ };
475
+ const { discreteValue, discretePercent } = calcDiscreteValueAndPercent({ leftPercent });
476
+ return {
477
+ value: discreteValue,
478
+ left: discretePercent * 100
479
+ };
480
+ };
481
+ const calcDistanceToHandle = (handle, clientX) => {
482
+ const handleBoundingRect = getHandleBoundingRect(handle);
483
+ /** x-coordinate of the midpoint. */
484
+ const handleX = handleBoundingRect.left + handleBoundingRect.width / 2;
485
+ return Math.abs(handleX - clientX);
486
+ };
487
+ /**
488
+ * Calculates a new slider value based on the current value, a change delta,
489
+ * and a step.
490
+ *
491
+ * @param currentValue - The starting value from which the slider is moving.
492
+ * @param delta - The amount to adjust the current value by.
493
+ * @param step - The step. Defaults to `1`.
494
+ * @returns The new slider value, rounded to the same number of decimal places
495
+ * as the step.
496
+ */
497
+ const calcValueForDelta = (currentValue, delta, step = 1) => {
498
+ const newValue = (delta > 0 ? Math.round(currentValue / step) * step : currentValue) + delta;
499
+ const decimals = (step.toString().split(".")[1] || "").length;
500
+ return Number(newValue.toFixed(decimals));
501
+ };
502
+ /**
503
+ * Sets state relevant to the given handle position.
504
+ *
505
+ * Guards against setting either lower or upper values beyond its counterpart.
506
+ */
507
+ const setValueLeftForHandle = (handle, { value: newValue, left: newLeft }) => {
508
+ const { value, valueUpper, left, leftUpper } = state;
509
+ if (handle === HandlePosition.LOWER) setState({
510
+ value: valueUpper && newValue > valueUpper ? valueUpper : newValue,
511
+ left: valueUpper && newValue > valueUpper ? leftUpper : newLeft,
512
+ isValid: true
513
+ });
514
+ else setState({
515
+ valueUpper: value && newValue < value ? value : newValue,
516
+ leftUpper: value && newValue < value ? left : newLeft,
517
+ isValidUpper: true
518
+ });
519
+ };
520
+ const setValueForHandle = (handle, value) => {
521
+ if (handle === HandlePosition.LOWER) setState({
522
+ value,
523
+ isValid: true
524
+ });
525
+ else setState({
526
+ valueUpper: value,
527
+ isValidUpper: true
528
+ });
529
+ };
530
+ const isValidValueForPosition = ({ handle, value: newValue, min, max }) => {
531
+ const { value, valueUpper } = state;
532
+ if (!isValidValue({
533
+ value: newValue,
534
+ min,
535
+ max
536
+ })) return false;
537
+ if (handle === HandlePosition.LOWER) return !valueUpper || newValue <= valueUpper;
538
+ else if (handle === HandlePosition.UPPER) return !value || newValue >= value;
539
+ return false;
540
+ };
541
+ const isValidValue = ({ value, min, max }) => {
542
+ return !(value < min || value > max);
543
+ };
544
+ const getAdjustedValueForPosition = ({ handle, value: newValueInput, min, max }) => {
545
+ const { value, valueUpper } = state;
546
+ let newValue = getAdjustedValue({
547
+ value: newValueInput,
548
+ min,
549
+ max
550
+ });
551
+ if (handle === HandlePosition.LOWER && valueUpper) newValue = newValue > valueUpper ? valueUpper : newValue;
552
+ else if (handle === HandlePosition.UPPER && value) newValue = newValue < value ? value : newValue;
553
+ return newValue;
554
+ };
555
+ const getAdjustedValue = ({ value, min, max }) => {
556
+ if (value < min) value = min;
557
+ if (value > max) value = max;
558
+ return value;
559
+ };
560
+ /**
561
+ * Get the bounding rect for the requested handles' DOM element.
562
+ *
563
+ * If the bounding rect is not available, a new, empty DOMRect is returned.
564
+ */
565
+ const getHandleBoundingRect = (handle) => {
566
+ let boundingRect;
567
+ if (handle === HandlePosition.LOWER) boundingRect = thumbRef.current?.getBoundingClientRect();
568
+ else boundingRect = thumbRefUpper.current?.getBoundingClientRect();
569
+ return boundingRect ?? new DOMRect();
570
+ };
571
+ const getClientXFromEvent = (event) => {
572
+ let clientX;
573
+ if ("clientX" in event) clientX = event.clientX;
574
+ else if ("touches" in event && 0 in event.touches && "clientX" in event.touches[0]) clientX = event.touches[0].clientX;
575
+ return clientX;
576
+ };
577
+ useEffect(() => {
578
+ const { isValid, isValidUpper } = stateRef.current;
579
+ const derivedState = {};
580
+ if (props.invalid === true) {
581
+ if (isValid === true) derivedState.isValid = false;
582
+ if (isValidUpper === true) derivedState.isValidUpper = false;
583
+ } else if (props.invalid === false) {
584
+ if (isValid === false) derivedState.isValid = true;
585
+ if (isValidUpper === false) derivedState.isValidUpper = true;
586
+ }
587
+ if (Object.keys(derivedState).length) setState(derivedState);
588
+ }, [props.invalid]);
589
+ const { ariaLabelInput, unstable_ariaLabelInputUpper: ariaLabelInputUpper, className, hideTextInput = false, id: idProp, min, minLabel, max, maxLabel, formatLabel = defaultFormatLabel, labelText, hideLabel, step = 1, inputType = "number", invalidText, required, disabled = false, name, unstable_nameUpper: nameUpper, light, readOnly = false, warn = false, warnText, translateWithId: t = defaultTranslateWithId, ...other } = props;
590
+ const id = idProp ?? generatedId;
591
+ const { value, valueUpper, isValid, isValidUpper, correctedValue, correctedPosition, isRtl } = state;
592
+ const normalizedProps = useNormalizedInputProps({
593
+ id,
594
+ disabled,
595
+ readOnly,
596
+ invalid: !isValid,
597
+ warn
598
+ });
599
+ const normalizedUpperProps = useNormalizedInputProps({
600
+ id,
601
+ disabled,
602
+ readOnly,
603
+ invalid: !isValidUpper,
604
+ warn
605
+ });
606
+ delete other.invalid;
607
+ delete other.onRelease;
608
+ delete other.stepMultiplier;
609
+ delete other.unstable_valueUpper;
610
+ const showWarning = normalizedProps.warn || correctedPosition === HandlePosition.LOWER && isValid;
611
+ const showWarningUpper = normalizedUpperProps.warn || correctedPosition === (twoHandles ? HandlePosition.UPPER : HandlePosition.LOWER) && (twoHandles ? isValidUpper : isValid);
612
+ const labelId = `${id}-label`;
613
+ const labelClasses = classNames(`${prefix}--label`, {
614
+ [`${prefix}--visually-hidden`]: hideLabel,
615
+ [`${prefix}--label--disabled`]: disabled
616
+ });
617
+ const containerClasses = classNames(`${prefix}--slider-container`, {
618
+ [`${prefix}--slider-container--two-handles`]: twoHandles,
619
+ [`${prefix}--slider-container--disabled`]: disabled,
620
+ [`${prefix}--slider-container--readonly`]: readOnly,
621
+ [`${prefix}--slider-container--rtl`]: isRtl
622
+ });
623
+ const sliderClasses = classNames(`${prefix}--slider`, {
624
+ [`${prefix}--slider--disabled`]: disabled,
625
+ [`${prefix}--slider--readonly`]: readOnly
626
+ });
627
+ const fixedInputClasses = [`${prefix}--text-input`, `${prefix}--slider-text-input`];
628
+ const conditionalInputClasses = { [`${prefix}--text-input--light`]: light };
629
+ const lowerInputClasses = classNames([
630
+ ...fixedInputClasses,
631
+ `${prefix}--slider-text-input--lower`,
632
+ conditionalInputClasses,
633
+ {
634
+ [`${prefix}--text-input--invalid`]: normalizedProps.invalid,
635
+ [`${prefix}--slider-text-input--warn`]: showWarning
636
+ }
637
+ ]);
638
+ const upperInputClasses = classNames([
639
+ ...fixedInputClasses,
640
+ `${prefix}--slider-text-input--upper`,
641
+ conditionalInputClasses,
642
+ {
643
+ [`${prefix}--text-input--invalid`]: twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid,
644
+ [`${prefix}--slider-text-input--warn`]: showWarningUpper
645
+ }
646
+ ]);
647
+ const lowerInputWrapperClasses = classNames([
648
+ `${prefix}--text-input-wrapper`,
649
+ `${prefix}--slider-text-input-wrapper`,
650
+ `${prefix}--slider-text-input-wrapper--lower`,
651
+ {
652
+ [`${prefix}--text-input-wrapper--readonly`]: readOnly,
653
+ [`${prefix}--slider-text-input-wrapper--hidden`]: hideTextInput
654
+ }
655
+ ]);
656
+ const upperInputWrapperClasses = classNames([
657
+ `${prefix}--text-input-wrapper`,
658
+ `${prefix}--slider-text-input-wrapper`,
659
+ `${prefix}--slider-text-input-wrapper--upper`,
660
+ {
661
+ [`${prefix}--text-input-wrapper--readonly`]: readOnly,
662
+ [`${prefix}--slider-text-input-wrapper--hidden`]: hideTextInput
663
+ }
664
+ ]);
665
+ const lowerThumbClasses = classNames(`${prefix}--slider__thumb`, { [`${prefix}--slider__thumb--lower`]: twoHandles });
666
+ const upperThumbClasses = classNames(`${prefix}--slider__thumb`, { [`${prefix}--slider__thumb--upper`]: twoHandles });
667
+ const lowerThumbWrapperClasses = classNames([
668
+ `${prefix}--icon-tooltip`,
669
+ `${prefix}--slider__thumb-wrapper`,
670
+ { [`${prefix}--slider__thumb-wrapper--lower`]: twoHandles }
671
+ ]);
672
+ const upperThumbWrapperClasses = classNames([
673
+ `${prefix}--icon-tooltip`,
674
+ `${prefix}--slider__thumb-wrapper`,
675
+ { [`${prefix}--slider__thumb-wrapper--upper`]: twoHandles }
676
+ ]);
677
+ const lowerThumbWrapperProps = { style: { insetInlineStart: `${state.left}%` } };
678
+ const upperThumbWrapperProps = { style: { insetInlineStart: `${state.leftUpper}%` } };
679
+ return /* @__PURE__ */ jsxs("div", {
680
+ className: classNames(`${prefix}--form-item`, className),
681
+ children: [
682
+ /* @__PURE__ */ jsx(Text, {
683
+ as: "label",
684
+ htmlFor: twoHandles ? void 0 : id,
685
+ className: labelClasses,
686
+ id: labelId,
687
+ children: labelText
688
+ }),
689
+ /* @__PURE__ */ jsxs("div", {
690
+ className: containerClasses,
691
+ children: [
692
+ twoHandles ? /* @__PURE__ */ jsxs("div", {
693
+ className: lowerInputWrapperClasses,
694
+ children: [
695
+ /* @__PURE__ */ jsx("input", {
696
+ type: hideTextInput ? "hidden" : inputType,
697
+ id: `${id}-lower-input-for-slider`,
698
+ name,
699
+ className: lowerInputClasses,
700
+ value,
701
+ "aria-label": ariaLabelInput,
702
+ disabled,
703
+ required,
704
+ min,
705
+ max,
706
+ step,
707
+ onChange: onChangeInput,
708
+ onBlur: onBlurInput,
709
+ onKeyUp: props.onInputKeyUp,
710
+ onKeyDown: onInputKeyDown,
711
+ "data-invalid": normalizedProps.invalid ? true : null,
712
+ "data-handle-position": HandlePosition.LOWER,
713
+ "aria-invalid": normalizedProps.invalid ? true : void 0,
714
+ readOnly
715
+ }),
716
+ normalizedProps.invalid && /* @__PURE__ */ jsx(WarningFilled, { className: `${prefix}--slider__invalid-icon` }),
717
+ showWarning && /* @__PURE__ */ jsx(WarningAltFilled, { className: `${prefix}--slider__invalid-icon ${prefix}--slider__invalid-icon--warning` })
718
+ ]
719
+ }) : null,
720
+ /* @__PURE__ */ jsx(Text, {
721
+ className: `${prefix}--slider__range-label`,
722
+ children: formatLabel(min, minLabel)
723
+ }),
724
+ /* @__PURE__ */ jsxs("div", {
725
+ className: sliderClasses,
726
+ ref: (node) => {
727
+ elementRef.current = node;
728
+ },
729
+ onMouseDown: onDragStart,
730
+ onTouchStart: onDragStart,
731
+ onKeyDown,
732
+ role: "presentation",
733
+ tabIndex: -1,
734
+ "data-invalid": (twoHandles ? normalizedProps.invalid || normalizedUpperProps.invalid : normalizedProps.invalid) ? true : null,
735
+ ...other,
736
+ children: [
737
+ /* @__PURE__ */ jsx(ThumbWrapper, {
738
+ hasTooltip: hideTextInput,
739
+ className: lowerThumbWrapperClasses,
740
+ label: formatLabel(value, void 0),
741
+ align: "top",
742
+ ...lowerThumbWrapperProps,
743
+ children: /* @__PURE__ */ jsx("div", {
744
+ className: lowerThumbClasses,
745
+ role: "slider",
746
+ id: twoHandles ? void 0 : id,
747
+ tabIndex: readOnly || disabled ? void 0 : 0,
748
+ "aria-valuetext": formatLabel(value, void 0),
749
+ "aria-valuemax": twoHandles ? valueUpper : max,
750
+ "aria-valuemin": min,
751
+ "aria-valuenow": value,
752
+ "aria-labelledby": twoHandles ? void 0 : labelId,
753
+ "aria-label": twoHandles ? ariaLabelInput : void 0,
754
+ ref: thumbRef,
755
+ onFocus: () => setState({ activeHandle: HandlePosition.LOWER }),
756
+ children: twoHandles && !isRtl ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(LowerHandle, { "aria-label": ariaLabelInput }), /* @__PURE__ */ jsx(LowerHandleFocus, { "aria-label": ariaLabelInput })] }) : twoHandles && isRtl ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(UpperHandle, { "aria-label": ariaLabelInputUpper }), /* @__PURE__ */ jsx(UpperHandleFocus, { "aria-label": ariaLabelInputUpper })] }) : void 0
757
+ })
758
+ }),
759
+ hasUpperValue(valueUpper) ? /* @__PURE__ */ jsx(ThumbWrapper, {
760
+ hasTooltip: hideTextInput,
761
+ className: upperThumbWrapperClasses,
762
+ label: formatLabel(valueUpper, void 0),
763
+ align: "top",
764
+ ...upperThumbWrapperProps,
765
+ children: /* @__PURE__ */ jsx("div", {
766
+ className: upperThumbClasses,
767
+ role: "slider",
768
+ tabIndex: readOnly || disabled ? void 0 : 0,
769
+ "aria-valuemax": max,
770
+ "aria-valuemin": value,
771
+ "aria-valuenow": valueUpper,
772
+ "aria-label": ariaLabelInputUpper,
773
+ ref: thumbRefUpper,
774
+ onFocus: () => setState({ activeHandle: HandlePosition.UPPER }),
775
+ children: !isRtl ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(UpperHandle, { "aria-label": ariaLabelInputUpper }), /* @__PURE__ */ jsx(UpperHandleFocus, { "aria-label": ariaLabelInputUpper })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(LowerHandle, { "aria-label": ariaLabelInput }), /* @__PURE__ */ jsx(LowerHandleFocus, { "aria-label": ariaLabelInput })] })
776
+ })
777
+ }) : null,
778
+ /* @__PURE__ */ jsx("div", {
779
+ className: `${prefix}--slider__track`,
780
+ ref: (node) => {
781
+ trackRef.current = node;
782
+ }
783
+ }),
784
+ /* @__PURE__ */ jsx("div", {
785
+ className: `${prefix}--slider__filled-track`,
786
+ ref: filledTrackRef
787
+ })
788
+ ]
789
+ }),
790
+ /* @__PURE__ */ jsx(Text, {
791
+ className: `${prefix}--slider__range-label`,
792
+ children: formatLabel(max, maxLabel)
793
+ }),
794
+ /* @__PURE__ */ jsxs("div", {
795
+ className: upperInputWrapperClasses,
796
+ children: [
797
+ /* @__PURE__ */ jsx("input", {
798
+ type: hideTextInput ? "hidden" : inputType,
799
+ id: `${id}-${twoHandles ? "upper-" : ""}input-for-slider`,
800
+ name: twoHandles ? nameUpper : name,
801
+ className: upperInputClasses,
802
+ value: twoHandles ? valueUpper : value,
803
+ "aria-labelledby": !ariaLabelInput && !twoHandles ? labelId : void 0,
804
+ "aria-label": twoHandles ? ariaLabelInputUpper : ariaLabelInput ? ariaLabelInput : void 0,
805
+ disabled,
806
+ required,
807
+ min,
808
+ max,
809
+ step,
810
+ onChange: onChangeInput,
811
+ onBlur: onBlurInput,
812
+ onKeyDown: onInputKeyDown,
813
+ onKeyUp: props.onInputKeyUp,
814
+ "data-invalid": (twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid) ? true : null,
815
+ "data-handle-position": twoHandles ? HandlePosition.UPPER : null,
816
+ "aria-invalid": (twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid) ? true : void 0,
817
+ readOnly
818
+ }),
819
+ (twoHandles ? normalizedUpperProps.invalid : normalizedProps.invalid) && /* @__PURE__ */ jsx(WarningFilled, { className: `${prefix}--slider__invalid-icon` }),
820
+ showWarningUpper && /* @__PURE__ */ jsx(WarningAltFilled, { className: `${prefix}--slider__invalid-icon ${prefix}--slider__invalid-icon--warning` })
821
+ ]
822
+ })
823
+ ]
824
+ }),
825
+ (normalizedProps.invalid || normalizedUpperProps.invalid) && /* @__PURE__ */ jsx(Text, {
826
+ as: "div",
827
+ className: classNames(`${prefix}--slider__validation-msg`, `${prefix}--slider__validation-msg--invalid`, `${prefix}--form-requirement`),
828
+ children: invalidText
829
+ }),
830
+ (normalizedProps.warn || normalizedUpperProps.warn) && /* @__PURE__ */ jsx(Text, {
831
+ as: "div",
832
+ className: classNames(`${prefix}--slider__validation-msg`, `${prefix}--form-requirement`),
833
+ children: warnText
834
+ }),
835
+ correctedValue && /* @__PURE__ */ jsx(Text, {
836
+ as: "div",
837
+ role: "alert",
838
+ className: classNames(`${prefix}--slider__status-msg`, `${prefix}--form-requirement`),
839
+ children: t(translationIds["carbon.slider.auto-correct-announcement"], { correctedValue })
840
+ })
841
+ ]
842
+ });
1191
843
  };
1192
844
  Slider.propTypes = {
1193
- /**
1194
- * The `ariaLabel` for the `<input>`.
1195
- */
1196
- ariaLabelInput: PropTypes.string,
1197
- /**
1198
- * The child nodes.
1199
- */
1200
- children: PropTypes.node,
1201
- /**
1202
- * The CSS class name for the slider.
1203
- */
1204
- className: PropTypes.string,
1205
- /**
1206
- * `true` to disable this slider.
1207
- */
1208
- disabled: PropTypes.bool,
1209
- /**
1210
- * The callback to format the label associated with the minimum/maximum value.
1211
- */
1212
- formatLabel: PropTypes.func,
1213
- /**
1214
- * `true` to hide the number input box.
1215
- */
1216
- hideTextInput: PropTypes.bool,
1217
- /**
1218
- * The ID of the `<input>`.
1219
- */
1220
- id: PropTypes.string,
1221
- /**
1222
- * The `type` attribute of the `<input>`.
1223
- */
1224
- inputType: PropTypes.string,
1225
- /**
1226
- * `Specify whether the Slider is currently invalid
1227
- */
1228
- invalid: PropTypes.bool,
1229
- /**
1230
- * Provide the text that is displayed when the Slider is in an invalid state
1231
- */
1232
- invalidText: PropTypes.node,
1233
- /**
1234
- * The label for the slider.
1235
- */
1236
- labelText: PropTypes.node,
1237
- /**
1238
- * Specify whether you want the underlying label to be visually hidden
1239
- */
1240
- hideLabel: PropTypes.bool,
1241
- /**
1242
- * `true` to use the light version.
1243
- */
1244
- light: deprecate(PropTypes.bool, 'The `light` prop for `Slider` is no longer needed and has ' + 'been deprecated in v11 in favor of the new `Layer` component. It will be moved in the next major release.'),
1245
- /**
1246
- * The maximum value.
1247
- */
1248
- max: PropTypes.number.isRequired,
1249
- /**
1250
- * The label associated with the maximum value.
1251
- */
1252
- maxLabel: PropTypes.string,
1253
- /**
1254
- * The minimum value.
1255
- */
1256
- min: PropTypes.number.isRequired,
1257
- /**
1258
- * The label associated with the minimum value.
1259
- */
1260
- minLabel: PropTypes.string,
1261
- /**
1262
- * The `name` attribute of the `<input>`.
1263
- */
1264
- name: PropTypes.string,
1265
- /**
1266
- * Provide an optional function to be called when the input element
1267
- * loses focus
1268
- */
1269
- onBlur: PropTypes.func,
1270
- /**
1271
- * The callback to get notified of change in value.
1272
- */
1273
- onChange: PropTypes.func,
1274
- /**
1275
- * Provide an optional function to be called when a key is pressed in the number input.
1276
- */
1277
- onInputKeyUp: PropTypes.func,
1278
- /**
1279
- * The callback to get notified of value on handle release.
1280
- */
1281
- onRelease: PropTypes.func,
1282
- /**
1283
- * Whether the slider should be read-only
1284
- */
1285
- readOnly: PropTypes.bool,
1286
- /**
1287
- * `true` to specify if the control is required.
1288
- */
1289
- required: PropTypes.bool,
1290
- /**
1291
- * A value determining how much the value should increase/decrease by moving the thumb by mouse. If a value other than 1 is provided and the input is *not* hidden, the new step requirement should be added to a visible label. Values outside the `step` increment will be considered invalid.
1292
- */
1293
- step: PropTypes.number,
1294
- /**
1295
- * A value determining how much the value should increase/decrease by Shift+arrow keys,
1296
- * which will be `(max - min) / stepMultiplier`.
1297
- */
1298
- stepMultiplier: PropTypes.number,
1299
- /**
1300
- * Supply a method to translate internal strings with your i18n tool of
1301
- * choice. Translation keys are available on the `translationIds` field for
1302
- * this component.
1303
- */
1304
- translateWithId: PropTypes.func,
1305
- /**
1306
- * The `ariaLabel` for the upper bound `<input>` when there are two handles.
1307
- */
1308
- unstable_ariaLabelInputUpper: PropTypes.string,
1309
- /**
1310
- * The `name` attribute of the upper bound `<input>` when there are two handles.
1311
- */
1312
- unstable_nameUpper: PropTypes.string,
1313
- /**
1314
- * The upper bound when there are two handles.
1315
- */
1316
- unstable_valueUpper: PropTypes.number,
1317
- /**
1318
- * The value of the slider. When there are two handles, value is the lower
1319
- * bound.
1320
- */
1321
- value: PropTypes.number.isRequired,
1322
- /**
1323
- * `Specify whether the Slider is in a warn state
1324
- */
1325
- warn: PropTypes.bool,
1326
- /**
1327
- * Provide the text that is displayed when the Slider is in a warn state
1328
- */
1329
- warnText: PropTypes.node
845
+ ariaLabelInput: PropTypes.string,
846
+ children: PropTypes.node,
847
+ className: PropTypes.string,
848
+ disabled: PropTypes.bool,
849
+ formatLabel: PropTypes.func,
850
+ hideTextInput: PropTypes.bool,
851
+ id: PropTypes.string,
852
+ inputType: PropTypes.string,
853
+ invalid: PropTypes.bool,
854
+ invalidText: PropTypes.node,
855
+ labelText: PropTypes.node,
856
+ hideLabel: PropTypes.bool,
857
+ light: deprecate(PropTypes.bool, "The `light` prop for `Slider` is no longer needed and has been deprecated in v11 in favor of the new `Layer` component. It will be moved in the next major release."),
858
+ max: PropTypes.number.isRequired,
859
+ maxLabel: PropTypes.string,
860
+ min: PropTypes.number.isRequired,
861
+ minLabel: PropTypes.string,
862
+ name: PropTypes.string,
863
+ onBlur: PropTypes.func,
864
+ onChange: PropTypes.func,
865
+ onInputKeyUp: PropTypes.func,
866
+ onRelease: PropTypes.func,
867
+ readOnly: PropTypes.bool,
868
+ required: PropTypes.bool,
869
+ step: PropTypes.number,
870
+ stepMultiplier: PropTypes.number,
871
+ translateWithId: PropTypes.func,
872
+ unstable_ariaLabelInputUpper: PropTypes.string,
873
+ unstable_nameUpper: PropTypes.string,
874
+ unstable_valueUpper: PropTypes.number,
875
+ value: PropTypes.number.isRequired,
876
+ warn: PropTypes.bool,
877
+ warnText: PropTypes.node
1330
878
  };
1331
879
 
1332
- export { Slider as default };
880
+ //#endregion
881
+ export { Slider as default };