@sanity/ui 4.0.0-static.4 → 4.0.0-static.41

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 (341) hide show
  1. package/dist/_chunks-es/{refractor.js → Refractor.js} +1 -1
  2. package/dist/_chunks-es/{refractor.js.map → Refractor.js.map} +1 -1
  3. package/dist/css/index.css +2 -1
  4. package/dist/css/index.css.map +1 -0
  5. package/dist/css/index.d.ts +51 -7
  6. package/dist/css/index.js +17979 -55
  7. package/dist/css/index.js.map +1 -1
  8. package/dist/index.d.ts +26 -38
  9. package/dist/index.js +1752 -1132
  10. package/dist/index.js.map +1 -1
  11. package/exports/css/index.css +1 -0
  12. package/package.json +39 -51
  13. package/src/core/Root.tsx +1 -1
  14. package/src/core/RootProvider.tsx +5 -5
  15. package/src/core/__workshop__/index.ts +1 -1
  16. package/src/core/components/autocomplete/{autocomplete.tsx → Autocomplete.tsx} +90 -58
  17. package/src/core/components/autocomplete/__workshop__/{custom.tsx → Custom.tsx} +14 -1
  18. package/src/core/components/autocomplete/__workshop__/{example.tsx → Example.tsx} +12 -1
  19. package/src/core/components/autocomplete/__workshop__/index.ts +6 -6
  20. package/src/core/components/autocomplete/types.ts +1 -1
  21. package/src/core/components/breadcrumbs/{breadcrumbs.tsx → Breadcrumbs.tsx} +80 -47
  22. package/src/core/components/breadcrumbs/__workshop__/index.ts +1 -1
  23. package/src/core/components/dialog/{dialog.tsx → Dialog.tsx} +20 -11
  24. package/src/core/components/dialog/{dialogCard.tsx → DialogCard.tsx} +9 -9
  25. package/src/core/components/dialog/{dialogContext.ts → DialogContext.ts} +1 -1
  26. package/src/core/components/dialog/{dialogProvider.tsx → DialogProvider.tsx} +2 -2
  27. package/src/core/components/dialog/__workshop__/{panes.tsx → Panes.tsx} +9 -21
  28. package/src/core/components/dialog/__workshop__/{position.tsx → Position.tsx} +9 -1
  29. package/src/core/components/dialog/__workshop__/{props.tsx → Props.tsx} +2 -0
  30. package/src/core/components/dialog/__workshop__/index.ts +10 -10
  31. package/src/core/components/dialog/__workshop__/styles.css.ts +18 -0
  32. package/src/core/components/dialog/useDialog.ts +3 -3
  33. package/src/core/components/hotkeys/{hotkeys.tsx → Hotkeys.tsx} +2 -2
  34. package/src/core/components/hotkeys/__workshop__/index.ts +1 -1
  35. package/src/core/components/menu/{menu.test.tsx → Menu.test.tsx} +9 -13
  36. package/src/core/components/menu/{menu.tsx → Menu.tsx} +19 -24
  37. package/src/core/components/menu/{menuButton.tsx → MenuButton.tsx} +14 -9
  38. package/src/core/components/menu/{menuContext.ts → MenuContext.ts} +3 -4
  39. package/src/core/components/menu/{menuGroup.tsx → MenuGroup.tsx} +16 -11
  40. package/src/core/components/menu/{menuItem.tsx → MenuItem.tsx} +7 -9
  41. package/src/core/components/menu/__workshop__/DataProps.tsx +27 -0
  42. package/src/core/components/menu/__workshop__/{menuButton.tsx → MenuButton.tsx} +6 -1
  43. package/src/core/components/menu/__workshop__/{tones.tsx → Tones.tsx} +7 -1
  44. package/src/core/components/menu/__workshop__/index.ts +22 -17
  45. package/src/core/components/menu/useMenu.ts +5 -5
  46. package/src/core/components/menu/useMenuController.ts +5 -5
  47. package/src/core/components/tab/{tab.tsx → Tab.tsx} +1 -1
  48. package/src/core/components/tab/{tabList.tsx → TabList.tsx} +2 -2
  49. package/src/core/components/tab/{tabPanel.tsx → TabPanel.tsx} +1 -1
  50. package/src/core/components/tab/__workshop__/index.ts +1 -1
  51. package/src/core/components/toast/{toast.test.tsx → Toast.test.tsx} +7 -7
  52. package/src/core/components/toast/{toast.tsx → Toast.tsx} +6 -6
  53. package/src/core/components/toast/{toastContext.ts → ToastContext.ts} +1 -1
  54. package/src/core/components/toast/{toastLayer.tsx → ToastLayer.tsx} +1 -1
  55. package/src/core/components/toast/{toastProvider.tsx → ToastProvider.tsx} +24 -9
  56. package/src/core/components/toast/__workshop__/{toast.tsx → Toast.tsx} +2 -0
  57. package/src/core/components/toast/__workshop__/index.ts +2 -2
  58. package/src/core/components/toast/useToast.ts +3 -3
  59. package/src/core/components/tree/{tree.tsx → Tree.tsx} +4 -4
  60. package/src/core/components/tree/{treeContext.ts → TreeContext.ts} +1 -1
  61. package/src/core/components/tree/{treeGroup.tsx → TreeGroup.tsx} +1 -1
  62. package/src/core/components/tree/{treeItem.tsx → TreeItem.tsx} +28 -25
  63. package/src/core/components/tree/__workshop__/index.ts +4 -4
  64. package/src/core/components/tree/useTree.ts +3 -3
  65. package/src/core/components/virtualList/{virtualList.tsx → VirtualList.tsx} +87 -45
  66. package/src/core/components/virtualList/__workshop__/index.ts +4 -4
  67. package/src/core/helpers/props.ts +0 -9
  68. package/src/core/hooks/useGlobalKeyDown.ts +11 -4
  69. package/src/core/hooks/useMediaIndex/__workshop__/index.ts +1 -1
  70. package/src/core/hooks/useResponsiveProp.ts +4 -17
  71. package/src/core/index.ts +68 -66
  72. package/src/core/lib/createGlobalScopedContext.ts +5 -3
  73. package/src/core/primitives/avatar/{avatar.tsx → Avatar.tsx} +7 -6
  74. package/src/core/primitives/avatar/{avatarCounter.tsx → AvatarCounter.tsx} +2 -2
  75. package/src/core/primitives/avatar/{avatarStack.tsx → AvatarStack.tsx} +3 -3
  76. package/src/core/primitives/avatar/__workshop__/{asButton.tsx → AsButton.tsx} +8 -1
  77. package/src/core/primitives/avatar/__workshop__/PropsStory.tsx +22 -0
  78. package/src/core/primitives/avatar/__workshop__/{stack.tsx → Stack.tsx} +5 -1
  79. package/src/core/primitives/avatar/__workshop__/index.ts +9 -4
  80. package/src/core/primitives/badge/{badge.test.tsx → Badge.test.tsx} +1 -1
  81. package/src/core/primitives/badge/{badge.tsx → Badge.tsx} +2 -2
  82. package/src/core/primitives/badge/__workshop__/{props.tsx → Props.tsx} +12 -1
  83. package/src/core/primitives/badge/__workshop__/index.ts +2 -2
  84. package/src/core/primitives/box/__workshop__/{props.tsx → Props.tsx} +6 -1
  85. package/src/core/primitives/box/__workshop__/index.ts +2 -2
  86. package/src/core/primitives/button/{button.test.tsx → Button.test.tsx} +1 -1
  87. package/src/core/primitives/button/{button.tsx → Button.tsx} +12 -11
  88. package/src/core/primitives/button/__workshop__/DataProps.tsx +22 -0
  89. package/src/core/primitives/button/__workshop__/{props.tsx → Props.tsx} +22 -0
  90. package/src/core/primitives/button/__workshop__/SanityUploadButton.tsx +21 -0
  91. package/src/core/primitives/button/__workshop__/{stacked.tsx → Stacked.tsx} +16 -0
  92. package/src/core/primitives/button/__workshop__/Styled1.tsx +11 -0
  93. package/src/core/primitives/button/__workshop__/index.ts +15 -15
  94. package/src/core/primitives/button/__workshop__/styles.css.ts +30 -0
  95. package/src/core/primitives/card/{card.tsx → Card.tsx} +10 -10
  96. package/src/core/primitives/card/{cardContext.ts → CardContext.ts} +1 -1
  97. package/src/core/primitives/card/{cardProvider.tsx → CardProvider.tsx} +3 -12
  98. package/src/core/primitives/card/__workshop__/DataProps.tsx +30 -0
  99. package/src/core/primitives/card/__workshop__/{props.tsx → Props.tsx} +10 -0
  100. package/src/core/primitives/card/__workshop__/{selected.tsx → Selected.tsx} +1 -1
  101. package/src/core/primitives/card/__workshop__/{styled.tsx → Styled.tsx} +2 -5
  102. package/src/core/primitives/card/__workshop__/index.ts +10 -9
  103. package/src/core/primitives/card/useCard.ts +11 -6
  104. package/src/core/primitives/checkbox/__workshop__/index.ts +4 -4
  105. package/src/core/primitives/code/{code.tsx → Code.tsx} +26 -2
  106. package/src/core/primitives/code/__workshop__/{props.tsx → Props.tsx} +6 -1
  107. package/src/core/primitives/code/__workshop__/index.ts +2 -2
  108. package/src/core/primitives/container/{container.tsx → Container.tsx} +1 -1
  109. package/src/core/primitives/container/__workshop__/{example.tsx → Example.tsx} +6 -1
  110. package/src/core/primitives/container/__workshop__/index.ts +1 -1
  111. package/src/core/primitives/flex/{flex.tsx → Flex.tsx} +1 -1
  112. package/src/core/primitives/flex/__workshop__/{example.tsx → Example.tsx} +14 -16
  113. package/src/core/primitives/flex/__workshop__/index.ts +2 -2
  114. package/src/core/primitives/flex/__workshop__/styles.css.ts +12 -0
  115. package/src/core/primitives/grid/{grid.tsx → Grid.tsx} +1 -1
  116. package/src/core/primitives/grid/__workshop__/index.ts +1 -1
  117. package/src/core/primitives/heading/{heading.tsx → Heading.tsx} +16 -0
  118. package/src/core/primitives/heading/__workshop__/{plain.tsx → Plain.tsx} +12 -1
  119. package/src/core/primitives/heading/__workshop__/index.ts +2 -2
  120. package/src/core/primitives/inline/{inline.tsx → Inline.tsx} +2 -1
  121. package/src/core/primitives/inline/__workshop__/{plain.tsx → Plain.tsx} +5 -1
  122. package/src/core/primitives/inline/__workshop__/index.ts +1 -1
  123. package/src/core/primitives/kbd/{kbd.tsx → Kbd.tsx} +2 -2
  124. package/src/core/primitives/kbd/__workshop__/index.ts +1 -1
  125. package/src/core/primitives/label/{label.tsx → Label.tsx} +16 -0
  126. package/src/core/primitives/label/__workshop__/{plain.tsx → Plain.tsx} +15 -1
  127. package/src/core/primitives/label/__workshop__/index.ts +2 -2
  128. package/src/core/primitives/layer/{layer.test.tsx → Layer.test.tsx} +7 -7
  129. package/src/core/primitives/layer/{layer.tsx → Layer.tsx} +3 -3
  130. package/src/core/primitives/layer/{layerCard.tsx → LayerCard.tsx} +2 -2
  131. package/src/core/primitives/layer/{layerContext.ts → LayerContext.ts} +1 -1
  132. package/src/core/primitives/layer/{layerProvider.tsx → LayerProvider.tsx} +6 -6
  133. package/src/core/primitives/layer/__workshop__/index.ts +3 -3
  134. package/src/core/primitives/layer/useLayer.ts +3 -3
  135. package/src/core/primitives/popover/{popover.tsx → Popover.tsx} +170 -150
  136. package/src/core/primitives/popover/{popoverLayer.tsx → PopoverLayer.tsx} +3 -3
  137. package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +13 -1
  138. package/src/core/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +2 -0
  139. package/src/core/primitives/popover/__workshop__/PlainStory.tsx +8 -0
  140. package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +7 -1
  141. package/src/core/primitives/popover/__workshop__/TestStory.tsx +6 -0
  142. package/src/core/primitives/popover/floating-ui/size.ts +17 -16
  143. package/src/core/primitives/radio/{radio.tsx → Radio.tsx} +2 -2
  144. package/src/core/primitives/radio/__workshop__/index.ts +2 -2
  145. package/src/core/primitives/select/{select.tsx → Select.tsx} +7 -5
  146. package/src/core/primitives/select/__workshop__/{plain.tsx → Plain.tsx} +4 -0
  147. package/src/core/primitives/select/__workshop__/index.ts +2 -2
  148. package/src/core/primitives/selectable/{selectable.tsx → Selectable.tsx} +2 -2
  149. package/src/core/primitives/selectable/__workshop__/DataProps.tsx +27 -0
  150. package/src/core/primitives/selectable/__workshop__/index.ts +14 -0
  151. package/src/core/primitives/skeleton/{codeSkeleton.tsx → CodeSkeleton.tsx} +1 -1
  152. package/src/core/primitives/skeleton/{headingSkeleton.tsx → HeadingSkeleton.tsx} +1 -1
  153. package/src/core/primitives/skeleton/{labelSkeleton.tsx → LabelSkeleton.tsx} +1 -1
  154. package/src/core/primitives/skeleton/{skeleton.tsx → Skeleton.tsx} +2 -2
  155. package/src/core/primitives/skeleton/{textSkeleton.tsx → TextSkeleton.tsx} +1 -1
  156. package/src/core/primitives/skeleton/__workshop__/{delay.tsx → Delay.tsx} +9 -1
  157. package/src/core/primitives/skeleton/__workshop__/{skeleton.tsx → Skeleton.tsx} +9 -1
  158. package/src/core/primitives/skeleton/__workshop__/index.ts +2 -2
  159. package/src/core/primitives/spinner/{spinner.tsx → Spinner.tsx} +2 -2
  160. package/src/core/primitives/spinner/__workshop__/Props.tsx +6 -1
  161. package/src/core/primitives/stack/{stack.tsx → Stack.tsx} +1 -1
  162. package/src/core/primitives/stack/__workshop__/{plain.tsx → Plain.tsx} +4 -1
  163. package/src/core/primitives/stack/__workshop__/index.ts +1 -1
  164. package/src/core/primitives/switch/{switch.tsx → Switch.tsx} +2 -10
  165. package/src/core/primitives/switch/__workshop__/index.ts +2 -2
  166. package/src/core/primitives/text/{text.tsx → Text.tsx} +14 -0
  167. package/src/core/primitives/text/__workshop__/{colored.tsx → Colored.tsx} +10 -8
  168. package/src/core/primitives/text/__workshop__/{example.tsx → Example.tsx} +15 -1
  169. package/src/core/primitives/text/__workshop__/index.ts +3 -3
  170. package/src/core/primitives/textArea/{textArea.tsx → TextArea.tsx} +7 -1
  171. package/src/core/primitives/textArea/__workshop__/{plain.tsx → Plain.tsx} +8 -0
  172. package/src/core/primitives/textArea/__workshop__/index.ts +1 -1
  173. package/src/core/primitives/textInput/{textInput.tsx → TextInput.tsx} +93 -72
  174. package/src/core/primitives/textInput/__workshop__/{plain.tsx → Plain.tsx} +34 -4
  175. package/src/core/primitives/textInput/__workshop__/{typed.tsx → Typed.tsx} +7 -1
  176. package/src/core/primitives/textInput/__workshop__/index.ts +7 -7
  177. package/src/core/primitives/tooltip/{tooltip.test.tsx → Tooltip.test.tsx} +4 -4
  178. package/src/core/primitives/tooltip/{tooltip.tsx → Tooltip.tsx} +102 -63
  179. package/src/core/primitives/tooltip/{tooltipLayer.tsx → TooltipLayer.tsx} +2 -2
  180. package/src/core/primitives/tooltip/__workshop__/{customPortal.tsx → CustomPortal.tsx} +2 -0
  181. package/src/core/primitives/tooltip/__workshop__/{overflowingBoundary.tsx → OverflowingBoundary.tsx} +2 -0
  182. package/src/core/primitives/tooltip/__workshop__/{props.tsx → Props.tsx} +12 -0
  183. package/src/core/primitives/tooltip/__workshop__/{resizableBoundary.tsx → ResizableBoundary.tsx} +5 -0
  184. package/src/core/primitives/tooltip/__workshop__/index.ts +4 -4
  185. package/src/core/primitives/tooltip/tooltipDelayGroup/{tooltipDelayGroupContext.tsx → TooltipDelayGroupContext.tsx} +1 -1
  186. package/src/core/primitives/tooltip/tooltipDelayGroup/{tooltipDelayGroupProvider.tsx → TooltipDelayGroupProvider.tsx} +2 -4
  187. package/src/core/primitives/tooltip/tooltipDelayGroup/useTooltipDelayGroup.ts +3 -3
  188. package/src/core/types.ts +6 -5
  189. package/src/core/utils/{errorBoundary.tsx → ErrorBoundary.tsx} +1 -1
  190. package/src/core/utils/boundaryElement/{boundaryElementContext.ts → BoundaryElementContext.ts} +2 -5
  191. package/src/core/utils/boundaryElement/BoundaryElementProvider.tsx +16 -0
  192. package/src/core/utils/boundaryElement/__workshop__/index.ts +1 -1
  193. package/src/core/utils/boundaryElement/types.ts +1 -4
  194. package/src/core/utils/boundaryElement/useBoundaryElement.ts +7 -19
  195. package/src/core/utils/elementQuery/__workshop__/CustomMedia.tsx +19 -0
  196. package/src/core/utils/elementQuery/__workshop__/index.ts +1 -1
  197. package/src/core/utils/elementQuery/__workshop__/styles.css.ts +31 -0
  198. package/src/core/utils/portal/{portal.test.tsx → Portal.test.tsx} +7 -7
  199. package/src/core/utils/portal/{portal.tsx → Portal.tsx} +7 -4
  200. package/src/core/utils/portal/{portalContext.ts → PortalContext.ts} +1 -1
  201. package/src/core/utils/portal/PortalProvider.tsx +38 -0
  202. package/src/core/utils/portal/__workshop__/index.ts +1 -1
  203. package/src/core/utils/portal/usePortal.ts +12 -5
  204. package/src/css/_responsiveStyle.css.ts +2 -2
  205. package/src/css/primitives/_input/_input.css.ts +13 -12
  206. package/src/css/primitives/_input/input.ts +2 -0
  207. package/src/css/primitives/_input/types.ts +2 -1
  208. package/src/css/primitives/avatar/avatar.css.ts +17 -5
  209. package/src/css/primitives/box/box.css.ts +19 -1
  210. package/src/css/primitives/button/button.css.ts +252 -183
  211. package/src/css/primitives/card/__workshop__/{color.tsx → Color.tsx} +9 -1
  212. package/src/css/primitives/card/__workshop__/index.ts +1 -1
  213. package/src/css/primitives/card/card.css.ts +133 -130
  214. package/src/css/primitives/checkbox/checkbox.css.ts +1 -0
  215. package/src/css/primitives/code/code.ts +4 -0
  216. package/src/css/primitives/code/types.ts +7 -1
  217. package/src/css/primitives/heading/heading.ts +4 -0
  218. package/src/css/primitives/heading/types.ts +7 -1
  219. package/src/css/primitives/label/label.ts +4 -0
  220. package/src/css/primitives/label/types.ts +7 -1
  221. package/src/css/primitives/radio/radio.css.ts +1 -1
  222. package/src/css/primitives/root/root.css.ts +1 -1
  223. package/src/css/primitives/select/select.css.ts +7 -1
  224. package/src/css/primitives/selectable/selectable.css.ts +79 -70
  225. package/src/css/primitives/switch/switch.css.ts +10 -1
  226. package/src/css/primitives/text/text.ts +2 -0
  227. package/src/css/primitives/text/types.ts +6 -1
  228. package/src/css/primitives/textInput/textInput.css.ts +15 -3
  229. package/src/css/props/width/types.ts +1 -1
  230. package/src/css/props/width/width.css.ts +5 -2
  231. package/src/css/theme/buildCSSTheme.ts +4 -0
  232. package/src/css/types.ts +4 -0
  233. package/src/css/vars.css.ts +4 -0
  234. package/dist/_chunks-cjs/refractor.cjs +0 -22
  235. package/dist/_chunks-cjs/refractor.cjs.map +0 -1
  236. package/dist/css/index.cjs +0 -966
  237. package/dist/css/index.cjs.map +0 -1
  238. package/dist/css/index.d.cts +0 -1370
  239. package/dist/index.cjs +0 -4515
  240. package/dist/index.cjs.map +0 -1
  241. package/dist/index.d.cts +0 -2521
  242. package/dist/theme.cjs +0 -870
  243. package/dist/theme.cjs.map +0 -1
  244. package/dist/theme.d.cts +0 -499
  245. package/src/core/primitives/button/__workshop__/sanityUploadButton.tsx +0 -36
  246. package/src/core/primitives/button/__workshop__/styled1.tsx +0 -17
  247. package/src/core/primitives/button/__workshop__/styled2.tsx +0 -19
  248. package/src/core/primitives/popover/helpers.ts +0 -32
  249. package/src/core/primitives/tooltip/tooltipDelayGroup/index.ts +0 -4
  250. package/src/core/utils/boundaryElement/boundaryElement.test.tsx +0 -102
  251. package/src/core/utils/boundaryElement/boundaryElementProvider.tsx +0 -18
  252. package/src/core/utils/elementQuery/__workshop__/customMedia.tsx +0 -41
  253. package/src/core/utils/portal/portalProvider.tsx +0 -70
  254. /package/src/core/__workshop__/{boundary.tsx → Boundary.tsx} +0 -0
  255. /package/src/core/components/autocomplete/{autocompleteOption.tsx → AutocompleteOption.tsx} +0 -0
  256. /package/src/core/components/autocomplete/__workshop__/{async.tsx → Async.tsx} +0 -0
  257. /package/src/core/components/autocomplete/__workshop__/{constrainedHeight.tsx → ConstrainedHeight.tsx} +0 -0
  258. /package/src/core/components/autocomplete/__workshop__/{focusAndBlur.tsx → FocusAndBlur.tsx} +0 -0
  259. /package/src/core/components/autocomplete/__workshop__/{fullscreen.tsx → Fullscreen.tsx} +0 -0
  260. /package/src/core/components/breadcrumbs/__workshop__/{example.tsx → Example.tsx} +0 -0
  261. /package/src/core/components/dialog/__workshop__/{activate.tsx → Activate.tsx} +0 -0
  262. /package/src/core/components/dialog/__workshop__/{autoFocus.tsx → AutoFocus.tsx} +0 -0
  263. /package/src/core/components/dialog/__workshop__/{layering.tsx → Layering.tsx} +0 -0
  264. /package/src/core/components/dialog/__workshop__/{nested.tsx → Nested.tsx} +0 -0
  265. /package/src/core/components/dialog/__workshop__/{onScroll.tsx → OnScroll.tsx} +0 -0
  266. /package/src/core/components/dialog/__workshop__/{provider.tsx → Provider.tsx} +0 -0
  267. /package/src/core/components/dialog/__workshop__/{wrapped.tsx → Wrapped.tsx} +0 -0
  268. /package/src/core/components/hotkeys/__workshop__/{plain.tsx → Plain.tsx} +0 -0
  269. /package/src/core/components/menu/{menuDivider.tsx → MenuDivider.tsx} +0 -0
  270. /package/src/core/components/menu/__workshop__/{asComponent.tsx → AsComponent.tsx} +0 -0
  271. /package/src/core/components/menu/__workshop__/{avatarMenu.tsx → AvatarMenu.tsx} +0 -0
  272. /package/src/core/components/menu/__workshop__/{closableMenuButton.tsx → ClosableMenuButton.tsx} +0 -0
  273. /package/src/core/components/menu/__workshop__/{constrainedInBoundary.tsx → ConstrainedInBoundary.tsx} +0 -0
  274. /package/src/core/components/menu/__workshop__/{customMenuItem.tsx → CustomMenuItem.tsx} +0 -0
  275. /package/src/core/components/menu/__workshop__/{customSelectedState.tsx → CustomSelectedState.tsx} +0 -0
  276. /package/src/core/components/menu/__workshop__/{disableFocusOnClose.tsx → DisableFocusOnClose.tsx} +0 -0
  277. /package/src/core/components/menu/__workshop__/{groups.tsx → Groups.tsx} +0 -0
  278. /package/src/core/components/menu/__workshop__/{menuGroupRight.tsx → MenuGroupRight.tsx} +0 -0
  279. /package/src/core/components/menu/__workshop__/{nestedMenu.tsx → NestedMenu.tsx} +0 -0
  280. /package/src/core/components/menu/__workshop__/{onCloseMenuButton.tsx → OnCloseMenuButton.tsx} +0 -0
  281. /package/src/core/components/menu/__workshop__/{selectedItem.tsx → SelectedItem.tsx} +0 -0
  282. /package/src/core/components/menu/__workshop__/{shouldFocus.tsx → ShouldFocus.tsx} +0 -0
  283. /package/src/core/components/menu/__workshop__/{withoutArrow.tsx → WithoutArrow.tsx} +0 -0
  284. /package/src/core/components/tab/__workshop__/{example.tsx → Example.tsx} +0 -0
  285. /package/src/core/components/toast/__workshop__/{hook.tsx → Hook.tsx} +0 -0
  286. /package/src/core/components/tree/__workshop__/{basic.tsx → Basic.tsx} +0 -0
  287. /package/src/core/components/tree/__workshop__/{tabFromElement.tsx → TabFromElement.tsx} +0 -0
  288. /package/src/core/components/virtualList/__workshop__/{changingProps.tsx → ChangingProps.tsx} +0 -0
  289. /package/src/core/components/virtualList/__workshop__/{elementScroll.tsx → ElementScroll.tsx} +0 -0
  290. /package/src/core/components/virtualList/__workshop__/{infiniteList.tsx → InfiniteList.tsx} +0 -0
  291. /package/src/core/components/virtualList/__workshop__/{windowScrolll.tsx → WindowScrolll.tsx} +0 -0
  292. /package/src/core/hooks/useMediaIndex/__workshop__/{test.tsx → Test.tsx} +0 -0
  293. /package/src/core/primitives/arrow/{arrow.tsx → Arrow.tsx} +0 -0
  294. /package/src/core/primitives/avatar/__workshop__/{withinButton.tsx → WithinButton.tsx} +0 -0
  295. /package/src/core/primitives/avatar/__workshop__/{withinMenuItem.tsx → WithinMenuItem.tsx} +0 -0
  296. /package/src/core/primitives/badge/__workshop__/{tones.tsx → Tones.tsx} +0 -0
  297. /package/src/core/primitives/box/{box.tsx → Box.tsx} +0 -0
  298. /package/src/core/primitives/box/__workshop__/{responsive.tsx → Responsive.tsx} +0 -0
  299. /package/src/core/primitives/button/__workshop__/{custom.tsx → Custom.tsx} +0 -0
  300. /package/src/core/primitives/button/__workshop__/{customIcons.tsx → CustomIcons.tsx} +0 -0
  301. /package/src/core/primitives/button/__workshop__/{disabled.tsx → Disabled.tsx} +0 -0
  302. /package/src/core/primitives/button/__workshop__/{mixedChildren.tsx → MixedChildren.tsx} +0 -0
  303. /package/src/core/primitives/button/__workshop__/{textOverflow.tsx → TextOverflow.tsx} +0 -0
  304. /package/src/core/primitives/button/__workshop__/{uploadButton.tsx → UploadButton.tsx} +0 -0
  305. /package/src/core/primitives/card/__workshop__/{asButton.tsx → AsButton.tsx} +0 -0
  306. /package/src/core/primitives/card/__workshop__/{asComponent.tsx → AsComponent.tsx} +0 -0
  307. /package/src/core/primitives/card/__workshop__/{checkered.tsx → Checkered.tsx} +0 -0
  308. /package/src/core/primitives/card/__workshop__/{interactive.tsx → Interactive.tsx} +0 -0
  309. /package/src/core/primitives/card/__workshop__/{listNavigation.tsx → ListNavigation.tsx} +0 -0
  310. /package/src/core/primitives/card/__workshop__/{tones.tsx → Tones.tsx} +0 -0
  311. /package/src/core/primitives/checkbox/{checkbox.tsx → Checkbox.tsx} +0 -0
  312. /package/src/core/primitives/checkbox/__workshop__/{example.tsx → Example.tsx} +0 -0
  313. /package/src/core/primitives/checkbox/__workshop__/{props.tsx → Props.tsx} +0 -0
  314. /package/src/core/primitives/checkbox/__workshop__/{readOnly.tsx → ReadOnly.tsx} +0 -0
  315. /package/src/core/primitives/checkbox/__workshop__/{tones.tsx → Tones.tsx} +0 -0
  316. /package/src/core/primitives/code/{refractor.tsx → Refractor.tsx} +0 -0
  317. /package/src/core/primitives/code/__workshop__/{opticalAlignment.tsx → OpticalAlignment.tsx} +0 -0
  318. /package/src/core/primitives/flex/__workshop__/{gap.tsx → Gap.tsx} +0 -0
  319. /package/src/core/primitives/grid/__workshop__/{responsive.tsx → Responsive.tsx} +0 -0
  320. /package/src/core/primitives/heading/__workshop__/{opticalAlignment.tsx → OpticalAlignment.tsx} +0 -0
  321. /package/src/core/primitives/kbd/__workshop__/{plain.tsx → Plain.tsx} +0 -0
  322. /package/src/core/primitives/label/__workshop__/{opticalAlignment.tsx → OpticalAlignment.tsx} +0 -0
  323. /package/src/core/primitives/layer/__workshop__/{multipleRoots.tsx → MultipleRoots.tsx} +0 -0
  324. /package/src/core/primitives/layer/__workshop__/{nested.tsx → Nested.tsx} +0 -0
  325. /package/src/core/primitives/layer/__workshop__/{responsiveZOffset.tsx → ResponsiveZOffset.tsx} +0 -0
  326. /package/src/core/primitives/radio/__workshop__/{example.tsx → Example.tsx} +0 -0
  327. /package/src/core/primitives/radio/__workshop__/{plain.tsx → Plain.tsx} +0 -0
  328. /package/src/core/primitives/select/__workshop__/{readOnly.tsx → ReadOnly.tsx} +0 -0
  329. /package/src/core/primitives/spinner/{animatedSpinnerIcon.tsx → AnimatedSpinnerIcon.tsx} +0 -0
  330. /package/src/core/primitives/srOnly/{srOnly.tsx → SrOnly.tsx} +0 -0
  331. /package/src/core/primitives/switch/__workshop__/{example.tsx → Example.tsx} +0 -0
  332. /package/src/core/primitives/switch/__workshop__/{props.tsx → Props.tsx} +0 -0
  333. /package/src/core/primitives/text/__workshop__/{opticalAlignment.tsx → OpticalAlignment.tsx} +0 -0
  334. /package/src/core/primitives/textInput/__workshop__/{clearButton.tsx → ClearButton.tsx} +0 -0
  335. /package/src/core/primitives/textInput/__workshop__/{customValidity.tsx → CustomValidity.tsx} +0 -0
  336. /package/src/core/primitives/textInput/__workshop__/{readOnly.tsx → ReadOnly.tsx} +0 -0
  337. /package/src/core/primitives/textInput/__workshop__/{states.tsx → States.tsx} +0 -0
  338. /package/src/core/primitives/textInput/__workshop__/{tones.tsx → Tones.tsx} +0 -0
  339. /package/src/core/utils/boundaryElement/__workshop__/{plain.tsx → Plain.tsx} +0 -0
  340. /package/src/core/utils/elementQuery/{elementQuery.tsx → ElementQuery.tsx} +0 -0
  341. /package/src/core/utils/portal/__workshop__/{named.tsx → Named.tsx} +0 -0
@@ -23,13 +23,13 @@ import {
23
23
  import {isValidElementType} from 'react-is'
24
24
 
25
25
  import {EMPTY_RECORD} from '../../constants'
26
+ import {_getResponsiveProp} from '../../helpers/props'
26
27
  import {useCustomValidity} from '../../hooks/useCustomValidity'
27
- import {useResponsiveProp} from '../../hooks/useResponsiveProp'
28
28
  import {isRecord} from '../../lib/isRecord'
29
29
  import type {ComponentType, Props} from '../../types'
30
- import {Box} from '../box/box'
31
- import {Button, type ButtonProps} from '../button/button'
32
- import {Text} from '../text/text'
30
+ import {Box} from '../box/Box'
31
+ import {Button, type ButtonProps} from '../button/Button'
32
+ import {Text} from '../text/Text'
33
33
 
34
34
  /** @public */
35
35
  export const DEFAULT_TEXT_INPUT_ELEMENT = 'input'
@@ -86,6 +86,7 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
86
86
  className,
87
87
  clearButton,
88
88
  disabled = false,
89
+ flex,
89
90
  fontSize = 2,
90
91
  gap = 3,
91
92
  icon: IconComponent,
@@ -99,14 +100,14 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
99
100
  suffix,
100
101
  customValidity,
101
102
  type = 'text',
102
- weight: _width, // eslint-disable-line @typescript-eslint/no-unused-vars
103
+ weight: _width,
103
104
  width,
104
105
  ...rest
105
106
  } = props as TextInputProps<typeof DEFAULT_TEXT_INPUT_ELEMENT>
106
107
 
107
108
  const ref = useRef<HTMLInputElement | null>(null)
108
109
 
109
- const responsivePadding = useResponsiveProp(padding)
110
+ const responsivePadding = useMemo(() => _getResponsiveProp(padding), [padding])
110
111
 
111
112
  const withClearButton = Boolean(clearButton)
112
113
 
@@ -136,45 +137,16 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
136
137
  [onClear, ref],
137
138
  )
138
139
 
139
- const clearButtonBoxPadding = useMemo(() => {
140
- return Object.fromEntries(
141
- Object.entries(responsivePadding).map(([key, value]) => {
142
- if (value === 0) return [key, 0]
143
- if (value === 1) return [key, 1]
144
- if (value === 2) return [key, 1]
145
-
146
- return [key, typeof value === 'number' ? value - 2 : 0]
147
- }),
148
- ) as ResponsiveProp<Space>
149
- }, [responsivePadding])
150
-
151
- const clearButtonPadding = useMemo(() => {
152
- return Object.fromEntries(
153
- Object.entries(responsivePadding).map(([key, value]) => {
154
- if (value === 0) return [key, 0]
155
- if (value === 1) return [key, 0]
156
- if (value === 2) return [key, 1]
157
-
158
- return [key, typeof value === 'number' ? value - 1 : 0]
159
- }),
160
- ) as ResponsiveProp<Space>
161
- }, [responsivePadding])
162
-
163
- const clearButtonProps: TextInputClearButtonProps = useMemo(
164
- () => (isRecord(clearButton) ? clearButton : EMPTY_RECORD),
165
- [clearButton],
166
- )
167
-
168
140
  return (
169
- <Box
170
- alignItems="center"
141
+ <span
171
142
  className={textInput({
172
143
  className,
173
144
  border,
145
+ flex,
174
146
  fontSize,
175
147
  padding,
176
148
  radius,
177
- gap: gap,
149
+ gap,
178
150
  width,
179
151
  })}
180
152
  data-icon-left={IconComponent ? '' : undefined}
@@ -184,15 +156,14 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
184
156
  data-read-only={!disabled && readOnly ? '' : undefined}
185
157
  data-suffix={suffix ? '' : undefined}
186
158
  data-ui="TextInput"
187
- display="flex"
188
159
  >
189
160
  {prefix && (
190
- <Box className={textInputPrefix()} sizing="border">
161
+ <span className={textInputPrefix()}>
191
162
  <span>{prefix}</span>
192
- </Box>
163
+ </span>
193
164
  )}
194
165
 
195
- <Box className={textInputElement()} flex={1} position="relative">
166
+ <span className={textInputElement()}>
196
167
  <Element
197
168
  {...rest}
198
169
  className={_inputElement()}
@@ -203,10 +174,10 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
203
174
  type={type}
204
175
  />
205
176
 
206
- <Box className={_inputPresentation()} position="absolute">
177
+ <span className={_inputPresentation()}>
207
178
  {IconComponent && (
208
- <Box padding={padding} position="absolute" insetTop={0} insetLeft={0}>
209
- <Text size={fontSize}>
179
+ <Box as="span" padding={padding} position="absolute" insetTop={0} insetLeft={0}>
180
+ <Text as="span" size={fontSize}>
210
181
  {isValidElement(IconComponent) && IconComponent}
211
182
  {isValidElementType(IconComponent) && <IconComponent />}
212
183
  </Text>
@@ -214,45 +185,95 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
214
185
  )}
215
186
 
216
187
  {!withClearButton && IconRightComponent && (
217
- <Box padding={padding} position="absolute" insetTop={0} insetRight={0}>
218
- <Text size={fontSize}>
188
+ <Box as="span" padding={padding} position="absolute" insetTop={0} insetRight={0}>
189
+ <Text as="span" size={fontSize}>
219
190
  {isValidElement(IconRightComponent) && IconRightComponent}
220
191
  {isValidElementType(IconRightComponent) && <IconRightComponent />}
221
192
  </Text>
222
193
  </Box>
223
194
  )}
224
- </Box>
195
+ </span>
225
196
 
226
197
  {!disabled && !readOnly && clearButton && (
227
- <Box
228
- insetTop={0}
229
- insetRight={0}
230
- padding={clearButtonBoxPadding}
231
- position="absolute"
232
- style={{zIndex: 2}}
233
- >
234
- <Button
235
- aria-label="Clear"
236
- data-qa="clear-button"
237
- display="block"
238
- fontSize={fontSize}
239
- icon={CloseIcon}
240
- mode="bleed"
241
- padding={clearButtonPadding}
242
- radius={radius}
243
- {...clearButtonProps}
244
- onClick={handleClearClick}
245
- onMouseDown={handleClearMouseDown}
246
- />
247
- </Box>
198
+ <ClearButton
199
+ fontSize={fontSize}
200
+ radius={radius}
201
+ clearButtonProps={isRecord(clearButton) ? clearButton : EMPTY_RECORD}
202
+ handleClearClick={handleClearClick}
203
+ handleClearMouseDown={handleClearMouseDown}
204
+ padding={responsivePadding}
205
+ />
248
206
  )}
249
- </Box>
207
+ </span>
250
208
 
251
209
  {suffix && (
252
- <Box className={textInputSuffix()} sizing="border">
210
+ <span className={textInputSuffix()}>
253
211
  <span>{suffix}</span>
254
- </Box>
212
+ </span>
255
213
  )}
214
+ </span>
215
+ )
216
+ }
217
+
218
+ function ClearButton({
219
+ fontSize,
220
+ radius,
221
+ clearButtonProps,
222
+ handleClearClick,
223
+ handleClearMouseDown,
224
+ padding,
225
+ }: {
226
+ clearButtonProps: TextInputClearButtonProps
227
+ handleClearClick: (event: MouseEvent<HTMLButtonElement>) => void
228
+ handleClearMouseDown: (event: MouseEvent<HTMLButtonElement>) => void
229
+ padding: ResponsiveProp<Space>
230
+ } & Pick<TextInputOwnProps, 'fontSize' | 'radius'>) {
231
+ const clearButtonBoxPadding = useMemo(() => {
232
+ return Object.fromEntries(
233
+ Object.entries(padding).map(([key, value]) => {
234
+ if (value === 0) return [key, 0]
235
+ if (value === 1) return [key, 1]
236
+ if (value === 2) return [key, 1]
237
+
238
+ return [key, typeof value === 'number' ? value - 2 : 0]
239
+ }),
240
+ ) as ResponsiveProp<Space>
241
+ }, [padding])
242
+
243
+ const clearButtonPadding = useMemo(() => {
244
+ return Object.fromEntries(
245
+ Object.entries(padding).map(([key, value]) => {
246
+ if (value === 0) return [key, 0]
247
+ if (value === 1) return [key, 0]
248
+ if (value === 2) return [key, 1]
249
+
250
+ return [key, typeof value === 'number' ? value - 1 : 0]
251
+ }),
252
+ ) as ResponsiveProp<Space>
253
+ }, [padding])
254
+
255
+ return (
256
+ <Box
257
+ as="span"
258
+ insetTop={0}
259
+ insetRight={0}
260
+ padding={clearButtonBoxPadding}
261
+ position="absolute"
262
+ style={{zIndex: 2}}
263
+ >
264
+ <Button
265
+ aria-label="Clear"
266
+ data-qa="clear-button"
267
+ display="block"
268
+ fontSize={fontSize}
269
+ icon={CloseIcon}
270
+ mode="bleed"
271
+ padding={clearButtonPadding}
272
+ radius={radius}
273
+ {...clearButtonProps}
274
+ onClick={handleClearClick}
275
+ onMouseDown={handleClearMouseDown}
276
+ />
256
277
  </Box>
257
278
  )
258
279
  }
@@ -53,16 +53,23 @@ function TextInputTest(props: {inputRef: React.Ref<HTMLInputElement>}) {
53
53
  const border = useBoolean('Border', true)
54
54
  const customValidity = useText('Custom validity')
55
55
  const disabled = useBoolean('Disabled', false)
56
+ // @ts-expect-error - TODO: fix this
56
57
  const fontSize = useSelect('Font size', WORKSHOP_TEXT_FONT_SIZE_OPTIONS, 2)
58
+ // @ts-expect-error - TODO: fix this
57
59
  const gap = useSelect('Gap', WORKSHOP_SPACE_OPTIONS, 3)
60
+ // @ts-expect-error - TODO: fix this
58
61
  const icon = useSelect('Icon', WORKSHOP_ICON_SYMBOL_OPTIONS, 'search')
62
+ // @ts-expect-error - TODO: fix this
59
63
  const iconRight = useSelect('Icon (right)', WORKSHOP_ICON_SYMBOL_OPTIONS, 'cube')
64
+ // @ts-expect-error - TODO: fix this
60
65
  const padding = useSelect('Padding', WORKSHOP_SPACE_OPTIONS, 3)
61
66
  const placeholder = useText('Placeholder')
62
67
  const prefix = useBoolean('Prefix', false)
68
+ // @ts-expect-error - TODO: fix this
63
69
  const radius = useSelect('Radius', WORKSHOP_RADIUS_OPTIONS, 2)
64
70
  const readOnly = useBoolean('Read only', false)
65
71
  const suffix = useBoolean('Suffix', false)
72
+ // @ts-expect-error - TODO: fix this
66
73
  const weight = useSelect('Weight', WORKSHOP_FONT_WEIGHT_OPTIONS)
67
74
 
68
75
  const [value, setValue] = useState('')
@@ -77,33 +84,56 @@ function TextInputTest(props: {inputRef: React.Ref<HTMLInputElement>}) {
77
84
  border={border}
78
85
  customValidity={customValidity}
79
86
  disabled={disabled}
87
+ // @ts-expect-error - TODO: fix this
80
88
  fontSize={fontSize}
89
+ // @ts-expect-error - TODO: fix this
81
90
  gap={gap}
91
+ // @ts-expect-error - TODO: fix this
82
92
  icon={icon && icons[icon]}
93
+ // @ts-expect-error - TODO: fix this
83
94
  iconRight={iconRight && icons[iconRight]}
84
95
  id="text-input-example"
85
96
  name="test"
86
97
  onChange={handleChange}
98
+ // @ts-expect-error - TODO: fix this
87
99
  padding={padding}
88
100
  placeholder={placeholder}
89
101
  prefix={
90
102
  prefix && (
91
- <Box padding={padding}>
92
- <Text size={fontSize}>Prefix</Text>
103
+ <Box
104
+ // @ts-expect-error - TODO: fix this
105
+ padding={padding}
106
+ >
107
+ <Text
108
+ // @ts-expect-error - TODO: fix this
109
+ size={fontSize}
110
+ >
111
+ Prefix
112
+ </Text>
93
113
  </Box>
94
114
  )
95
115
  }
116
+ // @ts-expect-error - TODO: fix this
96
117
  radius={radius}
97
118
  readOnly={readOnly}
98
119
  ref={ref}
99
120
  suffix={
100
121
  suffix && (
101
- <Box padding={padding}>
102
- <Text size={fontSize}>Suffix</Text>
122
+ <Box
123
+ // @ts-expect-error - TODO: fix this
124
+ padding={padding}
125
+ >
126
+ <Text
127
+ // @ts-expect-error - TODO: fix this
128
+ size={fontSize}
129
+ >
130
+ Suffix
131
+ </Text>
103
132
  </Box>
104
133
  )
105
134
  }
106
135
  value={value}
136
+ // @ts-expect-error - TODO: fix this
107
137
  weight={weight}
108
138
  />
109
139
  )
@@ -5,6 +5,7 @@ import {useCallback, useState} from 'react'
5
5
  import {WORKSHOP_TEXT_INPUT_TYPE_OPTIONS} from '$workshop'
6
6
 
7
7
  export default function TypedStory(): React.JSX.Element {
8
+ // @ts-expect-error - TODO: fix this
8
9
  const type = useSelect('Type', WORKSHOP_TEXT_INPUT_TYPE_OPTIONS, 'text')
9
10
 
10
11
  const [value, setValue] = useState('')
@@ -16,7 +17,12 @@ export default function TypedStory(): React.JSX.Element {
16
17
  return (
17
18
  <Box padding={4}>
18
19
  <Container width={1}>
19
- <TextInput onChange={handleChange} type={type} value={value} />
20
+ <TextInput
21
+ onChange={handleChange}
22
+ // @ts-expect-error - TODO: fix this
23
+ type={type}
24
+ value={value}
25
+ />
20
26
  </Container>
21
27
  </Box>
22
28
  )
@@ -8,37 +8,37 @@ const scope: WorkshopScope = {
8
8
  {
9
9
  name: 'plain',
10
10
  title: 'Plain',
11
- component: lazy(() => import('./plain')),
11
+ component: lazy(() => import('./Plain')),
12
12
  },
13
13
  {
14
14
  name: 'custom-validity',
15
15
  title: 'Custom validity',
16
- component: lazy(() => import('./customValidity')),
16
+ component: lazy(() => import('./CustomValidity')),
17
17
  },
18
18
  {
19
19
  name: 'typed',
20
20
  title: 'Typed',
21
- component: lazy(() => import('./typed')),
21
+ component: lazy(() => import('./Typed')),
22
22
  },
23
23
  {
24
24
  name: 'tones',
25
25
  title: 'Tones',
26
- component: lazy(() => import('./tones')),
26
+ component: lazy(() => import('./Tones')),
27
27
  },
28
28
  {
29
29
  name: 'clear-button',
30
30
  title: 'Clear button',
31
- component: lazy(() => import('./clearButton')),
31
+ component: lazy(() => import('./ClearButton')),
32
32
  },
33
33
  {
34
34
  name: 'read-only',
35
35
  title: 'Read only',
36
- component: lazy(() => import('./readOnly')),
36
+ component: lazy(() => import('./ReadOnly')),
37
37
  },
38
38
  {
39
39
  name: 'states',
40
40
  title: 'States',
41
- component: lazy(() => import('./states')),
41
+ component: lazy(() => import('./States')),
42
42
  },
43
43
  ],
44
44
  }
@@ -3,10 +3,10 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'
3
3
 
4
4
  import {render} from '$test/utils'
5
5
 
6
- import {Button} from '../button/button'
7
- import {Text} from '../text/text'
8
- import {Tooltip} from './tooltip'
9
- import {TooltipDelayGroupProvider} from './tooltipDelayGroup'
6
+ import {Button} from '../button/Button'
7
+ import {Text} from '../text/Text'
8
+ import {Tooltip} from './Tooltip'
9
+ import {TooltipDelayGroupProvider} from './tooltipDelayGroup/TooltipDelayGroupProvider'
10
10
 
11
11
  // Fake timers
12
12
  beforeEach(() => {
@@ -19,6 +19,7 @@ import {
19
19
  type ReactElement,
20
20
  type ReactNode,
21
21
  type RefAttributes,
22
+ use,
22
23
  useCallback,
23
24
  useEffect,
24
25
  useId,
@@ -35,20 +36,22 @@ import {useDelayedState} from '../../hooks/useDelayedState'
35
36
  import {usePrefersReducedMotion} from '../../hooks/usePrefersReducedMotion'
36
37
  import {origin} from '../../middleware/origin'
37
38
  import type {ComponentType, Delay, Placement, Props} from '../../types'
38
- import {useBoundaryElement} from '../../utils/boundaryElement/useBoundaryElement'
39
+ import {BoundaryElementContext} from '../../utils/boundaryElement/BoundaryElementContext'
39
40
  import {getElementRef} from '../../utils/getElementRef'
40
- import {Portal} from '../../utils/portal/portal'
41
- import {usePortal} from '../../utils/portal/usePortal'
42
- import {CardProvider} from '../card/cardProvider'
43
- import {useCard} from '../card/useCard'
44
- import type {LayerOwnProps} from '../layer/layer'
41
+ import {Portal} from '../../utils/portal/Portal'
42
+ import {PortalContext} from '../../utils/portal/PortalContext'
43
+ import {assertPortalContext} from '../../utils/portal/usePortal'
44
+ import {CardContext} from '../card/CardContext'
45
+ import {CardProvider} from '../card/CardProvider'
46
+ import {assertCardContext} from '../card/useCard'
47
+ import type {LayerOwnProps} from '../layer/Layer'
45
48
  import {
46
49
  DEFAULT_FALLBACK_PLACEMENTS,
47
50
  DEFAULT_TOOLTIP_DISTANCE,
48
51
  DEFAULT_TOOLTIP_PADDING,
49
52
  } from './constants'
50
- import {useTooltipDelayGroup} from './tooltipDelayGroup'
51
- import {TooltipLayer} from './tooltipLayer'
53
+ import {TooltipDelayGroupContext} from './tooltipDelayGroup/TooltipDelayGroupContext'
54
+ import {TooltipLayer} from './TooltipLayer'
52
55
 
53
56
  /** @public */
54
57
  export const DEFAULT_TOOLTIP_ELEMENT = 'div'
@@ -105,20 +108,17 @@ export type TooltipProps<E extends TooltipElementType = TooltipElementType> = Pr
105
108
  export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_ELEMENT>(
106
109
  props: TooltipProps<E>,
107
110
  ): React.JSX.Element {
108
- const boundaryElementContext = useBoundaryElement()
109
-
110
111
  const {
111
112
  animate: _animate = false,
112
113
  arrow: arrowProp = false,
113
114
  as = DEFAULT_TOOLTIP_ELEMENT,
114
- boundaryElement = boundaryElementContext?.element,
115
+ boundaryElement: _boundaryElement,
115
116
  children: childProp,
116
117
  className,
117
118
  content,
118
119
  delay,
119
120
  disabled,
120
- fallbackPlacements = props.fallbackPlacements ??
121
- DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
121
+ fallbackPlacements: _fallbackPlacements,
122
122
  padding = 2,
123
123
  placement: placementProp = 'bottom',
124
124
  portal: portalProp,
@@ -130,8 +130,10 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
130
130
  tone = 'inherit',
131
131
  ...rest
132
132
  } = props as TooltipProps<typeof DEFAULT_TOOLTIP_ELEMENT>
133
+ const boundaryElement = _boundaryElement ?? use(BoundaryElementContext)
134
+ const fallbackPlacements =
135
+ _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom']
133
136
 
134
- const card = useCard()
135
137
  const prefersReducedMotion = usePrefersReducedMotion()
136
138
  const animate = prefersReducedMotion ? false : _animate
137
139
  const ref = useRef<HTMLDivElement | null>(null)
@@ -142,48 +144,22 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
142
144
 
143
145
  useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
144
146
 
145
- const portal = usePortal()
146
- const portalElement =
147
- typeof portalProp === 'string' ? portal.elements?.[portalProp] || null : portal.element
148
-
149
- const middleware = useMemo(() => {
150
- const ret: Middleware[] = []
151
-
152
- // Flip the floating element when leaving the boundary box
153
- ret.push(
154
- flip({
155
- boundary: boundaryElement || undefined,
156
- fallbackPlacements,
157
- padding: DEFAULT_TOOLTIP_PADDING,
158
- rootBoundary,
159
- }),
160
- )
161
-
162
- // Define distance between reference and floating element
163
- ret.push(offset({mainAxis: DEFAULT_TOOLTIP_DISTANCE}))
164
-
165
- // Shift the tooltip so its sits with the boundary element
166
- ret.push(
167
- shift({
168
- boundary: boundaryElement || undefined,
169
- rootBoundary,
170
- padding: DEFAULT_TOOLTIP_PADDING,
171
- }),
172
- )
173
-
174
- // Place arrow
175
- if (arrowProp) {
176
- ret.push(arrow({element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING}))
177
- }
178
-
179
- // Determine the origin to scale from.
180
- // Must be placed after `@sanity/ui/size` and `shift` middleware.
181
- if (animate) {
182
- ret.push(origin)
183
- }
147
+ let portalElement: HTMLElement | null = null
148
+ if (portalProp) {
149
+ const portal = use(PortalContext)
150
+ assertPortalContext(portal)
151
+ portalElement =
152
+ typeof portalProp === 'string' ? portal.elements?.[portalProp] || null : portal.element
153
+ }
184
154
 
185
- return ret
186
- }, [animate, arrowProp, boundaryElement, fallbackPlacements])
155
+ const middleware = useMiddleware({
156
+ animate,
157
+ arrowProp,
158
+ arrowRef,
159
+ boundaryElement,
160
+ fallbackPlacements,
161
+ rootBoundary,
162
+ })
187
163
 
188
164
  const {floatingStyles, placement, middlewareData, refs, update} = useFloating({
189
165
  middleware,
@@ -201,7 +177,7 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
201
177
 
202
178
  const tooltipId = useId()
203
179
  const [isOpen, setIsOpen] = useDelayedState(false)
204
- const delayGroupContext = useTooltipDelayGroup()
180
+ const delayGroupContext = use(TooltipDelayGroupContext)
205
181
  const {setIsGroupActive, setOpenTooltipId} = delayGroupContext || {}
206
182
  const showTooltip = isOpen || delayGroupContext?.openTooltipId === tooltipId
207
183
 
@@ -330,6 +306,7 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
330
306
  portalElement?.offsetWidth || document.body.offsetWidth,
331
307
  ]
332
308
 
309
+ // eslint-disable-next-line react-hooks/set-state-in-effect
333
310
  setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2)
334
311
  }, [boundaryElement, portalElement])
335
312
 
@@ -411,17 +388,24 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
411
388
  </TooltipLayer>
412
389
  )
413
390
 
414
- const children =
415
- showTooltip &&
416
- (portalProp ? (
391
+ let children = showTooltip ? node : null
392
+
393
+ if (showTooltip && portalProp) {
394
+ let resolvedTone = tone as Exclude<typeof tone, 'inherit'>
395
+ if (tone === 'inherit') {
396
+ const card = use(CardContext)
397
+ assertCardContext(card)
398
+ resolvedTone = card.tone
399
+ }
400
+
401
+ children = (
417
402
  <Portal __unstable_name={typeof portalProp === 'string' ? portalProp : undefined}>
418
- <CardProvider tone={tone === 'inherit' ? card.tone : tone} scheme={scheme ?? 'light'}>
403
+ <CardProvider tone={resolvedTone} scheme={scheme ?? 'light'}>
419
404
  {node}
420
405
  </CardProvider>
421
406
  </Portal>
422
- ) : (
423
- node
424
- ))
407
+ )
408
+ }
425
409
 
426
410
  return (
427
411
  <>
@@ -434,6 +418,61 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
434
418
  )
435
419
  }
436
420
 
421
+ function useMiddleware({
422
+ animate,
423
+ arrowProp,
424
+ arrowRef,
425
+ boundaryElement,
426
+ fallbackPlacements,
427
+ rootBoundary,
428
+ }: {
429
+ animate: boolean
430
+ arrowProp: boolean
431
+ arrowRef: React.RefObject<HTMLDivElement | null>
432
+ boundaryElement: HTMLElement | null
433
+ fallbackPlacements: Placement[]
434
+ rootBoundary: RootBoundary
435
+ }) {
436
+ return useMemo(() => {
437
+ const ret: Middleware[] = []
438
+
439
+ // Flip the floating element when leaving the boundary box
440
+ ret.push(
441
+ flip({
442
+ boundary: boundaryElement || undefined,
443
+ fallbackPlacements,
444
+ padding: DEFAULT_TOOLTIP_PADDING,
445
+ rootBoundary,
446
+ }),
447
+ )
448
+
449
+ // Define distance between reference and floating element
450
+ ret.push(offset({mainAxis: DEFAULT_TOOLTIP_DISTANCE}))
451
+
452
+ // Shift the tooltip so its sits with the boundary element
453
+ ret.push(
454
+ shift({
455
+ boundary: boundaryElement || undefined,
456
+ rootBoundary,
457
+ padding: DEFAULT_TOOLTIP_PADDING,
458
+ }),
459
+ )
460
+
461
+ // Place arrow
462
+ if (arrowProp) {
463
+ ret.push(arrow({element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING}))
464
+ }
465
+
466
+ // Determine the origin to scale from.
467
+ // Must be placed after `@sanity/ui/size` and `shift` middleware.
468
+ if (animate) {
469
+ ret.push(origin)
470
+ }
471
+
472
+ return ret
473
+ }, [animate, arrowProp, arrowRef, boundaryElement, fallbackPlacements, rootBoundary])
474
+ }
475
+
437
476
  /**
438
477
  * As `useEffectEvent` should never be passed to other components or hooks, this custom hook groups together the `useEffectEvent` and the `useEffect` hook using it.
439
478
  * @see https://19.dev/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events:~:text=Never%20pass%20them%20to%20other%20components%20or%20Hooks
@@ -3,8 +3,8 @@ import {type CSSProperties, type ForwardedRef, useMemo} from 'react'
3
3
 
4
4
  import {POPOVER_MOTION_PROPS} from '../../constants'
5
5
  import type {Placement} from '../../types'
6
- import {Arrow} from '../arrow/arrow'
7
- import {Layer, type LayerOwnProps, type LayerProps} from '../layer/layer'
6
+ import {Arrow} from '../arrow/Arrow'
7
+ import {Layer, type LayerOwnProps, type LayerProps} from '../layer/Layer'
8
8
  import {
9
9
  DEFAULT_TOOLTIP_ARROW_HEIGHT,
10
10
  DEFAULT_TOOLTIP_ARROW_RADIUS,