@react-md/core 1.0.0-next.16 → 1.0.0-next.18

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 (665) hide show
  1. package/dist/_box-shadows.scss +76 -0
  2. package/dist/_colors.scss +279 -277
  3. package/dist/_core.scss +107 -16
  4. package/dist/_object-fit.scss +86 -0
  5. package/dist/_utils.scss +246 -72
  6. package/dist/app-bar/AppBar.d.ts +1 -90
  7. package/dist/app-bar/AppBar.js +1 -40
  8. package/dist/app-bar/AppBar.js.map +1 -1
  9. package/dist/app-bar/AppBarTitle.d.ts +1 -27
  10. package/dist/app-bar/AppBarTitle.js +1 -15
  11. package/dist/app-bar/AppBarTitle.js.map +1 -1
  12. package/dist/app-bar/_app-bar.scss +156 -25
  13. package/dist/app-bar/styles.d.ts +117 -0
  14. package/dist/app-bar/styles.js +55 -0
  15. package/dist/app-bar/styles.js.map +1 -0
  16. package/dist/autocomplete/Autocomplete.d.ts +8 -79
  17. package/dist/autocomplete/Autocomplete.js +112 -83
  18. package/dist/autocomplete/Autocomplete.js.map +1 -1
  19. package/dist/autocomplete/AutocompleteChip.d.ts +8 -0
  20. package/dist/autocomplete/AutocompleteChip.js +34 -0
  21. package/dist/autocomplete/AutocompleteChip.js.map +1 -0
  22. package/dist/autocomplete/AutocompleteCircularProgress.d.ts +5 -11
  23. package/dist/autocomplete/AutocompleteCircularProgress.js +4 -0
  24. package/dist/autocomplete/AutocompleteCircularProgress.js.map +1 -1
  25. package/dist/autocomplete/AutocompleteClearButton.d.ts +9 -0
  26. package/dist/autocomplete/AutocompleteClearButton.js +29 -0
  27. package/dist/autocomplete/AutocompleteClearButton.js.map +1 -0
  28. package/dist/autocomplete/AutocompleteDropdownButton.d.ts +4 -26
  29. package/dist/autocomplete/AutocompleteDropdownButton.js +5 -1
  30. package/dist/autocomplete/AutocompleteDropdownButton.js.map +1 -1
  31. package/dist/autocomplete/AutocompleteListboxChildren.d.ts +22 -0
  32. package/dist/autocomplete/AutocompleteListboxChildren.js +37 -0
  33. package/dist/autocomplete/AutocompleteListboxChildren.js.map +1 -0
  34. package/dist/autocomplete/_autocomplete.scss +362 -34
  35. package/dist/autocomplete/autocompleteStyles.d.ts +22 -0
  36. package/dist/autocomplete/autocompleteStyles.js +17 -8
  37. package/dist/autocomplete/autocompleteStyles.js.map +1 -1
  38. package/dist/autocomplete/defaults.d.ts +9 -9
  39. package/dist/autocomplete/defaults.js +13 -13
  40. package/dist/autocomplete/defaults.js.map +1 -1
  41. package/dist/autocomplete/types.d.ts +554 -56
  42. package/dist/autocomplete/types.js.map +1 -1
  43. package/dist/autocomplete/useAutocomplete.d.ts +22 -0
  44. package/dist/autocomplete/useAutocomplete.js +281 -0
  45. package/dist/autocomplete/useAutocomplete.js.map +1 -0
  46. package/dist/autocomplete/utils.d.ts +81 -0
  47. package/dist/autocomplete/utils.js +108 -0
  48. package/dist/autocomplete/utils.js.map +1 -0
  49. package/dist/avatar/_avatar.scss +93 -2
  50. package/dist/badge/Badge.d.ts +1 -20
  51. package/dist/badge/Badge.js +1 -14
  52. package/dist/badge/Badge.js.map +1 -1
  53. package/dist/badge/_badge.scss +90 -3
  54. package/dist/badge/styles.d.ts +26 -0
  55. package/dist/badge/styles.js +18 -0
  56. package/dist/badge/styles.js.map +1 -0
  57. package/dist/box/Box.js +2 -1
  58. package/dist/box/Box.js.map +1 -1
  59. package/dist/box/_box.scss +130 -17
  60. package/dist/box/styles.d.ts +6 -0
  61. package/dist/box/styles.js +2 -1
  62. package/dist/box/styles.js.map +1 -1
  63. package/dist/button/AsyncButton.d.ts +1 -1
  64. package/dist/button/AsyncButton.js.map +1 -1
  65. package/dist/button/Button.d.ts +2 -1
  66. package/dist/button/Button.js +2 -1
  67. package/dist/button/Button.js.map +1 -1
  68. package/dist/button/_button.scss +157 -25
  69. package/dist/card/Card.d.ts +16 -0
  70. package/dist/card/Card.js +11 -3
  71. package/dist/card/Card.js.map +1 -1
  72. package/dist/card/ClickableCard.d.ts +2 -1
  73. package/dist/card/ClickableCard.js +5 -2
  74. package/dist/card/ClickableCard.js.map +1 -1
  75. package/dist/card/_card.scss +90 -19
  76. package/dist/card/styles.d.ts +0 -7
  77. package/dist/card/styles.js +2 -3
  78. package/dist/card/styles.js.map +1 -1
  79. package/dist/chip/Chip.d.ts +2 -1
  80. package/dist/chip/Chip.js +2 -1
  81. package/dist/chip/Chip.js.map +1 -1
  82. package/dist/chip/_chip.scss +45 -22
  83. package/dist/chip/styles.d.ts +12 -10
  84. package/dist/chip/styles.js.map +1 -1
  85. package/dist/cssUtils.js.map +1 -1
  86. package/dist/delegateEvent.d.ts +2 -2
  87. package/dist/delegateEvent.js.map +1 -1
  88. package/dist/dialog/Dialog.d.ts +8 -21
  89. package/dist/dialog/Dialog.js +27 -27
  90. package/dist/dialog/Dialog.js.map +1 -1
  91. package/dist/dialog/FixedDialog.d.ts +1 -3
  92. package/dist/dialog/FixedDialog.js +0 -8
  93. package/dist/dialog/FixedDialog.js.map +1 -1
  94. package/dist/dialog/_dialog.scss +67 -13
  95. package/dist/dialog/styles.d.ts +56 -0
  96. package/dist/dialog/styles.js +29 -2
  97. package/dist/dialog/styles.js.map +1 -1
  98. package/dist/divider/Divider.d.ts +0 -11
  99. package/dist/divider/Divider.js.map +1 -1
  100. package/dist/divider/_divider.scss +7 -1
  101. package/dist/divider/styles.d.ts +11 -0
  102. package/dist/divider/styles.js.map +1 -1
  103. package/dist/draggable/useDraggable.d.ts +6 -6
  104. package/dist/draggable/useDraggable.js.map +1 -1
  105. package/dist/draggable/utils.d.ts +3 -3
  106. package/dist/draggable/utils.js.map +1 -1
  107. package/dist/expansion-panel/ExpansionPanel.d.ts +1 -1
  108. package/dist/expansion-panel/ExpansionPanel.js.map +1 -1
  109. package/dist/expansion-panel/_expansion-panel.scss +5 -1
  110. package/dist/expansion-panel/useExpansionPanels.js +12 -24
  111. package/dist/expansion-panel/useExpansionPanels.js.map +1 -1
  112. package/dist/{form → files}/FileInput.d.ts +3 -6
  113. package/dist/{form → files}/FileInput.js +3 -6
  114. package/dist/files/FileInput.js.map +1 -0
  115. package/dist/files/_files.scss +22 -0
  116. package/dist/files/styles.d.ts +5 -0
  117. package/dist/files/styles.js +7 -0
  118. package/dist/files/styles.js.map +1 -0
  119. package/dist/{form → files}/useFileUpload.d.ts +7 -9
  120. package/dist/{form → files}/useFileUpload.js +5 -7
  121. package/dist/files/useFileUpload.js.map +1 -0
  122. package/dist/files/utils.d.ts +169 -0
  123. package/dist/files/utils.js +114 -0
  124. package/dist/files/utils.js.map +1 -0
  125. package/dist/{form/fileUtils.d.ts → files/validation.d.ts} +11 -176
  126. package/dist/{form/fileUtils.js → files/validation.js} +10 -135
  127. package/dist/files/validation.js.map +1 -0
  128. package/dist/focus/useFocusContainer.d.ts +2 -2
  129. package/dist/focus/useFocusContainer.js.map +1 -1
  130. package/dist/focus/utils.js.map +1 -1
  131. package/dist/form/FormMessage.js.map +1 -1
  132. package/dist/form/FormMessageContainer.js +4 -2
  133. package/dist/form/FormMessageContainer.js.map +1 -1
  134. package/dist/form/InputToggle.d.ts +2 -1
  135. package/dist/form/InputToggle.js +2 -1
  136. package/dist/form/InputToggle.js.map +1 -1
  137. package/dist/form/InputToggleIcon.js.map +1 -1
  138. package/dist/form/Label.js +2 -2
  139. package/dist/form/Label.js.map +1 -1
  140. package/dist/form/Listbox.d.ts +24 -0
  141. package/dist/form/Listbox.js +46 -0
  142. package/dist/form/Listbox.js.map +1 -0
  143. package/dist/form/ListboxProvider.d.ts +21 -0
  144. package/dist/form/{useListboxProvider.js → ListboxProvider.js} +1 -1
  145. package/dist/form/ListboxProvider.js.map +1 -0
  146. package/dist/form/MenuItemTextField.js +1 -2
  147. package/dist/form/MenuItemTextField.js.map +1 -1
  148. package/dist/form/NativeSelect.js +7 -4
  149. package/dist/form/NativeSelect.js.map +1 -1
  150. package/dist/form/Option.d.ts +49 -10
  151. package/dist/form/Option.js +11 -9
  152. package/dist/form/Option.js.map +1 -1
  153. package/dist/form/Password.js.map +1 -1
  154. package/dist/form/Select.d.ts +2 -2
  155. package/dist/form/Select.js +81 -85
  156. package/dist/form/Select.js.map +1 -1
  157. package/dist/form/SelectedOption.js +2 -1
  158. package/dist/form/SelectedOption.js.map +1 -1
  159. package/dist/form/Slider.d.ts +4 -4
  160. package/dist/form/Slider.js +6 -2
  161. package/dist/form/Slider.js.map +1 -1
  162. package/dist/form/SliderThumb.d.ts +3 -3
  163. package/dist/form/SliderThumb.js.map +1 -1
  164. package/dist/form/SliderValueMarks.d.ts +2 -2
  165. package/dist/form/SliderValueMarks.js.map +1 -1
  166. package/dist/form/SliderValueTooltip.js.map +1 -1
  167. package/dist/form/TextArea.js +1 -2
  168. package/dist/form/TextArea.js.map +1 -1
  169. package/dist/form/TextField.js +1 -2
  170. package/dist/form/TextField.js.map +1 -1
  171. package/dist/form/TextFieldContainer.js +1 -2
  172. package/dist/form/TextFieldContainer.js.map +1 -1
  173. package/dist/form/_form.scss +193 -124
  174. package/dist/form/formMessageContainerStyles.d.ts +10 -0
  175. package/dist/form/formMessageContainerStyles.js +11 -0
  176. package/dist/form/formMessageContainerStyles.js.map +1 -0
  177. package/dist/form/inputToggleStyles.js.map +1 -1
  178. package/dist/form/optionStyles.d.ts +1 -0
  179. package/dist/form/optionStyles.js +2 -2
  180. package/dist/form/optionStyles.js.map +1 -1
  181. package/dist/form/selectUtils.js.map +1 -1
  182. package/dist/form/sliderUtils.d.ts +1 -1
  183. package/dist/form/sliderUtils.js.map +1 -1
  184. package/dist/form/textFieldContainerStyles.d.ts +0 -2
  185. package/dist/form/textFieldContainerStyles.js +1 -2
  186. package/dist/form/textFieldContainerStyles.js.map +1 -1
  187. package/dist/form/types.d.ts +3 -10
  188. package/dist/form/types.js.map +1 -1
  189. package/dist/form/useCheckboxGroup.d.ts +17 -17
  190. package/dist/form/useCheckboxGroup.js +9 -17
  191. package/dist/form/useCheckboxGroup.js.map +1 -1
  192. package/dist/form/useCombobox.d.ts +56 -21
  193. package/dist/form/useCombobox.js +19 -4
  194. package/dist/form/useCombobox.js.map +1 -1
  195. package/dist/form/useEditableCombobox.d.ts +24 -4
  196. package/dist/form/useEditableCombobox.js +5 -0
  197. package/dist/form/useEditableCombobox.js.map +1 -1
  198. package/dist/form/useNumberField.js.map +1 -1
  199. package/dist/form/useRadioGroup.d.ts +6 -6
  200. package/dist/form/useRadioGroup.js.map +1 -1
  201. package/dist/form/useResizingTextArea.js.map +1 -1
  202. package/dist/form/useSelectCombobox.d.ts +3 -4
  203. package/dist/form/useSelectCombobox.js.map +1 -1
  204. package/dist/form/useTextField.d.ts +1 -1
  205. package/dist/form/useTextField.js.map +1 -1
  206. package/dist/form/useTextFieldContainerAddons.js.map +1 -1
  207. package/dist/hoverMode/useHoverMode.d.ts +3 -3
  208. package/dist/hoverMode/useHoverMode.js.map +1 -1
  209. package/dist/hoverMode/useHoverModeProvider.d.ts +4 -4
  210. package/dist/hoverMode/useHoverModeProvider.js.map +1 -1
  211. package/dist/icon/FontIcon.d.ts +4 -2
  212. package/dist/icon/FontIcon.js.map +1 -1
  213. package/dist/icon/TextIconSpacing.d.ts +3 -1
  214. package/dist/icon/TextIconSpacing.js.map +1 -1
  215. package/dist/icon/_icon.scss +151 -2
  216. package/dist/icon/iconConfig.d.ts +10 -0
  217. package/dist/icon/iconConfig.js +7 -0
  218. package/dist/icon/iconConfig.js.map +1 -1
  219. package/dist/icon/materialConfig.js.map +1 -1
  220. package/dist/icon/styles.js.map +1 -1
  221. package/dist/interaction/UserInteractionModeProvider.d.ts +5 -5
  222. package/dist/interaction/UserInteractionModeProvider.js +12 -8
  223. package/dist/interaction/UserInteractionModeProvider.js.map +1 -1
  224. package/dist/interaction/types.d.ts +20 -2
  225. package/dist/interaction/types.js.map +1 -1
  226. package/dist/interaction/useElementInteraction.d.ts +7 -1
  227. package/dist/interaction/useElementInteraction.js +1 -2
  228. package/dist/interaction/useElementInteraction.js.map +1 -1
  229. package/dist/interaction/utils.d.ts +2 -2
  230. package/dist/interaction/utils.js +2 -2
  231. package/dist/interaction/utils.js.map +1 -1
  232. package/dist/layout/LayoutWindowSplitter.js.map +1 -1
  233. package/dist/layout/_layout.scss +23 -10
  234. package/dist/layout/useExpandableLayout.d.ts +3 -3
  235. package/dist/layout/useExpandableLayout.js.map +1 -1
  236. package/dist/layout/useLayoutAppBarHeight.d.ts +2 -3
  237. package/dist/layout/useLayoutAppBarHeight.js.map +1 -1
  238. package/dist/layout/useTemporaryLayout.d.ts +2 -2
  239. package/dist/layout/useTemporaryLayout.js.map +1 -1
  240. package/dist/link/SkipToMainContent.js.map +1 -1
  241. package/dist/list/ListItem.d.ts +2 -1
  242. package/dist/list/ListItem.js +2 -1
  243. package/dist/list/ListItem.js.map +1 -1
  244. package/dist/list/ListItemChildren.js.map +1 -1
  245. package/dist/list/ListItemLink.d.ts +2 -1
  246. package/dist/list/ListItemLink.js +2 -1
  247. package/dist/list/ListItemLink.js.map +1 -1
  248. package/dist/list/_list.scss +6 -5
  249. package/dist/media-queries/_media-queries.scss +12 -0
  250. package/dist/media-queries/appSize.js.map +1 -1
  251. package/dist/media-queries/useMediaQuery.js +3 -1
  252. package/dist/media-queries/useMediaQuery.js.map +1 -1
  253. package/dist/menu/DropdownMenu.js.map +1 -1
  254. package/dist/menu/Menu.d.ts +8 -3
  255. package/dist/menu/Menu.js +2 -1
  256. package/dist/menu/Menu.js.map +1 -1
  257. package/dist/menu/MenuItemButton.js +6 -2
  258. package/dist/menu/MenuItemButton.js.map +1 -1
  259. package/dist/menu/useContextMenu.d.ts +3 -3
  260. package/dist/menu/useContextMenu.js.map +1 -1
  261. package/dist/movement/types.d.ts +5 -5
  262. package/dist/movement/types.js.map +1 -1
  263. package/dist/navigation/CollapsibleNavGroup.d.ts +5 -3
  264. package/dist/navigation/CollapsibleNavGroup.js +3 -4
  265. package/dist/navigation/CollapsibleNavGroup.js.map +1 -1
  266. package/dist/navigation/DefaultNavigationRenderer.d.ts +1 -2
  267. package/dist/navigation/DefaultNavigationRenderer.js +6 -2
  268. package/dist/navigation/DefaultNavigationRenderer.js.map +1 -1
  269. package/dist/navigation/NavItemButton.d.ts +1 -1
  270. package/dist/navigation/NavItemButton.js +1 -0
  271. package/dist/navigation/NavItemButton.js.map +1 -1
  272. package/dist/navigation/NavItemLink.d.ts +3 -2
  273. package/dist/navigation/NavItemLink.js +6 -2
  274. package/dist/navigation/NavItemLink.js.map +1 -1
  275. package/dist/navigation/NavSubheader.d.ts +2 -3
  276. package/dist/navigation/NavSubheader.js.map +1 -1
  277. package/dist/navigation/Navigation.d.ts +1 -1
  278. package/dist/navigation/Navigation.js.map +1 -1
  279. package/dist/navigation/_navigation.scss +6 -5
  280. package/dist/navigation/types.d.ts +54 -6
  281. package/dist/navigation/types.js.map +1 -1
  282. package/dist/navigation/useActiveHeadingId.d.ts +1 -1
  283. package/dist/navigation/useActiveHeadingId.js.map +1 -1
  284. package/dist/navigation/useNavigationExpansion.d.ts +104 -0
  285. package/dist/navigation/useNavigationExpansion.js +77 -0
  286. package/dist/navigation/useNavigationExpansion.js.map +1 -0
  287. package/dist/navigation/utils.d.ts +13 -0
  288. package/dist/navigation/utils.js +36 -0
  289. package/dist/navigation/utils.js.map +1 -0
  290. package/dist/objectFit.d.ts +69 -0
  291. package/dist/objectFit.js +52 -0
  292. package/dist/objectFit.js.map +1 -0
  293. package/dist/overlay/_overlay.scss +2 -1
  294. package/dist/positioning/useFixedPositioning.d.ts +17 -4
  295. package/dist/positioning/useFixedPositioning.js +10 -5
  296. package/dist/positioning/useFixedPositioning.js.map +1 -1
  297. package/dist/positioning/utils.js.map +1 -1
  298. package/dist/progress/LinearProgress.js.map +1 -1
  299. package/dist/progress/_progress.scss +20 -14
  300. package/dist/responsive-item/ResponsiveItem.d.ts +64 -0
  301. package/dist/responsive-item/ResponsiveItem.js +68 -0
  302. package/dist/responsive-item/ResponsiveItem.js.map +1 -0
  303. package/dist/responsive-item/ResponsiveItemOverlay.d.ts +1 -19
  304. package/dist/responsive-item/ResponsiveItemOverlay.js +1 -12
  305. package/dist/responsive-item/ResponsiveItemOverlay.js.map +1 -1
  306. package/dist/responsive-item/_responsive-item.scss +110 -133
  307. package/dist/responsive-item/responsiveItemOverlayStyles.d.ts +19 -0
  308. package/dist/responsive-item/responsiveItemOverlayStyles.js +14 -0
  309. package/dist/responsive-item/responsiveItemOverlayStyles.js.map +1 -0
  310. package/dist/responsive-item/responsiveItemStyles.d.ts +52 -0
  311. package/dist/responsive-item/responsiveItemStyles.js +15 -0
  312. package/dist/responsive-item/responsiveItemStyles.js.map +1 -0
  313. package/dist/scroll/useScrollLock.d.ts +5 -0
  314. package/dist/scroll/useScrollLock.js.map +1 -1
  315. package/dist/searching/utils.d.ts +2 -2
  316. package/dist/searching/utils.js.map +1 -1
  317. package/dist/segmented-button/SegmentedButton.d.ts +2 -1
  318. package/dist/segmented-button/SegmentedButton.js +2 -1
  319. package/dist/segmented-button/SegmentedButton.js.map +1 -1
  320. package/dist/segmented-button/_segmented-button.scss +6 -6
  321. package/dist/sheet/_sheet.scss +18 -6
  322. package/dist/snackbar/ToastManager.js +15 -5
  323. package/dist/snackbar/ToastManager.js.map +1 -1
  324. package/dist/snackbar/_snackbar.scss +30 -17
  325. package/dist/snackbar/useCurrentToastActions.d.ts +5 -5
  326. package/dist/snackbar/useCurrentToastActions.js.map +1 -1
  327. package/dist/table/_table.scss +15 -3
  328. package/dist/table/tableCellStyles.d.ts +7 -3
  329. package/dist/table/tableCellStyles.js +2 -2
  330. package/dist/table/tableCellStyles.js.map +1 -1
  331. package/dist/tabs/Tab.d.ts +2 -1
  332. package/dist/tabs/Tab.js +2 -1
  333. package/dist/tabs/Tab.js.map +1 -1
  334. package/dist/tabs/TabList.d.ts +2 -2
  335. package/dist/tabs/TabList.js.map +1 -1
  336. package/dist/tabs/TabListScrollButton.d.ts +1 -1
  337. package/dist/tabs/TabListScrollButton.js +1 -1
  338. package/dist/tabs/TabListScrollButton.js.map +1 -1
  339. package/dist/tabs/_tabs.scss +30 -9
  340. package/dist/tabs/getTabListScrollToOptions.d.ts +18 -0
  341. package/dist/tabs/getTabListScrollToOptions.js +19 -0
  342. package/dist/tabs/getTabListScrollToOptions.js.map +1 -0
  343. package/dist/tabs/tabStyles.d.ts +3 -0
  344. package/dist/tabs/tabStyles.js.map +1 -1
  345. package/dist/tabs/useTabList.d.ts +1 -8
  346. package/dist/tabs/useTabList.js +1 -0
  347. package/dist/tabs/useTabList.js.map +1 -1
  348. package/dist/tabs/useTabs.d.ts +6 -6
  349. package/dist/tabs/useTabs.js.map +1 -1
  350. package/dist/tabs/utils.d.ts +0 -18
  351. package/dist/tabs/utils.js +0 -15
  352. package/dist/tabs/utils.js.map +1 -1
  353. package/dist/test-utils/ResizeObserver.d.ts +11 -12
  354. package/dist/test-utils/ResizeObserver.js +11 -12
  355. package/dist/test-utils/ResizeObserver.js.map +1 -1
  356. package/dist/test-utils/matchMedia.d.ts +3 -3
  357. package/dist/test-utils/matchMedia.js +6 -6
  358. package/dist/test-utils/matchMedia.js.map +1 -1
  359. package/dist/test-utils/polyfills/TextDecoder.js +0 -1
  360. package/dist/test-utils/polyfills/TextDecoder.js.map +1 -1
  361. package/dist/test-utils/timers.d.ts +9 -5
  362. package/dist/test-utils/timers.js +5 -5
  363. package/dist/test-utils/timers.js.map +1 -1
  364. package/dist/theme/LocalStorageColorSchemeProvider.d.ts +1 -1
  365. package/dist/theme/LocalStorageColorSchemeProvider.js +2 -1
  366. package/dist/theme/LocalStorageColorSchemeProvider.js.map +1 -1
  367. package/dist/theme/ThemeProvider.js +3 -1
  368. package/dist/theme/ThemeProvider.js.map +1 -1
  369. package/dist/theme/_a11y.scss +86 -13
  370. package/dist/theme/_colors.scss +279 -277
  371. package/dist/theme/_theme.scss +308 -37
  372. package/dist/theme/isColorScheme.d.ts +16 -0
  373. package/dist/theme/isColorScheme.js +19 -0
  374. package/dist/theme/isColorScheme.js.map +1 -0
  375. package/dist/theme/types.d.ts +53 -1
  376. package/dist/theme/types.js +1 -23
  377. package/dist/theme/types.js.map +1 -1
  378. package/dist/theme/useCSSVariables.d.ts +2 -19
  379. package/dist/theme/useCSSVariables.js.map +1 -1
  380. package/dist/theme/useColorScheme.d.ts +1 -35
  381. package/dist/theme/useColorScheme.js.map +1 -1
  382. package/dist/theme/useColorSchemeMetaTag.d.ts +1 -1
  383. package/dist/theme/useColorSchemeMetaTag.js.map +1 -1
  384. package/dist/theme/useColorSchemeProvider.d.ts +1 -1
  385. package/dist/theme/useColorSchemeProvider.js +1 -1
  386. package/dist/theme/useColorSchemeProvider.js.map +1 -1
  387. package/dist/theme/{usePrefersColorScheme.js → usePrefersDarkScheme.js} +1 -1
  388. package/dist/theme/usePrefersDarkScheme.js.map +1 -0
  389. package/dist/theme/utils.js.map +1 -1
  390. package/dist/tooltip/useTooltip.d.ts +14 -9
  391. package/dist/tooltip/useTooltip.js +2 -1
  392. package/dist/tooltip/useTooltip.js.map +1 -1
  393. package/dist/transition/_transition.scss +16 -9
  394. package/dist/transition/skeletonPlaceholderUtils.js.map +1 -1
  395. package/dist/transition/types.d.ts +1 -1
  396. package/dist/transition/types.js.map +1 -1
  397. package/dist/transition/useCarousel.d.ts +3 -3
  398. package/dist/transition/useCarousel.js.map +1 -1
  399. package/dist/transition/useCollapseTransition.js.map +1 -1
  400. package/dist/transition/useTransition.js +1 -0
  401. package/dist/transition/useTransition.js.map +1 -1
  402. package/dist/transition/utils.js.map +1 -1
  403. package/dist/tree/TreeItem.d.ts +2 -1
  404. package/dist/tree/TreeItem.js +4 -3
  405. package/dist/tree/TreeItem.js.map +1 -1
  406. package/dist/tree/TreeItemExpander.js.map +1 -1
  407. package/dist/tree/_tree.scss +8 -6
  408. package/dist/tree/useTreeExpansion.d.ts +1 -1
  409. package/dist/tree/useTreeExpansion.js +6 -18
  410. package/dist/tree/useTreeExpansion.js.map +1 -1
  411. package/dist/tree/useTreeSelection.d.ts +1 -1
  412. package/dist/tree/useTreeSelection.js +7 -25
  413. package/dist/tree/useTreeSelection.js.map +1 -1
  414. package/dist/tree/utils.d.ts +1 -1
  415. package/dist/tree/utils.js.map +1 -1
  416. package/dist/types.d.ts +12 -4
  417. package/dist/types.js.map +1 -1
  418. package/dist/typography/WritingDirectionProvider.d.ts +1 -1
  419. package/dist/typography/WritingDirectionProvider.js.map +1 -1
  420. package/dist/typography/_typography.scss +94 -37
  421. package/dist/typography/typographyStyles.js.map +1 -1
  422. package/dist/useDebouncedFunction.d.ts +1 -5
  423. package/dist/useDebouncedFunction.js +3 -1
  424. package/dist/useDebouncedFunction.js.map +1 -1
  425. package/dist/useDropzone.d.ts +4 -4
  426. package/dist/useDropzone.js.map +1 -1
  427. package/dist/useEnsuredId.js.map +1 -1
  428. package/dist/useIntersectionObserver.d.ts +5 -5
  429. package/dist/useIntersectionObserver.js.map +1 -1
  430. package/dist/useLocalStorage.d.ts +3 -3
  431. package/dist/useLocalStorage.js +1 -1
  432. package/dist/useLocalStorage.js.map +1 -1
  433. package/dist/useMutationObserver.d.ts +1 -1
  434. package/dist/useMutationObserver.js.map +1 -1
  435. package/dist/useOrientation.js +3 -1
  436. package/dist/useOrientation.js.map +1 -1
  437. package/dist/usePageInactive.d.ts +2 -2
  438. package/dist/usePageInactive.js.map +1 -1
  439. package/dist/useReadonlySet.d.ts +76 -0
  440. package/dist/useReadonlySet.js +72 -0
  441. package/dist/useReadonlySet.js.map +1 -0
  442. package/dist/useResizeListener.d.ts +1 -1
  443. package/dist/useResizeListener.js.map +1 -1
  444. package/dist/useResizeObserver.d.ts +19 -0
  445. package/dist/useResizeObserver.js +19 -0
  446. package/dist/useResizeObserver.js.map +1 -1
  447. package/dist/useThrottledFunction.d.ts +1 -5
  448. package/dist/useThrottledFunction.js +3 -1
  449. package/dist/useThrottledFunction.js.map +1 -1
  450. package/dist/useToggle.d.ts +3 -3
  451. package/dist/useToggle.js.map +1 -1
  452. package/dist/utils/RenderRecursively.d.ts +2 -2
  453. package/dist/utils/RenderRecursively.js.map +1 -1
  454. package/dist/utils/alphaNumericSort.d.ts +5 -5
  455. package/dist/utils/alphaNumericSort.js.map +1 -1
  456. package/dist/utils/bem.d.ts +1 -1
  457. package/dist/utils/bem.js +1 -1
  458. package/dist/utils/bem.js.map +1 -1
  459. package/dist/utils/debounce.d.ts +5 -0
  460. package/dist/utils/debounce.js +17 -0
  461. package/dist/utils/debounce.js.map +1 -0
  462. package/dist/utils/nearest.js.map +1 -1
  463. package/dist/utils/parseCssLengthUnit.js.map +1 -1
  464. package/dist/utils/throttle.d.ts +5 -0
  465. package/dist/utils/throttle.js +30 -0
  466. package/dist/utils/throttle.js.map +1 -0
  467. package/dist/utils/wait.js +3 -1
  468. package/dist/utils/wait.js.map +1 -1
  469. package/dist/window-splitter/WindowSplitter.d.ts +37 -15
  470. package/dist/window-splitter/WindowSplitter.js +38 -17
  471. package/dist/window-splitter/WindowSplitter.js.map +1 -1
  472. package/dist/window-splitter/_window-splitter.scss +32 -14
  473. package/dist/window-splitter/styles.d.ts +14 -0
  474. package/dist/window-splitter/styles.js +18 -0
  475. package/dist/window-splitter/styles.js.map +1 -0
  476. package/package.json +25 -24
  477. package/src/app-bar/AppBar.tsx +1 -170
  478. package/src/app-bar/AppBarTitle.tsx +1 -44
  479. package/src/app-bar/styles.ts +206 -0
  480. package/src/autocomplete/Autocomplete.tsx +194 -211
  481. package/src/autocomplete/AutocompleteChip.tsx +48 -0
  482. package/src/autocomplete/AutocompleteCircularProgress.tsx +6 -17
  483. package/src/autocomplete/AutocompleteClearButton.tsx +44 -0
  484. package/src/autocomplete/AutocompleteDropdownButton.tsx +16 -37
  485. package/src/autocomplete/AutocompleteListboxChildren.tsx +68 -0
  486. package/src/autocomplete/autocompleteStyles.ts +48 -9
  487. package/src/autocomplete/defaults.ts +26 -17
  488. package/src/autocomplete/types.ts +744 -61
  489. package/src/autocomplete/useAutocomplete.ts +428 -0
  490. package/src/autocomplete/utils.ts +211 -0
  491. package/src/badge/Badge.tsx +1 -39
  492. package/src/badge/styles.ts +45 -0
  493. package/src/box/Box.tsx +11 -9
  494. package/src/box/styles.ts +14 -5
  495. package/src/button/AsyncButton.tsx +1 -1
  496. package/src/button/Button.tsx +5 -1
  497. package/src/card/Card.tsx +35 -4
  498. package/src/card/ClickableCard.tsx +9 -2
  499. package/src/card/styles.ts +1 -10
  500. package/src/chip/Chip.tsx +6 -1
  501. package/src/chip/styles.ts +12 -10
  502. package/src/delegateEvent.ts +5 -5
  503. package/src/dialog/Dialog.tsx +48 -61
  504. package/src/dialog/FixedDialog.tsx +1 -11
  505. package/src/dialog/styles.ts +97 -0
  506. package/src/divider/Divider.tsx +0 -12
  507. package/src/divider/styles.ts +12 -0
  508. package/src/draggable/useDraggable.ts +17 -10
  509. package/src/draggable/utils.ts +3 -3
  510. package/src/expansion-panel/ExpansionPanel.tsx +1 -1
  511. package/src/expansion-panel/useExpansionPanels.ts +18 -27
  512. package/src/{form → files}/FileInput.tsx +7 -15
  513. package/src/files/styles.ts +10 -0
  514. package/src/{form → files}/useFileUpload.ts +30 -34
  515. package/src/files/utils.ts +234 -0
  516. package/src/{form/fileUtils.ts → files/validation.ts} +15 -244
  517. package/src/focus/useFocusContainer.ts +16 -8
  518. package/src/form/FormMessageContainer.tsx +2 -2
  519. package/src/form/InputToggle.tsx +5 -1
  520. package/src/form/Label.tsx +18 -18
  521. package/src/form/Listbox.tsx +87 -0
  522. package/src/form/ListboxProvider.ts +37 -0
  523. package/src/form/MenuItemTextField.tsx +1 -2
  524. package/src/form/NativeSelect.tsx +14 -10
  525. package/src/form/Option.tsx +74 -22
  526. package/src/form/Select.tsx +89 -85
  527. package/src/form/SelectedOption.tsx +2 -0
  528. package/src/form/Slider.tsx +14 -11
  529. package/src/form/SliderThumb.tsx +4 -4
  530. package/src/form/SliderValueMarks.tsx +4 -4
  531. package/src/form/TextArea.tsx +6 -8
  532. package/src/form/TextField.tsx +0 -2
  533. package/src/form/TextFieldContainer.tsx +9 -11
  534. package/src/form/formMessageContainerStyles.ts +22 -0
  535. package/src/form/optionStyles.ts +7 -2
  536. package/src/form/sliderUtils.ts +1 -1
  537. package/src/form/textFieldContainerStyles.ts +9 -14
  538. package/src/form/types.ts +3 -11
  539. package/src/form/useCheckboxGroup.ts +28 -36
  540. package/src/form/useCombobox.ts +86 -38
  541. package/src/form/useEditableCombobox.ts +43 -8
  542. package/src/form/useRadioGroup.ts +6 -6
  543. package/src/form/useSelectCombobox.ts +4 -4
  544. package/src/form/useTextField.ts +1 -1
  545. package/src/hoverMode/useHoverMode.ts +3 -3
  546. package/src/hoverMode/useHoverModeProvider.ts +4 -4
  547. package/src/icon/FontIcon.tsx +4 -2
  548. package/src/icon/TextIconSpacing.tsx +1 -1
  549. package/src/icon/iconConfig.tsx +12 -0
  550. package/src/interaction/UserInteractionModeProvider.tsx +12 -8
  551. package/src/interaction/types.ts +21 -2
  552. package/src/interaction/useElementInteraction.tsx +9 -2
  553. package/src/interaction/utils.ts +7 -7
  554. package/src/layout/useExpandableLayout.ts +3 -3
  555. package/src/layout/useLayoutAppBarHeight.ts +3 -4
  556. package/src/layout/useTemporaryLayout.ts +2 -2
  557. package/src/list/ListItem.tsx +5 -1
  558. package/src/list/ListItemLink.tsx +5 -1
  559. package/src/media-queries/useMediaQuery.ts +2 -1
  560. package/src/menu/Menu.tsx +11 -3
  561. package/src/menu/MenuItemButton.tsx +7 -1
  562. package/src/menu/useContextMenu.ts +3 -3
  563. package/src/movement/types.ts +5 -5
  564. package/src/navigation/CollapsibleNavGroup.tsx +16 -8
  565. package/src/navigation/DefaultNavigationRenderer.tsx +8 -6
  566. package/src/navigation/NavItemButton.tsx +2 -1
  567. package/src/navigation/NavItemLink.tsx +11 -3
  568. package/src/navigation/NavSubheader.tsx +1 -1
  569. package/src/navigation/Navigation.tsx +1 -1
  570. package/src/navigation/types.ts +60 -10
  571. package/src/navigation/useActiveHeadingId.ts +1 -1
  572. package/src/navigation/useNavigationExpansion.ts +170 -0
  573. package/src/navigation/utils.ts +47 -0
  574. package/src/objectFit.ts +88 -0
  575. package/src/positioning/useFixedPositioning.ts +34 -11
  576. package/src/responsive-item/ResponsiveItem.tsx +96 -0
  577. package/src/responsive-item/ResponsiveItemOverlay.tsx +6 -46
  578. package/src/responsive-item/responsiveItemOverlayStyles.ts +46 -0
  579. package/src/responsive-item/responsiveItemStyles.ts +81 -0
  580. package/src/scroll/useScrollLock.ts +6 -0
  581. package/src/searching/utils.ts +3 -3
  582. package/src/segmented-button/SegmentedButton.tsx +5 -1
  583. package/src/snackbar/ToastManager.tsx +16 -5
  584. package/src/snackbar/useCurrentToastActions.ts +5 -5
  585. package/src/table/tableCellStyles.ts +10 -6
  586. package/src/tabs/Tab.tsx +4 -1
  587. package/src/tabs/TabList.tsx +2 -2
  588. package/src/tabs/TabListScrollButton.tsx +4 -4
  589. package/src/tabs/getTabListScrollToOptions.ts +37 -0
  590. package/src/tabs/tabStyles.ts +4 -0
  591. package/src/tabs/useTabList.ts +2 -9
  592. package/src/tabs/useTabs.ts +6 -6
  593. package/src/tabs/utils.ts +0 -38
  594. package/src/test-utils/ResizeObserver.ts +11 -12
  595. package/src/test-utils/matchMedia.ts +7 -7
  596. package/src/test-utils/polyfills/TextDecoder.ts +0 -1
  597. package/src/test-utils/timers.ts +10 -7
  598. package/src/theme/LocalStorageColorSchemeProvider.tsx +4 -4
  599. package/src/theme/ThemeProvider.tsx +3 -3
  600. package/src/theme/isColorScheme.ts +22 -0
  601. package/src/theme/types.ts +67 -1
  602. package/src/theme/useCSSVariables.ts +7 -30
  603. package/src/theme/useColorScheme.ts +1 -40
  604. package/src/theme/useColorSchemeMetaTag.ts +1 -1
  605. package/src/theme/useColorSchemeProvider.ts +2 -2
  606. package/src/tooltip/useTooltip.ts +17 -9
  607. package/src/transition/types.ts +1 -1
  608. package/src/transition/useCarousel.ts +3 -3
  609. package/src/transition/useTransition.ts +1 -0
  610. package/src/tree/TreeItem.tsx +7 -1
  611. package/src/tree/TreeItemExpander.tsx +1 -1
  612. package/src/tree/useTreeExpansion.ts +7 -25
  613. package/src/tree/useTreeSelection.ts +8 -32
  614. package/src/tree/utils.ts +6 -2
  615. package/src/types.ts +20 -4
  616. package/src/typography/WritingDirectionProvider.tsx +1 -1
  617. package/src/useDebouncedFunction.ts +4 -9
  618. package/src/useDropzone.ts +4 -4
  619. package/src/useIntersectionObserver.ts +5 -5
  620. package/src/useLocalStorage.ts +6 -6
  621. package/src/useMutationObserver.ts +1 -1
  622. package/src/useOrientation.ts +3 -1
  623. package/src/usePageInactive.ts +2 -2
  624. package/src/useReadonlySet.ts +122 -0
  625. package/src/useResizeListener.ts +1 -1
  626. package/src/useResizeObserver.ts +19 -0
  627. package/src/useThrottledFunction.ts +6 -9
  628. package/src/useToggle.ts +3 -3
  629. package/src/utils/RenderRecursively.tsx +2 -2
  630. package/src/utils/alphaNumericSort.ts +5 -5
  631. package/src/utils/bem.ts +1 -1
  632. package/src/utils/debounce.ts +22 -0
  633. package/src/utils/throttle.ts +38 -0
  634. package/src/utils/wait.ts +5 -1
  635. package/src/window-splitter/WindowSplitter.tsx +38 -43
  636. package/src/window-splitter/styles.ts +42 -0
  637. package/dist/autocomplete/FilterAutocompleteOptions.d.ts +0 -8
  638. package/dist/autocomplete/FilterAutocompleteOptions.js +0 -57
  639. package/dist/autocomplete/FilterAutocompleteOptions.js.map +0 -1
  640. package/dist/dialog/DialogContainer.d.ts +0 -14
  641. package/dist/dialog/DialogContainer.js +0 -20
  642. package/dist/dialog/DialogContainer.js.map +0 -1
  643. package/dist/form/FileInput.js.map +0 -1
  644. package/dist/form/fileUtils.js.map +0 -1
  645. package/dist/form/useFileUpload.js.map +0 -1
  646. package/dist/form/useListboxProvider.d.ts +0 -31
  647. package/dist/form/useListboxProvider.js.map +0 -1
  648. package/dist/navigation/getHrefFromParents.d.ts +0 -5
  649. package/dist/navigation/getHrefFromParents.js +0 -13
  650. package/dist/navigation/getHrefFromParents.js.map +0 -1
  651. package/dist/responsive-item/ResponsiveItemContainer.d.ts +0 -115
  652. package/dist/responsive-item/ResponsiveItemContainer.js +0 -80
  653. package/dist/responsive-item/ResponsiveItemContainer.js.map +0 -1
  654. package/dist/responsive-item/styles.d.ts +0 -34
  655. package/dist/responsive-item/styles.js +0 -17
  656. package/dist/responsive-item/styles.js.map +0 -1
  657. package/dist/theme/usePrefersColorScheme.js.map +0 -1
  658. package/src/autocomplete/FilterAutocompleteOptions.tsx +0 -86
  659. package/src/dialog/DialogContainer.tsx +0 -28
  660. package/src/form/useListboxProvider.ts +0 -45
  661. package/src/navigation/getHrefFromParents.ts +0 -15
  662. package/src/responsive-item/ResponsiveItemContainer.tsx +0 -174
  663. package/src/responsive-item/styles.ts +0 -58
  664. /package/dist/theme/{usePrefersColorScheme.d.ts → usePrefersDarkScheme.d.ts} +0 -0
  665. /package/src/theme/{usePrefersColorScheme.ts → usePrefersDarkScheme.ts} +0 -0
@@ -23,8 +23,7 @@ import { nanoid } from "nanoid";
23
23
  *
24
24
  * @param message - An optional message for the error.
25
25
  */ constructor(message){
26
- super(message);
27
- /**
26
+ super(message), /**
28
27
  * A unique key generated by `nanoid` that can be used as a `React` key
29
28
  */ _define_property(this, "key", void 0);
30
29
  this.key = nanoid();
@@ -41,14 +40,9 @@ import { nanoid } from "nanoid";
41
40
  * @param files - A list of files that caused the error.
42
41
  * @param reason - An optional reason for the error
43
42
  */ constructor(files, reason){
44
- super("Invalid files");
45
- _define_property(this, "files", void 0);
46
- _define_property(this, "reason", void 0);
47
- /**
43
+ super("Invalid files"), _define_property(this, "files", void 0), _define_property(this, "reason", void 0), /**
48
44
  * A unique key generated by `nanoid` that can be used as a `React` key
49
- */ _define_property(this, "key", void 0);
50
- this.files = files;
51
- this.reason = reason;
45
+ */ _define_property(this, "key", void 0), this.files = files, this.reason = reason;
52
46
  this.key = nanoid();
53
47
  this.name = "GenericFileError";
54
48
  }
@@ -65,9 +59,7 @@ import { nanoid } from "nanoid";
65
59
  * limit defined.
66
60
  * @param limit - The max limit of files allowed.
67
61
  */ constructor(files, limit){
68
- super(files, "file limit");
69
- _define_property(this, "limit", void 0);
70
- this.limit = limit;
62
+ super(files, "file limit"), _define_property(this, "limit", void 0), this.limit = limit;
71
63
  this.name = "TooManyFilesError";
72
64
  }
73
65
  }
@@ -86,11 +78,7 @@ import { nanoid } from "nanoid";
86
78
  * @param type - The file size error type
87
79
  * @param limit - The number of bytes allowed based on the type
88
80
  */ constructor(files, type, limit){
89
- super(files, "file size");
90
- _define_property(this, "type", void 0);
91
- _define_property(this, "limit", void 0);
92
- this.type = type;
93
- this.limit = limit;
81
+ super(files, "file size"), _define_property(this, "type", void 0), _define_property(this, "limit", void 0), this.type = type, this.limit = limit;
94
82
  this.name = "FileSizeError";
95
83
  }
96
84
  }
@@ -105,9 +93,7 @@ import { nanoid } from "nanoid";
105
93
  * @param files - The file that caused the error
106
94
  * @param extensions - The allowed list of file extensions
107
95
  */ constructor(files, extensions){
108
- super(files, "extension");
109
- _define_property(this, "extensions", void 0);
110
- this.extensions = extensions;
96
+ super(files, "extension"), _define_property(this, "extensions", void 0), this.extensions = extensions;
111
97
  this.name = "FileExtensionError";
112
98
  }
113
99
  }
@@ -171,12 +157,13 @@ import { nanoid } from "nanoid";
171
157
  * {@link useFileUpload} that ensures the {@link FilesValidationOptions} are
172
158
  * enforced before allowing a file to be uploaded.
173
159
  *
174
- * @typeparam E - An optional custom file validation error.
160
+ * @typeParam E - An optional custom file validation error.
175
161
  * @param files - The list of files to check
176
162
  * @param options - The {@link FilesValidationOptions}
177
163
  * @returns the {@link ValidatedFilesResult}
178
164
  * @since 2.9.0
179
- */ export function validateFiles(files, { maxFiles, extensions, minFileSize, maxFileSize, totalBytes, totalFiles, totalFileSize, isValidFileName }) {
165
+ */ export function validateFiles(files, options) {
166
+ const { maxFiles, extensions, minFileSize, maxFileSize, totalBytes, totalFiles, totalFileSize, isValidFileName } = options;
180
167
  const errors = [];
181
168
  const pending = [];
182
169
  const extraFiles = [];
@@ -235,117 +222,5 @@ import { nanoid } from "nanoid";
235
222
  errors
236
223
  };
237
224
  }
238
- /**
239
- * This will first check if the mime-type of the file starts with `text/` and
240
- * fallback to checking a few file names or extensions that should be considered
241
- * text.
242
- *
243
- * This function is not guaranteed to be 100% correct and is only useful if
244
- * trying to generate a preview of files uploaded to the browser.
245
- *
246
- * @param file - The file to check
247
- * @returns `true` if the file should be considered as a text-content file.
248
- * @since 2.9.0
249
- */ export function isTextFile(file) {
250
- return /\.((j|t)sx?|json|lock|hbs|ya?ml|log|txt|md)$/i.test(file.name);
251
- }
252
- /**
253
- * This will first check if the mime-type of the file starts with `text\/` and
254
- * fallback to checking a few file names or extensions that should be considered
255
- * text.
256
- *
257
- * This function is not guaranteed to be 100% correct and is only useful if
258
- * trying to generate a preview of files uploaded to the browser.
259
- *
260
- * @param file - The file to check
261
- * @returns `true` if the file should be considered as a text content file.
262
- * @since 2.9.0
263
- */ export function isImageFile(file) {
264
- return /\.(a?png|avif|svg|tiff|gifv?|jpe?g)/i.test(file.name);
265
- }
266
- /**
267
- * This will first check if the mime-type of the file starts with `audio/` and
268
- * fallback to checking a few file names or extensions that should be considered
269
- * audio.
270
- *
271
- * This function is not guaranteed to be 100% correct and is only useful if
272
- * trying to generate a preview of files uploaded to the browser.
273
- *
274
- * @param file - The file to check
275
- * @returns `true` if the file should be considered as a audio content file.
276
- * @since 2.9.0
277
- */ export function isAudioFile(file) {
278
- return /\.(mp3|wav|ogg|m4p|flac)$/i.test(file.name);
279
- }
280
- /**
281
- * This will first check if the mime-type of the file starts with `video/` and
282
- * fallback to checking a few file names or extensions that should be considered
283
- * video.
284
- *
285
- * This function is not guaranteed to be 100% correct and is only useful if
286
- * trying to generate a preview of files uploaded to the browser.
287
- *
288
- * @param file - The file to check
289
- * @returns `true` if the file should be considered as a video content file.
290
- * @since 2.9.0
291
- */ export function isVideoFile(file) {
292
- return /\.(mkv|mpe?g|mov|avi|flv|webm|mp4)$/i.test(file.name);
293
- }
294
- /**
295
- * This function is not guaranteed to be 100% correct and is only useful if
296
- * trying to generate a preview of files uploaded to the browser.
297
- *
298
- * @param file - The file to check
299
- * @returns `true` if the file matches an image, audio, or video file.
300
- * @since 2.9.0
301
- */ export function isMediaFile(file) {
302
- return isImageFile(file) || isAudioFile(file) || isVideoFile(file);
303
- }
304
- /**
305
- * This function will attempt to read:
306
- * - media (image, audio, and video) files as a data url so they can be
307
- * previewed in `<img>`, `<audio>`, and `<video>` tags
308
- * - text files as plain text
309
- * - everything else as an `ArrayBuffer` which can be manually converted into a
310
- * data url if needed with `URL.createObjectURL`
311
- *
312
- * @since 2.9.0
313
- */ export const getFileParser = (file)=>{
314
- if (isMediaFile(file)) {
315
- return "readAsDataURL";
316
- }
317
- if (isTextFile(file)) {
318
- return "readAsText";
319
- }
320
- return "readAsArrayBuffer";
321
- };
322
- /**
323
- * This util will split all the current upload stats by status.
324
- *
325
- * @param stats - The {@link FileUploadStats} list generally returned by the
326
- * {@link useFileUpload} hook.
327
- * @returns the {@link SplitFileUploads}.
328
- * @since 2.9.0
329
- */ export function getSplitFileUploads(stats) {
330
- const pending = [];
331
- const uploading = [];
332
- const complete = [];
333
- stats.forEach((stat)=>{
334
- if (stat.status === "pending") {
335
- pending.push(stat);
336
- } else if (stat.status === "uploading") {
337
- uploading.push(stat);
338
- } else if (stat.status === "complete") {
339
- complete.push(stat);
340
- } else {
341
- /* istanbul ignore next */ throw new Error("Invalid upload stat");
342
- }
343
- });
344
- return {
345
- pending,
346
- uploading,
347
- complete
348
- };
349
- }
350
225
 
351
- //# sourceMappingURL=fileUtils.js.map
226
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/files/validation.ts"],"sourcesContent":["import { nanoid } from \"nanoid\";\n\n/**\n * An error that will be created if a user tries dragging and dropping files\n * from a shared directory that they do not have access to. This error will not\n * occur much.\n *\n * @since 2.9.0\n */\nexport class FileAccessError extends Error {\n /**\n * A unique key generated by `nanoid` that can be used as a `React` key\n */\n public key: string;\n\n /**\n *\n * @param message - An optional message for the error.\n */\n constructor(message?: string) {\n super(message);\n this.key = nanoid();\n this.name = \"FileAccessError\";\n }\n}\n\n/**\n * An error that just requires a `File` to be passed as the first argument.\n *\n * @since 2.9.0\n */\nexport class GenericFileError extends Error {\n /**\n * A unique key generated by `nanoid` that can be used as a `React` key\n */\n public key: string;\n\n /**\n *\n * @param files - A list of files that caused the error.\n * @param reason - An optional reason for the error\n */\n constructor(\n public files: readonly File[],\n public reason?: string\n ) {\n super(\"Invalid files\");\n this.key = nanoid();\n this.name = \"GenericFileError\";\n }\n}\n\n/**\n * An error that is created during the upload process if the number of files\n * exceeds the {@link FileUploadOptions.maxFiles} amount.\n *\n * @since 2.9.0\n */\nexport class TooManyFilesError extends GenericFileError {\n /**\n *\n * @param files - The list of files that could not be uploaded due to the file\n * limit defined.\n * @param limit - The max limit of files allowed.\n */\n constructor(\n files: readonly File[],\n public limit: number\n ) {\n super(files, \"file limit\");\n this.name = \"TooManyFilesError\";\n }\n}\n\n/**\n * An error that will be created if a user tries to upload a file that\n * is either:\n * - less than the {@link FileValidationOptions.minFileSize}\n * - greater than the {@link FileValidationOptions.maxFileSize}\n * - including the file would be greater than the {@link FileValidationOptions.totalFileSize}\n *\n * @since 2.9.0\n */\nexport class FileSizeError extends GenericFileError {\n /**\n *\n * @param files - The list of files that have the file size error\n * @param type - The file size error type\n * @param limit - The number of bytes allowed based on the type\n */\n constructor(\n files: readonly File[],\n public type: \"min\" | \"max\" | \"total\",\n public limit: number\n ) {\n super(files, \"file size\");\n this.name = \"FileSizeError\";\n }\n}\n\n/**\n * An error that will be created if a user tries to upload a file that does not\n * end with one of the {@link FileValidationOptions.extensions}.\n *\n * @since 2.9.0\n */\nexport class FileExtensionError extends GenericFileError {\n /**\n *\n * @param files - The file that caused the error\n * @param extensions - The allowed list of file extensions\n */\n constructor(\n files: readonly File[],\n public extensions: readonly string[]\n ) {\n super(files, \"extension\");\n this.name = \"FileExtensionError\";\n }\n}\n\n/**\n * Mostly an internal type that is used to allow custom validation errors\n *\n * @since 2.9.0\n */\nexport type FileValidationError<E = GenericFileError> =\n | FileAccessError\n | TooManyFilesError\n | FileSizeError\n | FileExtensionError\n | E;\n\n/**\n * A simple type-guard that can be used to check if the\n * {@link FileValidationError} is the {@link GenericFileError} which can be\n * useful when displaying the errors to the user.\n *\n * @param error - The error to check\n * @returns true if the error is a {@link FileAccessError}\n */\nexport function isGenericFileError<CustomError extends object>(\n error: FileValidationError<CustomError>\n): error is GenericFileError {\n return \"name\" in error && error.name === \"GenericFileError\";\n}\n\n/**\n * A simple type-guard that can be used to check if the\n * {@link FileValidationError} is the {@link FileAccessError} which can be\n * useful when displaying the errors to the user.\n *\n * @param error - The error to check\n * @returns true if the error is a {@link FileAccessError}\n */\nexport function isFileAccessError<CustomError extends object>(\n error: FileValidationError<CustomError>\n): error is FileAccessError {\n return \"name\" in error && error.name === \"FileAccessError\";\n}\n\n/**\n * A simple type-guard that can be used to check if the\n * {@link FileValidationError} is the {@link TooManyFilesError} which can be\n * useful when displaying the errors to the user.\n *\n * @param error - The error to check\n * @returns true if the error is a {@link TooManyFilesError}\n */\nexport function isTooManyFilesError<CustomError extends object>(\n error: FileValidationError<CustomError>\n): error is TooManyFilesError {\n return \"name\" in error && error.name === \"TooManyFilesError\";\n}\n\n/**\n * A simple type-guard that can be used to check if the\n * {@link FileValidationError} is the {@link FileSizeError} which can be\n * useful when displaying the errors to the user.\n *\n * @param error - The error to check\n * @returns true if the error is a {@link FileSizeError}\n */\nexport function isFileSizeError<CustomError extends object>(\n error: FileValidationError<CustomError>\n): error is FileSizeError {\n return \"name\" in error && error.name === \"FileSizeError\";\n}\n\n/**\n * A simple type-guard that can be used to check if the\n * {@link FileValidationError} is the {@link FileExtensionError} which can be\n * useful when displaying the errors to the user.\n *\n * @param error - The error to check\n * @returns true if the error is a {@link FileExtensionError}\n */\nexport function isFileExtensionError<CustomError extends object>(\n error: FileValidationError<CustomError>\n): error is FileExtensionError {\n return \"name\" in error && error.name === \"FileExtensionError\";\n}\n\n/**\n * This function is used to determine if a file should be added to the\n * {@link FileExtensionError}. The default implementation should work for most\n * use cases except when files that do not have extensions can be uploaded. i.e.\n * LICENSE files.\n *\n * @param file - The file being checked\n * @param extensionRegExp - A regex that will only be defined if the\n * `extensions` list had at least one value.\n * @param extensions - The list of extensions allowed\n * @returns true if the file has a valid name.\n * @since 3.1.0\n */\nexport type IsValidFileName = (\n file: File,\n extensionRegExp: RegExp | undefined,\n extensions: readonly string[]\n) => boolean;\n\n/**\n *\n * @defaultValue `matcher?.test(file.name) ?? true`\n * @since 3.1.0\n */\nexport const isValidFileName: IsValidFileName = (file, matcher) =>\n matcher?.test(file.name) ?? true;\n\n/** @since 2.9.0 */\nexport interface FileValidationOptions {\n /**\n * If the number of files should be limited, set this value to a number\n * greater than `0`.\n *\n * Note: This still allows \"infinite\" files when set to `0` since the\n * `<input>` element should normally be set to `disabled` if files should not\n * be able to be uploaded.\n *\n * @defaultValue `-1`\n */\n maxFiles?: number;\n\n /**\n * An optional minimum file size to enforce for each file. This will only be\n * used when it is greater than `0`.\n *\n * @defaultValue `-1`\n */\n minFileSize?: number;\n\n /**\n * An optional maximum file size to enforce for each file. This will only be\n * used when it is greater than `0`.\n *\n * @defaultValue `-1`\n */\n maxFileSize?: number;\n\n /**\n * An optional list of extensions to enforce when uploading files.\n *\n * Note: The extensions and file names will be compared ignoring case.\n *\n * @example Only Allow Images\n * ```ts\n * const extensions = [\"png\", \"jpeg\", \"jpg\", \"gif\"];\n * ```\n */\n extensions?: readonly string[];\n\n /** {@inheritDoc IsValidFileName} */\n isValidFileName?: IsValidFileName;\n\n /**\n * An optional total file size to enforce when the {@link maxFiles} option is\n * not set to `1`.\n *\n * @defaultValue `-1`\n */\n totalFileSize?: number;\n}\n\n/** @since 2.9.0 */\nexport interface FilesValidationOptions\n extends Required<FileValidationOptions> {\n /**\n * The total number of bytes in the {@link FileUploadHookReturnValue.stats}\n * list. This is really just:\n *\n * ```ts\n * const totalBytes = stats.reduce((total, stat) => total + stat.file.size, 0);\n * ```\n */\n totalBytes: number;\n\n /**\n * The total number of files in the {@link FileUploadHookReturnValue.stats}.\n */\n totalFiles: number;\n}\n\n/**\n * @since 2.9.0\n */\nexport interface ValidatedFilesResult<CustomError> {\n /**\n * A filtered list of files that have been validated and can be queued for the\n * upload process.\n */\n pending: readonly File[];\n\n /**\n * A list of {@link FileValidationError} that occurred during the validation\n * step.\n *\n * Note: If an error has occurred, the file **should not** be added to the\n * {@link pending} list of files.\n */\n errors: readonly FileValidationError<CustomError>[];\n}\n\n/**\n * This function will be called whenever a file has been uploaded by the user\n * either through an `<input type=\"file\">` or drag and drop behavior.\n *\n * @example Simple Example\n * ```ts\n * const validateFiles: FilesValidator = (files, options) => {\n * const invalid: File[] = [];\n * const pending: File[] = [];\n * for (const file of files) {\n * if (!/\\.(jpe?g|svg|png)$/i.test(name)) {\n * invalid.push(file);\n * } else {\n * pending.push(file);\n * }\n * }\n *\n * const errors: FileValidationError[] = [];\n * if (invalid.length) {\n * errors.push(new GenericFileError(invalid))\n * }\n *\n * return { pending, errors };\n * };\n * ```\n *\n * @typeParam E - An optional custom file validation error.\n * @param files - The list of files to check\n * @param options - The {@link FilesValidationOptions}\n * @returns the {@link ValidatedFilesResult}\n * @see {@link validateFiles} for the default implementation\n * @since 2.9.0\n */\nexport type FilesValidator<CustomError = never> = (\n files: readonly File[],\n options: FilesValidationOptions\n) => ValidatedFilesResult<CustomError>;\n\n/**\n * A pretty decent default implementation for validating files with the\n * {@link useFileUpload} that ensures the {@link FilesValidationOptions} are\n * enforced before allowing a file to be uploaded.\n *\n * @typeParam E - An optional custom file validation error.\n * @param files - The list of files to check\n * @param options - The {@link FilesValidationOptions}\n * @returns the {@link ValidatedFilesResult}\n * @since 2.9.0\n */\nexport function validateFiles<CustomError>(\n files: readonly File[],\n options: FilesValidationOptions\n): ValidatedFilesResult<CustomError> {\n const {\n maxFiles,\n extensions,\n minFileSize,\n maxFileSize,\n totalBytes,\n totalFiles,\n totalFileSize,\n isValidFileName,\n } = options;\n\n const errors: FileValidationError<CustomError>[] = [];\n const pending: File[] = [];\n const extraFiles: File[] = [];\n const extensionRegExp =\n extensions.length > 0\n ? new RegExp(`\\\\.(${extensions.join(\"|\")})$`, \"i\")\n : undefined;\n\n let maxFilesReached = maxFiles > 0 && totalFiles >= maxFiles;\n let remainingBytes = totalFileSize - totalBytes;\n const extensionErrors: File[] = [];\n const minErrors: File[] = [];\n const maxErrors: File[] = [];\n const totalSizeErrors: File[] = [];\n for (let i = 0; i < files.length; i += 1) {\n const file = files[i];\n\n let valid = true;\n const { size } = file;\n if (!isValidFileName(file, extensionRegExp, extensions)) {\n valid = false;\n extensionErrors.push(file);\n }\n\n if (minFileSize > 0 && size < minFileSize) {\n valid = false;\n minErrors.push(file);\n }\n\n if (maxFileSize > 0 && size > maxFileSize) {\n valid = false;\n maxErrors.push(file);\n } else if (totalFileSize > 0 && remainingBytes - file.size < 0) {\n // don't want both errors displaying\n valid = false;\n totalSizeErrors.push(file);\n }\n\n if (maxFilesReached && valid) {\n extraFiles.push(file);\n } else if (!maxFilesReached && valid) {\n pending.push(file);\n remainingBytes -= file.size;\n maxFilesReached =\n maxFilesReached ||\n (maxFiles > 0 && totalFiles + pending.length >= maxFiles);\n }\n }\n\n if (extensionErrors.length) {\n errors.push(new FileExtensionError(extensionErrors, extensions));\n }\n\n if (minErrors.length) {\n errors.push(new FileSizeError(minErrors, \"min\", minFileSize));\n }\n\n if (maxErrors.length) {\n errors.push(new FileSizeError(maxErrors, \"max\", maxFileSize));\n }\n\n if (totalSizeErrors.length) {\n errors.push(new FileSizeError(totalSizeErrors, \"total\", totalFileSize));\n }\n\n if (extraFiles.length) {\n errors.push(new TooManyFilesError(extraFiles, maxFiles));\n }\n\n return { pending, errors };\n}\n"],"names":["nanoid","FileAccessError","Error","constructor","message","key","name","GenericFileError","files","reason","TooManyFilesError","limit","FileSizeError","type","FileExtensionError","extensions","isGenericFileError","error","isFileAccessError","isTooManyFilesError","isFileSizeError","isFileExtensionError","isValidFileName","file","matcher","test","validateFiles","options","maxFiles","minFileSize","maxFileSize","totalBytes","totalFiles","totalFileSize","errors","pending","extraFiles","extensionRegExp","length","RegExp","join","undefined","maxFilesReached","remainingBytes","extensionErrors","minErrors","maxErrors","totalSizeErrors","i","valid","size","push"],"mappings":";;;;;;;;;;;;;AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC;;;;;;CAMC,GACD,OAAO,MAAMC,wBAAwBC;IAMnC;;;GAGC,GACDC,YAAYC,OAAgB,CAAE;QAC5B,KAAK,CAACA,UAVR;;GAEC,GACD,uBAAOC,OAAP,KAAA;QAQE,IAAI,CAACA,GAAG,GAAGL;QACX,IAAI,CAACM,IAAI,GAAG;IACd;AACF;AAEA;;;;CAIC,GACD,OAAO,MAAMC,yBAAyBL;IAMpC;;;;GAIC,GACDC,YACE,AAAOK,KAAsB,EAC7B,AAAOC,MAAe,CACtB;QACA,KAAK,CAAC,qGAdR;;GAEC,GACD,uBAAOJ,OAAP,KAAA,SAQSG,QAAAA,YACAC,SAAAA;QAGP,IAAI,CAACJ,GAAG,GAAGL;QACX,IAAI,CAACM,IAAI,GAAG;IACd;AACF;AAEA;;;;;CAKC,GACD,OAAO,MAAMI,0BAA0BH;IACrC;;;;;GAKC,GACDJ,YACEK,KAAsB,EACtB,AAAOG,KAAa,CACpB;QACA,KAAK,CAACH,OAAO,6DAFNG,QAAAA;QAGP,IAAI,CAACL,IAAI,GAAG;IACd;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMM,sBAAsBL;IACjC;;;;;GAKC,GACDJ,YACEK,KAAsB,EACtB,AAAOK,IAA6B,EACpC,AAAOF,KAAa,CACpB;QACA,KAAK,CAACH,OAAO,oGAHNK,OAAAA,WACAF,QAAAA;QAGP,IAAI,CAACL,IAAI,GAAG;IACd;AACF;AAEA;;;;;CAKC,GACD,OAAO,MAAMQ,2BAA2BP;IACtC;;;;GAIC,GACDJ,YACEK,KAAsB,EACtB,AAAOO,UAA6B,CACpC;QACA,KAAK,CAACP,OAAO,iEAFNO,aAAAA;QAGP,IAAI,CAACT,IAAI,GAAG;IACd;AACF;AAcA;;;;;;;CAOC,GACD,OAAO,SAASU,mBACdC,KAAuC;IAEvC,OAAO,UAAUA,SAASA,MAAMX,IAAI,KAAK;AAC3C;AAEA;;;;;;;CAOC,GACD,OAAO,SAASY,kBACdD,KAAuC;IAEvC,OAAO,UAAUA,SAASA,MAAMX,IAAI,KAAK;AAC3C;AAEA;;;;;;;CAOC,GACD,OAAO,SAASa,oBACdF,KAAuC;IAEvC,OAAO,UAAUA,SAASA,MAAMX,IAAI,KAAK;AAC3C;AAEA;;;;;;;CAOC,GACD,OAAO,SAASc,gBACdH,KAAuC;IAEvC,OAAO,UAAUA,SAASA,MAAMX,IAAI,KAAK;AAC3C;AAEA;;;;;;;CAOC,GACD,OAAO,SAASe,qBACdJ,KAAuC;IAEvC,OAAO,UAAUA,SAASA,MAAMX,IAAI,KAAK;AAC3C;AAqBA;;;;CAIC,GACD,OAAO,MAAMgB,kBAAmC,CAACC,MAAMC,UACrDA,SAASC,KAAKF,KAAKjB,IAAI,KAAK,KAAK;AAqInC;;;;;;;;;;CAUC,GACD,OAAO,SAASoB,cACdlB,KAAsB,EACtBmB,OAA+B;IAE/B,MAAM,EACJC,QAAQ,EACRb,UAAU,EACVc,WAAW,EACXC,WAAW,EACXC,UAAU,EACVC,UAAU,EACVC,aAAa,EACbX,eAAe,EAChB,GAAGK;IAEJ,MAAMO,SAA6C,EAAE;IACrD,MAAMC,UAAkB,EAAE;IAC1B,MAAMC,aAAqB,EAAE;IAC7B,MAAMC,kBACJtB,WAAWuB,MAAM,GAAG,IAChB,IAAIC,OAAO,CAAC,IAAI,EAAExB,WAAWyB,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,OAC5CC;IAEN,IAAIC,kBAAkBd,WAAW,KAAKI,cAAcJ;IACpD,IAAIe,iBAAiBV,gBAAgBF;IACrC,MAAMa,kBAA0B,EAAE;IAClC,MAAMC,YAAoB,EAAE;IAC5B,MAAMC,YAAoB,EAAE;IAC5B,MAAMC,kBAA0B,EAAE;IAClC,IAAK,IAAIC,IAAI,GAAGA,IAAIxC,MAAM8B,MAAM,EAAEU,KAAK,EAAG;QACxC,MAAMzB,OAAOf,KAAK,CAACwC,EAAE;QAErB,IAAIC,QAAQ;QACZ,MAAM,EAAEC,IAAI,EAAE,GAAG3B;QACjB,IAAI,CAACD,gBAAgBC,MAAMc,iBAAiBtB,aAAa;YACvDkC,QAAQ;YACRL,gBAAgBO,IAAI,CAAC5B;QACvB;QAEA,IAAIM,cAAc,KAAKqB,OAAOrB,aAAa;YACzCoB,QAAQ;YACRJ,UAAUM,IAAI,CAAC5B;QACjB;QAEA,IAAIO,cAAc,KAAKoB,OAAOpB,aAAa;YACzCmB,QAAQ;YACRH,UAAUK,IAAI,CAAC5B;QACjB,OAAO,IAAIU,gBAAgB,KAAKU,iBAAiBpB,KAAK2B,IAAI,GAAG,GAAG;YAC9D,oCAAoC;YACpCD,QAAQ;YACRF,gBAAgBI,IAAI,CAAC5B;QACvB;QAEA,IAAImB,mBAAmBO,OAAO;YAC5Bb,WAAWe,IAAI,CAAC5B;QAClB,OAAO,IAAI,CAACmB,mBAAmBO,OAAO;YACpCd,QAAQgB,IAAI,CAAC5B;YACboB,kBAAkBpB,KAAK2B,IAAI;YAC3BR,kBACEA,mBACCd,WAAW,KAAKI,aAAaG,QAAQG,MAAM,IAAIV;QACpD;IACF;IAEA,IAAIgB,gBAAgBN,MAAM,EAAE;QAC1BJ,OAAOiB,IAAI,CAAC,IAAIrC,mBAAmB8B,iBAAiB7B;IACtD;IAEA,IAAI8B,UAAUP,MAAM,EAAE;QACpBJ,OAAOiB,IAAI,CAAC,IAAIvC,cAAciC,WAAW,OAAOhB;IAClD;IAEA,IAAIiB,UAAUR,MAAM,EAAE;QACpBJ,OAAOiB,IAAI,CAAC,IAAIvC,cAAckC,WAAW,OAAOhB;IAClD;IAEA,IAAIiB,gBAAgBT,MAAM,EAAE;QAC1BJ,OAAOiB,IAAI,CAAC,IAAIvC,cAAcmC,iBAAiB,SAASd;IAC1D;IAEA,IAAIG,WAAWE,MAAM,EAAE;QACrBJ,OAAOiB,IAAI,CAAC,IAAIzC,kBAAkB0B,YAAYR;IAChD;IAEA,OAAO;QAAEO;QAASD;IAAO;AAC3B"}
@@ -1,5 +1,5 @@
1
- import type { KeyboardEventHandler, Ref, RefObject } from "react";
2
- import type { TransitionCallbacks } from "../transition/types.js";
1
+ import { type KeyboardEventHandler, type Ref, type RefObject } from "react";
2
+ import { type TransitionCallbacks } from "../transition/types.js";
3
3
  /**
4
4
  * `"mount"` - this will attempt to focus the container element if:
5
5
  * - there is no `document.activeElement`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/focus/useFocusContainer.ts"],"sourcesContent":["\"use client\";\nimport type { KeyboardEventHandler, Ref, RefObject } from \"react\";\nimport { useEffect, useRef } from \"react\";\nimport { TRANSITION_CONFIG } from \"../transition/config.js\";\nimport type {\n TransitionCallbacks,\n TransitionEnterHandler,\n TransitionExitHandler,\n} from \"../transition/types.js\";\nimport { useEnsuredRef } from \"../useEnsuredRef.js\";\nimport type { FocusElementWithinType } from \"./utils.js\";\nimport { focusElementWithin, getFocusableElements } from \"./utils.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * `\"mount\"` - this will attempt to focus the container element if:\n * - there is no `document.activeElement`\n * - the container element does not contain the `document.activeElement`\n *\n * `\"unmount\"` - attempts to re-focus the element that was focused before the\n * focus container became active. The previous focus element is captured\n * whenever the `activate` option on the `useFocusContainer` hook is set to\n * `true`. This is normally when an element becomes `visible`.\n *\n * `\"keyboard\"` - refocuses the first focusable element if pressing `Tab` would\n * move the focus outside of the container element. If `Shift + Tab` was used,\n * the last focusable element will be used instead.\n *\n * @since 6.0.0\n */\nexport type FocusType = \"mount\" | \"unmount\" | \"keyboard\";\n\n/** @since 6.0.0 */\nexport type FocusContainerTransitionCallbacks = Pick<\n TransitionCallbacks,\n \"onEntering\" | \"onEntered\" | \"onExiting\" | \"onExited\"\n>;\n\n/** @since 6.0.0 */\nexport interface FocusContainerTransitionOptions<E extends HTMLElement>\n extends FocusContainerTransitionCallbacks {\n /**\n * An optional ref that will be merged with the\n * {@link FocusContainerImplementation.nodeRef}\n */\n nodeRef?: Ref<E>;\n}\n\n/** @since 6.0.0 */\nexport interface FocusContainerEventHandlers<E extends HTMLElement> {\n onKeyDown?: KeyboardEventHandler<E>;\n}\n\n/**\n * @since 6.0.0\n */\nexport type IsFocusTypeDisabled = (type: FocusType) => boolean;\n\nexport interface FocusContainerComponentProps {\n /**\n * @defaultValue `() => false`\n */\n isFocusTypeDisabled?: IsFocusTypeDisabled;\n\n /**\n * @defaultValue `false`\n */\n disableTransition?: boolean;\n}\n\n/** @since 6.0.0 */\nexport interface FocusContainerOptions<E extends HTMLElement>\n extends FocusContainerTransitionOptions<E>,\n FocusContainerComponentProps {\n onKeyDown?: KeyboardEventHandler<E>;\n /**\n * This to `true` will capture the current focused element as a focus target\n * once the `onExited` hook is fired. This should usually be set to the\n * `transitionIn` prop for `useTransition`.\n */\n activate: boolean;\n\n /**\n * Set this to true if elements that can be programmatically focused should be\n * included. These would be elements with a `tabIndex={-1}`.\n *\n * @defaultValue `false`\n */\n programmatic?: boolean;\n}\n\n/** @since 6.0.0 */\nexport interface FocusContainerImplementation<E extends HTMLElement> {\n nodeRef: RefObject<E>;\n eventHandlers: Required<FocusContainerEventHandlers<E>>;\n transitionOptions: Required<FocusContainerTransitionOptions<E>>;\n}\n\n/**\n * This hook is mostly for internal use only for dialog accessibility behavior\n * to prevent the focus from moving outside of the dialog while it is visible.\n * This API was developed to be used with the `useCSSTransition`/`useTransition`\n * hooks as well.\n *\n * @example Main Usage\n * ```tsx\n * import {\n * Button,\n * useFocusContainer,\n * useScaleTransition,\n * useToggle,\n * } from \"@react-md/core\";\n * import type { ReactElement } from \"react\";\n *\n * function Example(): ReactElement {\n * const { toggled, enable, disable } = useToggle(false);\n *\n * const { eventHandlers, transitionOptions } = useFocusContainer({\n * activate: toggled,\n * });\n * const { elementProps, rendered } = useScaleTransition({\n * transitionIn: toggled,\n * temporary: true,\n * ...transitionOptions,\n * });\n *\n * return (\n * <>\n * <Button onClick={enable}>Toggle</Button>\n * {rendered && (\n * <div {...eventHandlers} {...elementProps}>\n * <Button onClick={disable}>Button 1</Button>\n * <Button onClick={disable}>Button 2</Button>\n * <Button onClick={disable}>Button 3</Button>\n * <Button onClick={disable}>Button 4</Button>\n * </div>\n * )}\n * </>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useFocusContainer<E extends HTMLElement>(\n options: FocusContainerOptions<E>\n): FocusContainerImplementation<E> {\n const {\n nodeRef,\n activate,\n onEntering = noop,\n onEntered = noop,\n onExiting = noop,\n onExited = noop,\n onKeyDown = noop,\n programmatic = false,\n disableTransition = false,\n isFocusTypeDisabled = noop,\n } = options;\n\n const [ref, refCallback] = useEnsuredRef(nodeRef);\n const prevFocus = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!activate || !(document.activeElement instanceof HTMLElement)) {\n return;\n }\n\n prevFocus.current = document.activeElement;\n }, [activate]);\n\n const handleMountFocus =\n (callback: TransitionEnterHandler, skipped: boolean) =>\n (appearing: boolean) => {\n callback(appearing);\n const instance = ref.current;\n if (\n instance &&\n !skipped &&\n !isFocusTypeDisabled(\"mount\") &&\n (!document.activeElement || !instance.contains(document.activeElement))\n ) {\n instance.focus();\n }\n };\n\n const handleUnmountFocus =\n (callback: TransitionExitHandler, skipped: boolean) => (): void => {\n callback();\n if (skipped || isFocusTypeDisabled(\"unmount\")) {\n return;\n }\n\n // For some reason, the `\"Enter\"` keydown event fires at a different timing\n // than the Space keydown event.\n window.requestAnimationFrame(() => {\n prevFocus.current?.focus();\n });\n };\n\n return {\n nodeRef: ref,\n transitionOptions: {\n nodeRef: refCallback,\n onEntering: handleMountFocus(onEntering, false),\n onEntered: handleMountFocus(\n onEntered,\n !disableTransition && !TRANSITION_CONFIG.disabled\n ),\n onExiting: handleUnmountFocus(onExiting, false),\n onExited: handleUnmountFocus(\n onExited,\n !disableTransition && !TRANSITION_CONFIG.disabled\n ),\n },\n eventHandlers: {\n onKeyDown(event) {\n onKeyDown(event);\n if (\n event.isPropagationStopped() ||\n event.key !== \"Tab\" ||\n isFocusTypeDisabled(\"keyboard\")\n ) {\n return;\n }\n\n const { target, shiftKey, currentTarget } = event;\n const elements = getFocusableElements(currentTarget, programmatic);\n const count = elements.length;\n if (count === 0) {\n event.preventDefault();\n return;\n }\n\n // if the container element is the current focus, need to either focus\n // the first or last element so focus doesn't escape\n let type: FocusElementWithinType | undefined;\n if (\n count === 1 ||\n (!shiftKey &&\n (target === currentTarget || target === elements[count - 1]))\n ) {\n type = \"first\";\n } else if (\n shiftKey &&\n (target === currentTarget || target === elements[0])\n ) {\n type = \"last\";\n }\n\n if (type) {\n event.preventDefault();\n focusElementWithin({\n type,\n elements,\n container: currentTarget,\n });\n }\n },\n },\n };\n}\n"],"names":["useEffect","useRef","TRANSITION_CONFIG","useEnsuredRef","focusElementWithin","getFocusableElements","noop","useFocusContainer","options","nodeRef","activate","onEntering","onEntered","onExiting","onExited","onKeyDown","programmatic","disableTransition","isFocusTypeDisabled","ref","refCallback","prevFocus","document","activeElement","HTMLElement","current","handleMountFocus","callback","skipped","appearing","instance","contains","focus","handleUnmountFocus","window","requestAnimationFrame","transitionOptions","disabled","eventHandlers","event","isPropagationStopped","key","target","shiftKey","currentTarget","elements","count","length","preventDefault","type","container"],"mappings":"AAAA;AAEA,SAASA,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAC1C,SAASC,iBAAiB,QAAQ,0BAA0B;AAM5D,SAASC,aAAa,QAAQ,sBAAsB;AAEpD,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,aAAa;AAEtE,MAAMC,OAAO;AACX,aAAa;AACf;AAsFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CC,GACD,OAAO,SAASC,kBACdC,OAAiC;IAEjC,MAAM,EACJC,OAAO,EACPC,QAAQ,EACRC,aAAaL,IAAI,EACjBM,YAAYN,IAAI,EAChBO,YAAYP,IAAI,EAChBQ,WAAWR,IAAI,EACfS,YAAYT,IAAI,EAChBU,eAAe,KAAK,EACpBC,oBAAoB,KAAK,EACzBC,sBAAsBZ,IAAI,EAC3B,GAAGE;IAEJ,MAAM,CAACW,KAAKC,YAAY,GAAGjB,cAAcM;IACzC,MAAMY,YAAYpB,OAA2B;IAE7CD,UAAU;QACR,IAAI,CAACU,YAAY,CAAEY,CAAAA,SAASC,aAAa,YAAYC,WAAU,GAAI;YACjE;QACF;QAEAH,UAAUI,OAAO,GAAGH,SAASC,aAAa;IAC5C,GAAG;QAACb;KAAS;IAEb,MAAMgB,mBACJ,CAACC,UAAkCC,UACnC,CAACC;YACCF,SAASE;YACT,MAAMC,WAAWX,IAAIM,OAAO;YAC5B,IACEK,YACA,CAACF,WACD,CAACV,oBAAoB,YACpB,CAAA,CAACI,SAASC,aAAa,IAAI,CAACO,SAASC,QAAQ,CAACT,SAASC,aAAa,CAAA,GACrE;gBACAO,SAASE,KAAK;YAChB;QACF;IAEF,MAAMC,qBACJ,CAACN,UAAiCC,UAAqB;YACrDD;YACA,IAAIC,WAAWV,oBAAoB,YAAY;gBAC7C;YACF;YAEA,2EAA2E;YAC3E,iCAAiC;YACjCgB,OAAOC,qBAAqB,CAAC;gBAC3Bd,UAAUI,OAAO,EAAEO;YACrB;QACF;IAEF,OAAO;QACLvB,SAASU;QACTiB,mBAAmB;YACjB3B,SAASW;YACTT,YAAYe,iBAAiBf,YAAY;YACzCC,WAAWc,iBACTd,WACA,CAACK,qBAAqB,CAACf,kBAAkBmC,QAAQ;YAEnDxB,WAAWoB,mBAAmBpB,WAAW;YACzCC,UAAUmB,mBACRnB,UACA,CAACG,qBAAqB,CAACf,kBAAkBmC,QAAQ;QAErD;QACAC,eAAe;YACbvB,WAAUwB,KAAK;gBACbxB,UAAUwB;gBACV,IACEA,MAAMC,oBAAoB,MAC1BD,MAAME,GAAG,KAAK,SACdvB,oBAAoB,aACpB;oBACA;gBACF;gBAEA,MAAM,EAAEwB,MAAM,EAAEC,QAAQ,EAAEC,aAAa,EAAE,GAAGL;gBAC5C,MAAMM,WAAWxC,qBAAqBuC,eAAe5B;gBACrD,MAAM8B,QAAQD,SAASE,MAAM;gBAC7B,IAAID,UAAU,GAAG;oBACfP,MAAMS,cAAc;oBACpB;gBACF;gBAEA,sEAAsE;gBACtE,oDAAoD;gBACpD,IAAIC;gBACJ,IACEH,UAAU,KACT,CAACH,YACCD,CAAAA,WAAWE,iBAAiBF,WAAWG,QAAQ,CAACC,QAAQ,EAAE,AAAD,GAC5D;oBACAG,OAAO;gBACT,OAAO,IACLN,YACCD,CAAAA,WAAWE,iBAAiBF,WAAWG,QAAQ,CAAC,EAAE,AAAD,GAClD;oBACAI,OAAO;gBACT;gBAEA,IAAIA,MAAM;oBACRV,MAAMS,cAAc;oBACpB5C,mBAAmB;wBACjB6C;wBACAJ;wBACAK,WAAWN;oBACb;gBACF;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/focus/useFocusContainer.ts"],"sourcesContent":["\"use client\";\nimport {\n useEffect,\n useRef,\n type KeyboardEventHandler,\n type Ref,\n type RefObject,\n} from \"react\";\nimport { TRANSITION_CONFIG } from \"../transition/config.js\";\nimport {\n type TransitionCallbacks,\n type TransitionEnterHandler,\n type TransitionExitHandler,\n} from \"../transition/types.js\";\nimport { useEnsuredRef } from \"../useEnsuredRef.js\";\nimport {\n focusElementWithin,\n getFocusableElements,\n type FocusElementWithinType,\n} from \"./utils.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * `\"mount\"` - this will attempt to focus the container element if:\n * - there is no `document.activeElement`\n * - the container element does not contain the `document.activeElement`\n *\n * `\"unmount\"` - attempts to re-focus the element that was focused before the\n * focus container became active. The previous focus element is captured\n * whenever the `activate` option on the `useFocusContainer` hook is set to\n * `true`. This is normally when an element becomes `visible`.\n *\n * `\"keyboard\"` - refocuses the first focusable element if pressing `Tab` would\n * move the focus outside of the container element. If `Shift + Tab` was used,\n * the last focusable element will be used instead.\n *\n * @since 6.0.0\n */\nexport type FocusType = \"mount\" | \"unmount\" | \"keyboard\";\n\n/** @since 6.0.0 */\nexport type FocusContainerTransitionCallbacks = Pick<\n TransitionCallbacks,\n \"onEntering\" | \"onEntered\" | \"onExiting\" | \"onExited\"\n>;\n\n/** @since 6.0.0 */\nexport interface FocusContainerTransitionOptions<E extends HTMLElement>\n extends FocusContainerTransitionCallbacks {\n /**\n * An optional ref that will be merged with the\n * {@link FocusContainerImplementation.nodeRef}\n */\n nodeRef?: Ref<E>;\n}\n\n/** @since 6.0.0 */\nexport interface FocusContainerEventHandlers<E extends HTMLElement> {\n onKeyDown?: KeyboardEventHandler<E>;\n}\n\n/**\n * @since 6.0.0\n */\nexport type IsFocusTypeDisabled = (type: FocusType) => boolean;\n\nexport interface FocusContainerComponentProps {\n /**\n * @defaultValue `() => false`\n */\n isFocusTypeDisabled?: IsFocusTypeDisabled;\n\n /**\n * @defaultValue `false`\n */\n disableTransition?: boolean;\n}\n\n/** @since 6.0.0 */\nexport interface FocusContainerOptions<E extends HTMLElement>\n extends FocusContainerTransitionOptions<E>,\n FocusContainerComponentProps {\n onKeyDown?: KeyboardEventHandler<E>;\n /**\n * This to `true` will capture the current focused element as a focus target\n * once the `onExited` hook is fired. This should usually be set to the\n * `transitionIn` prop for `useTransition`.\n */\n activate: boolean;\n\n /**\n * Set this to true if elements that can be programmatically focused should be\n * included. These would be elements with a `tabIndex={-1}`.\n *\n * @defaultValue `false`\n */\n programmatic?: boolean;\n}\n\n/** @since 6.0.0 */\nexport interface FocusContainerImplementation<E extends HTMLElement> {\n nodeRef: RefObject<E>;\n eventHandlers: Required<FocusContainerEventHandlers<E>>;\n transitionOptions: Required<FocusContainerTransitionOptions<E>>;\n}\n\n/**\n * This hook is mostly for internal use only for dialog accessibility behavior\n * to prevent the focus from moving outside of the dialog while it is visible.\n * This API was developed to be used with the `useCSSTransition`/`useTransition`\n * hooks as well.\n *\n * @example Main Usage\n * ```tsx\n * import {\n * Button,\n * useFocusContainer,\n * useScaleTransition,\n * useToggle,\n * } from \"@react-md/core\";\n * import type { ReactElement } from \"react\";\n *\n * function Example(): ReactElement {\n * const { toggled, enable, disable } = useToggle(false);\n *\n * const { eventHandlers, transitionOptions } = useFocusContainer({\n * activate: toggled,\n * });\n * const { elementProps, rendered } = useScaleTransition({\n * transitionIn: toggled,\n * temporary: true,\n * ...transitionOptions,\n * });\n *\n * return (\n * <>\n * <Button onClick={enable}>Toggle</Button>\n * {rendered && (\n * <div {...eventHandlers} {...elementProps}>\n * <Button onClick={disable}>Button 1</Button>\n * <Button onClick={disable}>Button 2</Button>\n * <Button onClick={disable}>Button 3</Button>\n * <Button onClick={disable}>Button 4</Button>\n * </div>\n * )}\n * </>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useFocusContainer<E extends HTMLElement>(\n options: FocusContainerOptions<E>\n): FocusContainerImplementation<E> {\n const {\n nodeRef,\n activate,\n onEntering = noop,\n onEntered = noop,\n onExiting = noop,\n onExited = noop,\n onKeyDown = noop,\n programmatic = false,\n disableTransition = false,\n isFocusTypeDisabled = noop,\n } = options;\n\n const [ref, refCallback] = useEnsuredRef(nodeRef);\n const prevFocus = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!activate || !(document.activeElement instanceof HTMLElement)) {\n return;\n }\n\n prevFocus.current = document.activeElement;\n }, [activate]);\n\n const handleMountFocus =\n (callback: TransitionEnterHandler, skipped: boolean) =>\n (appearing: boolean) => {\n callback(appearing);\n const instance = ref.current;\n if (\n instance &&\n !skipped &&\n !isFocusTypeDisabled(\"mount\") &&\n (!document.activeElement || !instance.contains(document.activeElement))\n ) {\n instance.focus();\n }\n };\n\n const handleUnmountFocus =\n (callback: TransitionExitHandler, skipped: boolean) => (): void => {\n callback();\n if (skipped || isFocusTypeDisabled(\"unmount\")) {\n return;\n }\n\n // For some reason, the `\"Enter\"` keydown event fires at a different timing\n // than the Space keydown event.\n window.requestAnimationFrame(() => {\n prevFocus.current?.focus();\n });\n };\n\n return {\n nodeRef: ref,\n transitionOptions: {\n nodeRef: refCallback,\n onEntering: handleMountFocus(onEntering, false),\n onEntered: handleMountFocus(\n onEntered,\n !disableTransition && !TRANSITION_CONFIG.disabled\n ),\n onExiting: handleUnmountFocus(onExiting, false),\n onExited: handleUnmountFocus(\n onExited,\n !disableTransition && !TRANSITION_CONFIG.disabled\n ),\n },\n eventHandlers: {\n onKeyDown(event) {\n onKeyDown(event);\n if (\n event.isPropagationStopped() ||\n event.key !== \"Tab\" ||\n isFocusTypeDisabled(\"keyboard\")\n ) {\n return;\n }\n\n const { target, shiftKey, currentTarget } = event;\n const elements = getFocusableElements(currentTarget, programmatic);\n const count = elements.length;\n if (count === 0) {\n event.preventDefault();\n return;\n }\n\n // if the container element is the current focus, need to either focus\n // the first or last element so focus doesn't escape\n let type: FocusElementWithinType | undefined;\n if (\n count === 1 ||\n (!shiftKey &&\n (target === currentTarget || target === elements[count - 1]))\n ) {\n type = \"first\";\n } else if (\n shiftKey &&\n (target === currentTarget || target === elements[0])\n ) {\n type = \"last\";\n }\n\n if (type) {\n event.preventDefault();\n focusElementWithin({\n type,\n elements,\n container: currentTarget,\n });\n }\n },\n },\n };\n}\n"],"names":["useEffect","useRef","TRANSITION_CONFIG","useEnsuredRef","focusElementWithin","getFocusableElements","noop","useFocusContainer","options","nodeRef","activate","onEntering","onEntered","onExiting","onExited","onKeyDown","programmatic","disableTransition","isFocusTypeDisabled","ref","refCallback","prevFocus","document","activeElement","HTMLElement","current","handleMountFocus","callback","skipped","appearing","instance","contains","focus","handleUnmountFocus","window","requestAnimationFrame","transitionOptions","disabled","eventHandlers","event","isPropagationStopped","key","target","shiftKey","currentTarget","elements","count","length","preventDefault","type","container"],"mappings":"AAAA;AACA,SACEA,SAAS,EACTC,MAAM,QAID,QAAQ;AACf,SAASC,iBAAiB,QAAQ,0BAA0B;AAM5D,SAASC,aAAa,QAAQ,sBAAsB;AACpD,SACEC,kBAAkB,EAClBC,oBAAoB,QAEf,aAAa;AAEpB,MAAMC,OAAO;AACX,aAAa;AACf;AAsFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CC,GACD,OAAO,SAASC,kBACdC,OAAiC;IAEjC,MAAM,EACJC,OAAO,EACPC,QAAQ,EACRC,aAAaL,IAAI,EACjBM,YAAYN,IAAI,EAChBO,YAAYP,IAAI,EAChBQ,WAAWR,IAAI,EACfS,YAAYT,IAAI,EAChBU,eAAe,KAAK,EACpBC,oBAAoB,KAAK,EACzBC,sBAAsBZ,IAAI,EAC3B,GAAGE;IAEJ,MAAM,CAACW,KAAKC,YAAY,GAAGjB,cAAcM;IACzC,MAAMY,YAAYpB,OAA2B;IAE7CD,UAAU;QACR,IAAI,CAACU,YAAY,CAAEY,CAAAA,SAASC,aAAa,YAAYC,WAAU,GAAI;YACjE;QACF;QAEAH,UAAUI,OAAO,GAAGH,SAASC,aAAa;IAC5C,GAAG;QAACb;KAAS;IAEb,MAAMgB,mBACJ,CAACC,UAAkCC,UACnC,CAACC;YACCF,SAASE;YACT,MAAMC,WAAWX,IAAIM,OAAO;YAC5B,IACEK,YACA,CAACF,WACD,CAACV,oBAAoB,YACpB,CAAA,CAACI,SAASC,aAAa,IAAI,CAACO,SAASC,QAAQ,CAACT,SAASC,aAAa,CAAA,GACrE;gBACAO,SAASE,KAAK;YAChB;QACF;IAEF,MAAMC,qBACJ,CAACN,UAAiCC,UAAqB;YACrDD;YACA,IAAIC,WAAWV,oBAAoB,YAAY;gBAC7C;YACF;YAEA,2EAA2E;YAC3E,iCAAiC;YACjCgB,OAAOC,qBAAqB,CAAC;gBAC3Bd,UAAUI,OAAO,EAAEO;YACrB;QACF;IAEF,OAAO;QACLvB,SAASU;QACTiB,mBAAmB;YACjB3B,SAASW;YACTT,YAAYe,iBAAiBf,YAAY;YACzCC,WAAWc,iBACTd,WACA,CAACK,qBAAqB,CAACf,kBAAkBmC,QAAQ;YAEnDxB,WAAWoB,mBAAmBpB,WAAW;YACzCC,UAAUmB,mBACRnB,UACA,CAACG,qBAAqB,CAACf,kBAAkBmC,QAAQ;QAErD;QACAC,eAAe;YACbvB,WAAUwB,KAAK;gBACbxB,UAAUwB;gBACV,IACEA,MAAMC,oBAAoB,MAC1BD,MAAME,GAAG,KAAK,SACdvB,oBAAoB,aACpB;oBACA;gBACF;gBAEA,MAAM,EAAEwB,MAAM,EAAEC,QAAQ,EAAEC,aAAa,EAAE,GAAGL;gBAC5C,MAAMM,WAAWxC,qBAAqBuC,eAAe5B;gBACrD,MAAM8B,QAAQD,SAASE,MAAM;gBAC7B,IAAID,UAAU,GAAG;oBACfP,MAAMS,cAAc;oBACpB;gBACF;gBAEA,sEAAsE;gBACtE,oDAAoD;gBACpD,IAAIC;gBACJ,IACEH,UAAU,KACT,CAACH,YACCD,CAAAA,WAAWE,iBAAiBF,WAAWG,QAAQ,CAACC,QAAQ,EAAE,AAAD,GAC5D;oBACAG,OAAO;gBACT,OAAO,IACLN,YACCD,CAAAA,WAAWE,iBAAiBF,WAAWG,QAAQ,CAAC,EAAE,AAAD,GAClD;oBACAI,OAAO;gBACT;gBAEA,IAAIA,MAAM;oBACRV,MAAMS,cAAc;oBACpB5C,mBAAmB;wBACjB6C;wBACAJ;wBACAK,WAAWN;oBACb;gBACF;YACF;QACF;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/focus/utils.ts"],"sourcesContent":["const queries = [\n 'input:not([type=\"hidden\"]):not([disabled])',\n \"button:not([disabled])\",\n \"textarea:not([disabled])\",\n \"select:not([disabled])\",\n \"a[href]\",\n \"area[href]\",\n \"[tabindex]\",\n] as const;\n\n/**\n * A query selector to find elements that are programmatically focusable.\n *\n * Example:\n *\n * ```ts\n * const focusableElements = document.querySelectorAll(PROGRAMMATICALLY_FOCUSABLE);\n * // do something with elements\n * ```\n */\nexport const PROGRAMMATICALLY_FOCUSABLE = queries.join(\",\");\n\n/**\n * A query selector to find elements that are focusable only with tab and shift+tab.\n *\n * Example:\n *\n * ```ts\n * const focusableElements = document.querySelectorAll(TAB_FOCUSABLE);\n * // do something with elements\n * ```\n *\n * @since 6.0.0 This was updated to remove ALL elements that have a\n * `tabindex=\"-1\"` applied instead of only elements that had a manual tab index\n * applied.\n */\nexport const TAB_FOCUSABLE = queries.reduce((fullQuery, query) => {\n const prefix = `${fullQuery}${fullQuery ? \",\" : \"\"}`;\n const notProgrammaticQuery = `${query}:not([tabindex=\"-1\"])`;\n\n return `${prefix}${notProgrammaticQuery}`;\n}, \"\");\n\n/**\n * A simple util that will find all the tab focusable elements within a\n * container element. The container should normally be a specific HTMLElement,\n * but it can also be the entire document if you want to find **all** focusable\n * elements within your page.\n *\n * @since 6.0.0 This function will be used for all keyboard focus behavior\n * instead of trying to use refs. I did some performance testing in Firefox and\n * Chrome and the `querySelectorAll` takes 4ms with 5000 elements for my use\n * cases. There is more of a performance issue around rendering all 5000\n * elements and since this is only used for specific keydown events, this is\n * good enough for me.\n *\n * @param container - The container element/document to find focusable elements\n * within.\n * @param programmatic - Boolean if programmatically focusable elements should be\n * included instead of only tab focusable.\n * @returns A list of HTMLElements that are focusable within the container.\n */\nexport function getFocusableElements(\n container: HTMLElement | Document,\n programmatic = false\n): readonly HTMLElement[] {\n // spread operator is faster than Array.from\n return [\n ...container.querySelectorAll<HTMLElement>(\n programmatic ? PROGRAMMATICALLY_FOCUSABLE : TAB_FOCUSABLE\n ),\n ];\n}\n\n/**\n * Attempts to find the first focusable element within a container.\n *\n * @since 6.0.0\n * @param container - The container element/document to find focusable elements\n * within.\n * @param programmatic - Boolean if programmatically focusable elements should be\n * included instead of only tab focusable.\n * @returns A list of HTMLElements that are focusable within the container.\n */\nexport function getFocusableElement(\n container: HTMLElement | Document,\n programmatic = false\n): HTMLElement | null {\n return container.querySelector<HTMLElement>(\n programmatic ? PROGRAMMATICALLY_FOCUSABLE : TAB_FOCUSABLE\n );\n}\n\n/**\n * An element can be tab focused if it is:\n * - an anchor or area with an `href`\n * - a non-disabled `input` element that is not `type=\"hidden\"`\n * - a non-disabled `button`, `textarea`, or `select` element\n * - an element with a `tabIndex >= 0`\n *\n * An element can be noted as \"programmatically focusable only\" has the above\n * rules, but the `tabIndex` will be set to `-1`.\n *\n * @since 2.8.0\n */\nexport type ElementFocusType = \"tab\" | \"programmatic\";\n\nexport function isFocusable(\n element: HTMLElement | Document | Window,\n type: ElementFocusType = \"programmatic\"\n): element is HTMLElement {\n const selector = type === \"tab\" ? TAB_FOCUSABLE : PROGRAMMATICALLY_FOCUSABLE;\n\n return \"matches\" in element && element.matches(selector);\n}\n\nexport type FocusElementWithinType =\n | \"first\"\n | \"last\"\n | \"query\"\n | \"self\"\n | \"none\";\n\nexport interface FocusElementWithinOptions {\n type: FocusElementWithinType;\n query?: string;\n elements: readonly HTMLElement[];\n container: HTMLElement | Document;\n}\n\nexport function focusElementWithin(options: FocusElementWithinOptions): void {\n const { type, query = \"\", container, elements } = options;\n if (type === \"none\") {\n return;\n }\n\n let element: HTMLElement | null = null;\n if (type === \"first\") {\n [element] = elements;\n } else if (type === \"last\") {\n element = elements[elements.length - 1];\n } else if (type === \"query\") {\n element = document.querySelector<HTMLElement>(query);\n }\n\n if (!element && isFocusable(container)) {\n element = container;\n }\n\n // TODO: Why did I add preventScroll?\n element?.focus();\n}\n"],"names":["queries","PROGRAMMATICALLY_FOCUSABLE","join","TAB_FOCUSABLE","reduce","fullQuery","query","prefix","notProgrammaticQuery","getFocusableElements","container","programmatic","querySelectorAll","getFocusableElement","querySelector","isFocusable","element","type","selector","matches","focusElementWithin","options","elements","length","document","focus"],"mappings":"AAAA,MAAMA,UAAU;IACd;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;;;CASC,GACD,OAAO,MAAMC,6BAA6BD,QAAQE,IAAI,CAAC,KAAK;AAE5D;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,gBAAgBH,QAAQI,MAAM,CAAC,CAACC,WAAWC;IACtD,MAAMC,SAAS,CAAC,EAAEF,UAAU,EAAEA,YAAY,MAAM,GAAG,CAAC;IACpD,MAAMG,uBAAuB,CAAC,EAAEF,MAAM,qBAAqB,CAAC;IAE5D,OAAO,CAAC,EAAEC,OAAO,EAAEC,qBAAqB,CAAC;AAC3C,GAAG,IAAI;AAEP;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,qBACdC,SAAiC,EACjCC,eAAe,KAAK;IAEpB,4CAA4C;IAC5C,OAAO;WACFD,UAAUE,gBAAgB,CAC3BD,eAAeV,6BAA6BE;KAE/C;AACH;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASU,oBACdH,SAAiC,EACjCC,eAAe,KAAK;IAEpB,OAAOD,UAAUI,aAAa,CAC5BH,eAAeV,6BAA6BE;AAEhD;AAgBA,OAAO,SAASY,YACdC,OAAwC,EACxCC,OAAyB,cAAc;IAEvC,MAAMC,WAAWD,SAAS,QAAQd,gBAAgBF;IAElD,OAAO,aAAae,WAAWA,QAAQG,OAAO,CAACD;AACjD;AAgBA,OAAO,SAASE,mBAAmBC,OAAkC;IACnE,MAAM,EAAEJ,IAAI,EAAEX,QAAQ,EAAE,EAAEI,SAAS,EAAEY,QAAQ,EAAE,GAAGD;IAClD,IAAIJ,SAAS,QAAQ;QACnB;IACF;IAEA,IAAID,UAA8B;IAClC,IAAIC,SAAS,SAAS;QACpB,CAACD,QAAQ,GAAGM;IACd,OAAO,IAAIL,SAAS,QAAQ;QAC1BD,UAAUM,QAAQ,CAACA,SAASC,MAAM,GAAG,EAAE;IACzC,OAAO,IAAIN,SAAS,SAAS;QAC3BD,UAAUQ,SAASV,aAAa,CAAcR;IAChD;IAEA,IAAI,CAACU,WAAWD,YAAYL,YAAY;QACtCM,UAAUN;IACZ;IAEA,qCAAqC;IACrCM,SAASS;AACX"}
1
+ {"version":3,"sources":["../../src/focus/utils.ts"],"sourcesContent":["const queries = [\n 'input:not([type=\"hidden\"]):not([disabled])',\n \"button:not([disabled])\",\n \"textarea:not([disabled])\",\n \"select:not([disabled])\",\n \"a[href]\",\n \"area[href]\",\n \"[tabindex]\",\n] as const;\n\n/**\n * A query selector to find elements that are programmatically focusable.\n *\n * Example:\n *\n * ```ts\n * const focusableElements = document.querySelectorAll(PROGRAMMATICALLY_FOCUSABLE);\n * // do something with elements\n * ```\n */\nexport const PROGRAMMATICALLY_FOCUSABLE = queries.join(\",\");\n\n/**\n * A query selector to find elements that are focusable only with tab and shift+tab.\n *\n * Example:\n *\n * ```ts\n * const focusableElements = document.querySelectorAll(TAB_FOCUSABLE);\n * // do something with elements\n * ```\n *\n * @since 6.0.0 This was updated to remove ALL elements that have a\n * `tabindex=\"-1\"` applied instead of only elements that had a manual tab index\n * applied.\n */\nexport const TAB_FOCUSABLE = queries.reduce((fullQuery, query) => {\n const prefix = `${fullQuery}${fullQuery ? \",\" : \"\"}`;\n const notProgrammaticQuery = `${query}:not([tabindex=\"-1\"])`;\n\n return `${prefix}${notProgrammaticQuery}`;\n}, \"\");\n\n/**\n * A simple util that will find all the tab focusable elements within a\n * container element. The container should normally be a specific HTMLElement,\n * but it can also be the entire document if you want to find **all** focusable\n * elements within your page.\n *\n * @since 6.0.0 This function will be used for all keyboard focus behavior\n * instead of trying to use refs. I did some performance testing in Firefox and\n * Chrome and the `querySelectorAll` takes 4ms with 5000 elements for my use\n * cases. There is more of a performance issue around rendering all 5000\n * elements and since this is only used for specific keydown events, this is\n * good enough for me.\n *\n * @param container - The container element/document to find focusable elements\n * within.\n * @param programmatic - Boolean if programmatically focusable elements should be\n * included instead of only tab focusable.\n * @returns A list of HTMLElements that are focusable within the container.\n */\nexport function getFocusableElements(\n container: HTMLElement | Document,\n programmatic = false\n): readonly HTMLElement[] {\n // spread operator is faster than Array.from\n return [\n ...container.querySelectorAll<HTMLElement>(\n programmatic ? PROGRAMMATICALLY_FOCUSABLE : TAB_FOCUSABLE\n ),\n ];\n}\n\n/**\n * Attempts to find the first focusable element within a container.\n *\n * @since 6.0.0\n * @param container - The container element/document to find focusable elements\n * within.\n * @param programmatic - Boolean if programmatically focusable elements should be\n * included instead of only tab focusable.\n * @returns A list of HTMLElements that are focusable within the container.\n */\nexport function getFocusableElement(\n container: HTMLElement | Document,\n programmatic = false\n): HTMLElement | null {\n return container.querySelector<HTMLElement>(\n programmatic ? PROGRAMMATICALLY_FOCUSABLE : TAB_FOCUSABLE\n );\n}\n\n/**\n * An element can be tab focused if it is:\n * - an anchor or area with an `href`\n * - a non-disabled `input` element that is not `type=\"hidden\"`\n * - a non-disabled `button`, `textarea`, or `select` element\n * - an element with a `tabIndex >= 0`\n *\n * An element can be noted as \"programmatically focusable only\" has the above\n * rules, but the `tabIndex` will be set to `-1`.\n *\n * @since 2.8.0\n */\nexport type ElementFocusType = \"tab\" | \"programmatic\";\n\nexport function isFocusable(\n element: HTMLElement | Document | Window,\n type: ElementFocusType = \"programmatic\"\n): element is HTMLElement {\n const selector = type === \"tab\" ? TAB_FOCUSABLE : PROGRAMMATICALLY_FOCUSABLE;\n\n return \"matches\" in element && element.matches(selector);\n}\n\nexport type FocusElementWithinType =\n | \"first\"\n | \"last\"\n | \"query\"\n | \"self\"\n | \"none\";\n\nexport interface FocusElementWithinOptions {\n type: FocusElementWithinType;\n query?: string;\n elements: readonly HTMLElement[];\n container: HTMLElement | Document;\n}\n\nexport function focusElementWithin(options: FocusElementWithinOptions): void {\n const { type, query = \"\", container, elements } = options;\n if (type === \"none\") {\n return;\n }\n\n let element: HTMLElement | null = null;\n if (type === \"first\") {\n [element] = elements;\n } else if (type === \"last\") {\n element = elements[elements.length - 1];\n } else if (type === \"query\") {\n element = document.querySelector<HTMLElement>(query);\n }\n\n if (!element && isFocusable(container)) {\n element = container;\n }\n\n // TODO: Why did I add preventScroll?\n element?.focus();\n}\n"],"names":["queries","PROGRAMMATICALLY_FOCUSABLE","join","TAB_FOCUSABLE","reduce","fullQuery","query","prefix","notProgrammaticQuery","getFocusableElements","container","programmatic","querySelectorAll","getFocusableElement","querySelector","isFocusable","element","type","selector","matches","focusElementWithin","options","elements","length","document","focus"],"mappings":"AAAA,MAAMA,UAAU;IACd;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;;;CASC,GACD,OAAO,MAAMC,6BAA6BD,QAAQE,IAAI,CAAC,KAAK;AAE5D;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,gBAAgBH,QAAQI,MAAM,CAAC,CAACC,WAAWC;IACtD,MAAMC,SAAS,GAAGF,YAAYA,YAAY,MAAM,IAAI;IACpD,MAAMG,uBAAuB,GAAGF,MAAM,qBAAqB,CAAC;IAE5D,OAAO,GAAGC,SAASC,sBAAsB;AAC3C,GAAG,IAAI;AAEP;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,qBACdC,SAAiC,EACjCC,eAAe,KAAK;IAEpB,4CAA4C;IAC5C,OAAO;WACFD,UAAUE,gBAAgB,CAC3BD,eAAeV,6BAA6BE;KAE/C;AACH;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASU,oBACdH,SAAiC,EACjCC,eAAe,KAAK;IAEpB,OAAOD,UAAUI,aAAa,CAC5BH,eAAeV,6BAA6BE;AAEhD;AAgBA,OAAO,SAASY,YACdC,OAAwC,EACxCC,OAAyB,cAAc;IAEvC,MAAMC,WAAWD,SAAS,QAAQd,gBAAgBF;IAElD,OAAO,aAAae,WAAWA,QAAQG,OAAO,CAACD;AACjD;AAgBA,OAAO,SAASE,mBAAmBC,OAAkC;IACnE,MAAM,EAAEJ,IAAI,EAAEX,QAAQ,EAAE,EAAEI,SAAS,EAAEY,QAAQ,EAAE,GAAGD;IAClD,IAAIJ,SAAS,QAAQ;QACnB;IACF;IAEA,IAAID,UAA8B;IAClC,IAAIC,SAAS,SAAS;QACpB,CAACD,QAAQ,GAAGM;IACd,OAAO,IAAIL,SAAS,QAAQ;QAC1BD,UAAUM,QAAQ,CAACA,SAASC,MAAM,GAAG,EAAE;IACzC,OAAO,IAAIN,SAAS,SAAS;QAC3BD,UAAUQ,SAASV,aAAa,CAAcR;IAChD;IAEA,IAAI,CAACU,WAAWD,YAAYL,YAAY;QACtCM,UAAUN;IACZ;IAEA,qCAAqC;IACrCM,SAASS;AACX"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/form/FormMessage.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { FormMessageCounter } from \"./FormMessageCounter.js\";\nimport { getFormConfig } from \"./formConfig.js\";\nimport { formMessage, formMessageText } from \"./formMessageStyles.js\";\nimport {\n type FormMessageInputLengthCounterProps,\n type FormMessageProps,\n} from \"./types.js\";\n\n/**\n * The `FormMessage` component is used to create additional helper messages or\n * error messages and generally placed below the related `TextField`. If a\n * `length` (of the `value`) and `maxLength` are provided, a counter will also\n * be displayed to the right of the `children`.\n *\n * This component can also be used to create form-level validation messages by\n * setting the `role` prop to `\"alert\"`.\n */\nexport const FormMessage = forwardRef<\n HTMLDivElement,\n FormMessageProps & Partial<FormMessageInputLengthCounterProps>\n>(function FormMessage(props, ref) {\n const {\n id: propId,\n role,\n className,\n counterStyle,\n counterClassName,\n messageStyle,\n messageClassName,\n error = false,\n disableWrap = false,\n theme: propTheme,\n children,\n length,\n maxLength,\n ...remaining\n } = props;\n const id = useEnsuredId(propId, \"form-message\");\n const theme = getFormConfig(\"theme\", propTheme);\n\n let message = children;\n if (!disableWrap && children) {\n message = (\n <p\n id={`${id}-message`}\n style={messageStyle}\n className={formMessageText({ className: messageClassName })}\n >\n {children}\n </p>\n );\n }\n\n return (\n <div\n {...remaining}\n id={id}\n ref={ref}\n aria-live={role !== \"alert\" ? \"polite\" : undefined}\n role={role}\n className={formMessage({ error, theme, className })}\n >\n {message}\n {typeof length === \"number\" && typeof maxLength === \"number\" && (\n <FormMessageCounter\n id={`${id}-counter`}\n style={counterStyle}\n className={counterClassName}\n >\n {`${length} / ${maxLength}`}\n </FormMessageCounter>\n )}\n </div>\n );\n});\n"],"names":["forwardRef","useEnsuredId","FormMessageCounter","getFormConfig","formMessage","formMessageText","FormMessage","props","ref","id","propId","role","className","counterStyle","counterClassName","messageStyle","messageClassName","error","disableWrap","theme","propTheme","children","length","maxLength","remaining","message","p","style","div","aria-live","undefined"],"mappings":";AAAA,SAASA,UAAU,QAAQ,QAAQ;AACnC,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,WAAW,EAAEC,eAAe,QAAQ,yBAAyB;AAMtE;;;;;;;;CAQC,GACD,OAAO,MAAMC,4BAAcN,WAGzB,SAASM,YAAYC,KAAK,EAAEC,GAAG;IAC/B,MAAM,EACJC,IAAIC,MAAM,EACVC,IAAI,EACJC,SAAS,EACTC,YAAY,EACZC,gBAAgB,EAChBC,YAAY,EACZC,gBAAgB,EAChBC,QAAQ,KAAK,EACbC,cAAc,KAAK,EACnBC,OAAOC,SAAS,EAChBC,QAAQ,EACRC,MAAM,EACNC,SAAS,EACT,GAAGC,WACJ,GAAGjB;IACJ,MAAME,KAAKR,aAAaS,QAAQ;IAChC,MAAMS,QAAQhB,cAAc,SAASiB;IAErC,IAAIK,UAAUJ;IACd,IAAI,CAACH,eAAeG,UAAU;QAC5BI,wBACE,KAACC;YACCjB,IAAI,CAAC,EAAEA,GAAG,QAAQ,CAAC;YACnBkB,OAAOZ;YACPH,WAAWP,gBAAgB;gBAAEO,WAAWI;YAAiB;sBAExDK;;IAGP;IAEA,qBACE,MAACO;QACE,GAAGJ,SAAS;QACbf,IAAIA;QACJD,KAAKA;QACLqB,aAAWlB,SAAS,UAAU,WAAWmB;QACzCnB,MAAMA;QACNC,WAAWR,YAAY;YAAEa;YAAOE;YAAOP;QAAU;;YAEhDa;YACA,OAAOH,WAAW,YAAY,OAAOC,cAAc,0BAClD,KAACrB;gBACCO,IAAI,CAAC,EAAEA,GAAG,QAAQ,CAAC;gBACnBkB,OAAOd;gBACPD,WAAWE;0BAEV,CAAC,EAAEQ,OAAO,GAAG,EAAEC,UAAU,CAAC;;;;AAKrC,GAAG"}
1
+ {"version":3,"sources":["../../src/form/FormMessage.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { FormMessageCounter } from \"./FormMessageCounter.js\";\nimport { getFormConfig } from \"./formConfig.js\";\nimport { formMessage, formMessageText } from \"./formMessageStyles.js\";\nimport {\n type FormMessageInputLengthCounterProps,\n type FormMessageProps,\n} from \"./types.js\";\n\n/**\n * The `FormMessage` component is used to create additional helper messages or\n * error messages and generally placed below the related `TextField`. If a\n * `length` (of the `value`) and `maxLength` are provided, a counter will also\n * be displayed to the right of the `children`.\n *\n * This component can also be used to create form-level validation messages by\n * setting the `role` prop to `\"alert\"`.\n */\nexport const FormMessage = forwardRef<\n HTMLDivElement,\n FormMessageProps & Partial<FormMessageInputLengthCounterProps>\n>(function FormMessage(props, ref) {\n const {\n id: propId,\n role,\n className,\n counterStyle,\n counterClassName,\n messageStyle,\n messageClassName,\n error = false,\n disableWrap = false,\n theme: propTheme,\n children,\n length,\n maxLength,\n ...remaining\n } = props;\n const id = useEnsuredId(propId, \"form-message\");\n const theme = getFormConfig(\"theme\", propTheme);\n\n let message = children;\n if (!disableWrap && children) {\n message = (\n <p\n id={`${id}-message`}\n style={messageStyle}\n className={formMessageText({ className: messageClassName })}\n >\n {children}\n </p>\n );\n }\n\n return (\n <div\n {...remaining}\n id={id}\n ref={ref}\n aria-live={role !== \"alert\" ? \"polite\" : undefined}\n role={role}\n className={formMessage({ error, theme, className })}\n >\n {message}\n {typeof length === \"number\" && typeof maxLength === \"number\" && (\n <FormMessageCounter\n id={`${id}-counter`}\n style={counterStyle}\n className={counterClassName}\n >\n {`${length} / ${maxLength}`}\n </FormMessageCounter>\n )}\n </div>\n );\n});\n"],"names":["forwardRef","useEnsuredId","FormMessageCounter","getFormConfig","formMessage","formMessageText","FormMessage","props","ref","id","propId","role","className","counterStyle","counterClassName","messageStyle","messageClassName","error","disableWrap","theme","propTheme","children","length","maxLength","remaining","message","p","style","div","aria-live","undefined"],"mappings":";AAAA,SAASA,UAAU,QAAQ,QAAQ;AACnC,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,WAAW,EAAEC,eAAe,QAAQ,yBAAyB;AAMtE;;;;;;;;CAQC,GACD,OAAO,MAAMC,4BAAcN,WAGzB,SAASM,YAAYC,KAAK,EAAEC,GAAG;IAC/B,MAAM,EACJC,IAAIC,MAAM,EACVC,IAAI,EACJC,SAAS,EACTC,YAAY,EACZC,gBAAgB,EAChBC,YAAY,EACZC,gBAAgB,EAChBC,QAAQ,KAAK,EACbC,cAAc,KAAK,EACnBC,OAAOC,SAAS,EAChBC,QAAQ,EACRC,MAAM,EACNC,SAAS,EACT,GAAGC,WACJ,GAAGjB;IACJ,MAAME,KAAKR,aAAaS,QAAQ;IAChC,MAAMS,QAAQhB,cAAc,SAASiB;IAErC,IAAIK,UAAUJ;IACd,IAAI,CAACH,eAAeG,UAAU;QAC5BI,wBACE,KAACC;YACCjB,IAAI,GAAGA,GAAG,QAAQ,CAAC;YACnBkB,OAAOZ;YACPH,WAAWP,gBAAgB;gBAAEO,WAAWI;YAAiB;sBAExDK;;IAGP;IAEA,qBACE,MAACO;QACE,GAAGJ,SAAS;QACbf,IAAIA;QACJD,KAAKA;QACLqB,aAAWlB,SAAS,UAAU,WAAWmB;QACzCnB,MAAMA;QACNC,WAAWR,YAAY;YAAEa;YAAOE;YAAOP;QAAU;;YAEhDa;YACA,OAAOH,WAAW,YAAY,OAAOC,cAAc,0BAClD,KAACrB;gBACCO,IAAI,GAAGA,GAAG,QAAQ,CAAC;gBACnBkB,OAAOd;gBACPD,WAAWE;0BAEV,GAAGQ,OAAO,GAAG,EAAEC,WAAW;;;;AAKrC,GAAG"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { cnb } from "cnbuilder";
3
2
  import { forwardRef } from "react";
4
3
  import { FormMessage } from "./FormMessage.js";
4
+ import { formMessageContainer } from "./formMessageContainerStyles.js";
5
5
  /**
6
6
  * Conditionally wraps the `children` in a `.rmd-form-message-container` wrapper
7
7
  * and renders the {@link FormMessage} component.
@@ -17,7 +17,9 @@ import { FormMessage } from "./FormMessage.js";
17
17
  return /*#__PURE__*/ _jsxs("div", {
18
18
  ...remaining,
19
19
  ref: ref,
20
- className: cnb("rmd-form-message-container", className),
20
+ className: formMessageContainer({
21
+ className
22
+ }),
21
23
  children: [
22
24
  children,
23
25
  /*#__PURE__*/ _jsx(FormMessage, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/form/FormMessageContainer.tsx"],"sourcesContent":["import { cnb } from \"cnbuilder\";\nimport { forwardRef, type HTMLAttributes } from \"react\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { FormMessage } from \"./FormMessage.js\";\nimport { type FormMessageProps } from \"./types.js\";\n\n/**\n * @since 2.5.0\n */\nexport interface FormMessageContainerProps\n extends HTMLAttributes<HTMLDivElement> {\n /**\n * If the extension doesn't actually want to render the `FormMessage`\n * component, these props are optional. It kind of eliminates the whole\n * purpose of this component though.\n */\n messageProps?: PropsWithRef<FormMessageProps, HTMLDivElement>;\n}\n\n/**\n * Conditionally wraps the `children` in a `.rmd-form-message-container` wrapper\n * and renders the {@link FormMessage} component.\n *\n * @since 2.5.0\n */\nexport const FormMessageContainer = forwardRef<\n HTMLDivElement,\n FormMessageContainerProps\n>(function FormMessageContainer(props, ref) {\n const { className, children, messageProps, ...remaining } = props;\n if (!messageProps) {\n return <>{children}</>;\n }\n\n return (\n <div\n {...remaining}\n ref={ref}\n className={cnb(\"rmd-form-message-container\", className)}\n >\n {children}\n <FormMessage {...messageProps} />\n </div>\n );\n});\n"],"names":["cnb","forwardRef","FormMessage","FormMessageContainer","props","ref","className","children","messageProps","remaining","div"],"mappings":";AAAA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAASC,UAAU,QAA6B,QAAQ;AAExD,SAASC,WAAW,QAAQ,mBAAmB;AAgB/C;;;;;CAKC,GACD,OAAO,MAAMC,qCAAuBF,WAGlC,SAASE,qBAAqBC,KAAK,EAAEC,GAAG;IACxC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,YAAY,EAAE,GAAGC,WAAW,GAAGL;IAC5D,IAAI,CAACI,cAAc;QACjB,qBAAO;sBAAGD;;IACZ;IAEA,qBACE,MAACG;QACE,GAAGD,SAAS;QACbJ,KAAKA;QACLC,WAAWN,IAAI,8BAA8BM;;YAE5CC;0BACD,KAACL;gBAAa,GAAGM,YAAY;;;;AAGnC,GAAG"}
1
+ {"version":3,"sources":["../../src/form/FormMessageContainer.tsx"],"sourcesContent":["import { forwardRef, type HTMLAttributes } from \"react\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { FormMessage } from \"./FormMessage.js\";\nimport { formMessageContainer } from \"./formMessageContainerStyles.js\";\nimport { type FormMessageProps } from \"./types.js\";\n\n/**\n * @since 2.5.0\n */\nexport interface FormMessageContainerProps\n extends HTMLAttributes<HTMLDivElement> {\n /**\n * If the extension doesn't actually want to render the `FormMessage`\n * component, these props are optional. It kind of eliminates the whole\n * purpose of this component though.\n */\n messageProps?: PropsWithRef<FormMessageProps, HTMLDivElement>;\n}\n\n/**\n * Conditionally wraps the `children` in a `.rmd-form-message-container` wrapper\n * and renders the {@link FormMessage} component.\n *\n * @since 2.5.0\n */\nexport const FormMessageContainer = forwardRef<\n HTMLDivElement,\n FormMessageContainerProps\n>(function FormMessageContainer(props, ref) {\n const { className, children, messageProps, ...remaining } = props;\n if (!messageProps) {\n return <>{children}</>;\n }\n\n return (\n <div\n {...remaining}\n ref={ref}\n className={formMessageContainer({ className })}\n >\n {children}\n <FormMessage {...messageProps} />\n </div>\n );\n});\n"],"names":["forwardRef","FormMessage","formMessageContainer","FormMessageContainer","props","ref","className","children","messageProps","remaining","div"],"mappings":";AAAA,SAASA,UAAU,QAA6B,QAAQ;AAExD,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,oBAAoB,QAAQ,kCAAkC;AAgBvE;;;;;CAKC,GACD,OAAO,MAAMC,qCAAuBH,WAGlC,SAASG,qBAAqBC,KAAK,EAAEC,GAAG;IACxC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,YAAY,EAAE,GAAGC,WAAW,GAAGL;IAC5D,IAAI,CAACI,cAAc;QACjB,qBAAO;sBAAGD;;IACZ;IAEA,qBACE,MAACG;QACE,GAAGD,SAAS;QACbJ,KAAKA;QACLC,WAAWJ,qBAAqB;YAAEI;QAAU;;YAE3CC;0BACD,KAACN;gBAAa,GAAGO,YAAY;;;;AAGnC,GAAG"}
@@ -1,4 +1,5 @@
1
1
  import { type CSSProperties, type HTMLAttributes, type InputHTMLAttributes, type LabelHTMLAttributes, type ReactNode } from "react";
2
+ import { type ComponentWithRippleProps } from "../interaction/types.js";
2
3
  import { type PropsWithRef } from "../types.js";
3
4
  import { type InputToggleSize } from "./inputToggleStyles.js";
4
5
  import { type FormComponentStates, type FormMessageContainerExtension } from "./types.js";
@@ -114,7 +115,7 @@ export interface InputToggleLabelProps {
114
115
  /**
115
116
  * @since 6.0.0
116
117
  */
117
- export interface BaseInputToggleProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size">, FormMessageContainerExtension, FormComponentStates, InputToggleIconProps, InputToggleLabelProps {
118
+ export interface BaseInputToggleProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size">, FormMessageContainerExtension, FormComponentStates, InputToggleIconProps, InputToggleLabelProps, ComponentWithRippleProps {
118
119
  /**
119
120
  * @see https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing
120
121
  * @defaultValue `type === "checkbox" ? "off" : undefined`
@@ -13,10 +13,11 @@ import { Label } from "./Label.js";
13
13
  * @since 6.0.0 Now supports the `FormMessage` behavior and requires
14
14
  * different icons for each checked state.
15
15
  */ export const InputToggle = /*#__PURE__*/ forwardRef(function InputToggle(props, ref) {
16
- const { id: propId, type, label, labelProps, style, className, autoComplete = type === "checkbox" ? "off" : undefined, disableLabelGap = false, stacked = false, iconAfter = false, size = "normal", error = false, active = false, indeterminate = false, messageProps, messageContainerProps, icon, checkedIcon, indeterminateIcon, iconProps, iconStyle, iconClassName, onBlur, onClick, onKeyDown, onKeyUp, onMouseDown, onMouseLeave, onDragStart, onMouseUp, onTouchEnd, onTouchMove, onTouchStart, ...remaining } = props;
16
+ const { id: propId, type, label, labelProps, style, className, autoComplete = type === "checkbox" ? "off" : undefined, disableLabelGap = false, stacked = false, iconAfter = false, size = "normal", error = false, active = false, indeterminate = false, messageProps, messageContainerProps, icon, checkedIcon, indeterminateIcon, iconProps, iconStyle, iconClassName, onBlur, onClick, onKeyDown, onKeyUp, onMouseDown, onMouseLeave, onDragStart, onMouseUp, onTouchEnd, onTouchMove, onTouchStart, disableRipple, ...remaining } = props;
17
17
  const { disabled = false, checked } = props;
18
18
  const id = useEnsuredId(propId, type);
19
19
  const { pressedClassName, ripples, handlers } = useElementInteraction({
20
+ mode: disableRipple ? "none" : undefined,
20
21
  disabled,
21
22
  onBlur,
22
23
  onClick,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/form/InputToggle.tsx"],"sourcesContent":["\"use client\";\nimport { cnb } from \"cnbuilder\";\nimport {\n forwardRef,\n type CSSProperties,\n type HTMLAttributes,\n type InputHTMLAttributes,\n type LabelHTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport { useElementInteraction } from \"../interaction/useElementInteraction.js\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { FormMessageContainer } from \"./FormMessageContainer.js\";\nimport { InputToggleIcon } from \"./InputToggleIcon.js\";\nimport { Label } from \"./Label.js\";\nimport { type InputToggleSize } from \"./inputToggleStyles.js\";\nimport {\n type FormComponentStates,\n type FormMessageContainerExtension,\n} from \"./types.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface InputToggleIconProps {\n /**\n * @see {@link InputToggleSize}\n * @defaultValue `\"normal\"`\n */\n size?: InputToggleSize;\n\n /**\n * The icon to use while unchecked. This defaults to the unchecked\n * checkbox/radio icon from the `ICON_CONFIG`.\n *\n * @defaultValue `getIcon(props.type)`\n */\n icon?: ReactNode;\n\n /**\n * The icon to use while unchecked. This defaults to the unchecked\n * checkbox/radio icon from the `ICON_CONFIG`.\n *\n * @defaultValue `getIcon(``${props.type}Checked``)`\n */\n checkedIcon?: ReactNode;\n\n /**\n * Any props that should be passed to the `<span>` that surrounds the current\n * icon element.\n */\n iconProps?: PropsWithRef<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>;\n\n /**\n * Optional style to set on the `<span>` that surrounds the current icon\n * element.\n */\n iconStyle?: CSSProperties;\n\n /**\n * Optional className to set on the `<span>` that surrounds the current icon\n * element.\n */\n iconClassName?: string;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface InputToggleLabelProps {\n /**\n * An optional label to display with the checkbox. If this is omitted, it is\n * recommended to provide an `aria-label` for accessibility.\n */\n label?: ReactNode;\n\n /**\n * Any props that should be passed to the `<Label>` component.\n *\n * Note: If `style` or `className` are provided in this object, they will be\n * ignored. Use the top-level `style` and `className` props instead.\n *\n * @example\n * ```\n * // bad\n * labelProps={{\n * \"aria-label\": \"checkbox\",\n * style: { color: \"red\" },\n * className: \"custom\"\n * }}\n *\n * // good\n * style={{ color: \"red\" }}\n * className=\"custom\"\n * labelProps={{\n * \"aria-label\": \"checkbox\",\n * }}\n * ```\n */\n labelProps?: PropsWithRef<\n LabelHTMLAttributes<HTMLLabelElement>,\n HTMLLabelElement\n >;\n\n /**\n * @see {@link LabelClassNameOptions.gap}\n * @defaultValue `false`\n */\n disableLabelGap?: boolean;\n\n /**\n * Set this to `true` to swap the position of the {@link label} and the current\n * icon. This prop can be used with the {@link stacked} prop to change the\n * position if the icon and label:\n *\n * ____________________________________\n * | stacked | iconAfter | position |\n * ____________________________________\n * | | | icon label |\n * ____________________________________\n * | | X | label icon |\n * ____________________________________\n * | X | | icon |\n * | | | label |\n * ____________________________________\n * | X | X | label |\n * | | | icon |\n * ____________________________________\n *\n *\n * @defaultValue `false`\n */\n iconAfter?: boolean;\n\n /**\n * Set this to `true` if the label should be stacked instead of inline with\n * the current icon.\n *\n * @see {@link iconAfter}\n * @defaultValue `false`\n */\n stacked?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface BaseInputToggleProps\n extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\">,\n FormMessageContainerExtension,\n FormComponentStates,\n InputToggleIconProps,\n InputToggleLabelProps {\n /**\n * @see https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing\n * @defaultValue `type === \"checkbox\" ? \"off\" : undefined`\n */\n autoComplete?: string;\n}\n\n/**\n * @since 2.8.5\n * @since 6.0.0 Removed the `aria-controls` prop and added the\n * `indeterminateIcon` prop.\n */\nexport interface IndeterminateCheckboxProps {\n /**\n * Set this value to `true` if the checkbox is in an \"indeterminate\" state:\n *\n * - this checkbox controls the select all/select none behavior of other\n * checkboxes in a group\n * - at least one of the checkboxes have been checked\n * - the `checked` prop for this Checkbox should also be `true`\n *\n * You should normally use the `useCheckboxGroup` hook to handle this\n * behavior.\n *\n * @defaultValue `false`\n */\n indeterminate?: boolean;\n\n /**\n * The icon to display when the checkbox is checked and the\n * {@link indeterminate} prop is `true`.\n *\n * @defaultValue `getIcon(\"checkboxIndeterminate\")`\n * @since 6.0.0\n */\n indeterminateIcon?: ReactNode;\n}\n\nexport interface CheckboxProps\n extends BaseInputToggleProps,\n IndeterminateCheckboxProps {}\n\n/** @since 6.0.0 */\nexport interface CheckboxInputToggleProps extends CheckboxProps {\n type: \"checkbox\";\n}\n\nexport interface RadioProps extends BaseInputToggleProps {\n /**\n * The value for the radio button.\n *\n * @since 6.0.0 This is now optional and no longer supports\n * `string[]` since there isn't much of a use case for array values.\n */\n value?: string | number;\n}\n\n/** @since 6.0.0 */\nexport interface RadioInputToggleProps extends RadioProps {\n type: \"radio\";\n}\n\n/**\n * @since 6.0.0 Updated to be a union between\n * `CheckboxInputToggleProps` and `RadioInputToggleProps`\n */\nexport type InputToggleProps = CheckboxInputToggleProps | RadioInputToggleProps;\n\n/**\n * **Client Component**\n *\n * @since 6.0.0 Now supports the `FormMessage` behavior and requires\n * different icons for each checked state.\n */\nexport const InputToggle = forwardRef<HTMLInputElement, InputToggleProps>(\n function InputToggle(props, ref) {\n const {\n id: propId,\n type,\n label,\n labelProps,\n style,\n className,\n autoComplete = type === \"checkbox\" ? \"off\" : undefined,\n disableLabelGap = false,\n stacked = false,\n iconAfter = false,\n size = \"normal\",\n error = false,\n active = false,\n indeterminate = false,\n messageProps,\n messageContainerProps,\n icon,\n checkedIcon,\n indeterminateIcon,\n iconProps,\n iconStyle,\n iconClassName,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onDragStart,\n onMouseUp,\n onTouchEnd,\n onTouchMove,\n onTouchStart,\n ...remaining\n } = props as CheckboxInputToggleProps;\n const { disabled = false, checked } = props;\n\n const id = useEnsuredId(propId, type);\n const { pressedClassName, ripples, handlers } = useElementInteraction({\n disabled,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onDragStart,\n onMouseUp,\n onTouchEnd,\n onTouchMove,\n onTouchStart,\n });\n\n // set on the `remaining` object to bypass the eslint rule about\n // aria-checked not being valid for textbox role\n remaining[\"aria-checked\"] =\n (remaining[\"aria-checked\"] ?? indeterminate) ? \"mixed\" : undefined;\n\n return (\n <FormMessageContainer\n {...messageContainerProps}\n messageProps={messageProps}\n >\n <Label\n {...labelProps}\n gap={!disableLabelGap}\n style={style}\n stacked={stacked}\n reversed={!iconAfter}\n active={active}\n error={error}\n disabled={disabled}\n className={className}\n >\n {label}\n <InputToggleIcon\n style={iconStyle}\n {...iconProps}\n className={cnb(\n pressedClassName,\n iconClassName,\n iconProps?.className\n )}\n error={error}\n checked={checked}\n disabled={disabled}\n size={size}\n type={type}\n icon={icon}\n checkedIcon={checkedIcon}\n indeterminate={indeterminate}\n indeterminateIcon={indeterminateIcon}\n >\n <input\n {...remaining}\n {...handlers}\n autoComplete={autoComplete}\n id={id}\n ref={ref}\n type={type}\n className=\"rmd-hidden-input\"\n />\n {ripples}\n </InputToggleIcon>\n </Label>\n </FormMessageContainer>\n );\n }\n);\n"],"names":["cnb","forwardRef","useElementInteraction","useEnsuredId","FormMessageContainer","InputToggleIcon","Label","InputToggle","props","ref","id","propId","type","label","labelProps","style","className","autoComplete","undefined","disableLabelGap","stacked","iconAfter","size","error","active","indeterminate","messageProps","messageContainerProps","icon","checkedIcon","indeterminateIcon","iconProps","iconStyle","iconClassName","onBlur","onClick","onKeyDown","onKeyUp","onMouseDown","onMouseLeave","onDragStart","onMouseUp","onTouchEnd","onTouchMove","onTouchStart","remaining","disabled","checked","pressedClassName","ripples","handlers","gap","reversed","input"],"mappings":"AAAA;;AACA,SAASA,GAAG,QAAQ,YAAY;AAChC,SACEC,UAAU,QAML,QAAQ;AACf,SAASC,qBAAqB,QAAQ,0CAA0C;AAEhF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,oBAAoB,QAAQ,4BAA4B;AACjE,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,KAAK,QAAQ,aAAa;AA+MnC;;;;;CAKC,GACD,OAAO,MAAMC,4BAAcN,WACzB,SAASM,YAAYC,KAAK,EAAEC,GAAG;IAC7B,MAAM,EACJC,IAAIC,MAAM,EACVC,IAAI,EACJC,KAAK,EACLC,UAAU,EACVC,KAAK,EACLC,SAAS,EACTC,eAAeL,SAAS,aAAa,QAAQM,SAAS,EACtDC,kBAAkB,KAAK,EACvBC,UAAU,KAAK,EACfC,YAAY,KAAK,EACjBC,OAAO,QAAQ,EACfC,QAAQ,KAAK,EACbC,SAAS,KAAK,EACdC,gBAAgB,KAAK,EACrBC,YAAY,EACZC,qBAAqB,EACrBC,IAAI,EACJC,WAAW,EACXC,iBAAiB,EACjBC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,YAAY,EACZ,GAAGC,WACJ,GAAGrC;IACJ,MAAM,EAAEsC,WAAW,KAAK,EAAEC,OAAO,EAAE,GAAGvC;IAEtC,MAAME,KAAKP,aAAaQ,QAAQC;IAChC,MAAM,EAAEoC,gBAAgB,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGhD,sBAAsB;QACpE4C;QACAZ;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;IACF;IAEA,gEAAgE;IAChE,gDAAgD;IAChDC,SAAS,CAAC,eAAe,GACvB,AAACA,SAAS,CAAC,eAAe,IAAIpB,gBAAiB,UAAUP;IAE3D,qBACE,KAACd;QACE,GAAGuB,qBAAqB;QACzBD,cAAcA;kBAEd,cAAA,MAACpB;YACE,GAAGQ,UAAU;YACdqC,KAAK,CAAChC;YACNJ,OAAOA;YACPK,SAASA;YACTgC,UAAU,CAAC/B;YACXG,QAAQA;YACRD,OAAOA;YACPuB,UAAUA;YACV9B,WAAWA;;gBAEVH;8BACD,MAACR;oBACCU,OAAOiB;oBACN,GAAGD,SAAS;oBACbf,WAAWhB,IACTgD,kBACAf,eACAF,WAAWf;oBAEbO,OAAOA;oBACPwB,SAASA;oBACTD,UAAUA;oBACVxB,MAAMA;oBACNV,MAAMA;oBACNgB,MAAMA;oBACNC,aAAaA;oBACbJ,eAAeA;oBACfK,mBAAmBA;;sCAEnB,KAACuB;4BACE,GAAGR,SAAS;4BACZ,GAAGK,QAAQ;4BACZjC,cAAcA;4BACdP,IAAIA;4BACJD,KAAKA;4BACLG,MAAMA;4BACNI,WAAU;;wBAEXiC;;;;;;AAKX,GACA"}
1
+ {"version":3,"sources":["../../src/form/InputToggle.tsx"],"sourcesContent":["\"use client\";\nimport { cnb } from \"cnbuilder\";\nimport {\n forwardRef,\n type CSSProperties,\n type HTMLAttributes,\n type InputHTMLAttributes,\n type LabelHTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport { type ComponentWithRippleProps } from \"../interaction/types.js\";\nimport { useElementInteraction } from \"../interaction/useElementInteraction.js\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { FormMessageContainer } from \"./FormMessageContainer.js\";\nimport { InputToggleIcon } from \"./InputToggleIcon.js\";\nimport { Label } from \"./Label.js\";\nimport { type InputToggleSize } from \"./inputToggleStyles.js\";\nimport {\n type FormComponentStates,\n type FormMessageContainerExtension,\n} from \"./types.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface InputToggleIconProps {\n /**\n * @see {@link InputToggleSize}\n * @defaultValue `\"normal\"`\n */\n size?: InputToggleSize;\n\n /**\n * The icon to use while unchecked. This defaults to the unchecked\n * checkbox/radio icon from the `ICON_CONFIG`.\n *\n * @defaultValue `getIcon(props.type)`\n */\n icon?: ReactNode;\n\n /**\n * The icon to use while unchecked. This defaults to the unchecked\n * checkbox/radio icon from the `ICON_CONFIG`.\n *\n * @defaultValue `getIcon(``${props.type}Checked``)`\n */\n checkedIcon?: ReactNode;\n\n /**\n * Any props that should be passed to the `<span>` that surrounds the current\n * icon element.\n */\n iconProps?: PropsWithRef<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>;\n\n /**\n * Optional style to set on the `<span>` that surrounds the current icon\n * element.\n */\n iconStyle?: CSSProperties;\n\n /**\n * Optional className to set on the `<span>` that surrounds the current icon\n * element.\n */\n iconClassName?: string;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface InputToggleLabelProps {\n /**\n * An optional label to display with the checkbox. If this is omitted, it is\n * recommended to provide an `aria-label` for accessibility.\n */\n label?: ReactNode;\n\n /**\n * Any props that should be passed to the `<Label>` component.\n *\n * Note: If `style` or `className` are provided in this object, they will be\n * ignored. Use the top-level `style` and `className` props instead.\n *\n * @example\n * ```\n * // bad\n * labelProps={{\n * \"aria-label\": \"checkbox\",\n * style: { color: \"red\" },\n * className: \"custom\"\n * }}\n *\n * // good\n * style={{ color: \"red\" }}\n * className=\"custom\"\n * labelProps={{\n * \"aria-label\": \"checkbox\",\n * }}\n * ```\n */\n labelProps?: PropsWithRef<\n LabelHTMLAttributes<HTMLLabelElement>,\n HTMLLabelElement\n >;\n\n /**\n * @see {@link LabelClassNameOptions.gap}\n * @defaultValue `false`\n */\n disableLabelGap?: boolean;\n\n /**\n * Set this to `true` to swap the position of the {@link label} and the current\n * icon. This prop can be used with the {@link stacked} prop to change the\n * position if the icon and label:\n *\n * ____________________________________\n * | stacked | iconAfter | position |\n * ____________________________________\n * | | | icon label |\n * ____________________________________\n * | | X | label icon |\n * ____________________________________\n * | X | | icon |\n * | | | label |\n * ____________________________________\n * | X | X | label |\n * | | | icon |\n * ____________________________________\n *\n *\n * @defaultValue `false`\n */\n iconAfter?: boolean;\n\n /**\n * Set this to `true` if the label should be stacked instead of inline with\n * the current icon.\n *\n * @see {@link iconAfter}\n * @defaultValue `false`\n */\n stacked?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface BaseInputToggleProps\n extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\">,\n FormMessageContainerExtension,\n FormComponentStates,\n InputToggleIconProps,\n InputToggleLabelProps,\n ComponentWithRippleProps {\n /**\n * @see https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing\n * @defaultValue `type === \"checkbox\" ? \"off\" : undefined`\n */\n autoComplete?: string;\n}\n\n/**\n * @since 2.8.5\n * @since 6.0.0 Removed the `aria-controls` prop and added the\n * `indeterminateIcon` prop.\n */\nexport interface IndeterminateCheckboxProps {\n /**\n * Set this value to `true` if the checkbox is in an \"indeterminate\" state:\n *\n * - this checkbox controls the select all/select none behavior of other\n * checkboxes in a group\n * - at least one of the checkboxes have been checked\n * - the `checked` prop for this Checkbox should also be `true`\n *\n * You should normally use the `useCheckboxGroup` hook to handle this\n * behavior.\n *\n * @defaultValue `false`\n */\n indeterminate?: boolean;\n\n /**\n * The icon to display when the checkbox is checked and the\n * {@link indeterminate} prop is `true`.\n *\n * @defaultValue `getIcon(\"checkboxIndeterminate\")`\n * @since 6.0.0\n */\n indeterminateIcon?: ReactNode;\n}\n\nexport interface CheckboxProps\n extends BaseInputToggleProps,\n IndeterminateCheckboxProps {}\n\n/** @since 6.0.0 */\nexport interface CheckboxInputToggleProps extends CheckboxProps {\n type: \"checkbox\";\n}\n\nexport interface RadioProps extends BaseInputToggleProps {\n /**\n * The value for the radio button.\n *\n * @since 6.0.0 This is now optional and no longer supports\n * `string[]` since there isn't much of a use case for array values.\n */\n value?: string | number;\n}\n\n/** @since 6.0.0 */\nexport interface RadioInputToggleProps extends RadioProps {\n type: \"radio\";\n}\n\n/**\n * @since 6.0.0 Updated to be a union between\n * `CheckboxInputToggleProps` and `RadioInputToggleProps`\n */\nexport type InputToggleProps = CheckboxInputToggleProps | RadioInputToggleProps;\n\n/**\n * **Client Component**\n *\n * @since 6.0.0 Now supports the `FormMessage` behavior and requires\n * different icons for each checked state.\n */\nexport const InputToggle = forwardRef<HTMLInputElement, InputToggleProps>(\n function InputToggle(props, ref) {\n const {\n id: propId,\n type,\n label,\n labelProps,\n style,\n className,\n autoComplete = type === \"checkbox\" ? \"off\" : undefined,\n disableLabelGap = false,\n stacked = false,\n iconAfter = false,\n size = \"normal\",\n error = false,\n active = false,\n indeterminate = false,\n messageProps,\n messageContainerProps,\n icon,\n checkedIcon,\n indeterminateIcon,\n iconProps,\n iconStyle,\n iconClassName,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onDragStart,\n onMouseUp,\n onTouchEnd,\n onTouchMove,\n onTouchStart,\n disableRipple,\n ...remaining\n } = props as CheckboxInputToggleProps;\n const { disabled = false, checked } = props;\n\n const id = useEnsuredId(propId, type);\n const { pressedClassName, ripples, handlers } = useElementInteraction({\n mode: disableRipple ? \"none\" : undefined,\n disabled,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onDragStart,\n onMouseUp,\n onTouchEnd,\n onTouchMove,\n onTouchStart,\n });\n\n // set on the `remaining` object to bypass the eslint rule about\n // aria-checked not being valid for textbox role\n remaining[\"aria-checked\"] =\n (remaining[\"aria-checked\"] ?? indeterminate) ? \"mixed\" : undefined;\n\n return (\n <FormMessageContainer\n {...messageContainerProps}\n messageProps={messageProps}\n >\n <Label\n {...labelProps}\n gap={!disableLabelGap}\n style={style}\n stacked={stacked}\n reversed={!iconAfter}\n active={active}\n error={error}\n disabled={disabled}\n className={className}\n >\n {label}\n <InputToggleIcon\n style={iconStyle}\n {...iconProps}\n className={cnb(\n pressedClassName,\n iconClassName,\n iconProps?.className\n )}\n error={error}\n checked={checked}\n disabled={disabled}\n size={size}\n type={type}\n icon={icon}\n checkedIcon={checkedIcon}\n indeterminate={indeterminate}\n indeterminateIcon={indeterminateIcon}\n >\n <input\n {...remaining}\n {...handlers}\n autoComplete={autoComplete}\n id={id}\n ref={ref}\n type={type}\n className=\"rmd-hidden-input\"\n />\n {ripples}\n </InputToggleIcon>\n </Label>\n </FormMessageContainer>\n );\n }\n);\n"],"names":["cnb","forwardRef","useElementInteraction","useEnsuredId","FormMessageContainer","InputToggleIcon","Label","InputToggle","props","ref","id","propId","type","label","labelProps","style","className","autoComplete","undefined","disableLabelGap","stacked","iconAfter","size","error","active","indeterminate","messageProps","messageContainerProps","icon","checkedIcon","indeterminateIcon","iconProps","iconStyle","iconClassName","onBlur","onClick","onKeyDown","onKeyUp","onMouseDown","onMouseLeave","onDragStart","onMouseUp","onTouchEnd","onTouchMove","onTouchStart","disableRipple","remaining","disabled","checked","pressedClassName","ripples","handlers","mode","gap","reversed","input"],"mappings":"AAAA;;AACA,SAASA,GAAG,QAAQ,YAAY;AAChC,SACEC,UAAU,QAML,QAAQ;AAEf,SAASC,qBAAqB,QAAQ,0CAA0C;AAEhF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,oBAAoB,QAAQ,4BAA4B;AACjE,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,KAAK,QAAQ,aAAa;AAgNnC;;;;;CAKC,GACD,OAAO,MAAMC,4BAAcN,WACzB,SAASM,YAAYC,KAAK,EAAEC,GAAG;IAC7B,MAAM,EACJC,IAAIC,MAAM,EACVC,IAAI,EACJC,KAAK,EACLC,UAAU,EACVC,KAAK,EACLC,SAAS,EACTC,eAAeL,SAAS,aAAa,QAAQM,SAAS,EACtDC,kBAAkB,KAAK,EACvBC,UAAU,KAAK,EACfC,YAAY,KAAK,EACjBC,OAAO,QAAQ,EACfC,QAAQ,KAAK,EACbC,SAAS,KAAK,EACdC,gBAAgB,KAAK,EACrBC,YAAY,EACZC,qBAAqB,EACrBC,IAAI,EACJC,WAAW,EACXC,iBAAiB,EACjBC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,YAAY,EACZC,aAAa,EACb,GAAGC,WACJ,GAAGtC;IACJ,MAAM,EAAEuC,WAAW,KAAK,EAAEC,OAAO,EAAE,GAAGxC;IAEtC,MAAME,KAAKP,aAAaQ,QAAQC;IAChC,MAAM,EAAEqC,gBAAgB,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGjD,sBAAsB;QACpEkD,MAAMP,gBAAgB,SAAS3B;QAC/B6B;QACAb;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;IACF;IAEA,gEAAgE;IAChE,gDAAgD;IAChDE,SAAS,CAAC,eAAe,GACvB,AAACA,SAAS,CAAC,eAAe,IAAIrB,gBAAiB,UAAUP;IAE3D,qBACE,KAACd;QACE,GAAGuB,qBAAqB;QACzBD,cAAcA;kBAEd,cAAA,MAACpB;YACE,GAAGQ,UAAU;YACduC,KAAK,CAAClC;YACNJ,OAAOA;YACPK,SAASA;YACTkC,UAAU,CAACjC;YACXG,QAAQA;YACRD,OAAOA;YACPwB,UAAUA;YACV/B,WAAWA;;gBAEVH;8BACD,MAACR;oBACCU,OAAOiB;oBACN,GAAGD,SAAS;oBACbf,WAAWhB,IACTiD,kBACAhB,eACAF,WAAWf;oBAEbO,OAAOA;oBACPyB,SAASA;oBACTD,UAAUA;oBACVzB,MAAMA;oBACNV,MAAMA;oBACNgB,MAAMA;oBACNC,aAAaA;oBACbJ,eAAeA;oBACfK,mBAAmBA;;sCAEnB,KAACyB;4BACE,GAAGT,SAAS;4BACZ,GAAGK,QAAQ;4BACZlC,cAAcA;4BACdP,IAAIA;4BACJD,KAAKA;4BACLG,MAAMA;4BACNI,WAAU;;wBAEXkC;;;;;;AAKX,GACA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/form/InputToggleIcon.tsx"],"sourcesContent":["import { cnb } from \"cnbuilder\";\nimport { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { getIcon } from \"../icon/iconConfig.js\";\nimport { FORM_CONFIG } from \"./formConfig.js\";\nimport { inputToggle, type InputToggleSize } from \"./inputToggleStyles.js\";\n\n/**\n * @since 2.8.0\n * @since 6.0.0 Removed the `circle` and `overlay` props since they are no\n * longer needed. Added the `icon`, `disableEm`, `checkedIcon` and\n * `indeterminateIcon` props.\n * @internal\n */\nexport interface InputToggleIconProps extends HTMLAttributes<HTMLSpanElement> {\n type: \"checkbox\" | \"radio\";\n /**\n * Note: If this is `undefined` and the {@link FORM_CONFIG.uncontrolledToggles} is `false`,\n * the icon state won't work.\n */\n checked?: boolean;\n\n /**\n * The icon to display while {@link checked} is `false`.\n */\n icon?: ReactNode;\n\n /**\n * The icon to display while {@link checked} is `true` and\n * {@link indeterminate} is `false`.\n */\n checkedIcon?: ReactNode;\n\n /**\n * The icon to display while both {@link checked} and {@link indeterminate}\n * are `true`.\n */\n indeterminateIcon?: ReactNode;\n\n /** @defaultValue `\"normal\"` */\n size?: InputToggleSize;\n\n /** @defaultValue `false` */\n error?: boolean;\n\n /** @defaultValue `false` */\n disabled?: boolean;\n\n /** @defaultValue `false` */\n disableEm?: boolean;\n\n /** @defaultValue `false` */\n indeterminate?: boolean;\n}\n\n/**\n * @since 2.8.0\n * @since 6.0.0 Updated to use different icons for each checked state instead\n * of a css overlay hack.\n * @internal\n */\nexport const InputToggleIcon = forwardRef<\n HTMLSpanElement,\n InputToggleIconProps\n>(function InputToggleIcon(props, ref) {\n const {\n type,\n size = \"normal\",\n icon: propIcon,\n error,\n checked,\n children,\n disabled,\n indeterminate,\n className,\n disableEm = false,\n checkedIcon: propCheckedIcon,\n indeterminateIcon: propIndeterminateIcon,\n ...remaining\n } = props;\n const uncheckedIcon = getIcon(type, propIcon);\n const checkedIcon = getIcon(`${type}Checked`, propCheckedIcon);\n const indeterminateIcon = getIcon(\n \"checkboxIndeterminate\",\n propIndeterminateIcon\n );\n\n let icon: ReactNode;\n let active = false;\n const uncontrolled = typeof checked !== \"boolean\";\n if (!uncontrolled || !FORM_CONFIG.uncontrolledToggles) {\n active = !!checked && !error;\n icon = checked\n ? indeterminate\n ? indeterminateIcon\n : checkedIcon\n : uncheckedIcon;\n } else {\n icon = (\n <>\n {uncheckedIcon}\n {indeterminate ? indeterminateIcon : checkedIcon}\n </>\n );\n }\n\n return (\n <span\n {...remaining}\n ref={ref}\n className={cnb(\n inputToggle({\n em: !disableEm,\n size,\n type,\n error,\n active,\n disabled,\n uncontrolled,\n className,\n })\n )}\n >\n {children}\n {icon}\n </span>\n );\n});\n"],"names":["cnb","forwardRef","getIcon","FORM_CONFIG","inputToggle","InputToggleIcon","props","ref","type","size","icon","propIcon","error","checked","children","disabled","indeterminate","className","disableEm","checkedIcon","propCheckedIcon","indeterminateIcon","propIndeterminateIcon","remaining","uncheckedIcon","active","uncontrolled","uncontrolledToggles","span","em"],"mappings":";AAAA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAASC,UAAU,QAA6C,QAAQ;AACxE,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,WAAW,QAA8B,yBAAyB;AAkD3E;;;;;CAKC,GACD,OAAO,MAAMC,gCAAkBJ,WAG7B,SAASI,gBAAgBC,KAAK,EAAEC,GAAG;IACnC,MAAM,EACJC,IAAI,EACJC,OAAO,QAAQ,EACfC,MAAMC,QAAQ,EACdC,KAAK,EACLC,OAAO,EACPC,QAAQ,EACRC,QAAQ,EACRC,aAAa,EACbC,SAAS,EACTC,YAAY,KAAK,EACjBC,aAAaC,eAAe,EAC5BC,mBAAmBC,qBAAqB,EACxC,GAAGC,WACJ,GAAGjB;IACJ,MAAMkB,gBAAgBtB,QAAQM,MAAMG;IACpC,MAAMQ,cAAcjB,QAAQ,CAAC,EAAEM,KAAK,OAAO,CAAC,EAAEY;IAC9C,MAAMC,oBAAoBnB,QACxB,yBACAoB;IAGF,IAAIZ;IACJ,IAAIe,SAAS;IACb,MAAMC,eAAe,OAAOb,YAAY;IACxC,IAAI,CAACa,gBAAgB,CAACvB,YAAYwB,mBAAmB,EAAE;QACrDF,SAAS,CAAC,CAACZ,WAAW,CAACD;QACvBF,OAAOG,UACHG,gBACEK,oBACAF,cACFK;IACN,OAAO;QACLd,qBACE;;gBACGc;gBACAR,gBAAgBK,oBAAoBF;;;IAG3C;IAEA,qBACE,MAACS;QACE,GAAGL,SAAS;QACbhB,KAAKA;QACLU,WAAWjB,IACTI,YAAY;YACVyB,IAAI,CAACX;YACLT;YACAD;YACAI;YACAa;YACAV;YACAW;YACAT;QACF;;YAGDH;YACAJ;;;AAGP,GAAG"}
1
+ {"version":3,"sources":["../../src/form/InputToggleIcon.tsx"],"sourcesContent":["import { cnb } from \"cnbuilder\";\nimport { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { getIcon } from \"../icon/iconConfig.js\";\nimport { FORM_CONFIG } from \"./formConfig.js\";\nimport { inputToggle, type InputToggleSize } from \"./inputToggleStyles.js\";\n\n/**\n * @since 2.8.0\n * @since 6.0.0 Removed the `circle` and `overlay` props since they are no\n * longer needed. Added the `icon`, `disableEm`, `checkedIcon` and\n * `indeterminateIcon` props.\n * @internal\n */\nexport interface InputToggleIconProps extends HTMLAttributes<HTMLSpanElement> {\n type: \"checkbox\" | \"radio\";\n /**\n * Note: If this is `undefined` and the {@link FORM_CONFIG.uncontrolledToggles} is `false`,\n * the icon state won't work.\n */\n checked?: boolean;\n\n /**\n * The icon to display while {@link checked} is `false`.\n */\n icon?: ReactNode;\n\n /**\n * The icon to display while {@link checked} is `true` and\n * {@link indeterminate} is `false`.\n */\n checkedIcon?: ReactNode;\n\n /**\n * The icon to display while both {@link checked} and {@link indeterminate}\n * are `true`.\n */\n indeterminateIcon?: ReactNode;\n\n /** @defaultValue `\"normal\"` */\n size?: InputToggleSize;\n\n /** @defaultValue `false` */\n error?: boolean;\n\n /** @defaultValue `false` */\n disabled?: boolean;\n\n /** @defaultValue `false` */\n disableEm?: boolean;\n\n /** @defaultValue `false` */\n indeterminate?: boolean;\n}\n\n/**\n * @since 2.8.0\n * @since 6.0.0 Updated to use different icons for each checked state instead\n * of a css overlay hack.\n * @internal\n */\nexport const InputToggleIcon = forwardRef<\n HTMLSpanElement,\n InputToggleIconProps\n>(function InputToggleIcon(props, ref) {\n const {\n type,\n size = \"normal\",\n icon: propIcon,\n error,\n checked,\n children,\n disabled,\n indeterminate,\n className,\n disableEm = false,\n checkedIcon: propCheckedIcon,\n indeterminateIcon: propIndeterminateIcon,\n ...remaining\n } = props;\n const uncheckedIcon = getIcon(type, propIcon);\n const checkedIcon = getIcon(`${type}Checked`, propCheckedIcon);\n const indeterminateIcon = getIcon(\n \"checkboxIndeterminate\",\n propIndeterminateIcon\n );\n\n let icon: ReactNode;\n let active = false;\n const uncontrolled = typeof checked !== \"boolean\";\n if (!uncontrolled || !FORM_CONFIG.uncontrolledToggles) {\n active = !!checked && !error;\n icon = checked\n ? indeterminate\n ? indeterminateIcon\n : checkedIcon\n : uncheckedIcon;\n } else {\n icon = (\n <>\n {uncheckedIcon}\n {indeterminate ? indeterminateIcon : checkedIcon}\n </>\n );\n }\n\n return (\n <span\n {...remaining}\n ref={ref}\n className={cnb(\n inputToggle({\n em: !disableEm,\n size,\n type,\n error,\n active,\n disabled,\n uncontrolled,\n className,\n })\n )}\n >\n {children}\n {icon}\n </span>\n );\n});\n"],"names":["cnb","forwardRef","getIcon","FORM_CONFIG","inputToggle","InputToggleIcon","props","ref","type","size","icon","propIcon","error","checked","children","disabled","indeterminate","className","disableEm","checkedIcon","propCheckedIcon","indeterminateIcon","propIndeterminateIcon","remaining","uncheckedIcon","active","uncontrolled","uncontrolledToggles","span","em"],"mappings":";AAAA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAASC,UAAU,QAA6C,QAAQ;AACxE,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,WAAW,QAA8B,yBAAyB;AAkD3E;;;;;CAKC,GACD,OAAO,MAAMC,gCAAkBJ,WAG7B,SAASI,gBAAgBC,KAAK,EAAEC,GAAG;IACnC,MAAM,EACJC,IAAI,EACJC,OAAO,QAAQ,EACfC,MAAMC,QAAQ,EACdC,KAAK,EACLC,OAAO,EACPC,QAAQ,EACRC,QAAQ,EACRC,aAAa,EACbC,SAAS,EACTC,YAAY,KAAK,EACjBC,aAAaC,eAAe,EAC5BC,mBAAmBC,qBAAqB,EACxC,GAAGC,WACJ,GAAGjB;IACJ,MAAMkB,gBAAgBtB,QAAQM,MAAMG;IACpC,MAAMQ,cAAcjB,QAAQ,GAAGM,KAAK,OAAO,CAAC,EAAEY;IAC9C,MAAMC,oBAAoBnB,QACxB,yBACAoB;IAGF,IAAIZ;IACJ,IAAIe,SAAS;IACb,MAAMC,eAAe,OAAOb,YAAY;IACxC,IAAI,CAACa,gBAAgB,CAACvB,YAAYwB,mBAAmB,EAAE;QACrDF,SAAS,CAAC,CAACZ,WAAW,CAACD;QACvBF,OAAOG,UACHG,gBACEK,oBACAF,cACFK;IACN,OAAO;QACLd,qBACE;;gBACGc;gBACAR,gBAAgBK,oBAAoBF;;;IAG3C;IAEA,qBACE,MAACS;QACE,GAAGL,SAAS;QACbhB,KAAKA;QACLU,WAAWjB,IACTI,YAAY;YACVyB,IAAI,CAACX;YACLT;YACAD;YACAI;YACAa;YACAV;YACAW;YACAT;QACF;;YAGDH;YACAJ;;;AAGP,GAAG"}
@@ -7,7 +7,7 @@ const labelStyles = bem("rmd-label");
7
7
  /**
8
8
  * @since 6.0.0
9
9
  */ export function label(options) {
10
- const { className, gap = false, error = false, dense = false, active = false, stacked = false, reversed = false, disabled = false, floating = false, inactive = false, floatingActive = active } = options;
10
+ const { className, gap, error, dense, active, stacked, reversed, disabled, floating, inactive, floatingActive = active } = options;
11
11
  let textColor;
12
12
  if (disabled) {
13
13
  textColor = "text-disabled";
@@ -41,7 +41,7 @@ const labelStyles = bem("rmd-label");
41
41
  * @since 6.0.0 Updated to be usable externally and combines the
42
42
  * floating label styles instead of having separate components.
43
43
  */ export const Label = /*#__PURE__*/ forwardRef(function Label(props, ref) {
44
- const { gap = false, error = false, dense = false, active = false, stacked = false, reversed = false, disabled = false, floating = false, inactive = false, floatingActive = active, className, children, ...remaining } = props;
44
+ const { gap, error, dense, active, stacked, reversed, disabled, floating, inactive, floatingActive = active, className, children, ...remaining } = props;
45
45
  return /*#__PURE__*/ _jsx("label", {
46
46
  ref: ref,
47
47
  ...remaining,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/form/Label.tsx"],"sourcesContent":["import { cnb } from \"cnbuilder\";\nimport { forwardRef } from \"react\";\nimport { type TextColor, type ThemeColor, cssUtils } from \"../cssUtils.js\";\nimport { bem } from \"../utils/bem.js\";\nimport { type LabelClassNameOptions, type LabelProps } from \"./types.js\";\n\ndeclare module \"react\" {\n interface CSSProperties {\n \"--rmd-label-floating-top\"?: string | number;\n \"--rmd-label-left-offset\"?: string | number;\n \"--rmd-label-top-offset\"?: string | number;\n \"--rmd-label-active-padding\"?: string | number;\n \"--rmd-label-active-background-color\"?: string;\n }\n}\n\nconst labelStyles = bem(\"rmd-label\");\n\n/**\n * @since 6.0.0\n */\nexport function label(options: LabelClassNameOptions): string {\n const {\n className,\n gap = false,\n error = false,\n dense = false,\n active = false,\n stacked = false,\n reversed = false,\n disabled = false,\n floating = false,\n inactive = false,\n floatingActive = active,\n } = options;\n\n let textColor: TextColor | ThemeColor | undefined;\n if (disabled) {\n textColor = \"text-disabled\";\n } else if (error) {\n textColor = \"error\";\n } else if (floating && inactive) {\n textColor = \"text-secondary\";\n }\n\n return cnb(\n labelStyles({\n gap,\n error,\n dense,\n active,\n disabled,\n floating,\n stacked: stacked && !reversed,\n reversed: !stacked && reversed,\n \"stacked-reversed\": stacked && reversed,\n \"floating-dense\": floating && dense,\n \"floating-active\": floating && floatingActive,\n }),\n cssUtils({\n textColor,\n }),\n className\n );\n}\n\n/**\n * Most of the form components already use this `Label` internally when a\n * `label` prop has been provided. You should generally use this component if\n * you need to separate the label from an existing form component or you need to\n * create a custom implementation of a form component.\n *\n * @since 6.0.0 Updated to be usable externally and combines the\n * floating label styles instead of having separate components.\n */\nexport const Label = forwardRef<HTMLLabelElement, LabelProps>(\n function Label(props, ref) {\n const {\n gap = false,\n error = false,\n dense = false,\n active = false,\n stacked = false,\n reversed = false,\n disabled = false,\n floating = false,\n inactive = false,\n floatingActive = active,\n className,\n children,\n ...remaining\n } = props;\n\n return (\n <label\n ref={ref}\n {...remaining}\n className={label({\n gap,\n error,\n dense,\n active,\n stacked,\n reversed,\n disabled,\n floating,\n floatingActive,\n inactive,\n className,\n })}\n >\n {children}\n </label>\n );\n }\n);\n"],"names":["cnb","forwardRef","cssUtils","bem","labelStyles","label","options","className","gap","error","dense","active","stacked","reversed","disabled","floating","inactive","floatingActive","textColor","Label","props","ref","children","remaining"],"mappings":";AAAA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAA0CC,QAAQ,QAAQ,iBAAiB;AAC3E,SAASC,GAAG,QAAQ,kBAAkB;AAatC,MAAMC,cAAcD,IAAI;AAExB;;CAEC,GACD,OAAO,SAASE,MAAMC,OAA8B;IAClD,MAAM,EACJC,SAAS,EACTC,MAAM,KAAK,EACXC,QAAQ,KAAK,EACbC,QAAQ,KAAK,EACbC,SAAS,KAAK,EACdC,UAAU,KAAK,EACfC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,iBAAiBN,MAAM,EACxB,GAAGL;IAEJ,IAAIY;IACJ,IAAIJ,UAAU;QACZI,YAAY;IACd,OAAO,IAAIT,OAAO;QAChBS,YAAY;IACd,OAAO,IAAIH,YAAYC,UAAU;QAC/BE,YAAY;IACd;IAEA,OAAOlB,IACLI,YAAY;QACVI;QACAC;QACAC;QACAC;QACAG;QACAC;QACAH,SAASA,WAAW,CAACC;QACrBA,UAAU,CAACD,WAAWC;QACtB,oBAAoBD,WAAWC;QAC/B,kBAAkBE,YAAYL;QAC9B,mBAAmBK,YAAYE;IACjC,IACAf,SAAS;QACPgB;IACF,IACAX;AAEJ;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMY,sBAAQlB,WACnB,SAASkB,MAAMC,KAAK,EAAEC,GAAG;IACvB,MAAM,EACJb,MAAM,KAAK,EACXC,QAAQ,KAAK,EACbC,QAAQ,KAAK,EACbC,SAAS,KAAK,EACdC,UAAU,KAAK,EACfC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,iBAAiBN,MAAM,EACvBJ,SAAS,EACTe,QAAQ,EACR,GAAGC,WACJ,GAAGH;IAEJ,qBACE,KAACf;QACCgB,KAAKA;QACJ,GAAGE,SAAS;QACbhB,WAAWF,MAAM;YACfG;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAE;YACAD;YACAT;QACF;kBAECe;;AAGP,GACA"}
1
+ {"version":3,"sources":["../../src/form/Label.tsx"],"sourcesContent":["import { cnb } from \"cnbuilder\";\nimport { forwardRef } from \"react\";\nimport { type TextColor, type ThemeColor, cssUtils } from \"../cssUtils.js\";\nimport { bem } from \"../utils/bem.js\";\nimport { type LabelClassNameOptions, type LabelProps } from \"./types.js\";\n\ndeclare module \"react\" {\n interface CSSProperties {\n \"--rmd-label-floating-top\"?: string | number;\n \"--rmd-label-left-offset\"?: string | number;\n \"--rmd-label-top-offset\"?: string | number;\n \"--rmd-label-active-padding\"?: string | number;\n \"--rmd-label-active-background-color\"?: string;\n }\n}\n\nconst labelStyles = bem(\"rmd-label\");\n\n/**\n * @since 6.0.0\n */\nexport function label(options: LabelClassNameOptions): string {\n const {\n className,\n gap,\n error,\n dense,\n active,\n stacked,\n reversed,\n disabled,\n floating,\n inactive,\n floatingActive = active,\n } = options;\n\n let textColor: TextColor | ThemeColor | undefined;\n if (disabled) {\n textColor = \"text-disabled\";\n } else if (error) {\n textColor = \"error\";\n } else if (floating && inactive) {\n textColor = \"text-secondary\";\n }\n\n return cnb(\n labelStyles({\n gap,\n error,\n dense,\n active,\n disabled,\n floating,\n stacked: stacked && !reversed,\n reversed: !stacked && reversed,\n \"stacked-reversed\": stacked && reversed,\n \"floating-dense\": floating && dense,\n \"floating-active\": floating && floatingActive,\n }),\n cssUtils({\n textColor,\n }),\n className\n );\n}\n\n/**\n * Most of the form components already use this `Label` internally when a\n * `label` prop has been provided. You should generally use this component if\n * you need to separate the label from an existing form component or you need to\n * create a custom implementation of a form component.\n *\n * @since 6.0.0 Updated to be usable externally and combines the\n * floating label styles instead of having separate components.\n */\nexport const Label = forwardRef<HTMLLabelElement, LabelProps>(\n function Label(props, ref) {\n const {\n gap,\n error,\n dense,\n active,\n stacked,\n reversed,\n disabled,\n floating,\n inactive,\n floatingActive = active,\n className,\n children,\n ...remaining\n } = props;\n\n return (\n <label\n ref={ref}\n {...remaining}\n className={label({\n gap,\n error,\n dense,\n active,\n stacked,\n reversed,\n disabled,\n floating,\n floatingActive,\n inactive,\n className,\n })}\n >\n {children}\n </label>\n );\n }\n);\n"],"names":["cnb","forwardRef","cssUtils","bem","labelStyles","label","options","className","gap","error","dense","active","stacked","reversed","disabled","floating","inactive","floatingActive","textColor","Label","props","ref","children","remaining"],"mappings":";AAAA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAA0CC,QAAQ,QAAQ,iBAAiB;AAC3E,SAASC,GAAG,QAAQ,kBAAkB;AAatC,MAAMC,cAAcD,IAAI;AAExB;;CAEC,GACD,OAAO,SAASE,MAAMC,OAA8B;IAClD,MAAM,EACJC,SAAS,EACTC,GAAG,EACHC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,iBAAiBN,MAAM,EACxB,GAAGL;IAEJ,IAAIY;IACJ,IAAIJ,UAAU;QACZI,YAAY;IACd,OAAO,IAAIT,OAAO;QAChBS,YAAY;IACd,OAAO,IAAIH,YAAYC,UAAU;QAC/BE,YAAY;IACd;IAEA,OAAOlB,IACLI,YAAY;QACVI;QACAC;QACAC;QACAC;QACAG;QACAC;QACAH,SAASA,WAAW,CAACC;QACrBA,UAAU,CAACD,WAAWC;QACtB,oBAAoBD,WAAWC;QAC/B,kBAAkBE,YAAYL;QAC9B,mBAAmBK,YAAYE;IACjC,IACAf,SAAS;QACPgB;IACF,IACAX;AAEJ;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMY,sBAAQlB,WACnB,SAASkB,MAAMC,KAAK,EAAEC,GAAG;IACvB,MAAM,EACJb,GAAG,EACHC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,iBAAiBN,MAAM,EACvBJ,SAAS,EACTe,QAAQ,EACR,GAAGC,WACJ,GAAGH;IAEJ,qBACE,KAACf;QACCgB,KAAKA;QACJ,GAAGE,SAAS;QACbhB,WAAWF,MAAM;YACfG;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAE;YACAD;YACAT;QACF;kBAECe;;AAGP,GACA"}
@@ -0,0 +1,24 @@
1
+ import { type Dispatch, type ReactElement, type ReactNode, type Ref } from "react";
2
+ import { type MenuProps } from "../menu/Menu.js";
3
+ import { type LabelRequiredForA11y } from "../types.js";
4
+ import { type OptionSelectedIconProps } from "./Option.js";
5
+ /**
6
+ * @since 6.0.0
7
+ * @internal
8
+ */
9
+ export type ListboxValue = string | number | null | Record<string, unknown>;
10
+ /**
11
+ * @since 6.0.0
12
+ * @internal
13
+ */
14
+ export interface ListboxProps<Value extends ListboxValue> extends MenuProps, OptionSelectedIconProps {
15
+ nodeRef?: Ref<HTMLDivElement>;
16
+ value: Value | readonly NonNullable<ListboxValue>[];
17
+ setValue: Dispatch<NonNullable<Value>>;
18
+ children: ReactNode;
19
+ }
20
+ /**
21
+ * @since 6.0.0
22
+ * @internal
23
+ */
24
+ export declare function Listbox<T extends ListboxValue>(props: LabelRequiredForA11y<ListboxProps<T>>): ReactElement;