@basic-ui/core 0.0.50 → 0.0.52

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 (337) hide show
  1. package/README.md +3 -3
  2. package/build/cjs/index.js +106 -92
  3. package/build/cjs/index.js.map +1 -1
  4. package/build/esm/Accordion/Accordion.d.ts +9 -9
  5. package/build/esm/Accordion/Accordion.js.map +1 -1
  6. package/build/esm/Accordion/AccordionBody.d.ts +6 -6
  7. package/build/esm/Accordion/AccordionBody.js.map +1 -1
  8. package/build/esm/Accordion/AccordionHeader.d.ts +7 -7
  9. package/build/esm/Accordion/AccordionHeader.js.map +1 -1
  10. package/build/esm/Accordion/AccordionItem.d.ts +9 -9
  11. package/build/esm/Accordion/AccordionItem.js.map +1 -1
  12. package/build/esm/Accordion/context.d.ts +19 -19
  13. package/build/esm/Accordion/context.js.map +1 -1
  14. package/build/esm/Accordion/index.d.ts +4 -4
  15. package/build/esm/Accordion/index.js.map +1 -1
  16. package/build/esm/Accordion/scopeQuery.d.ts +2 -2
  17. package/build/esm/Accordion/scopeQuery.js.map +1 -1
  18. package/build/esm/CheckBox/CheckBox.d.ts +7 -7
  19. package/build/esm/CheckBox/CheckBox.js.map +1 -1
  20. package/build/esm/CheckBox/index.d.ts +1 -1
  21. package/build/esm/CheckBox/index.js.map +1 -1
  22. package/build/esm/ComboBox/Combobox.d.ts +18 -18
  23. package/build/esm/ComboBox/Combobox.js.map +1 -1
  24. package/build/esm/ComboBox/ComboboxButton.d.ts +9 -9
  25. package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
  26. package/build/esm/ComboBox/ComboboxInput.d.ts +17 -17
  27. package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
  28. package/build/esm/ComboBox/ComboboxLabel.d.ts +7 -7
  29. package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
  30. package/build/esm/ComboBox/ComboboxList.d.ts +8 -8
  31. package/build/esm/ComboBox/ComboboxList.js.map +1 -1
  32. package/build/esm/ComboBox/ComboboxOption.d.ts +11 -11
  33. package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
  34. package/build/esm/ComboBox/ComboboxPopover.d.ts +9 -9
  35. package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
  36. package/build/esm/ComboBox/cities.d.ts +5 -5
  37. package/build/esm/ComboBox/cities.js.map +1 -1
  38. package/build/esm/ComboBox/context.d.ts +30 -30
  39. package/build/esm/ComboBox/context.js.map +1 -1
  40. package/build/esm/ComboBox/hooks.d.ts +37 -37
  41. package/build/esm/ComboBox/hooks.js.map +1 -1
  42. package/build/esm/ComboBox/index.d.ts +8 -8
  43. package/build/esm/ComboBox/index.js.map +1 -1
  44. package/build/esm/ComboBox/makeHash.d.ts +1 -1
  45. package/build/esm/ComboBox/makeHash.js.map +1 -1
  46. package/build/esm/ComboBox/scopeQuery.d.ts +1 -1
  47. package/build/esm/ComboBox/scopeQuery.js.map +1 -1
  48. package/build/esm/FocusLock/FocusLock.d.ts +9 -9
  49. package/build/esm/FocusLock/FocusLock.js.map +1 -1
  50. package/build/esm/FocusLock/index.d.ts +1 -1
  51. package/build/esm/FocusLock/index.js.map +1 -1
  52. package/build/esm/FocusLock/tabUtils.d.ts +3 -3
  53. package/build/esm/FocusLock/tabUtils.js.map +1 -1
  54. package/build/esm/FocusLock/useFocusLock.d.ts +7 -7
  55. package/build/esm/FocusLock/useFocusLock.js.map +1 -1
  56. package/build/esm/List/List.d.ts +7 -7
  57. package/build/esm/List/List.js.map +1 -1
  58. package/build/esm/List/ListItem.d.ts +7 -7
  59. package/build/esm/List/ListItem.js.map +1 -1
  60. package/build/esm/List/context.d.ts +4 -4
  61. package/build/esm/List/context.js.map +1 -1
  62. package/build/esm/List/index.d.ts +2 -2
  63. package/build/esm/List/index.js.map +1 -1
  64. package/build/esm/Menu/ContextMenuTrigger.d.ts +11 -11
  65. package/build/esm/Menu/ContextMenuTrigger.js.map +1 -1
  66. package/build/esm/Menu/Menu.d.ts +10 -10
  67. package/build/esm/Menu/Menu.js.map +1 -1
  68. package/build/esm/Menu/MenuButton.d.ts +11 -11
  69. package/build/esm/Menu/MenuButton.js.map +1 -1
  70. package/build/esm/Menu/MenuItem.d.ts +8 -8
  71. package/build/esm/Menu/MenuItem.js +1 -0
  72. package/build/esm/Menu/MenuItem.js.map +1 -1
  73. package/build/esm/Menu/MenuList.d.ts +7 -7
  74. package/build/esm/Menu/MenuList.js +17 -4
  75. package/build/esm/Menu/MenuList.js.map +1 -1
  76. package/build/esm/Menu/MenuPopover.d.ts +8 -8
  77. package/build/esm/Menu/MenuPopover.js.map +1 -1
  78. package/build/esm/Menu/context.d.ts +25 -25
  79. package/build/esm/Menu/context.js.map +1 -1
  80. package/build/esm/Menu/fixtures/countryList.d.ts +1 -1
  81. package/build/esm/Menu/fixtures/countryList.js.map +1 -1
  82. package/build/esm/Menu/index.d.ts +6 -6
  83. package/build/esm/Menu/index.js.map +1 -1
  84. package/build/esm/Menu/scope.d.ts +1 -1
  85. package/build/esm/Menu/scope.js.map +1 -1
  86. package/build/esm/Modal/Modal.d.ts +9 -9
  87. package/build/esm/Modal/Modal.js.map +1 -1
  88. package/build/esm/Modal/ModalBackdrop.d.ts +10 -10
  89. package/build/esm/Modal/ModalBackdrop.js.map +1 -1
  90. package/build/esm/Modal/index.d.ts +2 -2
  91. package/build/esm/Modal/index.js.map +1 -1
  92. package/build/esm/Popper/Popper.d.ts +35 -35
  93. package/build/esm/Popper/Popper.js.map +1 -1
  94. package/build/esm/Popper/PopperArrow.d.ts +6 -6
  95. package/build/esm/Popper/PopperArrow.js.map +1 -1
  96. package/build/esm/Popper/context.d.ts +6 -6
  97. package/build/esm/Popper/context.js.map +1 -1
  98. package/build/esm/Popper/index.d.ts +3 -3
  99. package/build/esm/Popper/index.js.map +1 -1
  100. package/build/esm/Portal/Portal.d.ts +6 -6
  101. package/build/esm/Portal/Portal.js.map +1 -1
  102. package/build/esm/Portal/index.d.ts +1 -1
  103. package/build/esm/Portal/index.js.map +1 -1
  104. package/build/esm/RadioButton/RadioButton.d.ts +10 -10
  105. package/build/esm/RadioButton/RadioButton.js.map +1 -1
  106. package/build/esm/RadioButton/RadioGroup.d.ts +12 -12
  107. package/build/esm/RadioButton/RadioGroup.js.map +1 -1
  108. package/build/esm/RadioButton/context.d.ts +9 -9
  109. package/build/esm/RadioButton/context.js.map +1 -1
  110. package/build/esm/RadioButton/index.d.ts +2 -2
  111. package/build/esm/RadioButton/index.js.map +1 -1
  112. package/build/esm/SkipNav/SkipNav.d.ts +7 -7
  113. package/build/esm/SkipNav/SkipNav.js.map +1 -1
  114. package/build/esm/SkipNav/index.d.ts +1 -1
  115. package/build/esm/SkipNav/index.js.map +1 -1
  116. package/build/esm/Slider/Slider.d.ts +197 -197
  117. package/build/esm/Slider/Slider.js +82 -82
  118. package/build/esm/Slider/Slider.js.map +1 -1
  119. package/build/esm/Slider/index.d.ts +1 -1
  120. package/build/esm/Slider/index.js.map +1 -1
  121. package/build/esm/Spinner/Spinner.d.ts +12 -12
  122. package/build/esm/Spinner/Spinner.js.map +1 -1
  123. package/build/esm/Spinner/SpinnerButton.d.ts +8 -8
  124. package/build/esm/Spinner/SpinnerButton.js.map +1 -1
  125. package/build/esm/Spinner/context.d.ts +12 -12
  126. package/build/esm/Spinner/context.js.map +1 -1
  127. package/build/esm/Spinner/index.d.ts +2 -2
  128. package/build/esm/Spinner/index.js.map +1 -1
  129. package/build/esm/Tabs/Tab.d.ts +7 -7
  130. package/build/esm/Tabs/Tab.js.map +1 -1
  131. package/build/esm/Tabs/TabList.d.ts +9 -9
  132. package/build/esm/Tabs/TabList.js.map +1 -1
  133. package/build/esm/Tabs/TabPanel.d.ts +8 -8
  134. package/build/esm/Tabs/TabPanel.js.map +1 -1
  135. package/build/esm/Tabs/TabPanels.d.ts +8 -8
  136. package/build/esm/Tabs/TabPanels.js.map +1 -1
  137. package/build/esm/Tabs/Tabs.d.ts +10 -10
  138. package/build/esm/Tabs/Tabs.js.map +1 -1
  139. package/build/esm/Tabs/context.d.ts +17 -17
  140. package/build/esm/Tabs/context.js.map +1 -1
  141. package/build/esm/Tabs/index.d.ts +5 -5
  142. package/build/esm/Tabs/index.js.map +1 -1
  143. package/build/esm/Tabs/scopeQuery.d.ts +1 -1
  144. package/build/esm/Tabs/scopeQuery.js.map +1 -1
  145. package/build/esm/Tooltip/Tooltip.d.ts +10 -10
  146. package/build/esm/Tooltip/Tooltip.js.map +1 -1
  147. package/build/esm/Tooltip/index.d.ts +1 -1
  148. package/build/esm/Tooltip/index.js.map +1 -1
  149. package/build/esm/Tooltip/stateMachine.d.ts +28 -28
  150. package/build/esm/Tooltip/stateMachine.js.map +1 -1
  151. package/build/esm/Tooltip/useTooltip.d.ts +10 -10
  152. package/build/esm/Tooltip/useTooltip.js.map +1 -1
  153. package/build/esm/hooks/index.d.ts +13 -13
  154. package/build/esm/hooks/index.js.map +1 -1
  155. package/build/esm/hooks/useAutoFocus.d.ts +2 -2
  156. package/build/esm/hooks/useAutoFocus.js.map +1 -1
  157. package/build/esm/hooks/useChildrenCounter.d.ts +7 -7
  158. package/build/esm/hooks/useChildrenCounter.js.map +1 -1
  159. package/build/esm/hooks/useControlledState.d.ts +3 -3
  160. package/build/esm/hooks/useControlledState.js +1 -1
  161. package/build/esm/hooks/useControlledState.js.map +1 -1
  162. package/build/esm/hooks/useFocusReturn.d.ts +2 -2
  163. package/build/esm/hooks/useFocusReturn.js.map +1 -1
  164. package/build/esm/hooks/useFocusState.d.ts +11 -11
  165. package/build/esm/hooks/useFocusState.js.map +1 -1
  166. package/build/esm/hooks/useGestureHandlers.d.ts +52 -52
  167. package/build/esm/hooks/useGestureHandlers.js.map +1 -1
  168. package/build/esm/hooks/useMeasure.d.ts +7 -7
  169. package/build/esm/hooks/useMeasure.js.map +1 -1
  170. package/build/esm/hooks/useOnClickOutside.d.ts +2 -2
  171. package/build/esm/hooks/useOnClickOutside.js.map +1 -1
  172. package/build/esm/hooks/useOnKeyDown.d.ts +1 -1
  173. package/build/esm/hooks/useOnKeyDown.js.map +1 -1
  174. package/build/esm/hooks/useReducerMachine.d.ts +24 -24
  175. package/build/esm/hooks/useReducerMachine.js.map +1 -1
  176. package/build/esm/hooks/useRemoveBodyScroll.d.ts +2 -2
  177. package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
  178. package/build/esm/hooks/useScope.d.ts +11 -11
  179. package/build/esm/hooks/useScope.js.map +1 -1
  180. package/build/esm/hooks/useThrottle.d.ts +1 -1
  181. package/build/esm/hooks/useThrottle.js.map +1 -1
  182. package/build/esm/index.d.ts +15 -15
  183. package/build/esm/index.js.map +1 -1
  184. package/build/esm/utils/assign-ref.d.ts +3 -3
  185. package/build/esm/utils/assign-ref.js.map +1 -1
  186. package/build/esm/utils/can-use-dom.d.ts +1 -1
  187. package/build/esm/utils/can-use-dom.js.map +1 -1
  188. package/build/esm/utils/clamp.d.ts +1 -1
  189. package/build/esm/utils/clamp.js.map +1 -1
  190. package/build/esm/utils/context.d.ts +7 -7
  191. package/build/esm/utils/context.js.map +1 -1
  192. package/build/esm/utils/create-subscription.d.ts +4 -4
  193. package/build/esm/utils/create-subscription.js.map +1 -1
  194. package/build/esm/utils/get-circular-index.d.ts +1 -1
  195. package/build/esm/utils/get-circular-index.js.map +1 -1
  196. package/build/esm/utils/index.d.ts +10 -10
  197. package/build/esm/utils/index.js.map +1 -1
  198. package/build/esm/utils/is-right-click.d.ts +6 -6
  199. package/build/esm/utils/is-right-click.js +4 -4
  200. package/build/esm/utils/is-right-click.js.map +1 -1
  201. package/build/esm/utils/owner-document.d.ts +7 -7
  202. package/build/esm/utils/owner-document.js +5 -5
  203. package/build/esm/utils/owner-document.js.map +1 -1
  204. package/build/esm/utils/polymorphic.d.ts +39 -39
  205. package/build/esm/utils/polymorphic.js.map +1 -1
  206. package/build/esm/utils/rubber-band-clamp.d.ts +2 -2
  207. package/build/esm/utils/rubber-band-clamp.js.map +1 -1
  208. package/build/esm/utils/use-stable-callback.d.ts +16 -16
  209. package/build/esm/utils/use-stable-callback.js +16 -16
  210. package/build/esm/utils/use-stable-callback.js.map +1 -1
  211. package/build/esm/utils/wrap-event.d.ts +3 -3
  212. package/build/esm/utils/wrap-event.js.map +1 -1
  213. package/build/tsconfig-build.tsbuildinfo +1 -1
  214. package/package.json +2 -2
  215. package/src/Accordion/Accordion.story.tsx +74 -74
  216. package/src/Accordion/Accordion.tsx +59 -59
  217. package/src/Accordion/AccordionBody.tsx +52 -52
  218. package/src/Accordion/AccordionHeader.tsx +167 -167
  219. package/src/Accordion/AccordionItem.tsx +50 -50
  220. package/src/Accordion/context.ts +37 -37
  221. package/src/Accordion/index.ts +4 -4
  222. package/src/Accordion/scopeQuery.ts +7 -7
  223. package/src/Accordion/styles.css +21 -21
  224. package/src/CheckBox/CheckBox.tsx +41 -41
  225. package/src/CheckBox/index.ts +1 -1
  226. package/src/ComboBox/ComboBox.story.tsx +120 -120
  227. package/src/ComboBox/Combobox.tsx +148 -148
  228. package/src/ComboBox/ComboboxButton.tsx +61 -61
  229. package/src/ComboBox/ComboboxInput.tsx +187 -187
  230. package/src/ComboBox/ComboboxLabel.tsx +33 -33
  231. package/src/ComboBox/ComboboxList.tsx +47 -47
  232. package/src/ComboBox/ComboboxOption.tsx +111 -111
  233. package/src/ComboBox/ComboboxPopover.tsx +64 -64
  234. package/src/ComboBox/cities.ts +23194 -23194
  235. package/src/ComboBox/context.ts +35 -35
  236. package/src/ComboBox/hooks.tsx +451 -451
  237. package/src/ComboBox/index.ts +8 -8
  238. package/src/ComboBox/makeHash.ts +19 -19
  239. package/src/ComboBox/scopeQuery.ts +6 -6
  240. package/src/ComboBox/styles.css +32 -32
  241. package/src/FocusLock/FocusLock.tsx +66 -66
  242. package/src/FocusLock/index.ts +1 -1
  243. package/src/FocusLock/tabUtils.ts +40 -40
  244. package/src/FocusLock/useFocusLock.ts +56 -56
  245. package/src/List/List.story.tsx +18 -18
  246. package/src/List/List.tsx +17 -17
  247. package/src/List/ListItem.tsx +23 -23
  248. package/src/List/context.ts +19 -19
  249. package/src/List/index.ts +2 -2
  250. package/src/Menu/ContextMenu.story.tsx +73 -73
  251. package/src/Menu/ContextMenuTrigger.tsx +76 -76
  252. package/src/Menu/Menu.story.tsx +160 -160
  253. package/src/Menu/Menu.tsx +83 -83
  254. package/src/Menu/MenuButton.tsx +83 -83
  255. package/src/Menu/MenuComplex.story.tsx +58 -58
  256. package/src/Menu/MenuItem.tsx +88 -87
  257. package/src/Menu/MenuList.tsx +254 -243
  258. package/src/Menu/MenuPopover.tsx +35 -35
  259. package/src/Menu/context.ts +44 -44
  260. package/src/Menu/fixtures/countryList.ts +198 -198
  261. package/src/Menu/index.ts +6 -6
  262. package/src/Menu/scope.ts +7 -7
  263. package/src/Menu/styles.css +42 -42
  264. package/src/Modal/Modal.story.tsx +258 -258
  265. package/src/Modal/Modal.tsx +48 -48
  266. package/src/Modal/ModalBackdrop.tsx +78 -78
  267. package/src/Modal/NavDrawer.story.tsx +158 -158
  268. package/src/Modal/index.ts +2 -2
  269. package/src/Modal/styles.css +46 -46
  270. package/src/Popper/Popper.story.tsx +263 -263
  271. package/src/Popper/Popper.tsx +154 -154
  272. package/src/Popper/PopperArrow.tsx +35 -35
  273. package/src/Popper/context.ts +10 -10
  274. package/src/Popper/index.ts +3 -3
  275. package/src/Popper/styles.css +60 -60
  276. package/src/Portal/Portal.tsx +20 -20
  277. package/src/Portal/index.ts +1 -1
  278. package/src/RadioButton/RadioButton.story.tsx +77 -77
  279. package/src/RadioButton/RadioButton.tsx +55 -55
  280. package/src/RadioButton/RadioGroup.tsx +60 -60
  281. package/src/RadioButton/context.ts +17 -17
  282. package/src/RadioButton/index.ts +2 -2
  283. package/src/SkipNav/SkipNav.tsx +16 -16
  284. package/src/SkipNav/index.tsx +1 -1
  285. package/src/Slider/Slider.story.tsx +45 -45
  286. package/src/Slider/Slider.tsx +1120 -1120
  287. package/src/Slider/index.ts +1 -1
  288. package/src/Slider/styles.css +131 -131
  289. package/src/Spinner/Spinner.story.tsx +31 -31
  290. package/src/Spinner/Spinner.tsx +117 -117
  291. package/src/Spinner/SpinnerButton.tsx +54 -54
  292. package/src/Spinner/context.ts +20 -20
  293. package/src/Spinner/index.ts +2 -2
  294. package/src/Spinner/styles.css +23 -23
  295. package/src/Tabs/Tab.story.tsx +80 -80
  296. package/src/Tabs/Tab.tsx +136 -136
  297. package/src/Tabs/TabList.tsx +71 -71
  298. package/src/Tabs/TabPanel.tsx +53 -53
  299. package/src/Tabs/TabPanels.tsx +30 -30
  300. package/src/Tabs/Tabs.tsx +46 -46
  301. package/src/Tabs/context.ts +30 -30
  302. package/src/Tabs/index.tsx +5 -5
  303. package/src/Tabs/scopeQuery.ts +6 -6
  304. package/src/Tooltip/Tooltip.story.tsx +61 -61
  305. package/src/Tooltip/Tooltip.tsx +50 -50
  306. package/src/Tooltip/index.ts +1 -1
  307. package/src/Tooltip/stateMachine.ts +192 -192
  308. package/src/Tooltip/styles.css +17 -17
  309. package/src/Tooltip/useTooltip.ts +136 -136
  310. package/src/hooks/index.ts +13 -13
  311. package/src/hooks/useAutoFocus.ts +22 -22
  312. package/src/hooks/useChildrenCounter.ts +51 -51
  313. package/src/hooks/useControlledState.ts +3 -3
  314. package/src/hooks/useFocusReturn.ts +43 -43
  315. package/src/hooks/useFocusState.ts +30 -30
  316. package/src/hooks/useGestureHandlers.ts +286 -286
  317. package/src/hooks/useMeasure.ts +33 -33
  318. package/src/hooks/useOnClickOutside.ts +32 -32
  319. package/src/hooks/useOnKeyDown.ts +19 -19
  320. package/src/hooks/useReducerMachine.ts +60 -60
  321. package/src/hooks/useRemoveBodyScroll.ts +39 -39
  322. package/src/hooks/useScope.ts +52 -52
  323. package/src/hooks/useThrottle.ts +19 -19
  324. package/src/index.ts +20 -20
  325. package/src/utils/assign-ref.ts +27 -27
  326. package/src/utils/can-use-dom.ts +7 -7
  327. package/src/utils/clamp.ts +3 -3
  328. package/src/utils/context.tsx +48 -48
  329. package/src/utils/create-subscription.ts +16 -16
  330. package/src/utils/get-circular-index.ts +7 -7
  331. package/src/utils/index.ts +10 -10
  332. package/src/utils/is-right-click.ts +14 -14
  333. package/src/utils/owner-document.ts +13 -13
  334. package/src/utils/polymorphic.ts +78 -78
  335. package/src/utils/rubber-band-clamp.ts +25 -25
  336. package/src/utils/use-stable-callback.ts +58 -58
  337. package/src/utils/wrap-event.ts +22 -22
@@ -1,8 +1,8 @@
1
- import type { ElementType, HTMLAttributes, ReactNode } from 'react';
2
- export interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {
3
- as?: ElementType<any>;
4
- innerAs?: ElementType<any>;
5
- children?: ReactNode;
6
- lazy?: boolean;
7
- }
8
- export declare const TabPanel: import("react").ForwardRefExoticComponent<TabPanelProps & import("react").RefAttributes<HTMLDivElement>>;
1
+ import type { ElementType, HTMLAttributes, ReactNode } from 'react';
2
+ export interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {
3
+ as?: ElementType<any>;
4
+ innerAs?: ElementType<any>;
5
+ children?: ReactNode;
6
+ lazy?: boolean;
7
+ }
8
+ export declare const TabPanel: import("react").ForwardRefExoticComponent<TabPanelProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"TabPanel.js","names":["forwardRef","useTabsContext","TabPanel","props","forwardedRef","as","Comp","index","lazy","children","otherProps","tabsContext","Error","isSelected","currentIndex","tabListId","undefined"],"sources":["../../../src/Tabs/TabPanel.tsx"],"sourcesContent":["import type { ElementType, HTMLAttributes, ReactNode } from 'react';\nimport { forwardRef } from 'react';\n\nimport { useTabsContext } from './context';\n\nexport interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n lazy?: boolean;\n}\n\nexport const TabPanel = forwardRef<HTMLDivElement, TabPanelProps>(\n function TabPanel(props, forwardedRef) {\n const {\n as: Comp = 'div',\n index,\n lazy = false,\n children,\n ...otherProps\n } = props as TabPanelProps & { index: number };\n const tabsContext = useTabsContext();\n\n if (!tabsContext) {\n throw new Error('Missing <Tabs /> in the component tree.');\n }\n\n const isSelected = tabsContext.currentIndex === index;\n\n return (\n <Comp\n ref={forwardedRef}\n data-tab-panel=\"\"\n role=\"tabpanel\"\n id={\n tabsContext.tabListId !== null\n ? `tabpanel-${tabsContext.tabListId}-${index}`\n : undefined\n }\n aria-labelledby={\n tabsContext.tabListId !== null\n ? `tab-${tabsContext.tabListId}-${index}`\n : undefined\n }\n hidden={isSelected ? undefined : 'hidden'}\n tabIndex={0}\n {...otherProps}\n >\n {(isSelected || !lazy) && children}\n </Comp>\n );\n }\n);\n"],"mappings":";;;AACA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,cAAT,QAA+B,WAA/B;;AASA,OAAO,IAAMC,QAAQ,gBAAGF,UAAU,CAChC,SAASE,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;EACrC,WAMID,KANJ;EAAA,mBACEE,EADF;EAAA,IACMC,IADN,wBACa,KADb;EAAA,IAEEC,KAFF,QAEEA,KAFF;EAAA,qBAGEC,IAHF;EAAA,IAGEA,IAHF,0BAGS,KAHT;EAAA,IAIEC,QAJF,QAIEA,QAJF;EAAA,IAKKC,UALL;;EAOA,IAAMC,WAAW,GAAGV,cAAc,EAAlC;;EAEA,IAAI,CAACU,WAAL,EAAkB;IAChB,MAAM,IAAIC,KAAJ,CAAU,yCAAV,CAAN;EACD;;EAED,IAAMC,UAAU,GAAGF,WAAW,CAACG,YAAZ,KAA6BP,KAAhD;EAEA,oBACE,KAAC,IAAD;IACE,GAAG,EAAEH,YADP;IAEE,kBAAe,EAFjB;IAGE,IAAI,EAAC,UAHP;IAIE,EAAE,EACAO,WAAW,CAACI,SAAZ,KAA0B,IAA1B,sBACgBJ,WAAW,CAACI,SAD5B,cACyCR,KADzC,IAEIS,SAPR;IASE,mBACEL,WAAW,CAACI,SAAZ,KAA0B,IAA1B,iBACWJ,WAAW,CAACI,SADvB,cACoCR,KADpC,IAEIS,SAZR;IAcE,MAAM,EAAEH,UAAU,GAAGG,SAAH,GAAe,QAdnC;IAeE,QAAQ,EAAE;EAfZ,GAgBMN,UAhBN;IAAA,UAkBG,CAACG,UAAU,IAAI,CAACL,IAAhB,KAAyBC;EAlB5B,GADF;AAsBD,CAvC+B,CAA3B"}
1
+ {"version":3,"file":"TabPanel.js","names":["forwardRef","useTabsContext","TabPanel","props","forwardedRef","as","Comp","index","lazy","children","otherProps","tabsContext","Error","isSelected","currentIndex","tabListId","undefined"],"sources":["../../../src/Tabs/TabPanel.tsx"],"sourcesContent":["import type { ElementType, HTMLAttributes, ReactNode } from 'react';\r\nimport { forwardRef } from 'react';\r\n\r\nimport { useTabsContext } from './context';\r\n\r\nexport interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {\r\n as?: ElementType<any>;\r\n innerAs?: ElementType<any>;\r\n children?: ReactNode;\r\n lazy?: boolean;\r\n}\r\n\r\nexport const TabPanel = forwardRef<HTMLDivElement, TabPanelProps>(\r\n function TabPanel(props, forwardedRef) {\r\n const {\r\n as: Comp = 'div',\r\n index,\r\n lazy = false,\r\n children,\r\n ...otherProps\r\n } = props as TabPanelProps & { index: number };\r\n const tabsContext = useTabsContext();\r\n\r\n if (!tabsContext) {\r\n throw new Error('Missing <Tabs /> in the component tree.');\r\n }\r\n\r\n const isSelected = tabsContext.currentIndex === index;\r\n\r\n return (\r\n <Comp\r\n ref={forwardedRef}\r\n data-tab-panel=\"\"\r\n role=\"tabpanel\"\r\n id={\r\n tabsContext.tabListId !== null\r\n ? `tabpanel-${tabsContext.tabListId}-${index}`\r\n : undefined\r\n }\r\n aria-labelledby={\r\n tabsContext.tabListId !== null\r\n ? `tab-${tabsContext.tabListId}-${index}`\r\n : undefined\r\n }\r\n hidden={isSelected ? undefined : 'hidden'}\r\n tabIndex={0}\r\n {...otherProps}\r\n >\r\n {(isSelected || !lazy) && children}\r\n </Comp>\r\n );\r\n }\r\n);\r\n"],"mappings":";;;AACA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,cAAT,QAA+B,WAA/B;;AASA,OAAO,IAAMC,QAAQ,gBAAGF,UAAU,CAChC,SAASE,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;EACrC,WAMID,KANJ;EAAA,mBACEE,EADF;EAAA,IACMC,IADN,wBACa,KADb;EAAA,IAEEC,KAFF,QAEEA,KAFF;EAAA,qBAGEC,IAHF;EAAA,IAGEA,IAHF,0BAGS,KAHT;EAAA,IAIEC,QAJF,QAIEA,QAJF;EAAA,IAKKC,UALL;;EAOA,IAAMC,WAAW,GAAGV,cAAc,EAAlC;;EAEA,IAAI,CAACU,WAAL,EAAkB;IAChB,MAAM,IAAIC,KAAJ,CAAU,yCAAV,CAAN;EACD;;EAED,IAAMC,UAAU,GAAGF,WAAW,CAACG,YAAZ,KAA6BP,KAAhD;EAEA,oBACE,KAAC,IAAD;IACE,GAAG,EAAEH,YADP;IAEE,kBAAe,EAFjB;IAGE,IAAI,EAAC,UAHP;IAIE,EAAE,EACAO,WAAW,CAACI,SAAZ,KAA0B,IAA1B,sBACgBJ,WAAW,CAACI,SAD5B,cACyCR,KADzC,IAEIS,SAPR;IASE,mBACEL,WAAW,CAACI,SAAZ,KAA0B,IAA1B,iBACWJ,WAAW,CAACI,SADvB,cACoCR,KADpC,IAEIS,SAZR;IAcE,MAAM,EAAEH,UAAU,GAAGG,SAAH,GAAe,QAdnC;IAeE,QAAQ,EAAE;EAfZ,GAgBMN,UAhBN;IAAA,UAkBG,CAACG,UAAU,IAAI,CAACL,IAAhB,KAAyBC;EAlB5B,GADF;AAsBD,CAvC+B,CAA3B"}
@@ -1,8 +1,8 @@
1
- import type { ElementType, ReactNode } from 'react';
2
- export interface TabPanelsProps {
3
- as?: ElementType<any>;
4
- innerAs?: ElementType<any>;
5
- lazy?: boolean;
6
- children?: ReactNode;
7
- }
8
- export declare const TabPanels: import("react").ForwardRefExoticComponent<TabPanelsProps & import("react").RefAttributes<HTMLDivElement>>;
1
+ import type { ElementType, ReactNode } from 'react';
2
+ export interface TabPanelsProps {
3
+ as?: ElementType<any>;
4
+ innerAs?: ElementType<any>;
5
+ lazy?: boolean;
6
+ children?: ReactNode;
7
+ }
8
+ export declare const TabPanels: import("react").ForwardRefExoticComponent<TabPanelsProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"TabPanels.js","names":["forwardRef","Fragment","Children","cloneElement","TabPanels","props","forwardedRef","as","Comp","childrenProps","children","lazy","otherProps","map","node","index"],"sources":["../../../src/Tabs/TabPanels.tsx"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport { forwardRef, Fragment, Children, cloneElement } from 'react';\n\nexport interface TabPanelsProps {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n lazy?: boolean;\n children?: ReactNode;\n}\n\nexport const TabPanels = forwardRef<HTMLDivElement, TabPanelsProps>(\n function TabPanels(props, forwardedRef) {\n const {\n as: Comp = Fragment,\n children: childrenProps,\n lazy,\n ...otherProps\n } = props;\n\n const children = Children.map(childrenProps, (node, index) =>\n cloneElement(node as any, { index, lazy })\n );\n\n return (\n <Comp ref={forwardedRef} {...otherProps}>\n {children}\n </Comp>\n );\n }\n);\n"],"mappings":";;;AACA,SAASA,UAAT,EAAqBC,QAArB,EAA+BC,QAA/B,EAAyCC,YAAzC,QAA6D,OAA7D;;AASA,OAAO,IAAMC,SAAS,gBAAGJ,UAAU,CACjC,SAASI,SAAT,CAAmBC,KAAnB,EAA0BC,YAA1B,EAAwC;EACtC,gBAKID,KALJ,CACEE,EADF;EAAA,IACMC,IADN,0BACaP,QADb;EAAA,IAEYQ,aAFZ,GAKIJ,KALJ,CAEEK,QAFF;EAAA,IAGEC,IAHF,GAKIN,KALJ,CAGEM,IAHF;EAAA,IAIKC,UAJL,4BAKIP,KALJ;;EAOA,IAAMK,QAAQ,GAAGR,QAAQ,CAACW,GAAT,CAAaJ,aAAb,EAA4B,UAACK,IAAD,EAAOC,KAAP;IAAA,oBAC3CZ,YAAY,CAACW,IAAD,EAAc;MAAEC,KAAK,EAALA,KAAF;MAASJ,IAAI,EAAJA;IAAT,CAAd,CAD+B;EAAA,CAA5B,CAAjB;EAIA,oBACE,KAAC,IAAD;IAAM,GAAG,EAAEL;EAAX,GAA6BM,UAA7B;IAAA,UACGF;EADH,GADF;AAKD,CAlBgC,CAA5B"}
1
+ {"version":3,"file":"TabPanels.js","names":["forwardRef","Fragment","Children","cloneElement","TabPanels","props","forwardedRef","as","Comp","childrenProps","children","lazy","otherProps","map","node","index"],"sources":["../../../src/Tabs/TabPanels.tsx"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\r\nimport { forwardRef, Fragment, Children, cloneElement } from 'react';\r\n\r\nexport interface TabPanelsProps {\r\n as?: ElementType<any>;\r\n innerAs?: ElementType<any>;\r\n lazy?: boolean;\r\n children?: ReactNode;\r\n}\r\n\r\nexport const TabPanels = forwardRef<HTMLDivElement, TabPanelsProps>(\r\n function TabPanels(props, forwardedRef) {\r\n const {\r\n as: Comp = Fragment,\r\n children: childrenProps,\r\n lazy,\r\n ...otherProps\r\n } = props;\r\n\r\n const children = Children.map(childrenProps, (node, index) =>\r\n cloneElement(node as any, { index, lazy })\r\n );\r\n\r\n return (\r\n <Comp ref={forwardedRef} {...otherProps}>\r\n {children}\r\n </Comp>\r\n );\r\n }\r\n);\r\n"],"mappings":";;;AACA,SAASA,UAAT,EAAqBC,QAArB,EAA+BC,QAA/B,EAAyCC,YAAzC,QAA6D,OAA7D;;AASA,OAAO,IAAMC,SAAS,gBAAGJ,UAAU,CACjC,SAASI,SAAT,CAAmBC,KAAnB,EAA0BC,YAA1B,EAAwC;EACtC,gBAKID,KALJ,CACEE,EADF;EAAA,IACMC,IADN,0BACaP,QADb;EAAA,IAEYQ,aAFZ,GAKIJ,KALJ,CAEEK,QAFF;EAAA,IAGEC,IAHF,GAKIN,KALJ,CAGEM,IAHF;EAAA,IAIKC,UAJL,4BAKIP,KALJ;;EAOA,IAAMK,QAAQ,GAAGR,QAAQ,CAACW,GAAT,CAAaJ,aAAb,EAA4B,UAACK,IAAD,EAAOC,KAAP;IAAA,oBAC3CZ,YAAY,CAACW,IAAD,EAAc;MAAEC,KAAK,EAALA,KAAF;MAASJ,IAAI,EAAJA;IAAT,CAAd,CAD+B;EAAA,CAA5B,CAAjB;EAIA,oBACE,KAAC,IAAD;IAAM,GAAG,EAAEL;EAAX,GAA6BM,UAA7B;IAAA,UACGF;EADH,GADF;AAKD,CAlBgC,CAA5B"}
@@ -1,10 +1,10 @@
1
- import type { ElementType, KeyboardEvent, MouseEvent, ReactNode } from 'react';
2
- export interface TabsProps {
3
- as?: ElementType<any>;
4
- innerAs?: ElementType<any>;
5
- children?: ReactNode;
6
- onChange?: (e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>, value: number) => void;
7
- index?: number;
8
- defaultIndex?: number;
9
- }
10
- export declare const Tabs: import("react").ForwardRefExoticComponent<TabsProps & import("react").RefAttributes<HTMLDivElement>>;
1
+ import type { ElementType, KeyboardEvent, MouseEvent, ReactNode } from 'react';
2
+ export interface TabsProps {
3
+ as?: ElementType<any>;
4
+ innerAs?: ElementType<any>;
5
+ children?: ReactNode;
6
+ onChange?: (e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>, value: number) => void;
7
+ index?: number;
8
+ defaultIndex?: number;
9
+ }
10
+ export declare const Tabs: import("react").ForwardRefExoticComponent<TabsProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Tabs.js","names":["forwardRef","Fragment","useState","TabsProvider","useControlledState","Tabs","props","forwardedRef","as","Comp","indexProp","index","onChangeProp","onChange","defaultIndex","otherProps","setState","e","idx","tabListId","setTabListId","currentIndex"],"sources":["../../../src/Tabs/Tabs.tsx"],"sourcesContent":["import type { ElementType, KeyboardEvent, MouseEvent, ReactNode } from 'react';\nimport { forwardRef, Fragment, useState } from 'react';\n\nimport { TabsProvider } from './context';\nimport { useControlledState } from '../hooks';\n\nexport interface TabsProps {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n onChange?: (\n e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>,\n value: number\n ) => void;\n index?: number;\n defaultIndex?: number;\n}\n\nexport const Tabs = forwardRef<HTMLDivElement, TabsProps>(function Tabs(\n props,\n forwardedRef\n) {\n const {\n as: Comp = Fragment,\n index: indexProp,\n onChange: onChangeProp,\n defaultIndex = 0,\n ...otherProps\n } = props;\n const [index, onChange] = useControlledState(\n indexProp,\n onChangeProp,\n defaultIndex,\n (setState) => (e, idx) => setState(idx)\n );\n\n const [tabListId, setTabListId] = useState<string | null>(null);\n\n return (\n <TabsProvider\n value={{ currentIndex: index || 0, onChange, tabListId, setTabListId }}\n >\n <Comp ref={forwardedRef} {...otherProps} />\n </TabsProvider>\n );\n});\n"],"mappings":";;;;AACA,SAASA,UAAT,EAAqBC,QAArB,EAA+BC,QAA/B,QAA+C,OAA/C;AAEA,SAASC,YAAT,QAA6B,WAA7B;AACA,SAASC,kBAAT,QAAmC,UAAnC;;AAcA,OAAO,IAAMC,IAAI,gBAAGL,UAAU,CAA4B,SAASK,IAAT,CACxDC,KADwD,EAExDC,YAFwD,EAGxD;EACA,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACaR,QADb;EAAA,IAESS,SAFT,GAMIJ,KANJ,CAEEK,KAFF;EAAA,IAGYC,YAHZ,GAMIN,KANJ,CAGEO,QAHF;EAAA,0BAMIP,KANJ,CAIEQ,YAJF;EAAA,IAIEA,YAJF,oCAIiB,CAJjB;EAAA,IAKKC,UALL,4BAMIT,KANJ;;EAOA,0BAA0BF,kBAAkB,CAC1CM,SAD0C,EAE1CE,YAF0C,EAG1CE,YAH0C,EAI1C,UAACE,QAAD;IAAA,OAAc,UAACC,CAAD,EAAIC,GAAJ;MAAA,OAAYF,QAAQ,CAACE,GAAD,CAApB;IAAA,CAAd;EAAA,CAJ0C,CAA5C;EAAA;EAAA,IAAOP,KAAP;EAAA,IAAcE,QAAd;;EAOA,gBAAkCX,QAAQ,CAAgB,IAAhB,CAA1C;EAAA;EAAA,IAAOiB,SAAP;EAAA,IAAkBC,YAAlB;;EAEA,oBACE,KAAC,YAAD;IACE,KAAK,EAAE;MAAEC,YAAY,EAAEV,KAAK,IAAI,CAAzB;MAA4BE,QAAQ,EAARA,QAA5B;MAAsCM,SAAS,EAATA,SAAtC;MAAiDC,YAAY,EAAZA;IAAjD,CADT;IAAA,uBAGE,KAAC,IAAD;MAAM,GAAG,EAAEb;IAAX,GAA6BQ,UAA7B;EAHF,EADF;AAOD,CA3B6B,CAAvB"}
1
+ {"version":3,"file":"Tabs.js","names":["forwardRef","Fragment","useState","TabsProvider","useControlledState","Tabs","props","forwardedRef","as","Comp","indexProp","index","onChangeProp","onChange","defaultIndex","otherProps","setState","e","idx","tabListId","setTabListId","currentIndex"],"sources":["../../../src/Tabs/Tabs.tsx"],"sourcesContent":["import type { ElementType, KeyboardEvent, MouseEvent, ReactNode } from 'react';\r\nimport { forwardRef, Fragment, useState } from 'react';\r\n\r\nimport { TabsProvider } from './context';\r\nimport { useControlledState } from '../hooks';\r\n\r\nexport interface TabsProps {\r\n as?: ElementType<any>;\r\n innerAs?: ElementType<any>;\r\n children?: ReactNode;\r\n onChange?: (\r\n e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>,\r\n value: number\r\n ) => void;\r\n index?: number;\r\n defaultIndex?: number;\r\n}\r\n\r\nexport const Tabs = forwardRef<HTMLDivElement, TabsProps>(function Tabs(\r\n props,\r\n forwardedRef\r\n) {\r\n const {\r\n as: Comp = Fragment,\r\n index: indexProp,\r\n onChange: onChangeProp,\r\n defaultIndex = 0,\r\n ...otherProps\r\n } = props;\r\n const [index, onChange] = useControlledState(\r\n indexProp,\r\n onChangeProp,\r\n defaultIndex,\r\n (setState) => (e, idx) => setState(idx)\r\n );\r\n\r\n const [tabListId, setTabListId] = useState<string | null>(null);\r\n\r\n return (\r\n <TabsProvider\r\n value={{ currentIndex: index || 0, onChange, tabListId, setTabListId }}\r\n >\r\n <Comp ref={forwardedRef} {...otherProps} />\r\n </TabsProvider>\r\n );\r\n});\r\n"],"mappings":";;;;AACA,SAASA,UAAT,EAAqBC,QAArB,EAA+BC,QAA/B,QAA+C,OAA/C;AAEA,SAASC,YAAT,QAA6B,WAA7B;AACA,SAASC,kBAAT,QAAmC,UAAnC;;AAcA,OAAO,IAAMC,IAAI,gBAAGL,UAAU,CAA4B,SAASK,IAAT,CACxDC,KADwD,EAExDC,YAFwD,EAGxD;EACA,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACaR,QADb;EAAA,IAESS,SAFT,GAMIJ,KANJ,CAEEK,KAFF;EAAA,IAGYC,YAHZ,GAMIN,KANJ,CAGEO,QAHF;EAAA,0BAMIP,KANJ,CAIEQ,YAJF;EAAA,IAIEA,YAJF,oCAIiB,CAJjB;EAAA,IAKKC,UALL,4BAMIT,KANJ;;EAOA,0BAA0BF,kBAAkB,CAC1CM,SAD0C,EAE1CE,YAF0C,EAG1CE,YAH0C,EAI1C,UAACE,QAAD;IAAA,OAAc,UAACC,CAAD,EAAIC,GAAJ;MAAA,OAAYF,QAAQ,CAACE,GAAD,CAApB;IAAA,CAAd;EAAA,CAJ0C,CAA5C;EAAA;EAAA,IAAOP,KAAP;EAAA,IAAcE,QAAd;;EAOA,gBAAkCX,QAAQ,CAAgB,IAAhB,CAA1C;EAAA;EAAA,IAAOiB,SAAP;EAAA,IAAkBC,YAAlB;;EAEA,oBACE,KAAC,YAAD;IACE,KAAK,EAAE;MAAEC,YAAY,EAAEV,KAAK,IAAI,CAAzB;MAA4BE,QAAQ,EAARA,QAA5B;MAAsCM,SAAS,EAATA,SAAtC;MAAiDC,YAAY,EAAZA;IAAjD,CADT;IAAA,uBAGE,KAAC,IAAD;MAAM,GAAG,EAAEb;IAAX,GAA6BQ,UAA7B;EAHF,EADF;AAOD,CA3B6B,CAAvB"}
@@ -1,17 +1,17 @@
1
- import type { KeyboardEvent, MouseEvent } from 'react';
2
- import type { Scope } from '../hooks/useScope';
3
- export interface TabsContextProps {
4
- currentIndex: number;
5
- onChange?: (e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>, value: number) => void;
6
- tabListId: string | null;
7
- setTabListId: (v: string | null) => void;
8
- }
9
- export declare const TabsProvider: import("react").Provider<TabsContextProps | null>;
10
- export declare const useTabsContext: () => TabsContextProps | null;
11
- export interface TabListContextProps {
12
- tabsScope: Scope<HTMLElement>;
13
- manualActivation: boolean;
14
- vertical: boolean;
15
- }
16
- export declare const TabListProvider: import("react").Provider<TabListContextProps | null>;
17
- export declare const useTabListContext: () => TabListContextProps | null;
1
+ import type { KeyboardEvent, MouseEvent } from 'react';
2
+ import type { Scope } from '../hooks/useScope';
3
+ export interface TabsContextProps {
4
+ currentIndex: number;
5
+ onChange?: (e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>, value: number) => void;
6
+ tabListId: string | null;
7
+ setTabListId: (v: string | null) => void;
8
+ }
9
+ export declare const TabsProvider: import("react").Provider<TabsContextProps | null>;
10
+ export declare const useTabsContext: () => TabsContextProps | null;
11
+ export interface TabListContextProps {
12
+ tabsScope: Scope<HTMLElement>;
13
+ manualActivation: boolean;
14
+ vertical: boolean;
15
+ }
16
+ export declare const TabListProvider: import("react").Provider<TabListContextProps | null>;
17
+ export declare const useTabListContext: () => TabListContextProps | null;
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":["createContext","useContext","tabsContext","TabsProvider","Provider","useTabsContext","tablistContext","TabListProvider","useTabListContext"],"sources":["../../../src/Tabs/context.ts"],"sourcesContent":["import type { KeyboardEvent, MouseEvent } from 'react';\nimport { createContext, useContext } from 'react';\n\nimport type { Scope } from '../hooks/useScope';\n\n// Tabs Component\nexport interface TabsContextProps {\n currentIndex: number;\n onChange?: (\n e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>,\n value: number\n ) => void;\n tabListId: string | null;\n setTabListId: (v: string | null) => void;\n}\n\nconst tabsContext = createContext<TabsContextProps | null>(null);\nexport const { Provider: TabsProvider } = tabsContext;\nexport const useTabsContext = () => useContext(tabsContext);\n\n// TabList Component\nexport interface TabListContextProps {\n tabsScope: Scope<HTMLElement>;\n manualActivation: boolean;\n vertical: boolean;\n}\n\nconst tablistContext = createContext<TabListContextProps | null>(null);\nexport const { Provider: TabListProvider } = tablistContext;\nexport const useTabListContext = () => useContext(tablistContext);\n"],"mappings":"AACA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAeA,IAAMC,WAAW,gBAAGF,aAAa,CAA0B,IAA1B,CAAjC;AACO,IAAkBG,YAAlB,GAAmCD,WAAnC,CAAQE,QAAR;;AACP,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB;EAAA,OAAMJ,UAAU,CAACC,WAAD,CAAhB;AAAA,CAAvB,C,CAEP;;AAOA,IAAMI,cAAc,gBAAGN,aAAa,CAA6B,IAA7B,CAApC;AACO,IAAkBO,eAAlB,GAAsCD,cAAtC,CAAQF,QAAR;;AACP,OAAO,IAAMI,iBAAiB,GAAG,SAApBA,iBAAoB;EAAA,OAAMP,UAAU,CAACK,cAAD,CAAhB;AAAA,CAA1B"}
1
+ {"version":3,"file":"context.js","names":["createContext","useContext","tabsContext","TabsProvider","Provider","useTabsContext","tablistContext","TabListProvider","useTabListContext"],"sources":["../../../src/Tabs/context.ts"],"sourcesContent":["import type { KeyboardEvent, MouseEvent } from 'react';\r\nimport { createContext, useContext } from 'react';\r\n\r\nimport type { Scope } from '../hooks/useScope';\r\n\r\n// Tabs Component\r\nexport interface TabsContextProps {\r\n currentIndex: number;\r\n onChange?: (\r\n e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>,\r\n value: number\r\n ) => void;\r\n tabListId: string | null;\r\n setTabListId: (v: string | null) => void;\r\n}\r\n\r\nconst tabsContext = createContext<TabsContextProps | null>(null);\r\nexport const { Provider: TabsProvider } = tabsContext;\r\nexport const useTabsContext = () => useContext(tabsContext);\r\n\r\n// TabList Component\r\nexport interface TabListContextProps {\r\n tabsScope: Scope<HTMLElement>;\r\n manualActivation: boolean;\r\n vertical: boolean;\r\n}\r\n\r\nconst tablistContext = createContext<TabListContextProps | null>(null);\r\nexport const { Provider: TabListProvider } = tablistContext;\r\nexport const useTabListContext = () => useContext(tablistContext);\r\n"],"mappings":"AACA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAeA,IAAMC,WAAW,gBAAGF,aAAa,CAA0B,IAA1B,CAAjC;AACO,IAAkBG,YAAlB,GAAmCD,WAAnC,CAAQE,QAAR;;AACP,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB;EAAA,OAAMJ,UAAU,CAACC,WAAD,CAAhB;AAAA,CAAvB,C,CAEP;;AAOA,IAAMI,cAAc,gBAAGN,aAAa,CAA6B,IAA7B,CAApC;AACO,IAAkBO,eAAlB,GAAsCD,cAAtC,CAAQF,QAAR;;AACP,OAAO,IAAMI,iBAAiB,GAAG,SAApBA,iBAAoB;EAAA,OAAMP,UAAU,CAACK,cAAD,CAAhB;AAAA,CAA1B"}
@@ -1,5 +1,5 @@
1
- export * from './Tabs';
2
- export * from './Tab';
3
- export * from './TabList';
4
- export * from './TabPanels';
5
- export * from './TabPanel';
1
+ export * from './Tabs';
2
+ export * from './Tab';
3
+ export * from './TabList';
4
+ export * from './TabPanels';
5
+ export * from './TabPanel';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/Tabs/index.tsx"],"sourcesContent":["export * from './Tabs';\nexport * from './Tab';\nexport * from './TabList';\nexport * from './TabPanels';\nexport * from './TabPanel';\n"],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,OAAd;AACA,cAAc,WAAd;AACA,cAAc,aAAd;AACA,cAAc,YAAd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/Tabs/index.tsx"],"sourcesContent":["export * from './Tabs';\r\nexport * from './Tab';\r\nexport * from './TabList';\r\nexport * from './TabPanels';\r\nexport * from './TabPanel';\r\n"],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,OAAd;AACA,cAAc,WAAd;AACA,cAAc,aAAd;AACA,cAAc,YAAd"}
@@ -1 +1 @@
1
- export declare function scopeQuery(nodeType: string, props: Record<string, unknown>): boolean;
1
+ export declare function scopeQuery(nodeType: string, props: Record<string, unknown>): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"scopeQuery.js","names":["scopeQuery","nodeType","props"],"sources":["../../../src/Tabs/scopeQuery.ts"],"sourcesContent":["export function scopeQuery(\n nodeType: string,\n props: Record<string, unknown>\n): boolean {\n return props['data-tab'] === '';\n}\n"],"mappings":"AAAA,OAAO,SAASA,UAAT,CACLC,QADK,EAELC,KAFK,EAGI;EACT,OAAOA,KAAK,CAAC,UAAD,CAAL,KAAsB,EAA7B;AACD"}
1
+ {"version":3,"file":"scopeQuery.js","names":["scopeQuery","nodeType","props"],"sources":["../../../src/Tabs/scopeQuery.ts"],"sourcesContent":["export function scopeQuery(\r\n nodeType: string,\r\n props: Record<string, unknown>\r\n): boolean {\r\n return props['data-tab'] === '';\r\n}\r\n"],"mappings":"AAAA,OAAO,SAASA,UAAT,CACLC,QADK,EAELC,KAFK,EAGI;EACT,OAAOA,KAAK,CAAC,UAAD,CAAL,KAAsB,EAA7B;AACD"}
@@ -1,10 +1,10 @@
1
- import type { ElementType, HTMLAttributes, ReactNode, RefAttributes } from 'react';
2
- export type { InjectedTooltipProps } from './useTooltip';
3
- export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
4
- as?: ElementType<any>;
5
- innerAs?: ElementType<any>;
6
- children?: ReactNode;
7
- label: ReactNode;
8
- disabled?: boolean;
9
- }
10
- export declare const Tooltip: import("react").ForwardRefExoticComponent<TooltipProps & RefAttributes<HTMLDivElement>>;
1
+ import type { ElementType, HTMLAttributes, ReactNode, RefAttributes } from 'react';
2
+ export type { InjectedTooltipProps } from './useTooltip';
3
+ export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
4
+ as?: ElementType<any>;
5
+ innerAs?: ElementType<any>;
6
+ children?: ReactNode;
7
+ label: ReactNode;
8
+ disabled?: boolean;
9
+ }
10
+ export declare const Tooltip: import("react").ForwardRefExoticComponent<TooltipProps & RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","names":["forwardRef","cloneElement","Children","useTooltip","Tooltip","props","forwardedRef","as","Comp","innerAs","children","disabled","otherProps","child","only","ref","childProps","visible","tooltipProps"],"sources":["../../../src/Tooltip/Tooltip.tsx"],"sourcesContent":["import type {\n ElementType,\n HTMLAttributes,\n ReactElement,\n ReactNode,\n RefAttributes,\n} from 'react';\nimport { forwardRef, cloneElement, Children } from 'react';\n\nimport { useTooltip } from './useTooltip';\nexport type { InjectedTooltipProps } from './useTooltip';\n\nexport interface TooltipProps extends HTMLAttributes<HTMLDivElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n label: ReactNode;\n disabled?: boolean;\n}\n\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(\n function Tooltip(props, forwardedRef) {\n const {\n as: Comp = 'div',\n innerAs,\n children,\n disabled = false,\n ...otherProps\n } = props;\n const child: ReactElement & RefAttributes<any> = Children.only(\n children\n ) as any;\n const [childProps, { visible, ...tooltipProps }] = useTooltip(\n child.props,\n child.ref,\n otherProps\n );\n\n if (disabled) {\n return <>{child}</>;\n }\n\n return (\n <>\n {cloneElement(child, childProps)}\n {visible && <Comp as={innerAs} ref={forwardedRef} {...tooltipProps} />}\n </>\n );\n }\n);\n"],"mappings":";;;;;AAOA,SAASA,UAAT,EAAqBC,YAArB,EAAmCC,QAAnC,QAAmD,OAAnD;AAEA,SAASC,UAAT,QAA2B,cAA3B;;;;AAWA,OAAO,IAAMC,OAAO,gBAAGJ,UAAU,CAC/B,SAASI,OAAT,CAAiBC,KAAjB,EAAwBC,YAAxB,EAAsC;EACpC,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,KADb;EAAA,IAEEC,OAFF,GAMIJ,KANJ,CAEEI,OAFF;EAAA,IAGEC,QAHF,GAMIL,KANJ,CAGEK,QAHF;EAAA,sBAMIL,KANJ,CAIEM,QAJF;EAAA,IAIEA,QAJF,gCAIa,KAJb;EAAA,IAKKC,UALL,4BAMIP,KANJ;;EAOA,IAAMQ,KAAwC,GAAGX,QAAQ,CAACY,IAAT,CAC/CJ,QAD+C,CAAjD;;EAGA,kBAAmDP,UAAU,CAC3DU,KAAK,CAACR,KADqD,EAE3DQ,KAAK,CAACE,GAFqD,EAG3DH,UAH2D,CAA7D;EAAA;EAAA,IAAOI,UAAP;EAAA;EAAA,IAAqBC,OAArB,iBAAqBA,OAArB;EAAA,IAAiCC,YAAjC;;EAMA,IAAIP,QAAJ,EAAc;IACZ,oBAAO;MAAA,UAAGE;IAAH,EAAP;EACD;;EAED,oBACE;IAAA,wBACGZ,YAAY,CAACY,KAAD,EAAQG,UAAR,CADf,EAEGC,OAAO,iBAAI,KAAC,IAAD;MAAM,EAAE,EAAER,OAAV;MAAmB,GAAG,EAAEH;IAAxB,GAA0CY,YAA1C,EAFd;EAAA,EADF;AAMD,CA5B8B,CAA1B"}
1
+ {"version":3,"file":"Tooltip.js","names":["forwardRef","cloneElement","Children","useTooltip","Tooltip","props","forwardedRef","as","Comp","innerAs","children","disabled","otherProps","child","only","ref","childProps","visible","tooltipProps"],"sources":["../../../src/Tooltip/Tooltip.tsx"],"sourcesContent":["import type {\r\n ElementType,\r\n HTMLAttributes,\r\n ReactElement,\r\n ReactNode,\r\n RefAttributes,\r\n} from 'react';\r\nimport { forwardRef, cloneElement, Children } from 'react';\r\n\r\nimport { useTooltip } from './useTooltip';\r\nexport type { InjectedTooltipProps } from './useTooltip';\r\n\r\nexport interface TooltipProps extends HTMLAttributes<HTMLDivElement> {\r\n as?: ElementType<any>;\r\n innerAs?: ElementType<any>;\r\n children?: ReactNode;\r\n label: ReactNode;\r\n disabled?: boolean;\r\n}\r\n\r\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(\r\n function Tooltip(props, forwardedRef) {\r\n const {\r\n as: Comp = 'div',\r\n innerAs,\r\n children,\r\n disabled = false,\r\n ...otherProps\r\n } = props;\r\n const child: ReactElement & RefAttributes<any> = Children.only(\r\n children\r\n ) as any;\r\n const [childProps, { visible, ...tooltipProps }] = useTooltip(\r\n child.props,\r\n child.ref,\r\n otherProps\r\n );\r\n\r\n if (disabled) {\r\n return <>{child}</>;\r\n }\r\n\r\n return (\r\n <>\r\n {cloneElement(child, childProps)}\r\n {visible && <Comp as={innerAs} ref={forwardedRef} {...tooltipProps} />}\r\n </>\r\n );\r\n }\r\n);\r\n"],"mappings":";;;;;AAOA,SAASA,UAAT,EAAqBC,YAArB,EAAmCC,QAAnC,QAAmD,OAAnD;AAEA,SAASC,UAAT,QAA2B,cAA3B;;;;AAWA,OAAO,IAAMC,OAAO,gBAAGJ,UAAU,CAC/B,SAASI,OAAT,CAAiBC,KAAjB,EAAwBC,YAAxB,EAAsC;EACpC,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,KADb;EAAA,IAEEC,OAFF,GAMIJ,KANJ,CAEEI,OAFF;EAAA,IAGEC,QAHF,GAMIL,KANJ,CAGEK,QAHF;EAAA,sBAMIL,KANJ,CAIEM,QAJF;EAAA,IAIEA,QAJF,gCAIa,KAJb;EAAA,IAKKC,UALL,4BAMIP,KANJ;;EAOA,IAAMQ,KAAwC,GAAGX,QAAQ,CAACY,IAAT,CAC/CJ,QAD+C,CAAjD;;EAGA,kBAAmDP,UAAU,CAC3DU,KAAK,CAACR,KADqD,EAE3DQ,KAAK,CAACE,GAFqD,EAG3DH,UAH2D,CAA7D;EAAA;EAAA,IAAOI,UAAP;EAAA;EAAA,IAAqBC,OAArB,iBAAqBA,OAArB;EAAA,IAAiCC,YAAjC;;EAMA,IAAIP,QAAJ,EAAc;IACZ,oBAAO;MAAA,UAAGE;IAAH,EAAP;EACD;;EAED,oBACE;IAAA,wBACGZ,YAAY,CAACY,KAAD,EAAQG,UAAR,CADf,EAEGC,OAAO,iBAAI,KAAC,IAAD;MAAM,EAAE,EAAER,OAAV;MAAmB,GAAG,EAAEH;IAAxB,GAA0CY,YAA1C,EAFd;EAAA,EADF;AAMD,CA5B8B,CAA1B"}
@@ -1 +1 @@
1
- export * from './Tooltip';
1
+ export * from './Tooltip';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/Tooltip/index.ts"],"sourcesContent":["export * from './Tooltip';\n"],"mappings":"AAAA,cAAc,WAAd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/Tooltip/index.ts"],"sourcesContent":["export * from './Tooltip';\r\n"],"mappings":"AAAA,cAAc,WAAd"}
@@ -1,28 +1,28 @@
1
- export declare type TooltipStates = 'IDLE' | 'FOCUSED' | 'VISIBLE' | 'LEAVING_VISIBLE' | 'DISMISSED';
2
- export declare const Idle: "IDLE";
3
- export declare const Focused: "FOCUSED";
4
- export declare const Visible: "VISIBLE";
5
- export declare const LeavingVisible: "LEAVING_VISIBLE";
6
- export declare const Dismissed: "DISMISSED";
7
- export declare type TooltipEventTypes = 'BLUR' | 'FOCUS' | 'GLOBAL_MOUSE_MOVE' | 'MOUSE_DOWN' | 'MOUSE_ENTER' | 'MOUSE_LEAVE' | 'MOUSE_MOVE' | 'REST' | 'SELECT_WITH_KEYBOARD' | 'TIME_COMPLETE';
8
- export declare const Blur: "BLUR";
9
- export declare const Focus: "FOCUS";
10
- export declare const GlobalMouseMove: "GLOBAL_MOUSE_MOVE";
11
- export declare const MouseDown: "MOUSE_DOWN";
12
- export declare const MouseEnter: "MOUSE_ENTER";
13
- export declare const MouseLeave: "MOUSE_LEAVE";
14
- export declare const MouseMove: "MOUSE_MOVE";
15
- export declare const Rest: "REST";
16
- export declare const SelectWithKeyboard: "SELECT_WITH_KEYBOARD";
17
- export declare const TimeComplete: "TIME_COMPLETE";
18
- export declare const subscription: {
19
- subscribe: (fn: () => void) => () => void;
20
- notify: () => void;
21
- };
22
- export declare const state: {
23
- current: {
24
- state: TooltipStates;
25
- id: string;
26
- };
27
- };
28
- export declare function send<T extends TooltipEventTypes>(event: T, payload?: Omit<typeof state['current'], 'state'>): void;
1
+ export declare type TooltipStates = 'IDLE' | 'FOCUSED' | 'VISIBLE' | 'LEAVING_VISIBLE' | 'DISMISSED';
2
+ export declare const Idle: "IDLE";
3
+ export declare const Focused: "FOCUSED";
4
+ export declare const Visible: "VISIBLE";
5
+ export declare const LeavingVisible: "LEAVING_VISIBLE";
6
+ export declare const Dismissed: "DISMISSED";
7
+ export declare type TooltipEventTypes = 'BLUR' | 'FOCUS' | 'GLOBAL_MOUSE_MOVE' | 'MOUSE_DOWN' | 'MOUSE_ENTER' | 'MOUSE_LEAVE' | 'MOUSE_MOVE' | 'REST' | 'SELECT_WITH_KEYBOARD' | 'TIME_COMPLETE';
8
+ export declare const Blur: "BLUR";
9
+ export declare const Focus: "FOCUS";
10
+ export declare const GlobalMouseMove: "GLOBAL_MOUSE_MOVE";
11
+ export declare const MouseDown: "MOUSE_DOWN";
12
+ export declare const MouseEnter: "MOUSE_ENTER";
13
+ export declare const MouseLeave: "MOUSE_LEAVE";
14
+ export declare const MouseMove: "MOUSE_MOVE";
15
+ export declare const Rest: "REST";
16
+ export declare const SelectWithKeyboard: "SELECT_WITH_KEYBOARD";
17
+ export declare const TimeComplete: "TIME_COMPLETE";
18
+ export declare const subscription: {
19
+ subscribe: (fn: () => void) => () => void;
20
+ notify: () => void;
21
+ };
22
+ export declare const state: {
23
+ current: {
24
+ state: TooltipStates;
25
+ id: string;
26
+ };
27
+ };
28
+ export declare function send<T extends TooltipEventTypes>(event: T, payload?: Omit<typeof state['current'], 'state'>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"stateMachine.js","names":["createSubscription","restTimeout","startRestTimer","clearTimeout","setTimeout","send","Rest","undefined","clearRestTimer","leavingVisibleTimer","startLeavingVisibleTimer","TimeComplete","clearLeavingVisibleTimer","Idle","Focused","Visible","LeavingVisible","Dismissed","Blur","Focus","GlobalMouseMove","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","subscription","state","current","id","clearContextId","chart","initial","states","enter","on","leave","transition","currentState","event","payload","currentStateValue","stateDef","nextState","nextStateValue","nextDef","notify"],"sources":["../../../src/Tooltip/stateMachine.ts"],"sourcesContent":["import { createSubscription } from '../utils/create-subscription';\nimport type { StateChart as GenericStateChart } from '../hooks/useReducerMachine';\n\n////////////////////////////////////////////////////////////////////////////////\n// Timeouts:\n\n// Manages when the user \"rests\" on an element. Keeps the interface from being\n// flashing tooltips all the time as the user moves the mouse around the screen.\nlet restTimeout: NodeJS.Timeout;\nfunction startRestTimer() {\n clearTimeout(restTimeout);\n restTimeout = setTimeout(() => {\n send(Rest, undefined);\n }, 200);\n}\n\nfunction clearRestTimer() {\n clearTimeout(restTimeout);\n}\n\n// Manages the delay to hide the tooltip after rest leaves.\nlet leavingVisibleTimer: NodeJS.Timeout;\nfunction startLeavingVisibleTimer() {\n clearTimeout(leavingVisibleTimer);\n leavingVisibleTimer = setTimeout(() => send(TimeComplete, undefined), 100);\n}\n\nfunction clearLeavingVisibleTimer() {\n clearTimeout(leavingVisibleTimer);\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// State machine\n\nexport type TooltipStates =\n | 'IDLE'\n | 'FOCUSED'\n | 'VISIBLE'\n | 'LEAVING_VISIBLE'\n | 'DISMISSED';\n\n// Nothing goin' on\nexport const Idle = 'IDLE' as const;\n// We're considering showing the tooltip, but we're gonna wait a sec\nexport const Focused = 'FOCUSED' as const;\n// It's on!\nexport const Visible = 'VISIBLE' as const;\n// Focus has left, but we want to keep it visible for a sec\nexport const LeavingVisible = 'LEAVING_VISIBLE' as const;\n// The user clicked the tool, so we want to hide the thing, we can't just use\n// IDLE because we need to ignore mousemove, etc.\nexport const Dismissed = 'DISMISSED' as const;\n\nexport type TooltipEventTypes =\n | 'BLUR'\n | 'FOCUS'\n | 'GLOBAL_MOUSE_MOVE'\n | 'MOUSE_DOWN'\n | 'MOUSE_ENTER'\n | 'MOUSE_LEAVE'\n | 'MOUSE_MOVE'\n | 'REST'\n | 'SELECT_WITH_KEYBOARD'\n | 'TIME_COMPLETE';\n\nexport const Blur = 'BLUR' as const;\nexport const Focus = 'FOCUS' as const;\nexport const GlobalMouseMove = 'GLOBAL_MOUSE_MOVE' as const;\nexport const MouseDown = 'MOUSE_DOWN' as const;\nexport const MouseEnter = 'MOUSE_ENTER' as const;\nexport const MouseLeave = 'MOUSE_LEAVE' as const;\nexport const MouseMove = 'MOUSE_MOVE' as const;\nexport const Rest = 'REST' as const;\nexport const SelectWithKeyboard = 'SELECT_WITH_KEYBOARD' as const;\nexport const TimeComplete = 'TIME_COMPLETE' as const;\n\nexport const subscription = createSubscription();\nexport const state = {\n current: {\n state: Idle as TooltipStates,\n id: '',\n },\n};\n\nfunction clearContextId() {\n state.current.id = '';\n}\n\nconst chart: GenericStateChart<TooltipStates, TooltipEventTypes> = {\n initial: Idle,\n states: {\n [Idle]: {\n enter: () => {\n clearContextId();\n },\n on: {\n [MouseEnter]: Focused,\n [Focus]: Visible,\n },\n },\n [Focused]: {\n enter: startRestTimer,\n leave: clearRestTimer,\n on: {\n [MouseMove]: Focused,\n [MouseLeave]: Idle,\n [MouseDown]: Dismissed,\n [Blur]: Idle,\n [Rest]: Visible,\n },\n },\n [Visible]: {\n on: {\n [Focus]: Focused,\n [MouseEnter]: Focused,\n [MouseLeave]: LeavingVisible,\n [Blur]: LeavingVisible,\n [MouseDown]: Dismissed,\n [SelectWithKeyboard]: Dismissed,\n [GlobalMouseMove]: LeavingVisible,\n },\n },\n [LeavingVisible]: {\n enter: () => {\n startLeavingVisibleTimer();\n },\n leave: () => {\n clearLeavingVisibleTimer();\n clearContextId();\n },\n on: {\n [MouseEnter]: Visible,\n [Focus]: Visible,\n [TimeComplete]: Idle,\n },\n },\n [Dismissed]: {\n leave: () => {\n clearContextId();\n },\n on: {\n [MouseLeave]: Idle,\n [Blur]: Idle,\n },\n },\n },\n};\n\nfunction transition(\n currentState: typeof state['current'],\n event: TooltipEventTypes,\n payload?: Omit<typeof state['current'], 'state'>\n): typeof state['current'] {\n const currentStateValue = currentState.state;\n const stateDef = chart.states[currentState.state];\n const nextState = stateDef?.on?.[event];\n\n // Really useful for debugging\n // console.log({\n // event,\n // state: state.current.state,\n // id: state.current.id,\n // nextState,\n // });\n\n if (!nextState) {\n return currentState;\n }\n\n if (stateDef && stateDef.leave) {\n stateDef.leave(currentStateValue, payload);\n }\n\n const nextStateValue = nextState;\n const nextDef = chart.states[nextStateValue];\n if (nextDef && nextDef.enter) {\n nextDef.enter(nextStateValue, payload);\n }\n\n return { ...currentState, ...payload, state: nextStateValue };\n}\n\nexport function send<T extends TooltipEventTypes>(\n event: T,\n payload?: Omit<typeof state['current'], 'state'>\n) {\n const nextState = transition(state.current, event, payload);\n if (state.current !== nextState) {\n state.current = nextState;\n subscription.notify();\n }\n}\n"],"mappings":";;;;;AAAA,SAASA,kBAAT,QAAmC,8BAAnC;AAGA;AACA;AAEA;AACA;AACA,IAAIC,WAAJ;;AACA,SAASC,cAAT,GAA0B;EACxBC,YAAY,CAACF,WAAD,CAAZ;EACAA,WAAW,GAAGG,UAAU,CAAC,YAAM;IAC7BC,IAAI,CAACC,IAAD,EAAOC,SAAP,CAAJ;EACD,CAFuB,EAErB,GAFqB,CAAxB;AAGD;;AAED,SAASC,cAAT,GAA0B;EACxBL,YAAY,CAACF,WAAD,CAAZ;AACD,C,CAED;;;AACA,IAAIQ,mBAAJ;;AACA,SAASC,wBAAT,GAAoC;EAClCP,YAAY,CAACM,mBAAD,CAAZ;EACAA,mBAAmB,GAAGL,UAAU,CAAC;IAAA,OAAMC,IAAI,CAACM,YAAD,EAAeJ,SAAf,CAAV;EAAA,CAAD,EAAsC,GAAtC,CAAhC;AACD;;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,CAACN,KAAzB,EAAgC;IAC9BM,QAAQ,CAACN,KAAT,CAAeK,iBAAf,EAAkCD,OAAlC;EACD;;EAED,IAAMI,cAAc,GAAGD,SAAvB;EACA,IAAME,OAAO,GAAGd,KAAK,CAACE,MAAN,CAAaW,cAAb,CAAhB;;EACA,IAAIC,OAAO,IAAIA,OAAO,CAACX,KAAvB,EAA8B;IAC5BW,OAAO,CAACX,KAAR,CAAcU,cAAd,EAA8BJ,OAA9B;EACD;;EAED,sCAAYF,YAAZ,GAA6BE,OAA7B;IAAsCb,KAAK,EAAEiB;EAA7C;AACD;;AAED,OAAO,SAASvC,IAAT,CACLkC,KADK,EAELC,OAFK,EAGL;EACA,IAAMG,SAAS,GAAGN,UAAU,CAACV,KAAK,CAACC,OAAP,EAAgBW,KAAhB,EAAuBC,OAAvB,CAA5B;;EACA,IAAIb,KAAK,CAACC,OAAN,KAAkBe,SAAtB,EAAiC;IAC/BhB,KAAK,CAACC,OAAN,GAAgBe,SAAhB;IACAjB,YAAY,CAACoB,MAAb;EACD;AACF"}
1
+ {"version":3,"file":"stateMachine.js","names":["createSubscription","restTimeout","startRestTimer","clearTimeout","setTimeout","send","Rest","undefined","clearRestTimer","leavingVisibleTimer","startLeavingVisibleTimer","TimeComplete","clearLeavingVisibleTimer","Idle","Focused","Visible","LeavingVisible","Dismissed","Blur","Focus","GlobalMouseMove","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","subscription","state","current","id","clearContextId","chart","initial","states","enter","on","leave","transition","currentState","event","payload","currentStateValue","stateDef","nextState","nextStateValue","nextDef","notify"],"sources":["../../../src/Tooltip/stateMachine.ts"],"sourcesContent":["import { createSubscription } from '../utils/create-subscription';\r\nimport type { StateChart as GenericStateChart } from '../hooks/useReducerMachine';\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\n// Timeouts:\r\n\r\n// Manages when the user \"rests\" on an element. Keeps the interface from being\r\n// flashing tooltips all the time as the user moves the mouse around the screen.\r\nlet restTimeout: NodeJS.Timeout;\r\nfunction startRestTimer() {\r\n clearTimeout(restTimeout);\r\n restTimeout = setTimeout(() => {\r\n send(Rest, undefined);\r\n }, 200);\r\n}\r\n\r\nfunction clearRestTimer() {\r\n clearTimeout(restTimeout);\r\n}\r\n\r\n// Manages the delay to hide the tooltip after rest leaves.\r\nlet leavingVisibleTimer: NodeJS.Timeout;\r\nfunction startLeavingVisibleTimer() {\r\n clearTimeout(leavingVisibleTimer);\r\n leavingVisibleTimer = setTimeout(() => send(TimeComplete, undefined), 100);\r\n}\r\n\r\nfunction clearLeavingVisibleTimer() {\r\n clearTimeout(leavingVisibleTimer);\r\n}\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\n// State machine\r\n\r\nexport type TooltipStates =\r\n | 'IDLE'\r\n | 'FOCUSED'\r\n | 'VISIBLE'\r\n | 'LEAVING_VISIBLE'\r\n | 'DISMISSED';\r\n\r\n// Nothing goin' on\r\nexport const Idle = 'IDLE' as const;\r\n// We're considering showing the tooltip, but we're gonna wait a sec\r\nexport const Focused = 'FOCUSED' as const;\r\n// It's on!\r\nexport const Visible = 'VISIBLE' as const;\r\n// Focus has left, but we want to keep it visible for a sec\r\nexport const LeavingVisible = 'LEAVING_VISIBLE' as const;\r\n// The user clicked the tool, so we want to hide the thing, we can't just use\r\n// IDLE because we need to ignore mousemove, etc.\r\nexport const Dismissed = 'DISMISSED' as const;\r\n\r\nexport type TooltipEventTypes =\r\n | 'BLUR'\r\n | 'FOCUS'\r\n | 'GLOBAL_MOUSE_MOVE'\r\n | 'MOUSE_DOWN'\r\n | 'MOUSE_ENTER'\r\n | 'MOUSE_LEAVE'\r\n | 'MOUSE_MOVE'\r\n | 'REST'\r\n | 'SELECT_WITH_KEYBOARD'\r\n | 'TIME_COMPLETE';\r\n\r\nexport const Blur = 'BLUR' as const;\r\nexport const Focus = 'FOCUS' as const;\r\nexport const GlobalMouseMove = 'GLOBAL_MOUSE_MOVE' as const;\r\nexport const MouseDown = 'MOUSE_DOWN' as const;\r\nexport const MouseEnter = 'MOUSE_ENTER' as const;\r\nexport const MouseLeave = 'MOUSE_LEAVE' as const;\r\nexport const MouseMove = 'MOUSE_MOVE' as const;\r\nexport const Rest = 'REST' as const;\r\nexport const SelectWithKeyboard = 'SELECT_WITH_KEYBOARD' as const;\r\nexport const TimeComplete = 'TIME_COMPLETE' as const;\r\n\r\nexport const subscription = createSubscription();\r\nexport const state = {\r\n current: {\r\n state: Idle as TooltipStates,\r\n id: '',\r\n },\r\n};\r\n\r\nfunction clearContextId() {\r\n state.current.id = '';\r\n}\r\n\r\nconst chart: GenericStateChart<TooltipStates, TooltipEventTypes> = {\r\n initial: Idle,\r\n states: {\r\n [Idle]: {\r\n enter: () => {\r\n clearContextId();\r\n },\r\n on: {\r\n [MouseEnter]: Focused,\r\n [Focus]: Visible,\r\n },\r\n },\r\n [Focused]: {\r\n enter: startRestTimer,\r\n leave: clearRestTimer,\r\n on: {\r\n [MouseMove]: Focused,\r\n [MouseLeave]: Idle,\r\n [MouseDown]: Dismissed,\r\n [Blur]: Idle,\r\n [Rest]: Visible,\r\n },\r\n },\r\n [Visible]: {\r\n on: {\r\n [Focus]: Focused,\r\n [MouseEnter]: Focused,\r\n [MouseLeave]: LeavingVisible,\r\n [Blur]: LeavingVisible,\r\n [MouseDown]: Dismissed,\r\n [SelectWithKeyboard]: Dismissed,\r\n [GlobalMouseMove]: LeavingVisible,\r\n },\r\n },\r\n [LeavingVisible]: {\r\n enter: () => {\r\n startLeavingVisibleTimer();\r\n },\r\n leave: () => {\r\n clearLeavingVisibleTimer();\r\n clearContextId();\r\n },\r\n on: {\r\n [MouseEnter]: Visible,\r\n [Focus]: Visible,\r\n [TimeComplete]: Idle,\r\n },\r\n },\r\n [Dismissed]: {\r\n leave: () => {\r\n clearContextId();\r\n },\r\n on: {\r\n [MouseLeave]: Idle,\r\n [Blur]: Idle,\r\n },\r\n },\r\n },\r\n};\r\n\r\nfunction transition(\r\n currentState: typeof state['current'],\r\n event: TooltipEventTypes,\r\n payload?: Omit<typeof state['current'], 'state'>\r\n): typeof state['current'] {\r\n const currentStateValue = currentState.state;\r\n const stateDef = chart.states[currentState.state];\r\n const nextState = stateDef?.on?.[event];\r\n\r\n // Really useful for debugging\r\n // console.log({\r\n // event,\r\n // state: state.current.state,\r\n // id: state.current.id,\r\n // nextState,\r\n // });\r\n\r\n if (!nextState) {\r\n return currentState;\r\n }\r\n\r\n if (stateDef && stateDef.leave) {\r\n stateDef.leave(currentStateValue, payload);\r\n }\r\n\r\n const nextStateValue = nextState;\r\n const nextDef = chart.states[nextStateValue];\r\n if (nextDef && nextDef.enter) {\r\n nextDef.enter(nextStateValue, payload);\r\n }\r\n\r\n return { ...currentState, ...payload, state: nextStateValue };\r\n}\r\n\r\nexport function send<T extends TooltipEventTypes>(\r\n event: T,\r\n payload?: Omit<typeof state['current'], 'state'>\r\n) {\r\n const nextState = transition(state.current, event, payload);\r\n if (state.current !== nextState) {\r\n state.current = nextState;\r\n subscription.notify();\r\n }\r\n}\r\n"],"mappings":";;;;;AAAA,SAASA,kBAAT,QAAmC,8BAAnC;AAGA;AACA;AAEA;AACA;AACA,IAAIC,WAAJ;;AACA,SAASC,cAAT,GAA0B;EACxBC,YAAY,CAACF,WAAD,CAAZ;EACAA,WAAW,GAAGG,UAAU,CAAC,YAAM;IAC7BC,IAAI,CAACC,IAAD,EAAOC,SAAP,CAAJ;EACD,CAFuB,EAErB,GAFqB,CAAxB;AAGD;;AAED,SAASC,cAAT,GAA0B;EACxBL,YAAY,CAACF,WAAD,CAAZ;AACD,C,CAED;;;AACA,IAAIQ,mBAAJ;;AACA,SAASC,wBAAT,GAAoC;EAClCP,YAAY,CAACM,mBAAD,CAAZ;EACAA,mBAAmB,GAAGL,UAAU,CAAC;IAAA,OAAMC,IAAI,CAACM,YAAD,EAAeJ,SAAf,CAAV;EAAA,CAAD,EAAsC,GAAtC,CAAhC;AACD;;AAED,SAASK,wBAAT,GAAoC;EAClCT,YAAY,CAACM,mBAAD,CAA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,iBAAf,EAAkCD,OAAlC;EACD;;EAED,IAAMI,cAAc,GAAGD,SAAvB;EACA,IAAME,OAAO,GAAGd,KAAK,CAACE,MAAN,CAAaW,cAAb,CAAhB;;EACA,IAAIC,OAAO,IAAIA,OAAO,CAACX,KAAvB,EAA8B;IAC5BW,OAAO,CAACX,KAAR,CAAcU,cAAd,EAA8BJ,OAA9B;EACD;;EAED,sCAAYF,YAAZ,GAA6BE,OAA7B;IAAsCb,KAAK,EAAEiB;EAA7C;AACD;;AAED,OAAO,SAASvC,IAAT,CACLkC,KADK,EAELC,OAFK,EAGL;EACA,IAAMG,SAAS,GAAGN,UAAU,CAACV,KAAK,CAACC,OAAP,EAAgBW,KAAhB,EAAuBC,OAAvB,CAA5B;;EACA,IAAIb,KAAK,CAACC,OAAN,KAAkBe,SAAtB,EAAiC;IAC/BhB,KAAK,CAACC,OAAN,GAAgBe,SAAhB;IACAjB,YAAY,CAACoB,MAAb;EACD;AACF"}
@@ -1,10 +1,10 @@
1
- import type { HTMLAttributes, ReactNode, Ref, RefAttributes, RefObject } from 'react';
2
- export declare type ChildProps = HTMLAttributes<HTMLElement> & RefAttributes<HTMLElement>;
3
- export interface InjectedTooltipProps extends HTMLAttributes<HTMLElement> {
4
- anchorEl: RefObject<HTMLElement>;
5
- visible: boolean;
6
- children?: ReactNode;
7
- }
8
- export declare function useTooltip(childProps: ChildProps, childRef: Ref<HTMLElement> | undefined, tooltipProps: HTMLAttributes<HTMLElement> & {
9
- label?: ReactNode;
10
- }): [ChildProps, InjectedTooltipProps];
1
+ import type { HTMLAttributes, ReactNode, Ref, RefAttributes, RefObject } from 'react';
2
+ export declare type ChildProps = HTMLAttributes<HTMLElement> & RefAttributes<HTMLElement>;
3
+ export interface InjectedTooltipProps extends HTMLAttributes<HTMLElement> {
4
+ anchorEl: RefObject<HTMLElement>;
5
+ visible: boolean;
6
+ children?: ReactNode;
7
+ }
8
+ export declare function useTooltip(childProps: ChildProps, childRef: Ref<HTMLElement> | undefined, tooltipProps: HTMLAttributes<HTMLElement> & {
9
+ label?: ReactNode;
10
+ }): [ChildProps, InjectedTooltipProps];
@@ -1 +1 @@
1
- {"version":3,"file":"useTooltip.js","names":["useRef","useEffect","useState","useId","assignMultipleRefs","wrapEvent","send","state","subscription","Blur","Focus","LeavingVisible","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","Visible","useTooltip","childProps","childRef","tooltipProps","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onKeyDown","onFocus","onBlur","anchorEl","visible","setVisible","id","subscribe","current","handleMouseEnter","handleMouseMove","handleMouseLeave","handleMouseDown","handleFocus","handleBlur","undefined","handleKeyDown","event","key","children","label","tooltipOnMouseEnter","tooltipOnMouseLeave","tooltipOnMouseMove","otherTooltipProps","tooltipId","ref","role"],"sources":["../../../src/Tooltip/useTooltip.ts"],"sourcesContent":["import type {\n HTMLAttributes,\n KeyboardEvent,\n ReactNode,\n Ref,\n RefAttributes,\n RefObject,\n} from 'react';\nimport { useRef, useEffect, useState, useId } from 'react';\n\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { wrapEvent } from '../utils/wrap-event';\nimport {\n send,\n state,\n subscription,\n Blur,\n Focus,\n LeavingVisible,\n MouseDown,\n MouseEnter,\n MouseLeave,\n MouseMove,\n SelectWithKeyboard,\n Visible,\n} from './stateMachine';\n\nexport type ChildProps = HTMLAttributes<HTMLElement> &\n RefAttributes<HTMLElement>;\n\nexport interface InjectedTooltipProps extends HTMLAttributes<HTMLElement> {\n anchorEl: RefObject<HTMLElement>;\n visible: boolean;\n children?: ReactNode;\n}\n\nexport function useTooltip(\n childProps: ChildProps,\n childRef: Ref<HTMLElement> | undefined,\n tooltipProps: HTMLAttributes<HTMLElement> & { label?: ReactNode }\n): [ChildProps, InjectedTooltipProps] {\n const {\n onMouseEnter,\n onMouseLeave,\n onMouseMove,\n onMouseDown,\n onKeyDown,\n onFocus,\n onBlur,\n } = childProps;\n const anchorEl = useRef<HTMLElement>(null);\n const [visible, setVisible] = useState(false);\n const id = useId();\n\n useEffect(() => {\n subscription.subscribe(() => {\n setVisible(\n (state.current.state === Visible ||\n state.current.state === LeavingVisible) &&\n state.current.id === id\n );\n });\n }, [id]);\n\n function handleMouseEnter() {\n send(MouseEnter, { id });\n }\n\n function handleMouseMove() {\n send(MouseMove, { id });\n }\n\n function handleMouseLeave() {\n send(MouseLeave);\n }\n\n function handleMouseDown() {\n // Allow quick click from one tool to another\n if (state.current.id === id) {\n send(MouseDown);\n }\n }\n\n function handleFocus() {\n send(Focus, { id });\n }\n\n function handleBlur() {\n // Allow quick click from one tool to another\n if (state.current.id === id) {\n send(Blur, undefined);\n }\n }\n\n function handleKeyDown(event: KeyboardEvent<HTMLElement>) {\n if (event.key === 'Enter' || event.key === ' ') {\n send(SelectWithKeyboard);\n }\n }\n\n const {\n label: children,\n onMouseEnter: tooltipOnMouseEnter,\n onMouseLeave: tooltipOnMouseLeave,\n onMouseMove: tooltipOnMouseMove,\n ...otherTooltipProps\n } = tooltipProps;\n\n const tooltipId = `tooltip-${id}`;\n return [\n {\n ...childProps,\n ref: assignMultipleRefs(childRef, anchorEl),\n ...(visible &&\n !childProps['aria-label'] && { 'aria-describedby': tooltipId }),\n onMouseEnter: wrapEvent(onMouseEnter, handleMouseEnter),\n onMouseLeave: wrapEvent(onMouseLeave, handleMouseLeave),\n onMouseMove: wrapEvent(onMouseMove, handleMouseMove),\n onMouseDown: wrapEvent(onMouseDown, handleMouseDown),\n onFocus: wrapEvent(onFocus, handleFocus),\n onBlur: wrapEvent(onBlur, handleBlur),\n onKeyDown: wrapEvent(onKeyDown, handleKeyDown),\n },\n {\n id: tooltipId,\n anchorEl,\n visible,\n children,\n onMouseEnter: wrapEvent(tooltipOnMouseEnter, handleMouseEnter),\n onMouseLeave: wrapEvent(tooltipOnMouseLeave, handleMouseLeave),\n onMouseMove: wrapEvent(tooltipOnMouseMove, handleMouseMove),\n role: 'tooltip',\n ...otherTooltipProps,\n },\n ];\n}\n"],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AAU,CAAC,YAAD,CADT,IAC2B;IAAE,oBAAoBgC;EAAtB,CAL5B;IAMH7B,YAAY,EAAEjB,SAAS,CAACiB,YAAD,EAAea,gBAAf,CANpB;IAOHZ,YAAY,EAAElB,SAAS,CAACkB,YAAD,EAAec,gBAAf,CAPpB;IAQHb,WAAW,EAAEnB,SAAS,CAACmB,WAAD,EAAcY,eAAd,CARnB;IASHX,WAAW,EAAEpB,SAAS,CAACoB,WAAD,EAAca,eAAd,CATnB;IAUHX,OAAO,EAAEtB,SAAS,CAACsB,OAAD,EAAUY,WAAV,CAVf;IAWHX,MAAM,EAAEvB,SAAS,CAACuB,MAAD,EAASY,UAAT,CAXd;IAYHd,SAAS,EAAErB,SAAS,CAACqB,SAAD,EAAYgB,aAAZ;EAZjB;IAeHV,EAAE,EAAEmB,SAfD;IAgBHtB,QAAQ,EAARA,QAhBG;IAiBHC,OAAO,EAAPA,OAjBG;IAkBHe,QAAQ,EAARA,QAlBG;IAmBHvB,YAAY,EAAEjB,SAAS,CAAC0C,mBAAD,EAAsBZ,gBAAtB,CAnBpB;IAoBHZ,YAAY,EAAElB,SAAS,CAAC2C,mBAAD,EAAsBX,gBAAtB,CApBpB;IAqBHb,WAAW,EAAEnB,SAAS,CAAC4C,kBAAD,EAAqBb,eAArB,CArBnB;IAsBHiB,IAAI,EAAE;EAtBH,GAuBAH,iBAvBA,EAAP;AA0BD"}
1
+ {"version":3,"file":"useTooltip.js","names":["useRef","useEffect","useState","useId","assignMultipleRefs","wrapEvent","send","state","subscription","Blur","Focus","LeavingVisible","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","Visible","useTooltip","childProps","childRef","tooltipProps","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onKeyDown","onFocus","onBlur","anchorEl","visible","setVisible","id","subscribe","current","handleMouseEnter","handleMouseMove","handleMouseLeave","handleMouseDown","handleFocus","handleBlur","undefined","handleKeyDown","event","key","children","label","tooltipOnMouseEnter","tooltipOnMouseLeave","tooltipOnMouseMove","otherTooltipProps","tooltipId","ref","role"],"sources":["../../../src/Tooltip/useTooltip.ts"],"sourcesContent":["import type {\r\n HTMLAttributes,\r\n KeyboardEvent,\r\n ReactNode,\r\n Ref,\r\n RefAttributes,\r\n RefObject,\r\n} from 'react';\r\nimport { useRef, useEffect, useState, useId } from 'react';\r\n\r\nimport { assignMultipleRefs } from '../utils/assign-ref';\r\nimport { wrapEvent } from '../utils/wrap-event';\r\nimport {\r\n send,\r\n state,\r\n subscription,\r\n Blur,\r\n Focus,\r\n LeavingVisible,\r\n MouseDown,\r\n MouseEnter,\r\n MouseLeave,\r\n MouseMove,\r\n SelectWithKeyboard,\r\n Visible,\r\n} from './stateMachine';\r\n\r\nexport type ChildProps = HTMLAttributes<HTMLElement> &\r\n RefAttributes<HTMLElement>;\r\n\r\nexport interface InjectedTooltipProps extends HTMLAttributes<HTMLElement> {\r\n anchorEl: RefObject<HTMLElement>;\r\n visible: boolean;\r\n children?: ReactNode;\r\n}\r\n\r\nexport function useTooltip(\r\n childProps: ChildProps,\r\n childRef: Ref<HTMLElement> | undefined,\r\n tooltipProps: HTMLAttributes<HTMLElement> & { label?: ReactNode }\r\n): [ChildProps, InjectedTooltipProps] {\r\n const {\r\n onMouseEnter,\r\n onMouseLeave,\r\n onMouseMove,\r\n onMouseDown,\r\n onKeyDown,\r\n onFocus,\r\n onBlur,\r\n } = childProps;\r\n const anchorEl = useRef<HTMLElement>(null);\r\n const [visible, setVisible] = useState(false);\r\n const id = useId();\r\n\r\n useEffect(() => {\r\n subscription.subscribe(() => {\r\n setVisible(\r\n (state.current.state === Visible ||\r\n state.current.state === LeavingVisible) &&\r\n state.current.id === id\r\n );\r\n });\r\n }, [id]);\r\n\r\n function handleMouseEnter() {\r\n send(MouseEnter, { id });\r\n }\r\n\r\n function handleMouseMove() {\r\n send(MouseMove, { id });\r\n }\r\n\r\n function handleMouseLeave() {\r\n send(MouseLeave);\r\n }\r\n\r\n function handleMouseDown() {\r\n // Allow quick click from one tool to another\r\n if (state.current.id === id) {\r\n send(MouseDown);\r\n }\r\n }\r\n\r\n function handleFocus() {\r\n send(Focus, { id });\r\n }\r\n\r\n function handleBlur() {\r\n // Allow quick click from one tool to another\r\n if (state.current.id === id) {\r\n send(Blur, undefined);\r\n }\r\n }\r\n\r\n function handleKeyDown(event: KeyboardEvent<HTMLElement>) {\r\n if (event.key === 'Enter' || event.key === ' ') {\r\n send(SelectWithKeyboard);\r\n }\r\n }\r\n\r\n const {\r\n label: children,\r\n onMouseEnter: tooltipOnMouseEnter,\r\n onMouseLeave: tooltipOnMouseLeave,\r\n onMouseMove: tooltipOnMouseMove,\r\n ...otherTooltipProps\r\n } = tooltipProps;\r\n\r\n const tooltipId = `tooltip-${id}`;\r\n return [\r\n {\r\n ...childProps,\r\n ref: assignMultipleRefs(childRef, anchorEl),\r\n ...(visible &&\r\n !childProps['aria-label'] && { 'aria-describedby': tooltipId }),\r\n onMouseEnter: wrapEvent(onMouseEnter, handleMouseEnter),\r\n onMouseLeave: wrapEvent(onMouseLeave, handleMouseLeave),\r\n onMouseMove: wrapEvent(onMouseMove, handleMouseMove),\r\n onMouseDown: wrapEvent(onMouseDown, handleMouseDown),\r\n onFocus: wrapEvent(onFocus, handleFocus),\r\n onBlur: wrapEvent(onBlur, handleBlur),\r\n onKeyDown: wrapEvent(onKeyDown, handleKeyDown),\r\n },\r\n {\r\n id: tooltipId,\r\n anchorEl,\r\n visible,\r\n children,\r\n onMouseEnter: wrapEvent(tooltipOnMouseEnter, handleMouseEnter),\r\n onMouseLeave: wrapEvent(tooltipOnMouseLeave, handleMouseLeave),\r\n onMouseMove: wrapEvent(tooltipOnMouseMove, handleMouseMove),\r\n role: 'tooltip',\r\n ...otherTooltipProps,\r\n },\r\n ];\r\n}\r\n"],"mappings":";;;;AAQA,SAASA,MAAT,EAAiBC,SAAjB,EAA4BC,QAA5B,EAAsCC,KAAtC,QAAmD,OAAnD;AAEA,SAASC,kBAAT,QAAmC,qBAAnC;AACA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,YAAY,EAAElB,SAAS,CAACkB,YAAD,EAAec,gBAAf,CAPpB;IAQHb,WAAW,EAAEnB,SAAS,CAACmB,WAAD,EAAcY,eAAd,CARnB;IASHX,WAAW,EAAEpB,SAAS,CAACoB,WAAD,EAAca,eAAd,CATnB;IAUHX,OAAO,EAAEtB,SAAS,CAACsB,OAAD,EAAUY,WAAV,CAVf;IAWHX,MAAM,EAAEvB,SAAS,CAACuB,MAAD,EAASY,UAAT,CAXd;IAYHd,SAAS,EAAErB,SAAS,CAACqB,SAAD,EAAYgB,aAAZ;EAZjB;IAeHV,EAAE,EAAEmB,SAfD;IAgBHtB,QAAQ,EAARA,QAhBG;IAiBHC,OAAO,EAAPA,OAjBG;IAkBHe,QAAQ,EAARA,QAlBG;IAmBHvB,YAAY,EAAEjB,SAAS,CAAC0C,mBAAD,EAAsBZ,gBAAtB,CAnBpB;IAoBHZ,YAAY,EAAElB,SAAS,CAAC2C,mBAAD,EAAsBX,gBAAtB,CApBpB;IAqBHb,WAAW,EAAEnB,SAAS,CAAC4C,kBAAD,EAAqBb,eAArB,CArBnB;IAsBHiB,IAAI,EAAE;EAtBH,GAuBAH,iBAvBA,EAAP;AA0BD"}
@@ -1,13 +1,13 @@
1
- export * from './useAutoFocus';
2
- export * from './useControlledState';
3
- export * from './useChildrenCounter';
4
- export * from './useFocusReturn';
5
- export * from './useFocusState';
6
- export * from './useOnClickOutside';
7
- export * from './useOnKeyDown';
8
- export * from './useReducerMachine';
9
- export * from './useRemoveBodyScroll';
10
- export * from './useThrottle';
11
- export * from './useMeasure';
12
- export * from './useGestureHandlers';
13
- export * from './useScope';
1
+ export * from './useAutoFocus';
2
+ export * from './useControlledState';
3
+ export * from './useChildrenCounter';
4
+ export * from './useFocusReturn';
5
+ export * from './useFocusState';
6
+ export * from './useOnClickOutside';
7
+ export * from './useOnKeyDown';
8
+ export * from './useReducerMachine';
9
+ export * from './useRemoveBodyScroll';
10
+ export * from './useThrottle';
11
+ export * from './useMeasure';
12
+ export * from './useGestureHandlers';
13
+ export * from './useScope';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useAutoFocus';\nexport * from './useControlledState';\nexport * from './useChildrenCounter';\nexport * from './useFocusReturn';\nexport * from './useFocusState';\nexport * from './useOnClickOutside';\nexport * from './useOnKeyDown';\nexport * from './useReducerMachine';\nexport * from './useRemoveBodyScroll';\nexport * from './useThrottle';\nexport * from './useMeasure';\nexport * from './useGestureHandlers';\nexport * from './useScope';\n"],"mappings":"AAAA,cAAc,gBAAd;AACA,cAAc,sBAAd;AACA,cAAc,sBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AACA,cAAc,qBAAd;AACA,cAAc,gBAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,eAAd;AACA,cAAc,cAAd;AACA,cAAc,sBAAd;AACA,cAAc,YAAd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useAutoFocus';\r\nexport * from './useControlledState';\r\nexport * from './useChildrenCounter';\r\nexport * from './useFocusReturn';\r\nexport * from './useFocusState';\r\nexport * from './useOnClickOutside';\r\nexport * from './useOnKeyDown';\r\nexport * from './useReducerMachine';\r\nexport * from './useRemoveBodyScroll';\r\nexport * from './useThrottle';\r\nexport * from './useMeasure';\r\nexport * from './useGestureHandlers';\r\nexport * from './useScope';\r\n"],"mappings":"AAAA,cAAc,gBAAd;AACA,cAAc,sBAAd;AACA,cAAc,sBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AACA,cAAc,qBAAd;AACA,cAAc,gBAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,eAAd;AACA,cAAc,cAAd;AACA,cAAc,sBAAd;AACA,cAAc,YAAd"}
@@ -1,2 +1,2 @@
1
- import type { MutableRefObject } from 'react';
2
- export declare function useAutoFocus(open: boolean, elementRef: MutableRefObject<HTMLElement | null>): void;
1
+ import type { MutableRefObject } from 'react';
2
+ export declare function useAutoFocus(open: boolean, elementRef: MutableRefObject<HTMLElement | null>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoFocus.js","names":["useEffect","focusOnChildNode","useAutoFocus","open","elementRef","current","contains","document","activeElement"],"sources":["../../../src/hooks/useAutoFocus.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nimport { focusOnChildNode } from '../FocusLock/tabUtils';\n\nexport function useAutoFocus(\n open: boolean,\n elementRef: MutableRefObject<HTMLElement | null>\n) {\n useEffect(() => {\n if (open) {\n // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal\n if (\n elementRef.current &&\n !elementRef.current.contains(document.activeElement)\n ) {\n focusOnChildNode(elementRef.current, 0);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n}\n"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,SAASC,gBAAT,QAAiC,uBAAjC;AAEA,OAAO,SAASC,YAAT,CACLC,IADK,EAELC,UAFK,EAGL;EACAJ,SAAS,CAAC,YAAM;IACd,IAAIG,IAAJ,EAAU;MACR;MACA,IACEC,UAAU,CAACC,OAAX,IACA,CAACD,UAAU,CAACC,OAAX,CAAmBC,QAAnB,CAA4BC,QAAQ,CAACC,aAArC,CAFH,EAGE;QACAP,gBAAgB,CAACG,UAAU,CAACC,OAAZ,EAAqB,CAArB,CAAhB;MACD;IACF,CATa,CAUd;;EACD,CAXQ,EAWN,CAACF,IAAD,CAXM,CAAT;AAYD"}
1
+ {"version":3,"file":"useAutoFocus.js","names":["useEffect","focusOnChildNode","useAutoFocus","open","elementRef","current","contains","document","activeElement"],"sources":["../../../src/hooks/useAutoFocus.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\r\nimport { useEffect } from 'react';\r\n\r\nimport { focusOnChildNode } from '../FocusLock/tabUtils';\r\n\r\nexport function useAutoFocus(\r\n open: boolean,\r\n elementRef: MutableRefObject<HTMLElement | null>\r\n) {\r\n useEffect(() => {\r\n if (open) {\r\n // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal\r\n if (\r\n elementRef.current &&\r\n !elementRef.current.contains(document.activeElement)\r\n ) {\r\n focusOnChildNode(elementRef.current, 0);\r\n }\r\n }\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, [open]);\r\n}\r\n"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,SAASC,gBAAT,QAAiC,uBAAjC;AAEA,OAAO,SAASC,YAAT,CACLC,IADK,EAELC,UAFK,EAGL;EACAJ,SAAS,CAAC,YAAM;IACd,IAAIG,IAAJ,EAAU;MACR;MACA,IACEC,UAAU,CAACC,OAAX,IACA,CAACD,UAAU,CAACC,OAAX,CAAmBC,QAAnB,CAA4BC,QAAQ,CAACC,aAArC,CAFH,EAGE;QACAP,gBAAgB,CAACG,UAAU,CAACC,OAAZ,EAAqB,CAArB,CAAhB;MACD;IACF,CATa,CAUd;;EACD,CAXQ,EAWN,CAACF,IAAD,CAXM,CAAT;AAYD"}
@@ -1,7 +1,7 @@
1
- import type { MutableRefObject } from 'react';
2
- export declare function useChildrenCounterParent<T>(itemsRef: MutableRefObject<T[] & {
3
- isNewRender?: boolean;
4
- }>): void;
5
- export declare function useChildrenCounterChild<T>(itemsRef: MutableRefObject<T[] & {
6
- isNewRender?: boolean;
7
- }> | undefined, itemIndexRef: MutableRefObject<number>, obj: T | ((idx: number) => T), disabled?: boolean): void;
1
+ import type { MutableRefObject } from 'react';
2
+ export declare function useChildrenCounterParent<T>(itemsRef: MutableRefObject<T[] & {
3
+ isNewRender?: boolean;
4
+ }>): void;
5
+ export declare function useChildrenCounterChild<T>(itemsRef: MutableRefObject<T[] & {
6
+ isNewRender?: boolean;
7
+ }> | undefined, itemIndexRef: MutableRefObject<number>, obj: T | ((idx: number) => T), disabled?: boolean): void;
@@ -1 +1 @@
1
- {"version":3,"file":"useChildrenCounter.js","names":["useEffect","useChildrenCounterParent","itemsRef","current","isNewRender","useChildrenCounterChild","itemIndexRef","obj","disabled","length","Function","push"],"sources":["../../../src/hooks/useChildrenCounter.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nexport function useChildrenCounterParent<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>\n) {\n // Reset the options ref every render so that they are always\n // accurate and ready for keyboard navigation handlers. Using layout\n // effect to schedule this effect before the ComboboxOptions push into\n // the array\n itemsRef.current = [];\n itemsRef.current.isNewRender = true;\n\n useEffect(() => {\n // Rendering is finished. Meaning any children can now rerender,\n // and they should not push any new items to our array, because\n // it is not a new render\n itemsRef.current.isNewRender = false;\n });\n\n useEffect(() => {\n // When we are unmounting, it means there are no children anymore.\n // Clear out our items array\n return () => {\n itemsRef.current = [];\n };\n }, [itemsRef]);\n}\n\nexport function useChildrenCounterChild<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,\n itemIndexRef: MutableRefObject<number>,\n obj: T | ((idx: number) => T),\n disabled = false\n) {\n if (itemsRef && itemsRef.current.isNewRender) {\n if (disabled) {\n itemIndexRef.current = -1;\n return;\n }\n\n // push this option to the optionsRef array\n itemIndexRef.current = itemsRef.current.length;\n\n if (obj instanceof Function) {\n itemsRef.current.push(obj(itemIndexRef.current));\n } else {\n itemsRef.current.push(obj);\n }\n }\n}\n"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,OAAO,SAASC,wBAAT,CACLC,QADK,EAEL;EACA;EACA;EACA;EACA;EACAA,QAAQ,CAACC,OAAT,GAAmB,EAAnB;EACAD,QAAQ,CAACC,OAAT,CAAiBC,WAAjB,GAA+B,IAA/B;EAEAJ,SAAS,CAAC,YAAM;IACd;IACA;IACA;IACAE,QAAQ,CAACC,OAAT,CAAiBC,WAAjB,GAA+B,KAA/B;EACD,CALQ,CAAT;EAOAJ,SAAS,CAAC,YAAM;IACd;IACA;IACA,OAAO,YAAM;MACXE,QAAQ,CAACC,OAAT,GAAmB,EAAnB;IACD,CAFD;EAGD,CANQ,EAMN,CAACD,QAAD,CANM,CAAT;AAOD;AAED,OAAO,SAASG,uBAAT,CACLH,QADK,EAELI,YAFK,EAGLC,GAHK,EAKL;EAAA,IADAC,QACA,uEADW,KACX;;EACA,IAAIN,QAAQ,IAAIA,QAAQ,CAACC,OAAT,CAAiBC,WAAjC,EAA8C;IAC5C,IAAII,QAAJ,EAAc;MACZF,YAAY,CAACH,OAAb,GAAuB,CAAC,CAAxB;MACA;IACD,CAJ2C,CAM5C;;;IACAG,YAAY,CAACH,OAAb,GAAuBD,QAAQ,CAACC,OAAT,CAAiBM,MAAxC;;IAEA,IAAIF,GAAG,YAAYG,QAAnB,EAA6B;MAC3BR,QAAQ,CAACC,OAAT,CAAiBQ,IAAjB,CAAsBJ,GAAG,CAACD,YAAY,CAACH,OAAd,CAAzB;IACD,CAFD,MAEO;MACLD,QAAQ,CAACC,OAAT,CAAiBQ,IAAjB,CAAsBJ,GAAtB;IACD;EACF;AACF"}
1
+ {"version":3,"file":"useChildrenCounter.js","names":["useEffect","useChildrenCounterParent","itemsRef","current","isNewRender","useChildrenCounterChild","itemIndexRef","obj","disabled","length","Function","push"],"sources":["../../../src/hooks/useChildrenCounter.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\r\nimport { useEffect } from 'react';\r\n\r\nexport function useChildrenCounterParent<T>(\r\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>\r\n) {\r\n // Reset the options ref every render so that they are always\r\n // accurate and ready for keyboard navigation handlers. Using layout\r\n // effect to schedule this effect before the ComboboxOptions push into\r\n // the array\r\n itemsRef.current = [];\r\n itemsRef.current.isNewRender = true;\r\n\r\n useEffect(() => {\r\n // Rendering is finished. Meaning any children can now rerender,\r\n // and they should not push any new items to our array, because\r\n // it is not a new render\r\n itemsRef.current.isNewRender = false;\r\n });\r\n\r\n useEffect(() => {\r\n // When we are unmounting, it means there are no children anymore.\r\n // Clear out our items array\r\n return () => {\r\n itemsRef.current = [];\r\n };\r\n }, [itemsRef]);\r\n}\r\n\r\nexport function useChildrenCounterChild<T>(\r\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,\r\n itemIndexRef: MutableRefObject<number>,\r\n obj: T | ((idx: number) => T),\r\n disabled = false\r\n) {\r\n if (itemsRef && itemsRef.current.isNewRender) {\r\n if (disabled) {\r\n itemIndexRef.current = -1;\r\n return;\r\n }\r\n\r\n // push this option to the optionsRef array\r\n itemIndexRef.current = itemsRef.current.length;\r\n\r\n if (obj instanceof Function) {\r\n itemsRef.current.push(obj(itemIndexRef.current));\r\n } else {\r\n itemsRef.current.push(obj);\r\n }\r\n }\r\n}\r\n"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,OAAO,SAASC,wBAAT,CACLC,QADK,EAEL;EACA;EACA;EACA;EACA;EACAA,QAAQ,CAACC,OAAT,GAAmB,EAAnB;EACAD,QAAQ,CAACC,OAAT,CAAiBC,WAAjB,GAA+B,IAA/B;EAEAJ,SAAS,CAAC,YAAM;IACd;IACA;IACA;IACAE,QAAQ,CAACC,OAAT,CAAiBC,WAAjB,GAA+B,KAA/B;EACD,CALQ,CAAT;EAOAJ,SAAS,CAAC,YAAM;IACd;IACA;IACA,OAAO,YAAM;MACXE,QAAQ,CAACC,OAAT,GAAmB,EAAnB;IACD,CAFD;EAGD,CANQ,EAMN,CAACD,QAAD,CANM,CAAT;AAOD;AAED,OAAO,SAASG,uBAAT,CACLH,QADK,EAELI,YAFK,EAGLC,GAHK,EAKL;EAAA,IADAC,QACA,uEADW,KACX;;EACA,IAAIN,QAAQ,IAAIA,QAAQ,CAACC,OAAT,CAAiBC,WAAjC,EAA8C;IAC5C,IAAII,QAAJ,EAAc;MACZF,YAAY,CAACH,OAAb,GAAuB,CAAC,CAAxB;MACA;IACD,CAJ2C,CAM5C;;;IACAG,YAAY,CAACH,OAAb,GAAuBD,QAAQ,CAACC,OAAT,CAAiBM,MAAxC;;IAEA,IAAIF,GAAG,YAAYG,QAAnB,EAA6B;MAC3BR,QAAQ,CAACC,OAAT,CAAiBQ,IAAjB,CAAsBJ,GAAG,CAACD,YAAY,CAACH,OAAd,CAAzB;IACD,CAFD,MAEO;MACLD,QAAQ,CAACC,OAAT,CAAiBQ,IAAjB,CAAsBJ,GAAtB;IACD;EACF;AACF"}
@@ -1,3 +1,3 @@
1
- import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';
2
- import type { CustomEventHandler } from '../utils';
3
- export declare function useControlledState<V, E extends SyntheticEvent<any> | Event, H extends unknown[]>(valueProp: V | undefined, onChangeProp: CustomEventHandler<E, H> | undefined, defaultValue: V | (() => V), defaultOnChange: (setValue: Dispatch<SetStateAction<V>>) => CustomEventHandler<E, H>): [V, CustomEventHandler<E, H>];
1
+ import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';
2
+ import type { CustomEventHandler } from '../utils';
3
+ export declare function useControlledState<V, E extends SyntheticEvent<any> | Event, H extends unknown[]>(valueProp: V | undefined, onChangeProp: CustomEventHandler<E, H> | undefined, defaultValue: V | (() => V), defaultOnChange: (setValue: Dispatch<SetStateAction<V>>) => CustomEventHandler<E, H>): [V, CustomEventHandler<E, H>];
@@ -12,7 +12,7 @@ export function useControlledState(valueProp, onChangeProp, defaultValue, defaul
12
12
  setValueState = _useState2[1];
13
13
 
14
14
  if (isControlled) {
15
- if (wasControlled.current && process.env.NODE_ENV !== 'production' && !hasWarned.current) {
15
+ if (!wasControlled.current && !hasWarned.current && process.env.NODE_ENV !== 'production') {
16
16
  console.warn('Trying to change from controlled to uncontrolled.');
17
17
  hasWarned.current = true;
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n wasControlled.current &&\n process.env.NODE_ENV !== 'production' &&\n !hasWarned.current\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueProp!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n }\n\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueState!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n}\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;AAGA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAO,SAASC,kBAAT,CAKLC,SALK,EAMLC,YANK,EAOLC,YAPK,EAQLC,eARK,EAW0B;EAC/B,IAAMC,YAAY,GAAGJ,SAAS,KAAKK,SAAnC;EACA,IAAMC,aAAa,GAAGV,MAAM,CAACQ,YAAD,CAA5B;EACA,IAAMG,SAAS,GAAGX,MAAM,CAAC,KAAD,CAAxB;;EACA,gBAAoCC,QAAQ,CAAIK,YAAJ,CAA5C;EAAA;EAAA,IAAOM,UAAP;EAAA,IAAmBC,aAAnB;;EAEA,IAAIL,YAAJ,EAAkB;IAChB,IACEE,aAAa,CAACI,OAAd,IACAC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YADzB,IAEA,CAACN,SAAS,CAACG,OAHb,EAIE;MACAI,OAAO,CAACC,IAAR,CAAa,mDAAb;MACAR,SAAS,CAACG,OAAV,GAAoB,IAApB;IACD;;IACD,OAAO,CACL;IACAV,SAFK,EAGLF,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;EAKD;;EAED,OAAO,CACL;EACAD,UAFK,EAGLV,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;AAKD"}
1
+ {"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n !wasControlled.current &&\n !hasWarned.current &&\n process.env.NODE_ENV !== 'production'\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueProp!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n }\n\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueState!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n}\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;AAGA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAO,SAASC,kBAAT,CAKLC,SALK,EAMLC,YANK,EAOLC,YAPK,EAQLC,eARK,EAW0B;EAC/B,IAAMC,YAAY,GAAGJ,SAAS,KAAKK,SAAnC;EACA,IAAMC,aAAa,GAAGV,MAAM,CAACQ,YAAD,CAA5B;EACA,IAAMG,SAAS,GAAGX,MAAM,CAAC,KAAD,CAAxB;;EACA,gBAAoCC,QAAQ,CAAIK,YAAJ,CAA5C;EAAA;EAAA,IAAOM,UAAP;EAAA,IAAmBC,aAAnB;;EAEA,IAAIL,YAAJ,EAAkB;IAChB,IACE,CAACE,aAAa,CAACI,OAAf,IACA,CAACH,SAAS,CAACG,OADX,IAEAC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAH3B,EAIE;MACAC,OAAO,CAACC,IAAR,CAAa,mDAAb;MACAR,SAAS,CAACG,OAAV,GAAoB,IAApB;IACD;;IACD,OAAO,CACL;IACAV,SAFK,EAGLF,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;EAKD;;EAED,OAAO,CACL;EACAD,UAFK,EAGLV,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;AAKD"}
@@ -1,2 +1,2 @@
1
- import type { MutableRefObject } from 'react';
2
- export declare function useFocusReturn(open: boolean, rootEl: MutableRefObject<HTMLElement | null>): void;
1
+ import type { MutableRefObject } from 'react';
2
+ export declare function useFocusReturn(open: boolean, rootEl: MutableRefObject<HTMLElement | null>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"useFocusReturn.js","names":["useEffect","useRef","useFocusReturn","open","rootEl","previousFocusRef","document","activeElement","HTMLElement","current","contains","rootElement","previousElement","focus","preventScroll"],"sources":["../../../src/hooks/useFocusReturn.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport function useFocusReturn(\n open: boolean,\n rootEl: MutableRefObject<HTMLElement | null>\n) {\n const previousFocusRef = useRef<HTMLElement | null>(\n (() => {\n if (\n open &&\n typeof document !== 'undefined' &&\n document.activeElement instanceof HTMLElement\n ) {\n return document.activeElement;\n }\n return null;\n })()\n );\n\n useEffect(() => {\n if (open) {\n // once opened, keep track of the element that triggered\n // the Modal opening\n if (\n !previousFocusRef.current &&\n document.activeElement instanceof HTMLElement &&\n !rootEl.current?.contains(document.activeElement)\n ) {\n previousFocusRef.current = document.activeElement;\n }\n\n const rootElement = rootEl.current;\n const previousElement = previousFocusRef.current;\n return () => {\n // on unmount, return focus to that element\n if (previousElement && !rootElement?.contains(document.activeElement)) {\n previousElement.focus({ preventScroll: true });\n }\n };\n }\n }, [open, rootEl]);\n}\n"],"mappings":"AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AAEA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,MAFK,EAGL;EACA,IAAMC,gBAAgB,GAAGJ,MAAM,CAC5B,YAAM;IACL,IACEE,IAAI,IACJ,OAAOG,QAAP,KAAoB,WADpB,IAEAA,QAAQ,CAACC,aAAT,YAAkCC,WAHpC,EAIE;MACA,OAAOF,QAAQ,CAACC,aAAhB;IACD;;IACD,OAAO,IAAP;EACD,CATD,EAD6B,CAA/B;EAaAP,SAAS,CAAC,YAAM;IACd,IAAIG,IAAJ,EAAU;MAAA;;MACR;MACA;MACA,IACE,CAACE,gBAAgB,CAACI,OAAlB,IACAH,QAAQ,CAACC,aAAT,YAAkCC,WADlC,IAEA,qBAACJ,MAAM,CAACK,OAAR,4CAAC,gBAAgBC,QAAhB,CAAyBJ,QAAQ,CAACC,aAAlC,CAAD,CAHF,EAIE;QACAF,gBAAgB,CAACI,OAAjB,GAA2BH,QAAQ,CAACC,aAApC;MACD;;MAED,IAAMI,WAAW,GAAGP,MAAM,CAACK,OAA3B;MACA,IAAMG,eAAe,GAAGP,gBAAgB,CAACI,OAAzC;MACA,OAAO,YAAM;QACX;QACA,IAAIG,eAAe,IAAI,EAACD,WAAD,aAACA,WAAD,eAACA,WAAW,CAAED,QAAb,CAAsBJ,QAAQ,CAACC,aAA/B,CAAD,CAAvB,EAAuE;UACrEK,eAAe,CAACC,KAAhB,CAAsB;YAAEC,aAAa,EAAE;UAAjB,CAAtB;QACD;MACF,CALD;IAMD;EACF,CArBQ,EAqBN,CAACX,IAAD,EAAOC,MAAP,CArBM,CAAT;AAsBD"}
1
+ {"version":3,"file":"useFocusReturn.js","names":["useEffect","useRef","useFocusReturn","open","rootEl","previousFocusRef","document","activeElement","HTMLElement","current","contains","rootElement","previousElement","focus","preventScroll"],"sources":["../../../src/hooks/useFocusReturn.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\r\nimport { useEffect, useRef } from 'react';\r\n\r\nexport function useFocusReturn(\r\n open: boolean,\r\n rootEl: MutableRefObject<HTMLElement | null>\r\n) {\r\n const previousFocusRef = useRef<HTMLElement | null>(\r\n (() => {\r\n if (\r\n open &&\r\n typeof document !== 'undefined' &&\r\n document.activeElement instanceof HTMLElement\r\n ) {\r\n return document.activeElement;\r\n }\r\n return null;\r\n })()\r\n );\r\n\r\n useEffect(() => {\r\n if (open) {\r\n // once opened, keep track of the element that triggered\r\n // the Modal opening\r\n if (\r\n !previousFocusRef.current &&\r\n document.activeElement instanceof HTMLElement &&\r\n !rootEl.current?.contains(document.activeElement)\r\n ) {\r\n previousFocusRef.current = document.activeElement;\r\n }\r\n\r\n const rootElement = rootEl.current;\r\n const previousElement = previousFocusRef.current;\r\n return () => {\r\n // on unmount, return focus to that element\r\n if (previousElement && !rootElement?.contains(document.activeElement)) {\r\n previousElement.focus({ preventScroll: true });\r\n }\r\n };\r\n }\r\n }, [open, rootEl]);\r\n}\r\n"],"mappings":"AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AAEA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,MAFK,EAGL;EACA,IAAMC,gBAAgB,GAAGJ,MAAM,CAC5B,YAAM;IACL,IACEE,IAAI,IACJ,OAAOG,QAAP,KAAoB,WADpB,IAEAA,QAAQ,CAACC,aAAT,YAAkCC,WAHpC,EAIE;MACA,OAAOF,QAAQ,CAACC,aAAhB;IACD;;IACD,OAAO,IAAP;EACD,CATD,EAD6B,CAA/B;EAaAP,SAAS,CAAC,YAAM;IACd,IAAIG,IAAJ,EAAU;MAAA;;MACR;MACA;MACA,IACE,CAACE,gBAAgB,CAACI,OAAlB,IACAH,QAAQ,CAACC,aAAT,YAAkCC,WADlC,IAEA,qBAACJ,MAAM,CAACK,OAAR,4CAAC,gBAAgBC,QAAhB,CAAyBJ,QAAQ,CAACC,aAAlC,CAAD,CAHF,EAIE;QACAF,gBAAgB,CAACI,OAAjB,GAA2BH,QAAQ,CAACC,aAApC;MACD;;MAED,IAAMI,WAAW,GAAGP,MAAM,CAACK,OAA3B;MACA,IAAMG,eAAe,GAAGP,gBAAgB,CAACI,OAAzC;MACA,OAAO,YAAM;QACX;QACA,IAAIG,eAAe,IAAI,EAACD,WAAD,aAACA,WAAD,eAACA,WAAW,CAAED,QAAb,CAAsBJ,QAAQ,CAACC,aAA/B,CAAD,CAAvB,EAAuE;UACrEK,eAAe,CAACC,KAAhB,CAAsB;YAAEC,aAAa,EAAE;UAAjB,CAAtB;QACD;MACF,CALD;IAMD;EACF,CArBQ,EAqBN,CAACX,IAAD,EAAOC,MAAP,CArBM,CAAT;AAsBD"}
@@ -1,11 +1,11 @@
1
- import type { FocusEventHandler } from 'react';
2
- export declare function useFocusState<T>(props?: {
3
- onFocus?: FocusEventHandler<T>;
4
- onBlur?: FocusEventHandler<T>;
5
- }): {
6
- bind: {
7
- onFocus: import("../utils/wrap-event").CustomEventHandler<import("react").FocusEvent<T, Element>, []>;
8
- onBlur: import("../utils/wrap-event").CustomEventHandler<import("react").FocusEvent<T, Element>, []>;
9
- };
10
- hasFocus: boolean;
11
- };
1
+ import type { FocusEventHandler } from 'react';
2
+ export declare function useFocusState<T>(props?: {
3
+ onFocus?: FocusEventHandler<T>;
4
+ onBlur?: FocusEventHandler<T>;
5
+ }): {
6
+ bind: {
7
+ onFocus: import("../utils/wrap-event").CustomEventHandler<import("react").FocusEvent<T, Element>, []>;
8
+ onBlur: import("../utils/wrap-event").CustomEventHandler<import("react").FocusEvent<T, Element>, []>;
9
+ };
10
+ hasFocus: boolean;
11
+ };