@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,136 +1,136 @@
1
- import type {
2
- HTMLAttributes,
3
- KeyboardEvent,
4
- ReactNode,
5
- Ref,
6
- RefAttributes,
7
- RefObject,
8
- } from 'react';
9
- import { useRef, useEffect, useState, useId } from 'react';
10
-
11
- import { assignMultipleRefs } from '../utils/assign-ref';
12
- import { wrapEvent } from '../utils/wrap-event';
13
- import {
14
- send,
15
- state,
16
- subscription,
17
- Blur,
18
- Focus,
19
- LeavingVisible,
20
- MouseDown,
21
- MouseEnter,
22
- MouseLeave,
23
- MouseMove,
24
- SelectWithKeyboard,
25
- Visible,
26
- } from './stateMachine';
27
-
28
- export type ChildProps = HTMLAttributes<HTMLElement> &
29
- RefAttributes<HTMLElement>;
30
-
31
- export interface InjectedTooltipProps extends HTMLAttributes<HTMLElement> {
32
- anchorEl: RefObject<HTMLElement>;
33
- visible: boolean;
34
- children?: ReactNode;
35
- }
36
-
37
- export function useTooltip(
38
- childProps: ChildProps,
39
- childRef: Ref<HTMLElement> | undefined,
40
- tooltipProps: HTMLAttributes<HTMLElement> & { label?: ReactNode }
41
- ): [ChildProps, InjectedTooltipProps] {
42
- const {
43
- onMouseEnter,
44
- onMouseLeave,
45
- onMouseMove,
46
- onMouseDown,
47
- onKeyDown,
48
- onFocus,
49
- onBlur,
50
- } = childProps;
51
- const anchorEl = useRef<HTMLElement>(null);
52
- const [visible, setVisible] = useState(false);
53
- const id = useId();
54
-
55
- useEffect(() => {
56
- subscription.subscribe(() => {
57
- setVisible(
58
- (state.current.state === Visible ||
59
- state.current.state === LeavingVisible) &&
60
- state.current.id === id
61
- );
62
- });
63
- }, [id]);
64
-
65
- function handleMouseEnter() {
66
- send(MouseEnter, { id });
67
- }
68
-
69
- function handleMouseMove() {
70
- send(MouseMove, { id });
71
- }
72
-
73
- function handleMouseLeave() {
74
- send(MouseLeave);
75
- }
76
-
77
- function handleMouseDown() {
78
- // Allow quick click from one tool to another
79
- if (state.current.id === id) {
80
- send(MouseDown);
81
- }
82
- }
83
-
84
- function handleFocus() {
85
- send(Focus, { id });
86
- }
87
-
88
- function handleBlur() {
89
- // Allow quick click from one tool to another
90
- if (state.current.id === id) {
91
- send(Blur, undefined);
92
- }
93
- }
94
-
95
- function handleKeyDown(event: KeyboardEvent<HTMLElement>) {
96
- if (event.key === 'Enter' || event.key === ' ') {
97
- send(SelectWithKeyboard);
98
- }
99
- }
100
-
101
- const {
102
- label: children,
103
- onMouseEnter: tooltipOnMouseEnter,
104
- onMouseLeave: tooltipOnMouseLeave,
105
- onMouseMove: tooltipOnMouseMove,
106
- ...otherTooltipProps
107
- } = tooltipProps;
108
-
109
- const tooltipId = `tooltip-${id}`;
110
- return [
111
- {
112
- ...childProps,
113
- ref: assignMultipleRefs(childRef, anchorEl),
114
- ...(visible &&
115
- !childProps['aria-label'] && { 'aria-describedby': tooltipId }),
116
- onMouseEnter: wrapEvent(onMouseEnter, handleMouseEnter),
117
- onMouseLeave: wrapEvent(onMouseLeave, handleMouseLeave),
118
- onMouseMove: wrapEvent(onMouseMove, handleMouseMove),
119
- onMouseDown: wrapEvent(onMouseDown, handleMouseDown),
120
- onFocus: wrapEvent(onFocus, handleFocus),
121
- onBlur: wrapEvent(onBlur, handleBlur),
122
- onKeyDown: wrapEvent(onKeyDown, handleKeyDown),
123
- },
124
- {
125
- id: tooltipId,
126
- anchorEl,
127
- visible,
128
- children,
129
- onMouseEnter: wrapEvent(tooltipOnMouseEnter, handleMouseEnter),
130
- onMouseLeave: wrapEvent(tooltipOnMouseLeave, handleMouseLeave),
131
- onMouseMove: wrapEvent(tooltipOnMouseMove, handleMouseMove),
132
- role: 'tooltip',
133
- ...otherTooltipProps,
134
- },
135
- ];
136
- }
1
+ import type {
2
+ HTMLAttributes,
3
+ KeyboardEvent,
4
+ ReactNode,
5
+ Ref,
6
+ RefAttributes,
7
+ RefObject,
8
+ } from 'react';
9
+ import { useRef, useEffect, useState, useId } from 'react';
10
+
11
+ import { assignMultipleRefs } from '../utils/assign-ref';
12
+ import { wrapEvent } from '../utils/wrap-event';
13
+ import {
14
+ send,
15
+ state,
16
+ subscription,
17
+ Blur,
18
+ Focus,
19
+ LeavingVisible,
20
+ MouseDown,
21
+ MouseEnter,
22
+ MouseLeave,
23
+ MouseMove,
24
+ SelectWithKeyboard,
25
+ Visible,
26
+ } from './stateMachine';
27
+
28
+ export type ChildProps = HTMLAttributes<HTMLElement> &
29
+ RefAttributes<HTMLElement>;
30
+
31
+ export interface InjectedTooltipProps extends HTMLAttributes<HTMLElement> {
32
+ anchorEl: RefObject<HTMLElement>;
33
+ visible: boolean;
34
+ children?: ReactNode;
35
+ }
36
+
37
+ export function useTooltip(
38
+ childProps: ChildProps,
39
+ childRef: Ref<HTMLElement> | undefined,
40
+ tooltipProps: HTMLAttributes<HTMLElement> & { label?: ReactNode }
41
+ ): [ChildProps, InjectedTooltipProps] {
42
+ const {
43
+ onMouseEnter,
44
+ onMouseLeave,
45
+ onMouseMove,
46
+ onMouseDown,
47
+ onKeyDown,
48
+ onFocus,
49
+ onBlur,
50
+ } = childProps;
51
+ const anchorEl = useRef<HTMLElement>(null);
52
+ const [visible, setVisible] = useState(false);
53
+ const id = useId();
54
+
55
+ useEffect(() => {
56
+ subscription.subscribe(() => {
57
+ setVisible(
58
+ (state.current.state === Visible ||
59
+ state.current.state === LeavingVisible) &&
60
+ state.current.id === id
61
+ );
62
+ });
63
+ }, [id]);
64
+
65
+ function handleMouseEnter() {
66
+ send(MouseEnter, { id });
67
+ }
68
+
69
+ function handleMouseMove() {
70
+ send(MouseMove, { id });
71
+ }
72
+
73
+ function handleMouseLeave() {
74
+ send(MouseLeave);
75
+ }
76
+
77
+ function handleMouseDown() {
78
+ // Allow quick click from one tool to another
79
+ if (state.current.id === id) {
80
+ send(MouseDown);
81
+ }
82
+ }
83
+
84
+ function handleFocus() {
85
+ send(Focus, { id });
86
+ }
87
+
88
+ function handleBlur() {
89
+ // Allow quick click from one tool to another
90
+ if (state.current.id === id) {
91
+ send(Blur, undefined);
92
+ }
93
+ }
94
+
95
+ function handleKeyDown(event: KeyboardEvent<HTMLElement>) {
96
+ if (event.key === 'Enter' || event.key === ' ') {
97
+ send(SelectWithKeyboard);
98
+ }
99
+ }
100
+
101
+ const {
102
+ label: children,
103
+ onMouseEnter: tooltipOnMouseEnter,
104
+ onMouseLeave: tooltipOnMouseLeave,
105
+ onMouseMove: tooltipOnMouseMove,
106
+ ...otherTooltipProps
107
+ } = tooltipProps;
108
+
109
+ const tooltipId = `tooltip-${id}`;
110
+ return [
111
+ {
112
+ ...childProps,
113
+ ref: assignMultipleRefs(childRef, anchorEl),
114
+ ...(visible &&
115
+ !childProps['aria-label'] && { 'aria-describedby': tooltipId }),
116
+ onMouseEnter: wrapEvent(onMouseEnter, handleMouseEnter),
117
+ onMouseLeave: wrapEvent(onMouseLeave, handleMouseLeave),
118
+ onMouseMove: wrapEvent(onMouseMove, handleMouseMove),
119
+ onMouseDown: wrapEvent(onMouseDown, handleMouseDown),
120
+ onFocus: wrapEvent(onFocus, handleFocus),
121
+ onBlur: wrapEvent(onBlur, handleBlur),
122
+ onKeyDown: wrapEvent(onKeyDown, handleKeyDown),
123
+ },
124
+ {
125
+ id: tooltipId,
126
+ anchorEl,
127
+ visible,
128
+ children,
129
+ onMouseEnter: wrapEvent(tooltipOnMouseEnter, handleMouseEnter),
130
+ onMouseLeave: wrapEvent(tooltipOnMouseLeave, handleMouseLeave),
131
+ onMouseMove: wrapEvent(tooltipOnMouseMove, handleMouseMove),
132
+ role: 'tooltip',
133
+ ...otherTooltipProps,
134
+ },
135
+ ];
136
+ }
@@ -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,22 +1,22 @@
1
- import type { MutableRefObject } from 'react';
2
- import { useEffect } from 'react';
3
-
4
- import { focusOnChildNode } from '../FocusLock/tabUtils';
5
-
6
- export function useAutoFocus(
7
- open: boolean,
8
- elementRef: MutableRefObject<HTMLElement | null>
9
- ) {
10
- useEffect(() => {
11
- if (open) {
12
- // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal
13
- if (
14
- elementRef.current &&
15
- !elementRef.current.contains(document.activeElement)
16
- ) {
17
- focusOnChildNode(elementRef.current, 0);
18
- }
19
- }
20
- // eslint-disable-next-line react-hooks/exhaustive-deps
21
- }, [open]);
22
- }
1
+ import type { MutableRefObject } from 'react';
2
+ import { useEffect } from 'react';
3
+
4
+ import { focusOnChildNode } from '../FocusLock/tabUtils';
5
+
6
+ export function useAutoFocus(
7
+ open: boolean,
8
+ elementRef: MutableRefObject<HTMLElement | null>
9
+ ) {
10
+ useEffect(() => {
11
+ if (open) {
12
+ // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal
13
+ if (
14
+ elementRef.current &&
15
+ !elementRef.current.contains(document.activeElement)
16
+ ) {
17
+ focusOnChildNode(elementRef.current, 0);
18
+ }
19
+ }
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ }, [open]);
22
+ }
@@ -1,51 +1,51 @@
1
- import type { MutableRefObject } from 'react';
2
- import { useEffect } from 'react';
3
-
4
- export function useChildrenCounterParent<T>(
5
- itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>
6
- ) {
7
- // Reset the options ref every render so that they are always
8
- // accurate and ready for keyboard navigation handlers. Using layout
9
- // effect to schedule this effect before the ComboboxOptions push into
10
- // the array
11
- itemsRef.current = [];
12
- itemsRef.current.isNewRender = true;
13
-
14
- useEffect(() => {
15
- // Rendering is finished. Meaning any children can now rerender,
16
- // and they should not push any new items to our array, because
17
- // it is not a new render
18
- itemsRef.current.isNewRender = false;
19
- });
20
-
21
- useEffect(() => {
22
- // When we are unmounting, it means there are no children anymore.
23
- // Clear out our items array
24
- return () => {
25
- itemsRef.current = [];
26
- };
27
- }, [itemsRef]);
28
- }
29
-
30
- export function useChildrenCounterChild<T>(
31
- itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,
32
- itemIndexRef: MutableRefObject<number>,
33
- obj: T | ((idx: number) => T),
34
- disabled = false
35
- ) {
36
- if (itemsRef && itemsRef.current.isNewRender) {
37
- if (disabled) {
38
- itemIndexRef.current = -1;
39
- return;
40
- }
41
-
42
- // push this option to the optionsRef array
43
- itemIndexRef.current = itemsRef.current.length;
44
-
45
- if (obj instanceof Function) {
46
- itemsRef.current.push(obj(itemIndexRef.current));
47
- } else {
48
- itemsRef.current.push(obj);
49
- }
50
- }
51
- }
1
+ import type { MutableRefObject } from 'react';
2
+ import { useEffect } from 'react';
3
+
4
+ export function useChildrenCounterParent<T>(
5
+ itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>
6
+ ) {
7
+ // Reset the options ref every render so that they are always
8
+ // accurate and ready for keyboard navigation handlers. Using layout
9
+ // effect to schedule this effect before the ComboboxOptions push into
10
+ // the array
11
+ itemsRef.current = [];
12
+ itemsRef.current.isNewRender = true;
13
+
14
+ useEffect(() => {
15
+ // Rendering is finished. Meaning any children can now rerender,
16
+ // and they should not push any new items to our array, because
17
+ // it is not a new render
18
+ itemsRef.current.isNewRender = false;
19
+ });
20
+
21
+ useEffect(() => {
22
+ // When we are unmounting, it means there are no children anymore.
23
+ // Clear out our items array
24
+ return () => {
25
+ itemsRef.current = [];
26
+ };
27
+ }, [itemsRef]);
28
+ }
29
+
30
+ export function useChildrenCounterChild<T>(
31
+ itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,
32
+ itemIndexRef: MutableRefObject<number>,
33
+ obj: T | ((idx: number) => T),
34
+ disabled = false
35
+ ) {
36
+ if (itemsRef && itemsRef.current.isNewRender) {
37
+ if (disabled) {
38
+ itemIndexRef.current = -1;
39
+ return;
40
+ }
41
+
42
+ // push this option to the optionsRef array
43
+ itemIndexRef.current = itemsRef.current.length;
44
+
45
+ if (obj instanceof Function) {
46
+ itemsRef.current.push(obj(itemIndexRef.current));
47
+ } else {
48
+ itemsRef.current.push(obj);
49
+ }
50
+ }
51
+ }
@@ -23,9 +23,9 @@ export function useControlledState<
23
23
 
24
24
  if (isControlled) {
25
25
  if (
26
- wasControlled.current &&
27
- process.env.NODE_ENV !== 'production' &&
28
- !hasWarned.current
26
+ !wasControlled.current &&
27
+ !hasWarned.current &&
28
+ process.env.NODE_ENV !== 'production'
29
29
  ) {
30
30
  console.warn('Trying to change from controlled to uncontrolled.');
31
31
  hasWarned.current = true;
@@ -1,43 +1,43 @@
1
- import type { MutableRefObject } from 'react';
2
- import { useEffect, useRef } from 'react';
3
-
4
- export function useFocusReturn(
5
- open: boolean,
6
- rootEl: MutableRefObject<HTMLElement | null>
7
- ) {
8
- const previousFocusRef = useRef<HTMLElement | null>(
9
- (() => {
10
- if (
11
- open &&
12
- typeof document !== 'undefined' &&
13
- document.activeElement instanceof HTMLElement
14
- ) {
15
- return document.activeElement;
16
- }
17
- return null;
18
- })()
19
- );
20
-
21
- useEffect(() => {
22
- if (open) {
23
- // once opened, keep track of the element that triggered
24
- // the Modal opening
25
- if (
26
- !previousFocusRef.current &&
27
- document.activeElement instanceof HTMLElement &&
28
- !rootEl.current?.contains(document.activeElement)
29
- ) {
30
- previousFocusRef.current = document.activeElement;
31
- }
32
-
33
- const rootElement = rootEl.current;
34
- const previousElement = previousFocusRef.current;
35
- return () => {
36
- // on unmount, return focus to that element
37
- if (previousElement && !rootElement?.contains(document.activeElement)) {
38
- previousElement.focus({ preventScroll: true });
39
- }
40
- };
41
- }
42
- }, [open, rootEl]);
43
- }
1
+ import type { MutableRefObject } from 'react';
2
+ import { useEffect, useRef } from 'react';
3
+
4
+ export function useFocusReturn(
5
+ open: boolean,
6
+ rootEl: MutableRefObject<HTMLElement | null>
7
+ ) {
8
+ const previousFocusRef = useRef<HTMLElement | null>(
9
+ (() => {
10
+ if (
11
+ open &&
12
+ typeof document !== 'undefined' &&
13
+ document.activeElement instanceof HTMLElement
14
+ ) {
15
+ return document.activeElement;
16
+ }
17
+ return null;
18
+ })()
19
+ );
20
+
21
+ useEffect(() => {
22
+ if (open) {
23
+ // once opened, keep track of the element that triggered
24
+ // the Modal opening
25
+ if (
26
+ !previousFocusRef.current &&
27
+ document.activeElement instanceof HTMLElement &&
28
+ !rootEl.current?.contains(document.activeElement)
29
+ ) {
30
+ previousFocusRef.current = document.activeElement;
31
+ }
32
+
33
+ const rootElement = rootEl.current;
34
+ const previousElement = previousFocusRef.current;
35
+ return () => {
36
+ // on unmount, return focus to that element
37
+ if (previousElement && !rootElement?.contains(document.activeElement)) {
38
+ previousElement.focus({ preventScroll: true });
39
+ }
40
+ };
41
+ }
42
+ }, [open, rootEl]);
43
+ }
@@ -1,30 +1,30 @@
1
- import type { FocusEventHandler } from 'react';
2
- import { useState } from 'react';
3
-
4
- import { wrapEvent } from '../utils/wrap-event';
5
-
6
- export function useFocusState<T>(
7
- props: {
8
- onFocus?: FocusEventHandler<T>;
9
- onBlur?: FocusEventHandler<T>;
10
- } = {}
11
- ) {
12
- const { onFocus, onBlur } = props;
13
- const [hasFocus, setHasFocus] = useState(false);
14
-
15
- const handleFocus = () => {
16
- setHasFocus(true);
17
- };
18
-
19
- const handleBlur = () => {
20
- setHasFocus(false);
21
- };
22
-
23
- return {
24
- bind: {
25
- onFocus: wrapEvent(onFocus, handleFocus),
26
- onBlur: wrapEvent(onBlur, handleBlur),
27
- },
28
- hasFocus,
29
- };
30
- }
1
+ import type { FocusEventHandler } from 'react';
2
+ import { useState } from 'react';
3
+
4
+ import { wrapEvent } from '../utils/wrap-event';
5
+
6
+ export function useFocusState<T>(
7
+ props: {
8
+ onFocus?: FocusEventHandler<T>;
9
+ onBlur?: FocusEventHandler<T>;
10
+ } = {}
11
+ ) {
12
+ const { onFocus, onBlur } = props;
13
+ const [hasFocus, setHasFocus] = useState(false);
14
+
15
+ const handleFocus = () => {
16
+ setHasFocus(true);
17
+ };
18
+
19
+ const handleBlur = () => {
20
+ setHasFocus(false);
21
+ };
22
+
23
+ return {
24
+ bind: {
25
+ onFocus: wrapEvent(onFocus, handleFocus),
26
+ onBlur: wrapEvent(onBlur, handleBlur),
27
+ },
28
+ hasFocus,
29
+ };
30
+ }