@soroush.tech/design-system 2.0.0 → 2.1.0-alpha.1

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 (283) hide show
  1. package/dist/Accordion/Accordion.d.cts +2 -2
  2. package/dist/Accordion/Accordion.d.mts +2 -2
  3. package/dist/Accordion/AccordionGroup.d.cts +1 -1
  4. package/dist/Accordion/AccordionGroup.d.mts +1 -1
  5. package/dist/Alert/Alert.d.cts +1 -1
  6. package/dist/Alert/Alert.d.mts +1 -1
  7. package/dist/AppBar.d.cts +1 -1
  8. package/dist/AppBar.d.mts +1 -1
  9. package/dist/Autocomplete.cjs +1 -1
  10. package/dist/Autocomplete.d.cts +1 -1
  11. package/dist/Autocomplete.d.mts +1 -1
  12. package/dist/Autocomplete.mjs +1 -1
  13. package/dist/Avatar.d.cts +1 -1
  14. package/dist/Avatar.d.mts +1 -1
  15. package/dist/Backdrop.d.cts +1 -1
  16. package/dist/Backdrop.d.mts +1 -1
  17. package/dist/Badge.d.cts +1 -1
  18. package/dist/Badge.d.mts +1 -1
  19. package/dist/Breadcrumbs.d.cts +3 -3
  20. package/dist/Breadcrumbs.d.mts +3 -3
  21. package/dist/Button.d.cts +1 -1
  22. package/dist/Button.d.mts +1 -1
  23. package/dist/ButtonGroup.d.cts +1 -1
  24. package/dist/ButtonGroup.d.mts +1 -1
  25. package/dist/Card.d.cts +4 -4
  26. package/dist/Card.d.mts +4 -4
  27. package/dist/Checkbox.d.cts +1 -1
  28. package/dist/Checkbox.d.mts +1 -1
  29. package/dist/Chip.d.cts +1 -1
  30. package/dist/Chip.d.mts +1 -1
  31. package/dist/CircularProgress.d.cts +2 -2
  32. package/dist/CircularProgress.d.mts +2 -2
  33. package/dist/Collapse.d.cts +1 -1
  34. package/dist/Collapse.d.mts +1 -1
  35. package/dist/Drawer.d.cts +3 -3
  36. package/dist/Drawer.d.mts +3 -3
  37. package/dist/Fab.d.cts +1 -1
  38. package/dist/Fab.d.mts +1 -1
  39. package/dist/FabMenu/FabMenu.d.cts +1 -1
  40. package/dist/FabMenu/FabMenu.d.mts +1 -1
  41. package/dist/FabMenu/FabMenuItem.d.cts +1 -1
  42. package/dist/FabMenu/FabMenuItem.d.mts +1 -1
  43. package/dist/Fade.d.cts +1 -1
  44. package/dist/Fade.d.mts +1 -1
  45. package/dist/Flex.d.cts +1 -1
  46. package/dist/Flex.d.mts +1 -1
  47. package/dist/Form.d.cts +1 -1
  48. package/dist/Form.d.mts +1 -1
  49. package/dist/FormControl.d.cts +1 -1
  50. package/dist/FormControl.d.mts +1 -1
  51. package/dist/FormHelperText.d.cts +1 -1
  52. package/dist/FormHelperText.d.mts +1 -1
  53. package/dist/FormLabel.d.cts +1 -1
  54. package/dist/FormLabel.d.mts +1 -1
  55. package/dist/Grid.d.cts +1 -1
  56. package/dist/Grid.d.mts +1 -1
  57. package/dist/Grow.d.cts +1 -1
  58. package/dist/Grow.d.mts +1 -1
  59. package/dist/Icon.d.cts +1 -1
  60. package/dist/Icon.d.mts +1 -1
  61. package/dist/Image.d.cts +1 -1
  62. package/dist/Image.d.mts +1 -1
  63. package/dist/LinearProgress.d.cts +2 -2
  64. package/dist/LinearProgress.d.mts +2 -2
  65. package/dist/Link.d.cts +1 -1
  66. package/dist/Link.d.mts +1 -1
  67. package/dist/Menu/ContextMenu.cjs +23 -14
  68. package/dist/Menu/ContextMenu.d.cts +18 -8
  69. package/dist/Menu/ContextMenu.d.mts +18 -8
  70. package/dist/Menu/ContextMenu.mjs +24 -15
  71. package/dist/Menu/Menu.cjs +1 -1
  72. package/dist/Menu/Menu.d.cts +1 -1
  73. package/dist/Menu/Menu.d.mts +1 -1
  74. package/dist/Menu/Menu.mjs +1 -1
  75. package/dist/Menu/MenuItems.cjs +1 -1
  76. package/dist/Menu/MenuItems.d.cts +1 -1
  77. package/dist/Menu/MenuItems.d.mts +1 -1
  78. package/dist/Menu/MenuItems.mjs +1 -1
  79. package/dist/Menu/MenuList.cjs +1 -1
  80. package/dist/Menu/MenuList.d.cts +3 -36
  81. package/dist/Menu/MenuList.d.mts +3 -36
  82. package/dist/Menu/MenuList.mjs +1 -1
  83. package/dist/{Menu-Bx9jaHOy.cjs → Menu-C6eIdA1J.cjs} +8 -5
  84. package/dist/{Menu-D4AIpdJv.mjs → Menu-C_4jYHWE.mjs} +8 -5
  85. package/dist/Menu.cjs +2 -2
  86. package/dist/Menu.d.cts +5 -5
  87. package/dist/Menu.d.mts +5 -5
  88. package/dist/Menu.mjs +2 -2
  89. package/dist/{MenuItem-DXRw3Yca.cjs → MenuItem-Bg4iRvVe.cjs} +29 -26
  90. package/dist/{MenuItem-vXHGPK8g.mjs → MenuItem-kRGVRI6G.mjs} +29 -26
  91. package/dist/MenuItem.cjs +1 -1
  92. package/dist/MenuItem.d.cts +1 -1
  93. package/dist/MenuItem.d.mts +1 -1
  94. package/dist/MenuItem.mjs +1 -1
  95. package/dist/{MenuList-DsJmxNPu.cjs → MenuList-CSaaR3jt.cjs} +2 -1
  96. package/dist/{MenuList-CGZgfBno.mjs → MenuList-D7Pvpn_K.mjs} +2 -1
  97. package/dist/{MenuListContext-BwgQHUu9.d.cts → MenuListContext-AnAxu0he.d.cts} +2 -2
  98. package/dist/{MenuListContext-DbnAoUdJ.d.mts → MenuListContext-DURKFg_T.d.mts} +2 -2
  99. package/dist/Modal.d.cts +1 -1
  100. package/dist/Modal.d.mts +1 -1
  101. package/dist/NativeSelect.d.cts +2 -2
  102. package/dist/NativeSelect.d.mts +2 -2
  103. package/dist/NavTree/NavLink.d.cts +1 -1
  104. package/dist/NavTree/NavLink.d.mts +1 -1
  105. package/dist/NavTree/NavTree.d.cts +1 -1
  106. package/dist/NavTree/NavTree.d.mts +1 -1
  107. package/dist/NumberInput.d.cts +1 -1
  108. package/dist/NumberInput.d.mts +1 -1
  109. package/dist/Pagination/PaginationItem.d.cts +1 -1
  110. package/dist/Pagination/PaginationItem.d.mts +1 -1
  111. package/dist/Pagination.d.cts +2 -2
  112. package/dist/Pagination.d.mts +2 -2
  113. package/dist/Paper.d.cts +2 -2
  114. package/dist/Paper.d.mts +2 -2
  115. package/dist/Popover.d.cts +4 -14
  116. package/dist/Popover.d.mts +4 -14
  117. package/dist/Pressable.d.cts +1 -1
  118. package/dist/Pressable.d.mts +1 -1
  119. package/dist/Quote.d.cts +2 -2
  120. package/dist/Quote.d.mts +2 -2
  121. package/dist/Radio.d.cts +1 -1
  122. package/dist/Radio.d.mts +1 -1
  123. package/dist/RangeInput.d.cts +1 -1
  124. package/dist/RangeInput.d.mts +1 -1
  125. package/dist/Rating.d.cts +1 -1
  126. package/dist/Rating.d.mts +1 -1
  127. package/dist/ScrollArea.d.cts +1 -1
  128. package/dist/ScrollArea.d.mts +1 -1
  129. package/dist/Select.d.cts +2 -2
  130. package/dist/Select.d.mts +2 -2
  131. package/dist/Sidebar/Sidebar.d.cts +1 -1
  132. package/dist/Sidebar/Sidebar.d.mts +1 -1
  133. package/dist/Sidebar/SidebarItem.d.cts +3 -3
  134. package/dist/Sidebar/SidebarItem.d.mts +3 -3
  135. package/dist/Skeleton.d.cts +1 -1
  136. package/dist/Skeleton.d.mts +1 -1
  137. package/dist/Slide.d.cts +1 -1
  138. package/dist/Slide.d.mts +1 -1
  139. package/dist/Snackbar.d.cts +2 -2
  140. package/dist/Snackbar.d.mts +2 -2
  141. package/dist/Switch.d.cts +1 -1
  142. package/dist/Switch.d.mts +1 -1
  143. package/dist/Table/Table.d.cts +2 -2
  144. package/dist/Table/Table.d.mts +2 -2
  145. package/dist/Table/TableBody.d.cts +1 -1
  146. package/dist/Table/TableBody.d.mts +1 -1
  147. package/dist/Table/TableCell.d.cts +1 -1
  148. package/dist/Table/TableCell.d.mts +1 -1
  149. package/dist/Table/TableContainer.d.cts +1 -1
  150. package/dist/Table/TableContainer.d.mts +1 -1
  151. package/dist/Table/TableControl.d.cts +1 -1
  152. package/dist/Table/TableControl.d.mts +1 -1
  153. package/dist/Table/TableFooter.d.cts +1 -1
  154. package/dist/Table/TableFooter.d.mts +1 -1
  155. package/dist/Table/TableHead.d.cts +1 -1
  156. package/dist/Table/TableHead.d.mts +1 -1
  157. package/dist/Table/TablePagination.d.cts +2 -2
  158. package/dist/Table/TablePagination.d.mts +2 -2
  159. package/dist/Table/TablePaginationActions.d.cts +1 -1
  160. package/dist/Table/TablePaginationActions.d.mts +1 -1
  161. package/dist/Table/TableRow.d.cts +1 -1
  162. package/dist/Table/TableRow.d.mts +1 -1
  163. package/dist/Table/TableSortLabel.d.cts +1 -1
  164. package/dist/Table/TableSortLabel.d.mts +1 -1
  165. package/dist/Table/hooks.d.cts +1 -1
  166. package/dist/Table/hooks.d.mts +1 -1
  167. package/dist/Table.d.cts +5 -5
  168. package/dist/Table.d.mts +5 -5
  169. package/dist/{TableContext-0hifLOKH.d.mts → TableContext-CPxH920f.d.mts} +1 -1
  170. package/dist/{TableContext-fIyMD_Bj.d.cts → TableContext-VuMFtVNr.d.cts} +1 -1
  171. package/dist/Tabs/Tab.cjs +18 -14
  172. package/dist/Tabs/Tab.d.cts +2 -2
  173. package/dist/Tabs/Tab.d.mts +2 -2
  174. package/dist/Tabs/Tab.mjs +18 -14
  175. package/dist/Tabs/TabContext.d.cts +1 -1
  176. package/dist/Tabs/TabContext.d.mts +1 -1
  177. package/dist/Tabs/TabList.cjs +1 -1
  178. package/dist/Tabs/TabList.d.cts +1 -1
  179. package/dist/Tabs/TabList.d.mts +1 -1
  180. package/dist/Tabs/TabList.mjs +1 -1
  181. package/dist/Tabs/TabPanel.d.cts +2 -2
  182. package/dist/Tabs/TabPanel.d.mts +2 -2
  183. package/dist/Tabs/TabScrollButton.d.cts +1 -1
  184. package/dist/Tabs/TabScrollButton.d.mts +1 -1
  185. package/dist/Tabs/Tabs.cjs +1 -1
  186. package/dist/Tabs/Tabs.d.cts +2 -2
  187. package/dist/Tabs/Tabs.d.mts +2 -2
  188. package/dist/Tabs/Tabs.mjs +1 -1
  189. package/dist/{Tabs-JvjuCU8m.mjs → Tabs-C_qe9d4p.mjs} +28 -21
  190. package/dist/{Tabs-BsbX0jFL.cjs → Tabs-DmiA1J--.cjs} +28 -21
  191. package/dist/Tabs.cjs +1 -1
  192. package/dist/Tabs.d.cts +3 -3
  193. package/dist/Tabs.d.mts +3 -3
  194. package/dist/Tabs.mjs +1 -1
  195. package/dist/{TabsContext-0ZtedNyH.d.mts → TabsContext-DeP8oJpC.d.cts} +1 -1
  196. package/dist/{TabsContext-MpMEEVuB.d.cts → TabsContext-VJcdZQOf.d.mts} +1 -1
  197. package/dist/TextInput.d.cts +1 -1
  198. package/dist/TextInput.d.mts +1 -1
  199. package/dist/ToggleButton/ToggleButton.d.cts +1 -1
  200. package/dist/ToggleButton/ToggleButton.d.mts +1 -1
  201. package/dist/ToggleButton/ToggleButtonGroup.d.cts +1 -1
  202. package/dist/ToggleButton/ToggleButtonGroup.d.mts +1 -1
  203. package/dist/Tooltip-CrPRvmj3.cjs +338 -0
  204. package/dist/Tooltip-CwbuEQzf.mjs +332 -0
  205. package/dist/Tooltip.cjs +2 -267
  206. package/dist/Tooltip.d.cts +42 -7
  207. package/dist/Tooltip.d.mts +42 -7
  208. package/dist/Tooltip.mjs +1 -266
  209. package/dist/TransferList.d.cts +1 -1
  210. package/dist/TransferList.d.mts +1 -1
  211. package/dist/Typography.d.cts +2 -2
  212. package/dist/Typography.d.mts +2 -2
  213. package/dist/View.d.cts +1 -1
  214. package/dist/View.d.mts +1 -1
  215. package/dist/Zoom.d.cts +1 -1
  216. package/dist/Zoom.d.mts +1 -1
  217. package/dist/catalog.cjs +12 -0
  218. package/dist/catalog.d.cts +1 -1
  219. package/dist/catalog.d.mts +1 -1
  220. package/dist/catalog.mjs +12 -0
  221. package/dist/computePopoverPosition-JgOwCM7k.d.cts +12 -0
  222. package/dist/computePopoverPosition-JgOwCM7k.d.mts +12 -0
  223. package/dist/engine.d.cts +1 -1
  224. package/dist/engine.d.mts +1 -1
  225. package/dist/{index-4maWM1H8.d.mts → index-2jMSUeji.d.cts} +1 -1
  226. package/dist/{index-76zijQoi.d.mts → index-3Xe5X6Ny.d.mts} +2 -2
  227. package/dist/{index-C7EUYyom.d.cts → index-B-p51b0z.d.cts} +2 -2
  228. package/dist/index-B2XL_zZY.d.mts +44 -0
  229. package/dist/{index-D4PcgL-c.d.cts → index-B5_-Bxoo.d.cts} +2 -2
  230. package/dist/{index-DBF5n3ey.d.cts → index-BFUn2EWp.d.mts} +3 -3
  231. package/dist/{index-Byk1_ms9.d.cts → index-BKM4d_F4.d.cts} +2 -2
  232. package/dist/index-BL5Kj3Ka.d.mts +1 -0
  233. package/dist/{index-SotXsXXb.d.mts → index-BLypGp0N.d.mts} +4 -4
  234. package/dist/{index-hoHPfsc1.d.cts → index-BVDN2XbT.d.mts} +3 -3
  235. package/dist/{index-CLTFsCYC.d.cts → index-Bhb0bFxe.d.mts} +2 -2
  236. package/dist/index-Biqpy7c9.d.cts +44 -0
  237. package/dist/{index-CKywwIep.d.mts → index-C-ebcNOc.d.mts} +1 -1
  238. package/dist/{index-Lsm4v8fB.d.cts → index-C6a3kDn2.d.cts} +3 -0
  239. package/dist/{index-RaDENVX_.d.cts → index-C9nnnfhd.d.cts} +2 -2
  240. package/dist/{index-BuAKhHMs.d.cts → index-CBHCGizS.d.mts} +1 -1
  241. package/dist/{index-BChRNCld.d.mts → index-CCEfrBNN.d.mts} +1 -1
  242. package/dist/{index-Dxu6Ks2A.d.cts → index-CHWMSBhQ.d.cts} +1 -1
  243. package/dist/index-CJMvoc8h.d.cts +1 -0
  244. package/dist/{index-C2a-5yop.d.mts → index-COgZvhXQ.d.mts} +1 -1
  245. package/dist/{index-BC9S8Fpr.d.cts → index-CP55_Zs2.d.mts} +1 -1
  246. package/dist/{index-Dm7vQHor.d.cts → index-CgyyM3ty.d.cts} +10 -5
  247. package/dist/{index-CfB7OceY.d.cts → index-CtwlReZi.d.cts} +1 -1
  248. package/dist/{index-CnVvfG9_.d.mts → index-D0skdQEK.d.mts} +1 -1
  249. package/dist/{index-Cjh607-v.d.cts → index-D2tfsNPw.d.cts} +1 -1
  250. package/dist/{index-B3Bdupj3.d.mts → index-D7h8qFS1.d.cts} +2 -2
  251. package/dist/{index-BV5BvdeN.d.mts → index-DACdQ7-d.d.cts} +1 -1
  252. package/dist/{index-CAt0-L4i.d.cts → index-DAJ5DVHh.d.cts} +2 -2
  253. package/dist/{index-CGyIuCRh.d.cts → index-DMysZsti.d.cts} +1 -1
  254. package/dist/{index-CR8qkP8U.d.mts → index-DOH6uskj.d.mts} +3 -0
  255. package/dist/{index-C2tTbEBS.d.mts → index-DQo4XtH4.d.mts} +2 -2
  256. package/dist/{index-CQeTS_zL.d.cts → index-DTJN6JL2.d.cts} +1 -1
  257. package/dist/{index-Dt274Ngt.d.mts → index-DbKYSbLs.d.mts} +2 -2
  258. package/dist/{index-CJYWGPVO.d.mts → index-Dg0FPoms.d.mts} +2 -2
  259. package/dist/{index-C_J58B_n.d.mts → index-DlNBgVwb.d.mts} +1 -1
  260. package/dist/{index-UiyZAKID.d.mts → index-DsBOpK8T.d.mts} +2 -2
  261. package/dist/{index-DbgrItbx.d.cts → index-Dvx5TRET.d.cts} +2 -2
  262. package/dist/{index-tOrd12AJ.d.mts → index-Sq75GwA2.d.cts} +3 -3
  263. package/dist/{index-BAzMLTVi.d.mts → index-ZyigJMkV.d.mts} +10 -5
  264. package/dist/{index-Bo45R0nD.d.cts → index-gHMydoIS.d.cts} +4 -4
  265. package/dist/{index-BzQze7eY.d.cts → index-gxBafJdz.d.cts} +1 -1
  266. package/dist/{index-D48qVo1X.d.mts → index-hTgl9zwe.d.mts} +2 -2
  267. package/dist/{index-CF_pl72E.d.mts → index-i8BxMDEC.d.mts} +1 -1
  268. package/dist/{index-BXlBouWV.d.mts → index-v1I6VA9w.d.cts} +3 -3
  269. package/dist/index.d.cts +1 -1
  270. package/dist/index.d.mts +1 -1
  271. package/dist/style.d.cts +2 -2
  272. package/dist/style.d.mts +2 -2
  273. package/dist/theme.d.cts +2 -2
  274. package/dist/theme.d.mts +2 -2
  275. package/dist/{useAnchoredPlacement-ee6KzG3t.cjs → useAnchoredPlacement-BSfjNMut.cjs} +10 -5
  276. package/dist/{useAnchoredPlacement-COrXZxhm.mjs → useAnchoredPlacement-txSaWzfk.mjs} +10 -5
  277. package/dist/{useTablePagination-BlD8mK8k.d.mts → useTablePagination-CUsagS5T.d.mts} +1 -1
  278. package/dist/{useTablePagination-CGjb_jPX.d.cts → useTablePagination-jpEfHKUh.d.cts} +1 -1
  279. package/dist/{useTransition-3EoagwIe.d.mts → useTransition-BJ375Sto.d.cts} +1 -1
  280. package/dist/{useTransition-C89K0mS7.d.cts → useTransition-DDGpvgci.d.mts} +1 -1
  281. package/package.json +1 -1
  282. package/dist/index-1Xzj0iAs.d.mts +0 -1
  283. package/dist/index-323PrYLR.d.cts +0 -1
@@ -0,0 +1,332 @@
1
+ import { a as src_exports, o as styled, t as createShouldForwardProp } from "./src-B-rNjHIL.mjs";
2
+ import { n as useDefaultProps } from "./theme-DyyZQFzQ.mjs";
3
+ import { t as themeDefault } from "./themeDefault-BeZJzqJj.mjs";
4
+ import { t as getSurfaceRadius } from "./getSurfaceRadius-B1QE_VLa.mjs";
5
+ import { t as useControlled } from "./useControlled-B4uQ9Bj6.mjs";
6
+ import { Portal } from "./Portal.mjs";
7
+ import { t as useAnchoredPlacement } from "./useAnchoredPlacement-txSaWzfk.mjs";
8
+ import { t as useMergedRefs } from "./useMergedRefs-CdfwtmUd.mjs";
9
+ import { n as resolveTooltipPlacement, t as getTooltipOrigins } from "./getTooltipOrigins-D0bLLXwY.mjs";
10
+ import { cloneElement, useCallback, useEffect, useId, useRef, useState } from "react";
11
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
+ // src/Tooltip/hooks/useTooltip.ts
13
+ const isKeyboardFocus = (event) => {
14
+ try {
15
+ return event.target.matches(":focus-visible");
16
+ } catch {
17
+ return true;
18
+ }
19
+ };
20
+ /**
21
+ * The state of a tooltip: whether it is open (its own, or its owner's), the timers that open and
22
+ * close it, and the handlers its child and the tooltip itself take. Opening and closing are
23
+ * delayed; moving from the child onto the tooltip does not close it, so its text can be read and
24
+ * selected (WCAG 1.4.13); Escape closes it at once.
25
+ */
26
+ function useTooltip({ isOpen: isOpenProp, defaultOpen, isAtPoint = false, onOpen, onClose, enterDelay, leaveDelay, enterTouchDelay, leaveTouchDelay, shouldOpenOnHover, shouldOpenOnFocus, shouldOpenOnTouch }) {
27
+ const [isOpen, setIsOpen] = useControlled({
28
+ controlled: isOpenProp,
29
+ default: defaultOpen
30
+ });
31
+ const timer = useRef(void 0);
32
+ const latest = useRef({
33
+ isOpen,
34
+ isOpenProp,
35
+ isAtPoint,
36
+ onOpen,
37
+ onClose
38
+ });
39
+ useEffect(() => {
40
+ latest.current = {
41
+ isOpen,
42
+ isOpenProp,
43
+ isAtPoint,
44
+ onOpen,
45
+ onClose
46
+ };
47
+ });
48
+ const clear = useCallback(() => window.clearTimeout(timer.current), []);
49
+ const ask = useCallback((next, event, delay) => {
50
+ clear();
51
+ timer.current = window.setTimeout(() => {
52
+ const current = latest.current;
53
+ if (current.isOpen === next) return;
54
+ if (next && current.isAtPoint) return;
55
+ if (current.isOpenProp === void 0) setIsOpen(next);
56
+ (next ? current.onOpen : current.onClose)?.(event);
57
+ }, delay);
58
+ }, [clear, setIsOpen]);
59
+ useEffect(() => clear, [clear]);
60
+ useEffect(() => {
61
+ if (!isOpen) return void 0;
62
+ const handleKeyDown = (event) => {
63
+ if (event.key === "Escape") ask(false, event, 0);
64
+ };
65
+ document.addEventListener("keydown", handleKeyDown);
66
+ return () => document.removeEventListener("keydown", handleKeyDown);
67
+ }, [isOpen, ask]);
68
+ return {
69
+ isOpen,
70
+ childHandlers: {
71
+ onMouseEnter: (event) => {
72
+ if (shouldOpenOnHover) ask(true, event, enterDelay);
73
+ },
74
+ onMouseLeave: (event) => {
75
+ if (shouldOpenOnHover) ask(false, event, leaveDelay);
76
+ },
77
+ onFocus: (event) => {
78
+ if (shouldOpenOnFocus && isKeyboardFocus(event)) ask(true, event, enterDelay);
79
+ },
80
+ onBlur: (event) => {
81
+ if (shouldOpenOnFocus) ask(false, event, leaveDelay);
82
+ },
83
+ onTouchStart: (event) => {
84
+ if (shouldOpenOnTouch) ask(true, event, enterTouchDelay);
85
+ },
86
+ onTouchEnd: (event) => {
87
+ if (shouldOpenOnTouch) ask(false, event, leaveTouchDelay);
88
+ },
89
+ onTouchCancel: (event) => {
90
+ if (shouldOpenOnTouch) ask(false, event, leaveTouchDelay);
91
+ },
92
+ onPointerDown: (event) => {
93
+ if (event.pointerType !== "touch") ask(false, event, 0);
94
+ }
95
+ },
96
+ surfaceHandlers: {
97
+ onMouseEnter: () => {
98
+ if (shouldOpenOnHover) clear();
99
+ },
100
+ onMouseLeave: (event) => {
101
+ if (shouldOpenOnHover) ask(false, event, leaveDelay);
102
+ }
103
+ }
104
+ };
105
+ }
106
+ // src/Tooltip/Tooltip.tsx
107
+ const MARGIN = 8;
108
+ const GAP = 8;
109
+ const ARROW = 8;
110
+ const TooltipSurface = styled("div", {
111
+ name: "Tooltip",
112
+ label: "Tooltip",
113
+ shouldForwardProp: createShouldForwardProp([
114
+ "layer",
115
+ "isInteractive",
116
+ "borderRadius",
117
+ "bg",
118
+ "textColor"
119
+ ])
120
+ })(({ theme, layer, isInteractive, borderRadius, bg, textColor }) => ({
121
+ position: "fixed",
122
+ ...!isInteractive && { pointerEvents: "none" },
123
+ top: 0,
124
+ left: 0,
125
+ visibility: "hidden",
126
+ zIndex: theme.zOrder[layer],
127
+ boxSizing: "border-box",
128
+ maxWidth: "20rem",
129
+ padding: `${theme.space[.5]} ${theme.space[1]}`,
130
+ borderRadius: getSurfaceRadius(theme, borderRadius),
131
+ boxShadow: theme.shadows[4],
132
+ backgroundColor: (0, src_exports.get)(theme, `background.${bg ?? "modal"}`),
133
+ color: (0, src_exports.get)(theme, `text.${textColor ?? themeDefault(theme, "textColor", "initial")}`),
134
+ fontFamily: (0, src_exports.get)(theme, "fonts.body"),
135
+ fontSize: theme.fontSizes[0],
136
+ lineHeight: (0, src_exports.get)(theme, "lineHeights.base"),
137
+ overflowWrap: "break-word"
138
+ }));
139
+ const TooltipDescription = styled("span", { label: "TooltipDescription" })({
140
+ position: "absolute",
141
+ width: 1,
142
+ height: 1,
143
+ margin: -1,
144
+ padding: 0,
145
+ border: 0,
146
+ overflow: "hidden",
147
+ clip: "rect(0 0 0 0)",
148
+ whiteSpace: "nowrap"
149
+ });
150
+ const TooltipTarget = styled("span", { label: "TooltipTarget" })({ display: "inline-grid" });
151
+ const TooltipArrow = styled("span", {
152
+ name: "Tooltip",
153
+ slot: "arrow",
154
+ label: "TooltipArrow"
155
+ })({
156
+ position: "absolute",
157
+ width: ARROW,
158
+ height: ARROW,
159
+ backgroundColor: "inherit",
160
+ transform: "rotate(45deg)",
161
+ pointerEvents: "none"
162
+ });
163
+ const getArrow = ({ anchorRect, surfaceSize, top, left }) => {
164
+ const { width, height } = surfaceSize;
165
+ if (top + height <= anchorRect.top + 1 || top >= anchorRect.bottom - 1) {
166
+ const side = top + height <= anchorRect.top + 1 ? "top" : "bottom";
167
+ const middle = anchorRect.left + anchorRect.width / 2 - left;
168
+ return {
169
+ side,
170
+ offset: Math.min(Math.max(middle, ARROW), width - ARROW)
171
+ };
172
+ }
173
+ const side = left + width <= anchorRect.left + 1 ? "left" : "right";
174
+ const middle = anchorRect.top + anchorRect.height / 2 - top;
175
+ return {
176
+ side,
177
+ offset: Math.min(Math.max(middle, ARROW), height - ARROW)
178
+ };
179
+ };
180
+ const isSameArrow = (a, b) => a !== null && a.side === b.side && a.offset === b.offset;
181
+ const getArrowStyle = ({ side, offset }) => {
182
+ const half = ARROW / 2;
183
+ if (side === "top") return {
184
+ bottom: -4,
185
+ left: offset - half
186
+ };
187
+ if (side === "bottom") return {
188
+ top: -4,
189
+ left: offset - half
190
+ };
191
+ if (side === "left") return {
192
+ right: -4,
193
+ top: offset - half
194
+ };
195
+ return {
196
+ left: -4,
197
+ top: offset - half
198
+ };
199
+ };
200
+ const mergeForwarded = (own, forwarded) => Object.fromEntries(Object.entries(forwarded).filter(([, value]) => value !== void 0).map(([name, value]) => {
201
+ const current = own[name];
202
+ if (typeof value === "function" && typeof current === "function") return [name, (...args) => {
203
+ current(...args);
204
+ value(...args);
205
+ }];
206
+ if (name === "aria-describedby" && current) return [name, `${String(current)} ${String(value)}`];
207
+ return [name, value];
208
+ }));
209
+ const getChildName = (title, own) => {
210
+ const isHidden = own["aria-hidden"] === true || own["aria-hidden"] === "true";
211
+ const isNamed = own["aria-label"] !== void 0 || own["aria-labelledby"] !== void 0;
212
+ return typeof title === "string" && !isHidden && !isNamed ? { "aria-label": title } : {};
213
+ };
214
+ /**
215
+ * @description A short description of one child, shown on hover, keyboard focus and a long touch -
216
+ * a `role="tooltip"` in a `Portal`, placed beside its child and flipped for want of room. The
217
+ * child is named by it (`aria-label`) or described by it (`aria-describedby`, with
218
+ * `shouldDescribeChild`). It opens and closes after their delays, stays open while the pointer is
219
+ * on the tooltip itself, closes on Escape, and never takes or traps the focus.
220
+ */
221
+ function Tooltip({ children, anchorPosition, title, placement: placementProp, hasArrow: hasArrowProp, enterDelay: enterDelayProp, leaveDelay: leaveDelayProp, enterTouchDelay: enterTouchDelayProp, leaveTouchDelay: leaveTouchDelayProp, shouldDescribeChild: shouldDescribeChildProp, isDescriptionPersistent: isDescriptionPersistentProp, isOpen: isOpenProp, defaultOpen = false, onOpen, onClose, isInteractive: isInteractiveProp, shouldWrapDisabledChild: shouldWrapDisabledChildProp, shouldOpenOnHover: shouldOpenOnHoverProp, shouldOpenOnFocus: shouldOpenOnFocusProp, shouldOpenOnTouch: shouldOpenOnTouchProp, slots, slotProps, layer: layerProp, borderRadius: borderRadiusProp, bg: bgProp, textColor: textColorProp, className, "data-testid": dataTestid, ref: forwardedRef, ...forwarded }) {
222
+ const dp = useDefaultProps("Tooltip");
223
+ const placement = placementProp ?? dp.placement ?? "top";
224
+ const hasArrow = hasArrowProp ?? dp.hasArrow ?? false;
225
+ const shouldDescribeChild = shouldDescribeChildProp ?? dp.shouldDescribeChild ?? false;
226
+ const isDescriptionPersistent = isDescriptionPersistentProp ?? dp.isDescriptionPersistent ?? false;
227
+ const isInteractive = isInteractiveProp ?? dp.isInteractive ?? true;
228
+ const shouldWrapDisabledChild = shouldWrapDisabledChildProp ?? dp.shouldWrapDisabledChild ?? true;
229
+ const layer = layerProp ?? dp.layer ?? "tooltip";
230
+ const borderRadius = borderRadiusProp ?? dp.borderRadius;
231
+ const bg = bgProp ?? dp.bg;
232
+ const textColor = textColorProp ?? dp.textColor;
233
+ const id = useId();
234
+ const isAtPoint = anchorPosition !== void 0;
235
+ const { isOpen, childHandlers, surfaceHandlers } = useTooltip({
236
+ isOpen: isOpenProp,
237
+ defaultOpen,
238
+ isAtPoint,
239
+ onOpen,
240
+ onClose,
241
+ enterDelay: enterDelayProp ?? dp.enterDelay ?? 100,
242
+ leaveDelay: leaveDelayProp ?? dp.leaveDelay ?? 0,
243
+ enterTouchDelay: enterTouchDelayProp ?? dp.enterTouchDelay ?? 700,
244
+ leaveTouchDelay: leaveTouchDelayProp ?? dp.leaveTouchDelay ?? 1500,
245
+ shouldOpenOnHover: shouldOpenOnHoverProp ?? dp.shouldOpenOnHover ?? true,
246
+ shouldOpenOnFocus: shouldOpenOnFocusProp ?? dp.shouldOpenOnFocus ?? true,
247
+ shouldOpenOnTouch: shouldOpenOnTouchProp ?? dp.shouldOpenOnTouch ?? true
248
+ });
249
+ const hasTitle = title !== void 0 && title !== null && title !== "";
250
+ const isShown = isOpen && hasTitle;
251
+ const anchorRef = useRef(null);
252
+ const noAnchorRef = useRef(null);
253
+ const surfaceRef = useRef(null);
254
+ const childProps = children?.props ?? {};
255
+ const forwardedProps = mergeForwarded(childProps, forwarded);
256
+ const own = {
257
+ ...childProps,
258
+ ...forwardedProps
259
+ };
260
+ const isChildDisabled = shouldWrapDisabledChild && own.disabled === true;
261
+ const childRef = useMergedRefs(childProps.ref, forwardedRef);
262
+ const ref = useMergedRefs(isChildDisabled ? void 0 : anchorRef, childRef);
263
+ const [arrow, setArrow] = useState(null);
264
+ const getOrigins = useCallback((context) => getTooltipOrigins(resolveTooltipPlacement(placement, context), context.isRtl), [placement]);
265
+ const onPlaced = useCallback((placed) => {
266
+ if (!hasArrow) return;
267
+ const next = getArrow(placed);
268
+ setArrow((current) => isSameArrow(current, next) ? current : next);
269
+ }, [hasArrow]);
270
+ useAnchoredPlacement({
271
+ isOpen: isShown,
272
+ anchorRef: anchorPosition ? noAnchorRef : anchorRef,
273
+ anchorPosition,
274
+ surfaceRef,
275
+ getOrigins,
276
+ margin: MARGIN,
277
+ gap: GAP,
278
+ onPlaced
279
+ });
280
+ const handlers = Object.fromEntries(Object.entries(childHandlers).map(([name, handler]) => [name, (event) => {
281
+ own[name]?.(event);
282
+ handler(event);
283
+ }]));
284
+ const ownDescription = own["aria-describedby"];
285
+ const names = getChildName(title, own);
286
+ const descriptionId = `${id}-description`;
287
+ const hasPersistentDescription = children !== void 0 && shouldDescribeChild && isDescriptionPersistent && hasTitle;
288
+ const describedBy = (shown) => hasPersistentDescription ? [ownDescription, descriptionId].filter(Boolean).join(" ") : [ownDescription, shown ? id : void 0].filter(Boolean).join(" ") || void 0;
289
+ const ariaProps = shouldDescribeChild ? { "aria-describedby": describedBy(isShown) } : names;
290
+ const child = children ? cloneElement(children, {
291
+ ...forwardedProps,
292
+ ...isChildDisabled || isAtPoint ? {} : handlers,
293
+ ...ariaProps,
294
+ ref
295
+ }) : null;
296
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
297
+ isChildDisabled && !isAtPoint ? /* @__PURE__ */ jsx(TooltipTarget, {
298
+ ref: anchorRef,
299
+ ...handlers,
300
+ children: child
301
+ }) : child,
302
+ hasPersistentDescription && /* @__PURE__ */ jsx(TooltipDescription, {
303
+ id: descriptionId,
304
+ children: title
305
+ }),
306
+ isShown && /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(TooltipSurface, {
307
+ ...slotProps?.root,
308
+ as: slots?.root,
309
+ ref: surfaceRef,
310
+ id,
311
+ role: "tooltip",
312
+ layer,
313
+ isInteractive,
314
+ borderRadius,
315
+ bg,
316
+ textColor,
317
+ className: [slotProps?.root?.className, className].filter(Boolean).join(" ") || void 0,
318
+ "data-testid": dataTestid ?? slotProps?.root?.["data-testid"],
319
+ ...isAtPoint || !isInteractive ? {} : surfaceHandlers,
320
+ children: [title, hasArrow && arrow ? /* @__PURE__ */ jsx(TooltipArrow, {
321
+ ...slotProps?.arrow,
322
+ as: slots?.arrow,
323
+ style: {
324
+ ...slotProps?.arrow?.style,
325
+ ...getArrowStyle(arrow)
326
+ },
327
+ "aria-hidden": "true"
328
+ }) : null]
329
+ }) })
330
+ ] });
331
+ }
332
+ export { Tooltip as t };
package/dist/Tooltip.cjs CHANGED
@@ -1,268 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-yC1f5WR2.cjs");
3
- const require_theme = require("./theme-XJvMdOnY.cjs");
4
- const require_themeDefault = require("./themeDefault-DbPHBbNO.cjs");
5
- const require_getSurfaceRadius = require("./getSurfaceRadius-DwOn3ALC.cjs");
6
- const require_useControlled = require("./useControlled-CzCxM4J3.cjs");
7
- const require_Portal = require("./Portal.cjs");
8
- const require_useAnchoredPlacement = require("./useAnchoredPlacement-ee6KzG3t.cjs");
9
- const require_useMergedRefs = require("./useMergedRefs-BtctsnmX.cjs");
10
- const require_getTooltipOrigins = require("./getTooltipOrigins-8b5zQafY.cjs");
11
- let react = require("react");
12
- let react_jsx_runtime = require("react/jsx-runtime");
13
- let _soroush_tech_styled_system_should_forward_prop = require("@soroush.tech/styled-system/should-forward-prop");
14
- // src/Tooltip/hooks/useTooltip.ts
15
- const isKeyboardFocus = (event) => {
16
- try {
17
- return event.target.matches(":focus-visible");
18
- } catch {
19
- return true;
20
- }
21
- };
22
- /**
23
- * The state of a tooltip: whether it is open (its own, or its owner's), the timers that open and
24
- * close it, and the handlers its child and the tooltip itself take. Opening and closing are
25
- * delayed; moving from the child onto the tooltip does not close it, so its text can be read and
26
- * selected (WCAG 1.4.13); Escape closes it at once.
27
- */
28
- function useTooltip({ isOpen: isOpenProp, defaultOpen, onOpen, onClose, enterDelay, leaveDelay, enterTouchDelay, leaveTouchDelay, shouldOpenOnHover, shouldOpenOnFocus, shouldOpenOnTouch }) {
29
- const [isOpen, setIsOpen] = require_useControlled.useControlled({
30
- controlled: isOpenProp,
31
- default: defaultOpen
32
- });
33
- const timer = (0, react.useRef)(void 0);
34
- const latest = (0, react.useRef)({
35
- isOpen,
36
- isOpenProp,
37
- onOpen,
38
- onClose
39
- });
40
- (0, react.useEffect)(() => {
41
- latest.current = {
42
- isOpen,
43
- isOpenProp,
44
- onOpen,
45
- onClose
46
- };
47
- });
48
- const clear = (0, react.useCallback)(() => window.clearTimeout(timer.current), []);
49
- const ask = (0, react.useCallback)((next, event, delay) => {
50
- clear();
51
- timer.current = window.setTimeout(() => {
52
- const current = latest.current;
53
- if (current.isOpen === next) return;
54
- if (current.isOpenProp === void 0) setIsOpen(next);
55
- (next ? current.onOpen : current.onClose)?.(event);
56
- }, delay);
57
- }, [clear, setIsOpen]);
58
- (0, react.useEffect)(() => clear, [clear]);
59
- (0, react.useEffect)(() => {
60
- if (!isOpen) return void 0;
61
- const handleKeyDown = (event) => {
62
- if (event.key === "Escape") ask(false, event, 0);
63
- };
64
- document.addEventListener("keydown", handleKeyDown);
65
- return () => document.removeEventListener("keydown", handleKeyDown);
66
- }, [isOpen, ask]);
67
- return {
68
- isOpen,
69
- childHandlers: {
70
- onMouseEnter: (event) => {
71
- if (shouldOpenOnHover) ask(true, event, enterDelay);
72
- },
73
- onMouseLeave: (event) => {
74
- if (shouldOpenOnHover) ask(false, event, leaveDelay);
75
- },
76
- onFocus: (event) => {
77
- if (shouldOpenOnFocus && isKeyboardFocus(event)) ask(true, event, enterDelay);
78
- },
79
- onBlur: (event) => {
80
- if (shouldOpenOnFocus) ask(false, event, leaveDelay);
81
- },
82
- onTouchStart: (event) => {
83
- if (shouldOpenOnTouch) ask(true, event, enterTouchDelay);
84
- },
85
- onTouchEnd: (event) => {
86
- if (shouldOpenOnTouch) ask(false, event, leaveTouchDelay);
87
- },
88
- onTouchCancel: (event) => {
89
- if (shouldOpenOnTouch) ask(false, event, leaveTouchDelay);
90
- }
91
- },
92
- surfaceHandlers: {
93
- onMouseEnter: () => {
94
- if (shouldOpenOnHover) clear();
95
- },
96
- onMouseLeave: (event) => {
97
- if (shouldOpenOnHover) ask(false, event, leaveDelay);
98
- }
99
- }
100
- };
101
- }
102
- // src/Tooltip/Tooltip.tsx
103
- const MARGIN = 8;
104
- const GAP = 8;
105
- const ARROW = 8;
106
- const TooltipSurface = require_src.styled("div", {
107
- name: "Tooltip",
108
- label: "Tooltip",
109
- shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([
110
- "layer",
111
- "borderRadius",
112
- "bg",
113
- "textColor"
114
- ])
115
- })(({ theme, layer, borderRadius, bg, textColor }) => ({
116
- position: "fixed",
117
- top: 0,
118
- left: 0,
119
- visibility: "hidden",
120
- zIndex: theme.zOrder[layer],
121
- boxSizing: "border-box",
122
- maxWidth: "20rem",
123
- padding: `${theme.space[.5]} ${theme.space[1]}`,
124
- borderRadius: require_getSurfaceRadius.getSurfaceRadius(theme, borderRadius),
125
- boxShadow: theme.shadows[4],
126
- backgroundColor: (0, require_src.src_exports.get)(theme, `background.${bg ?? "modal"}`),
127
- color: (0, require_src.src_exports.get)(theme, `text.${textColor ?? require_themeDefault.themeDefault(theme, "textColor", "initial")}`),
128
- fontFamily: (0, require_src.src_exports.get)(theme, "fonts.body"),
129
- fontSize: theme.fontSizes[0],
130
- lineHeight: (0, require_src.src_exports.get)(theme, "lineHeights.base"),
131
- overflowWrap: "break-word"
132
- }));
133
- const TooltipArrow = require_src.styled("span", {
134
- name: "Tooltip",
135
- slot: "arrow",
136
- label: "TooltipArrow"
137
- })({
138
- position: "absolute",
139
- width: ARROW,
140
- height: ARROW,
141
- backgroundColor: "inherit",
142
- transform: "rotate(45deg)",
143
- pointerEvents: "none"
144
- });
145
- const getArrow = ({ anchorRect, surfaceSize, top, left }) => {
146
- const { width, height } = surfaceSize;
147
- if (top + height <= anchorRect.top + 1 || top >= anchorRect.bottom - 1) {
148
- const side = top + height <= anchorRect.top + 1 ? "top" : "bottom";
149
- const middle = anchorRect.left + anchorRect.width / 2 - left;
150
- return {
151
- side,
152
- offset: Math.min(Math.max(middle, ARROW), width - ARROW)
153
- };
154
- }
155
- const side = left + width <= anchorRect.left + 1 ? "left" : "right";
156
- const middle = anchorRect.top + anchorRect.height / 2 - top;
157
- return {
158
- side,
159
- offset: Math.min(Math.max(middle, ARROW), height - ARROW)
160
- };
161
- };
162
- const isSameArrow = (a, b) => a !== null && a.side === b.side && a.offset === b.offset;
163
- const getArrowStyle = ({ side, offset }) => {
164
- const half = ARROW / 2;
165
- if (side === "top") return {
166
- bottom: -4,
167
- left: offset - half
168
- };
169
- if (side === "bottom") return {
170
- top: -4,
171
- left: offset - half
172
- };
173
- if (side === "left") return {
174
- right: -4,
175
- top: offset - half
176
- };
177
- return {
178
- left: -4,
179
- top: offset - half
180
- };
181
- };
182
- /**
183
- * @description A short description of one child, shown on hover, keyboard focus and a long touch -
184
- * a `role="tooltip"` in a `Portal`, placed beside its child and flipped for want of room. The
185
- * child is named by it (`aria-label`) or described by it (`aria-describedby`, with
186
- * `shouldDescribeChild`). It opens and closes after their delays, stays open while the pointer is
187
- * on the tooltip itself, closes on Escape, and never takes or traps the focus.
188
- */
189
- function Tooltip({ children, title, placement: placementProp, hasArrow: hasArrowProp, enterDelay: enterDelayProp, leaveDelay: leaveDelayProp, enterTouchDelay: enterTouchDelayProp, leaveTouchDelay: leaveTouchDelayProp, shouldDescribeChild: shouldDescribeChildProp, isOpen: isOpenProp, defaultOpen = false, onOpen, onClose, shouldOpenOnHover: shouldOpenOnHoverProp, shouldOpenOnFocus: shouldOpenOnFocusProp, shouldOpenOnTouch: shouldOpenOnTouchProp, slots, slotProps, layer: layerProp, borderRadius: borderRadiusProp, bg: bgProp, textColor: textColorProp, className, "data-testid": dataTestid }) {
190
- const dp = require_theme.useDefaultProps("Tooltip");
191
- const placement = placementProp ?? dp.placement ?? "top";
192
- const hasArrow = hasArrowProp ?? dp.hasArrow ?? false;
193
- const shouldDescribeChild = shouldDescribeChildProp ?? dp.shouldDescribeChild ?? false;
194
- const layer = layerProp ?? dp.layer ?? "tooltip";
195
- const borderRadius = borderRadiusProp ?? dp.borderRadius;
196
- const bg = bgProp ?? dp.bg;
197
- const textColor = textColorProp ?? dp.textColor;
198
- const id = (0, react.useId)();
199
- const { isOpen, childHandlers, surfaceHandlers } = useTooltip({
200
- isOpen: isOpenProp,
201
- defaultOpen,
202
- onOpen,
203
- onClose,
204
- enterDelay: enterDelayProp ?? dp.enterDelay ?? 100,
205
- leaveDelay: leaveDelayProp ?? dp.leaveDelay ?? 0,
206
- enterTouchDelay: enterTouchDelayProp ?? dp.enterTouchDelay ?? 700,
207
- leaveTouchDelay: leaveTouchDelayProp ?? dp.leaveTouchDelay ?? 1500,
208
- shouldOpenOnHover: shouldOpenOnHoverProp ?? dp.shouldOpenOnHover ?? true,
209
- shouldOpenOnFocus: shouldOpenOnFocusProp ?? dp.shouldOpenOnFocus ?? true,
210
- shouldOpenOnTouch: shouldOpenOnTouchProp ?? dp.shouldOpenOnTouch ?? true
211
- });
212
- const isShown = isOpen && title !== void 0 && title !== null && title !== "";
213
- const anchorRef = (0, react.useRef)(null);
214
- const surfaceRef = (0, react.useRef)(null);
215
- const own = children.props;
216
- const ref = require_useMergedRefs.useMergedRefs(anchorRef, own.ref);
217
- const [arrow, setArrow] = (0, react.useState)(null);
218
- const getOrigins = (0, react.useCallback)((context) => require_getTooltipOrigins.getTooltipOrigins(require_getTooltipOrigins.resolveTooltipPlacement(placement, context), context.isRtl), [placement]);
219
- const onPlaced = (0, react.useCallback)((placed) => {
220
- if (!hasArrow) return;
221
- const next = getArrow(placed);
222
- setArrow((current) => isSameArrow(current, next) ? current : next);
223
- }, [hasArrow]);
224
- require_useAnchoredPlacement.useAnchoredPlacement({
225
- isOpen: isShown,
226
- anchorRef,
227
- surfaceRef,
228
- getOrigins,
229
- margin: MARGIN,
230
- gap: GAP,
231
- onPlaced
232
- });
233
- const handlers = Object.fromEntries(Object.entries(childHandlers).map(([name, handler]) => [name, (event) => {
234
- own[name]?.(event);
235
- handler(event);
236
- }]));
237
- const ownDescription = own["aria-describedby"];
238
- const names = typeof title === "string" && own["aria-label"] === void 0 && own["aria-labelledby"] === void 0 ? { "aria-label": title } : {};
239
- const ariaProps = shouldDescribeChild ? { "aria-describedby": isShown ? [ownDescription, id].filter(Boolean).join(" ") : ownDescription } : names;
240
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react.cloneElement)(children, {
241
- ...handlers,
242
- ...ariaProps,
243
- ref
244
- }), isShown && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Portal.Portal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(TooltipSurface, {
245
- ...slotProps?.root,
246
- as: slots?.root,
247
- ref: surfaceRef,
248
- id,
249
- role: "tooltip",
250
- layer,
251
- borderRadius,
252
- bg,
253
- textColor,
254
- className: [slotProps?.root?.className, className].filter(Boolean).join(" ") || void 0,
255
- "data-testid": dataTestid ?? slotProps?.root?.["data-testid"],
256
- ...surfaceHandlers,
257
- children: [title, hasArrow && arrow ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipArrow, {
258
- ...slotProps?.arrow,
259
- as: slots?.arrow,
260
- style: {
261
- ...slotProps?.arrow?.style,
262
- ...getArrowStyle(arrow)
263
- },
264
- "aria-hidden": "true"
265
- }) : null]
266
- }) })] });
267
- }
268
- exports.Tooltip = Tooltip;
2
+ const require_Tooltip = require("./Tooltip-CrPRvmj3.cjs");
3
+ exports.Tooltip = require_Tooltip.Tooltip;
@@ -1,5 +1,6 @@
1
- import { nt as Theme } from "./index-Lsm4v8fB.cjs";
2
- import { ElementType, HTMLAttributes, ReactElement, ReactNode, SyntheticEvent } from "react";
1
+ import { nt as Theme } from "./index-C6a3kDn2.cjs";
2
+ import { n as PopoverPosition } from "./computePopoverPosition-JgOwCM7k.cjs";
3
+ import { ElementType, HTMLAttributes, ReactElement, ReactNode, Ref, SyntheticEvent } from "react";
3
4
  /** A side of its child a tooltip sits on - and, after the dash, which end of that side it lines up with. */
4
5
  type FixedTooltipPlacement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end';
5
6
  /** A fixed placement, or `auto` - the side with the most room, chosen as it is placed. */
@@ -15,9 +16,25 @@ interface TooltipSlotProps {
15
16
  root?: SlotProps;
16
17
  arrow?: SlotProps;
17
18
  }
18
- interface TooltipProps {
19
- /** The one element the tooltip is about - it holds a `ref` and takes the handlers. */
20
- children: ReactElement;
19
+ /**
20
+ * What a parent that clones its child (a `Menu` with a `Tooltip` for a trigger) hands the tooltip
21
+ * instead: it is not the tooltip's, so it goes on to the child. The tooltip's own props are left out.
22
+ */
23
+ type TooltipForwardedProps = Omit<HTMLAttributes<HTMLElement>, 'title' | 'children' | 'className' | 'color'> & {
24
+ ref?: Ref<HTMLElement>;
25
+ };
26
+ interface TooltipProps extends TooltipForwardedProps {
27
+ /**
28
+ * The one element the tooltip is about - it holds a `ref` and takes the handlers. Without it, the
29
+ * tooltip is at `anchorPosition`, and open when `isOpen` says so.
30
+ */
31
+ children?: ReactElement;
32
+ /**
33
+ * A point in the window - client coordinates, as Popover's - to place the tooltip at instead of
34
+ * beside the child: a hint that depends on where the pointer is. It follows the point and the
35
+ * `title` as they change.
36
+ */
37
+ anchorPosition?: PopoverPosition;
21
38
  /** What the tooltip says. Nothing says no tooltip. */
22
39
  title?: ReactNode;
23
40
  /** The side of the child it sits on, and the end it lines up with; `auto` takes the side with the most room. Flips for want of room. Default: `'top'`. */
@@ -38,6 +55,12 @@ interface TooltipProps {
38
55
  leaveTouchDelay?: number;
39
56
  /** Describes the child (`aria-describedby`, while open) instead of naming it (`aria-label`). Default: `false`. */
40
57
  shouldDescribeChild?: boolean;
58
+ /**
59
+ * With `shouldDescribeChild`: the child is described the whole time, as by a native `title`, not
60
+ * only while the tooltip is open. A visually hidden copy of a `title` sits beside the child for it
61
+ * to point at. Default: `false`.
62
+ */
63
+ isDescriptionPersistent?: boolean;
41
64
  /** Whether it is shown. Controlled with `onOpen` and `onClose`. */
42
65
  isOpen?: boolean;
43
66
  /** Whether it is shown at first, when uncontrolled. Default: `false`. */
@@ -46,6 +69,18 @@ interface TooltipProps {
46
69
  onOpen?: (event: Event | SyntheticEvent) => void;
47
70
  /** Fired when it asks to close. */
48
71
  onClose?: (event: Event | SyntheticEvent) => void;
72
+ /**
73
+ * Whether a disabled child (`disabled`) is wrapped in an element of its own, which takes the pointer
74
+ * handlers and the placement, since a disabled control sends no pointer events. Left out for a child
75
+ * that is only marked disabled and still takes them - a menu row. Default: `true`.
76
+ */
77
+ shouldWrapDisabledChild?: boolean;
78
+ /**
79
+ * Whether the pointer can be moved onto the tooltip, which then stays open (WCAG 1.4.13). With
80
+ * `false` it takes no pointer events - a click goes to what is under it - and closes as the
81
+ * pointer leaves the child: for a text hint that holds nothing to use. Default: `true`.
82
+ */
83
+ isInteractive?: boolean;
49
84
  /** Opens on hover. Default: `true`. */
50
85
  shouldOpenOnHover?: boolean;
51
86
  /** Opens on keyboard focus. Default: `true`. */
@@ -70,5 +105,5 @@ interface TooltipProps {
70
105
  * `shouldDescribeChild`). It opens and closes after their delays, stays open while the pointer is
71
106
  * on the tooltip itself, closes on Escape, and never takes or traps the focus.
72
107
  */
73
- declare function Tooltip({ children, title, placement: placementProp, hasArrow: hasArrowProp, enterDelay: enterDelayProp, leaveDelay: leaveDelayProp, enterTouchDelay: enterTouchDelayProp, leaveTouchDelay: leaveTouchDelayProp, shouldDescribeChild: shouldDescribeChildProp, isOpen: isOpenProp, defaultOpen, onOpen, onClose, shouldOpenOnHover: shouldOpenOnHoverProp, shouldOpenOnFocus: shouldOpenOnFocusProp, shouldOpenOnTouch: shouldOpenOnTouchProp, slots, slotProps, layer: layerProp, borderRadius: borderRadiusProp, bg: bgProp, textColor: textColorProp, className, 'data-testid': dataTestid }: Readonly<TooltipProps>): import("react").JSX.Element;
74
- export { Tooltip, type TooltipPlacement, TooltipProps, TooltipSlotProps, TooltipSlots };
108
+ declare function Tooltip({ children, anchorPosition, title, placement: placementProp, hasArrow: hasArrowProp, enterDelay: enterDelayProp, leaveDelay: leaveDelayProp, enterTouchDelay: enterTouchDelayProp, leaveTouchDelay: leaveTouchDelayProp, shouldDescribeChild: shouldDescribeChildProp, isDescriptionPersistent: isDescriptionPersistentProp, isOpen: isOpenProp, defaultOpen, onOpen, onClose, isInteractive: isInteractiveProp, shouldWrapDisabledChild: shouldWrapDisabledChildProp, shouldOpenOnHover: shouldOpenOnHoverProp, shouldOpenOnFocus: shouldOpenOnFocusProp, shouldOpenOnTouch: shouldOpenOnTouchProp, slots, slotProps, layer: layerProp, borderRadius: borderRadiusProp, bg: bgProp, textColor: textColorProp, className, 'data-testid': dataTestid, ref: forwardedRef, ...forwarded }: Readonly<TooltipProps>): import("react").JSX.Element;
109
+ export { Tooltip, TooltipForwardedProps, type TooltipPlacement, TooltipProps, TooltipSlotProps, TooltipSlots };