@sanity/ui 4.0.0-beta.8 → 4.0.0-next.0

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 (393) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +21 -7
  3. package/dist/_chunks/getScopedTheme.cjs +4043 -0
  4. package/dist/_chunks/getScopedTheme.cjs.map +1 -0
  5. package/dist/_chunks/getScopedTheme.js +3803 -0
  6. package/dist/_chunks/getScopedTheme.js.map +1 -0
  7. package/dist/_chunks/portalProvider.cjs +3750 -0
  8. package/dist/_chunks/portalProvider.cjs.map +1 -0
  9. package/dist/_chunks/portalProvider.d.cts +1067 -0
  10. package/dist/_chunks/portalProvider.d.cts.map +1 -0
  11. package/dist/_chunks/portalProvider.d.ts +1067 -0
  12. package/dist/_chunks/portalProvider.d.ts.map +1 -0
  13. package/dist/_chunks/portalProvider.js +3300 -0
  14. package/dist/_chunks/portalProvider.js.map +1 -0
  15. package/dist/_chunks/refractor.cjs +18 -0
  16. package/dist/_chunks/refractor.cjs.map +1 -0
  17. package/dist/_chunks/refractor.js +20 -0
  18. package/dist/_chunks/refractor.js.map +1 -0
  19. package/dist/_chunks/rgba.d.cts +929 -0
  20. package/dist/_chunks/rgba.d.cts.map +1 -0
  21. package/dist/_chunks/rgba.d.ts +929 -0
  22. package/dist/_chunks/rgba.d.ts.map +1 -0
  23. package/dist/_visual-editing.cjs +4 -0
  24. package/dist/_visual-editing.d.cts +2 -0
  25. package/dist/_visual-editing.d.ts +2 -0
  26. package/dist/_visual-editing.js +3 -0
  27. package/dist/index.cjs +3007 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +1275 -0
  30. package/dist/index.d.cts.map +1 -0
  31. package/dist/index.d.ts +708 -1188
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2964 -4783
  34. package/dist/index.js.map +1 -1
  35. package/dist/theme.cjs +54 -0
  36. package/dist/theme.cjs.map +1 -0
  37. package/dist/theme.d.cts +278 -0
  38. package/dist/theme.d.cts.map +1 -0
  39. package/dist/theme.d.ts +278 -0
  40. package/dist/theme.d.ts.map +1 -0
  41. package/dist/theme.js +53 -0
  42. package/dist/theme.js.map +1 -0
  43. package/package.json +65 -88
  44. package/dist/_chunks-es/Syntax.js +0 -23
  45. package/dist/_chunks-es/Syntax.js.map +0 -1
  46. package/dist/index.css +0 -1
  47. package/exports/index.css +0 -1
  48. package/exports/index.ts +0 -125
  49. package/src/components/autocomplete/Autocomplete.tsx +0 -665
  50. package/src/components/autocomplete/AutocompleteOption.tsx +0 -42
  51. package/src/components/autocomplete/__workshop__/Async.tsx +0 -162
  52. package/src/components/autocomplete/__workshop__/ConstrainedHeight.tsx +0 -121
  53. package/src/components/autocomplete/__workshop__/Custom.tsx +0 -91
  54. package/src/components/autocomplete/__workshop__/Example.tsx +0 -70
  55. package/src/components/autocomplete/__workshop__/FocusAndBlur.tsx +0 -39
  56. package/src/components/autocomplete/__workshop__/Fullscreen.tsx +0 -307
  57. package/src/components/autocomplete/__workshop__/index.ts +0 -41
  58. package/src/components/autocomplete/__workshop__/mock/apiStore.ts +0 -49
  59. package/src/components/autocomplete/__workshop__/mock/countries.ts +0 -245
  60. package/src/components/autocomplete/__workshop__/types.ts +0 -4
  61. package/src/components/autocomplete/autocompleteReducer.ts +0 -47
  62. package/src/components/autocomplete/constants.ts +0 -28
  63. package/src/components/autocomplete/types.ts +0 -103
  64. package/src/components/breadcrumbs/Breadcrumbs.tsx +0 -163
  65. package/src/components/breadcrumbs/__workshop__/Example.tsx +0 -48
  66. package/src/components/breadcrumbs/__workshop__/index.ts +0 -16
  67. package/src/components/dialog/Dialog.tsx +0 -230
  68. package/src/components/dialog/DialogCard.tsx +0 -233
  69. package/src/components/dialog/DialogContext.ts +0 -21
  70. package/src/components/dialog/DialogProvider.tsx +0 -34
  71. package/src/components/dialog/__workshop__/Activate.tsx +0 -141
  72. package/src/components/dialog/__workshop__/AutoFocus.tsx +0 -29
  73. package/src/components/dialog/__workshop__/Layering.tsx +0 -41
  74. package/src/components/dialog/__workshop__/Nested.tsx +0 -71
  75. package/src/components/dialog/__workshop__/OnScroll.tsx +0 -51
  76. package/src/components/dialog/__workshop__/Panes.tsx +0 -75
  77. package/src/components/dialog/__workshop__/Position.tsx +0 -30
  78. package/src/components/dialog/__workshop__/Props.tsx +0 -93
  79. package/src/components/dialog/__workshop__/Provider.tsx +0 -11
  80. package/src/components/dialog/__workshop__/Wrapped.tsx +0 -76
  81. package/src/components/dialog/__workshop__/index.ts +0 -21
  82. package/src/components/dialog/isTargetWithinScope.ts +0 -14
  83. package/src/components/dialog/types.ts +0 -2
  84. package/src/components/dialog/useDialog.ts +0 -11
  85. package/src/components/hotkeys/Hotkeys.tsx +0 -70
  86. package/src/components/hotkeys/__workshop__/Plain.tsx +0 -9
  87. package/src/components/hotkeys/__workshop__/index.ts +0 -16
  88. package/src/components/menu/Menu.test.tsx +0 -125
  89. package/src/components/menu/Menu.tsx +0 -174
  90. package/src/components/menu/MenuButton.tsx +0 -231
  91. package/src/components/menu/MenuContext.ts +0 -19
  92. package/src/components/menu/MenuDivider.tsx +0 -32
  93. package/src/components/menu/MenuGroup.tsx +0 -240
  94. package/src/components/menu/MenuItem.tsx +0 -153
  95. package/src/components/menu/__workshop__/AsComponent.tsx +0 -45
  96. package/src/components/menu/__workshop__/AvatarMenu.tsx +0 -36
  97. package/src/components/menu/__workshop__/ClosableMenuButton.tsx +0 -47
  98. package/src/components/menu/__workshop__/ConstrainedInBoundary.tsx +0 -133
  99. package/src/components/menu/__workshop__/CustomMenuItem.tsx +0 -47
  100. package/src/components/menu/__workshop__/CustomSelectedState.tsx +0 -35
  101. package/src/components/menu/__workshop__/DataProps.tsx +0 -27
  102. package/src/components/menu/__workshop__/DisableFocusOnClose.tsx +0 -40
  103. package/src/components/menu/__workshop__/Groups.tsx +0 -164
  104. package/src/components/menu/__workshop__/MenuButton.tsx +0 -79
  105. package/src/components/menu/__workshop__/MenuGroupRight.tsx +0 -73
  106. package/src/components/menu/__workshop__/NestedMenu.tsx +0 -22
  107. package/src/components/menu/__workshop__/OnCloseMenuButton.tsx +0 -50
  108. package/src/components/menu/__workshop__/SelectedItem.tsx +0 -69
  109. package/src/components/menu/__workshop__/ShouldFocus.tsx +0 -42
  110. package/src/components/menu/__workshop__/Tones.tsx +0 -19
  111. package/src/components/menu/__workshop__/index.ts +0 -91
  112. package/src/components/menu/helpers.ts +0 -82
  113. package/src/components/menu/useMenu.ts +0 -21
  114. package/src/components/menu/useMenuController.ts +0 -245
  115. package/src/components/tab/Tab.tsx +0 -135
  116. package/src/components/tab/TabList.tsx +0 -157
  117. package/src/components/tab/TabListContext.ts +0 -10
  118. package/src/components/tab/TabPanel.tsx +0 -94
  119. package/src/components/tab/__workshop__/Example.tsx +0 -135
  120. package/src/components/tab/__workshop__/index.ts +0 -16
  121. package/src/components/tab/types.ts +0 -11
  122. package/src/components/toast/Toast.test.tsx +0 -103
  123. package/src/components/toast/Toast.tsx +0 -191
  124. package/src/components/toast/ToastContext.ts +0 -7
  125. package/src/components/toast/ToastLayer.tsx +0 -54
  126. package/src/components/toast/ToastProvider.tsx +0 -127
  127. package/src/components/toast/__workshop__/Hook.tsx +0 -71
  128. package/src/components/toast/__workshop__/Toast.tsx +0 -26
  129. package/src/components/toast/__workshop__/index.ts +0 -21
  130. package/src/components/toast/toastState.ts +0 -6
  131. package/src/components/toast/types.ts +0 -24
  132. package/src/components/toast/useToast.ts +0 -23
  133. package/src/components/tree/Tree.tsx +0 -248
  134. package/src/components/tree/TreeContext.ts +0 -10
  135. package/src/components/tree/TreeGroup.tsx +0 -46
  136. package/src/components/tree/TreeItem.tsx +0 -236
  137. package/src/components/tree/__workshop__/Basic.tsx +0 -108
  138. package/src/components/tree/__workshop__/TabFromElement.tsx +0 -84
  139. package/src/components/tree/__workshop__/basic.perf.ts +0 -19
  140. package/src/components/tree/__workshop__/index.ts +0 -23
  141. package/src/components/tree/helpers.ts +0 -105
  142. package/src/components/tree/types.ts +0 -24
  143. package/src/components/tree/useTree.ts +0 -17
  144. package/src/components/virtualList/VirtualList.tsx +0 -254
  145. package/src/components/virtualList/__workshop__/ChangingProps.tsx +0 -41
  146. package/src/components/virtualList/__workshop__/ElementScroll.tsx +0 -43
  147. package/src/components/virtualList/__workshop__/InfiniteList.tsx +0 -40
  148. package/src/components/virtualList/__workshop__/WindowScrolll.tsx +0 -23
  149. package/src/components/virtualList/__workshop__/index.ts +0 -31
  150. package/src/core/_keys.ts +0 -26
  151. package/src/core/constants.ts +0 -67
  152. package/src/core/getElementRef.ts +0 -29
  153. package/src/core/helpers/animation.ts +0 -26
  154. package/src/core/helpers/element.ts +0 -55
  155. package/src/core/helpers/focus.ts +0 -92
  156. package/src/core/helpers/props.ts +0 -51
  157. package/src/core/helpers/scroll.ts +0 -15
  158. package/src/core/lib/createGlobalScopedContext.ts +0 -39
  159. package/src/core/lib/globalScope.ts +0 -19
  160. package/src/core/lib/isArray.ts +0 -3
  161. package/src/core/lib/isRecord.ts +0 -3
  162. package/src/core/types.ts +0 -57
  163. package/src/hooks/useClickOutsideEvent.test.tsx +0 -114
  164. package/src/hooks/useClickOutsideEvent.ts +0 -66
  165. package/src/hooks/useCustomValidity.ts +0 -13
  166. package/src/hooks/useElementSize.ts +0 -19
  167. package/src/hooks/useGlobalKeyDown.ts +0 -23
  168. package/src/hooks/useMatchMedia.ts +0 -28
  169. package/src/hooks/useMediaIndex/__workshop__/Test.tsx +0 -14
  170. package/src/hooks/useMediaIndex/__workshop__/index.ts +0 -16
  171. package/src/hooks/useMediaIndex/useMediaIndex.test.tsx +0 -21
  172. package/src/hooks/useMediaIndex/useMediaIndex.ts +0 -111
  173. package/src/hooks/useMounted.ts +0 -15
  174. package/src/hooks/usePrefersDark.hydration.test.tsx +0 -56
  175. package/src/hooks/usePrefersDark.test.tsx +0 -20
  176. package/src/hooks/usePrefersDark.ts +0 -16
  177. package/src/hooks/usePrefersReducedMotion.hydration.test.tsx +0 -56
  178. package/src/hooks/usePrefersReducedMotion.test.tsx +0 -20
  179. package/src/hooks/usePrefersReducedMotion.ts +0 -16
  180. package/src/hooks/useResponsiveProp.ts +0 -14
  181. package/src/hooks/useUnique.ts +0 -54
  182. package/src/middleware/origin.ts +0 -47
  183. package/src/observers/elementSize.ts +0 -114
  184. package/src/primitives/_syntax/LazySyntax.tsx +0 -4
  185. package/src/primitives/_syntax/Syntax.tsx +0 -26
  186. package/src/primitives/avatar/Avatar.tsx +0 -145
  187. package/src/primitives/avatar/AvatarCounter.tsx +0 -69
  188. package/src/primitives/avatar/AvatarStack.tsx +0 -77
  189. package/src/primitives/avatar/__workshop__/AsButton.tsx +0 -12
  190. package/src/primitives/avatar/__workshop__/PropsStory.tsx +0 -24
  191. package/src/primitives/avatar/__workshop__/Stack.tsx +0 -27
  192. package/src/primitives/avatar/__workshop__/WithinButton.tsx +0 -51
  193. package/src/primitives/avatar/__workshop__/WithinMenuItem.tsx +0 -52
  194. package/src/primitives/avatar/__workshop__/index.ts +0 -36
  195. package/src/primitives/avatar/types.ts +0 -2
  196. package/src/primitives/badge/Badge.test.tsx +0 -16
  197. package/src/primitives/badge/Badge.tsx +0 -53
  198. package/src/primitives/badge/__workshop__/Props.tsx +0 -27
  199. package/src/primitives/badge/__workshop__/Tones.tsx +0 -15
  200. package/src/primitives/badge/__workshop__/index.ts +0 -26
  201. package/src/primitives/badge/__workshop__/within-button.tsx +0 -36
  202. package/src/primitives/box/Box.tsx +0 -73
  203. package/src/primitives/box/__workshop__/Props.tsx +0 -26
  204. package/src/primitives/box/__workshop__/Responsive.tsx +0 -19
  205. package/src/primitives/box/__workshop__/index.ts +0 -21
  206. package/src/primitives/button/Button.test.tsx +0 -30
  207. package/src/primitives/button/Button.tsx +0 -148
  208. package/src/primitives/button/__workshop__/Custom.tsx +0 -39
  209. package/src/primitives/button/__workshop__/CustomIcons.tsx +0 -37
  210. package/src/primitives/button/__workshop__/DataProps.tsx +0 -18
  211. package/src/primitives/button/__workshop__/Disabled.tsx +0 -43
  212. package/src/primitives/button/__workshop__/MixedChildren.tsx +0 -12
  213. package/src/primitives/button/__workshop__/Props.tsx +0 -60
  214. package/src/primitives/button/__workshop__/Stacked.tsx +0 -60
  215. package/src/primitives/button/__workshop__/Styled1.css.ts +0 -7
  216. package/src/primitives/button/__workshop__/Styled1.tsx +0 -11
  217. package/src/primitives/button/__workshop__/TextOverflow.tsx +0 -17
  218. package/src/primitives/button/__workshop__/UploadButton.tsx +0 -28
  219. package/src/primitives/button/__workshop__/index.ts +0 -61
  220. package/src/primitives/button/types.ts +0 -2
  221. package/src/primitives/card/Card.tsx +0 -124
  222. package/src/primitives/card/CardContext.ts +0 -10
  223. package/src/primitives/card/CardInternalContext.ts +0 -10
  224. package/src/primitives/card/CardInternalProvider.tsx +0 -15
  225. package/src/primitives/card/CardProvider.tsx +0 -16
  226. package/src/primitives/card/__workshop__/AsButton.tsx +0 -103
  227. package/src/primitives/card/__workshop__/AsComponent.tsx +0 -25
  228. package/src/primitives/card/__workshop__/Checkered.tsx +0 -25
  229. package/src/primitives/card/__workshop__/DataProps.tsx +0 -25
  230. package/src/primitives/card/__workshop__/Interactive.tsx +0 -29
  231. package/src/primitives/card/__workshop__/ListNavigation.tsx +0 -78
  232. package/src/primitives/card/__workshop__/Props.tsx +0 -59
  233. package/src/primitives/card/__workshop__/Selected.tsx +0 -62
  234. package/src/primitives/card/__workshop__/Styled.tsx +0 -11
  235. package/src/primitives/card/__workshop__/Tones.tsx +0 -26
  236. package/src/primitives/card/__workshop__/index.ts +0 -21
  237. package/src/primitives/card/types.ts +0 -21
  238. package/src/primitives/card/useCard.ts +0 -20
  239. package/src/primitives/checkbox/Checkbox.tsx +0 -80
  240. package/src/primitives/checkbox/__workshop__/Example.tsx +0 -25
  241. package/src/primitives/checkbox/__workshop__/Props.tsx +0 -35
  242. package/src/primitives/checkbox/__workshop__/ReadOnly.tsx +0 -16
  243. package/src/primitives/checkbox/__workshop__/Tones.tsx +0 -26
  244. package/src/primitives/checkbox/__workshop__/index.ts +0 -15
  245. package/src/primitives/code/Code.tsx +0 -47
  246. package/src/primitives/code/__workshop__/OpticalAlignment.tsx +0 -25
  247. package/src/primitives/code/__workshop__/Props.tsx +0 -20
  248. package/src/primitives/code/__workshop__/index.ts +0 -21
  249. package/src/primitives/container/Container.tsx +0 -43
  250. package/src/primitives/container/__workshop__/Example.tsx +0 -16
  251. package/src/primitives/container/__workshop__/index.ts +0 -16
  252. package/src/primitives/container/types.ts +0 -6
  253. package/src/primitives/flex/Flex.tsx +0 -38
  254. package/src/primitives/flex/__workshop__/Example.tsx +0 -26
  255. package/src/primitives/flex/__workshop__/Gap.tsx +0 -25
  256. package/src/primitives/flex/__workshop__/index.ts +0 -13
  257. package/src/primitives/flex/__workshop__/styles.css.ts +0 -12
  258. package/src/primitives/grid/Grid.tsx +0 -38
  259. package/src/primitives/grid/__workshop__/Responsive.tsx +0 -54
  260. package/src/primitives/grid/__workshop__/index.ts +0 -12
  261. package/src/primitives/heading/Heading.tsx +0 -68
  262. package/src/primitives/heading/__workshop__/OpticalAlignment.tsx +0 -27
  263. package/src/primitives/heading/__workshop__/Plain.tsx +0 -25
  264. package/src/primitives/heading/__workshop__/index.ts +0 -21
  265. package/src/primitives/inline/Inline.tsx +0 -37
  266. package/src/primitives/inline/__workshop__/Plain.tsx +0 -22
  267. package/src/primitives/inline/__workshop__/index.ts +0 -10
  268. package/src/primitives/kbd/Kbd.tsx +0 -36
  269. package/src/primitives/kbd/__workshop__/Plain.tsx +0 -9
  270. package/src/primitives/kbd/__workshop__/index.ts +0 -10
  271. package/src/primitives/label/Label.tsx +0 -67
  272. package/src/primitives/label/__workshop__/OpticalAlignment.tsx +0 -27
  273. package/src/primitives/label/__workshop__/Plain.tsx +0 -27
  274. package/src/primitives/label/__workshop__/index.ts +0 -21
  275. package/src/primitives/layer/Layer.test.tsx +0 -110
  276. package/src/primitives/layer/Layer.tsx +0 -35
  277. package/src/primitives/layer/LayerCard.tsx +0 -90
  278. package/src/primitives/layer/LayerContext.ts +0 -7
  279. package/src/primitives/layer/LayerProvider.tsx +0 -106
  280. package/src/primitives/layer/__workshop__/MultipleRoots.tsx +0 -49
  281. package/src/primitives/layer/__workshop__/Nested.tsx +0 -107
  282. package/src/primitives/layer/__workshop__/ResponsiveZOffset.tsx +0 -17
  283. package/src/primitives/layer/__workshop__/_debug.tsx +0 -17
  284. package/src/primitives/layer/__workshop__/index.ts +0 -26
  285. package/src/primitives/layer/getLayerContext.test.ts +0 -32
  286. package/src/primitives/layer/getLayerContext.ts +0 -21
  287. package/src/primitives/layer/types.ts +0 -9
  288. package/src/primitives/layer/useLayer.ts +0 -24
  289. package/src/primitives/popover/Popover.tsx +0 -291
  290. package/src/primitives/popover/PopoverLayer.tsx +0 -101
  291. package/src/primitives/popover/__workshop__/AlignedStory.tsx +0 -75
  292. package/src/primitives/popover/__workshop__/MarginsStory.tsx +0 -31
  293. package/src/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +0 -32
  294. package/src/primitives/popover/__workshop__/OpenOnMountStory.tsx +0 -11
  295. package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -67
  296. package/src/primitives/popover/__workshop__/RecursiveStory.tsx +0 -71
  297. package/src/primitives/popover/__workshop__/SidePanelStory.tsx +0 -95
  298. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -97
  299. package/src/primitives/popover/__workshop__/index.ts +0 -56
  300. package/src/primitives/popover/__workshop__/portal-inheritance.tsx +0 -15
  301. package/src/primitives/popover/constants.ts +0 -20
  302. package/src/primitives/popover/floating-ui/size.ts +0 -75
  303. package/src/primitives/popover/types.ts +0 -12
  304. package/src/primitives/popover/useMiddleware.ts +0 -126
  305. package/src/primitives/radio/Radio.tsx +0 -64
  306. package/src/primitives/radio/__workshop__/Example.tsx +0 -63
  307. package/src/primitives/radio/__workshop__/Plain.tsx +0 -28
  308. package/src/primitives/radio/__workshop__/index.ts +0 -13
  309. package/src/primitives/select/Select.tsx +0 -76
  310. package/src/primitives/select/__workshop__/Plain.tsx +0 -37
  311. package/src/primitives/select/__workshop__/ReadOnly.tsx +0 -23
  312. package/src/primitives/select/__workshop__/index.ts +0 -13
  313. package/src/primitives/selectable/Selectable.tsx +0 -48
  314. package/src/primitives/selectable/__workshop__/DataProps.tsx +0 -24
  315. package/src/primitives/selectable/__workshop__/as-link.tsx +0 -13
  316. package/src/primitives/selectable/__workshop__/index.ts +0 -19
  317. package/src/primitives/skeleton/CodeSkeleton.tsx +0 -49
  318. package/src/primitives/skeleton/HeadingSkeleton.tsx +0 -48
  319. package/src/primitives/skeleton/LabelSkeleton.tsx +0 -47
  320. package/src/primitives/skeleton/Skeleton.tsx +0 -70
  321. package/src/primitives/skeleton/TextSkeleton.tsx +0 -49
  322. package/src/primitives/skeleton/__workshop__/Delay.tsx +0 -69
  323. package/src/primitives/skeleton/__workshop__/Skeleton.tsx +0 -63
  324. package/src/primitives/skeleton/__workshop__/index.ts +0 -13
  325. package/src/primitives/spinner/Spinner.tsx +0 -45
  326. package/src/primitives/spinner/SpinnerAnimatedIcon.tsx +0 -14
  327. package/src/primitives/spinner/__workshop__/Props.tsx +0 -13
  328. package/src/primitives/spinner/__workshop__/index.ts +0 -16
  329. package/src/primitives/srOnly/SrOnly.tsx +0 -33
  330. package/src/primitives/stack/Stack.tsx +0 -38
  331. package/src/primitives/stack/__workshop__/Plain.tsx +0 -30
  332. package/src/primitives/stack/__workshop__/index.ts +0 -16
  333. package/src/primitives/switch/Switch.tsx +0 -76
  334. package/src/primitives/switch/__workshop__/Example.tsx +0 -25
  335. package/src/primitives/switch/__workshop__/Props.tsx +0 -23
  336. package/src/primitives/switch/__workshop__/index.ts +0 -13
  337. package/src/primitives/text/InlineCode.tsx +0 -25
  338. package/src/primitives/text/Text.tsx +0 -68
  339. package/src/primitives/text/__workshop__/Example.tsx +0 -26
  340. package/src/primitives/text/__workshop__/OpticalAlignment.tsx +0 -27
  341. package/src/primitives/text/__workshop__/index.ts +0 -26
  342. package/src/primitives/text/__workshop__/inline-code.tsx +0 -13
  343. package/src/primitives/textArea/TextArea.tsx +0 -97
  344. package/src/primitives/textArea/__workshop__/Plain.tsx +0 -46
  345. package/src/primitives/textArea/__workshop__/index.ts +0 -16
  346. package/src/primitives/textInput/TextInput.tsx +0 -279
  347. package/src/primitives/textInput/__workshop__/ClearButton.tsx +0 -32
  348. package/src/primitives/textInput/__workshop__/CustomValidity.tsx +0 -17
  349. package/src/primitives/textInput/__workshop__/Plain.tsx +0 -102
  350. package/src/primitives/textInput/__workshop__/ReadOnly.tsx +0 -14
  351. package/src/primitives/textInput/__workshop__/States.tsx +0 -53
  352. package/src/primitives/textInput/__workshop__/Tones.tsx +0 -40
  353. package/src/primitives/textInput/__workshop__/Typed.tsx +0 -23
  354. package/src/primitives/textInput/__workshop__/index.ts +0 -46
  355. package/src/primitives/tooltip/Tooltip.test.tsx +0 -496
  356. package/src/primitives/tooltip/Tooltip.tsx +0 -546
  357. package/src/primitives/tooltip/TooltipLayer.tsx +0 -72
  358. package/src/primitives/tooltip/__workshop__/CustomPortal.tsx +0 -102
  359. package/src/primitives/tooltip/__workshop__/OverflowingBoundary.tsx +0 -74
  360. package/src/primitives/tooltip/__workshop__/Props.tsx +0 -107
  361. package/src/primitives/tooltip/__workshop__/ResizableBoundary.tsx +0 -91
  362. package/src/primitives/tooltip/__workshop__/index.ts +0 -31
  363. package/src/primitives/tooltip/constants.ts +0 -24
  364. package/src/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupContext.tsx +0 -13
  365. package/src/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupProvider.tsx +0 -96
  366. package/src/primitives/tooltip/tooltipDelayGroup/types.ts +0 -7
  367. package/src/primitives/tooltip/tooltipDelayGroup/useTooltipDelayGroup.ts +0 -13
  368. package/src/root/Root.tsx +0 -93
  369. package/src/root/RootProvider.tsx +0 -37
  370. package/src/root/__workshop__/Boundary.tsx +0 -43
  371. package/src/root/__workshop__/index.ts +0 -24
  372. package/src/root/__workshop__/primitives.tsx +0 -49
  373. package/src/root/__workshop__/tone-inheritance.tsx +0 -65
  374. package/src/utils/ErrorBoundary.tsx +0 -50
  375. package/src/utils/boundaryElement/BoundaryElementContext.ts +0 -7
  376. package/src/utils/boundaryElement/BoundaryElementProvider.tsx +0 -16
  377. package/src/utils/boundaryElement/__workshop__/Plain.tsx +0 -49
  378. package/src/utils/boundaryElement/__workshop__/index.ts +0 -16
  379. package/src/utils/boundaryElement/types.ts +0 -2
  380. package/src/utils/boundaryElement/useBoundaryElement.ts +0 -12
  381. package/src/utils/elementQuery/ElementQuery.tsx +0 -75
  382. package/src/utils/elementQuery/__workshop__/CustomMedia.tsx +0 -19
  383. package/src/utils/elementQuery/__workshop__/index.ts +0 -16
  384. package/src/utils/elementQuery/__workshop__/styles.css.ts +0 -31
  385. package/src/utils/elementQuery/helpers.ts +0 -27
  386. package/src/utils/portal/Portal.test.tsx +0 -105
  387. package/src/utils/portal/Portal.tsx +0 -42
  388. package/src/utils/portal/PortalContext.ts +0 -37
  389. package/src/utils/portal/PortalProvider.tsx +0 -38
  390. package/src/utils/portal/__workshop__/Named.tsx +0 -69
  391. package/src/utils/portal/__workshop__/index.ts +0 -16
  392. package/src/utils/portal/types.ts +0 -7
  393. package/src/utils/portal/usePortal.ts +0 -30
@@ -1,665 +0,0 @@
1
- import {ChevronDownIcon} from '@sanity/icons'
2
- import type {ResponsiveProp} from '@sanity/ui-css'
3
- import type {Radius, Space} from '@sanity/ui-tokens'
4
- import {
5
- type ChangeEvent,
6
- cloneElement,
7
- type ElementType,
8
- type FocusEvent,
9
- type ForwardedRef,
10
- type KeyboardEvent,
11
- type MouseEvent,
12
- type ReactNode,
13
- useEffect,
14
- useImperativeHandle,
15
- useReducer,
16
- useRef,
17
- useState,
18
- } from 'react'
19
-
20
- import {EMPTY_ARRAY, EMPTY_RECORD} from '../../core/constants'
21
- import {_raf} from '../../core/helpers/animation'
22
- import {_hasFocus, focusFirstDescendant} from '../../core/helpers/focus'
23
- import {_getResponsiveProp} from '../../core/helpers/props'
24
- import type {ComponentType, Props} from '../../core/types'
25
- import {Box, type BoxOwnProps} from '../../primitives/box/Box'
26
- import {Button} from '../../primitives/button/Button'
27
- import {Popover, type PopoverProps} from '../../primitives/popover/Popover'
28
- import {Selectable} from '../../primitives/selectable/Selectable'
29
- import {SpinnerAnimatedIcon} from '../../primitives/spinner/SpinnerAnimatedIcon'
30
- import {Stack} from '../../primitives/stack/Stack'
31
- import {Text} from '../../primitives/text/Text'
32
- import {TextInput, type TextInputOwnProps} from '../../primitives/textInput/TextInput'
33
- import {AutocompleteOption} from './AutocompleteOption'
34
- import {autocompleteReducer} from './autocompleteReducer'
35
- import {
36
- AUTOCOMPLETE_LISTBOX_IGNORE_KEYS,
37
- AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS,
38
- AUTOCOMPLETE_POPOVER_PLACEMENT,
39
- } from './constants'
40
- import type {AutocompleteOpenButtonProps, BaseAutocompleteOption} from './types'
41
-
42
- /** @public */
43
- export const DEFAULT_AUTOCOMPLETE_ELEMENT = 'input'
44
-
45
- /** @public */
46
- export type AutocompleteOwnProps<Option extends BaseAutocompleteOption = BaseAutocompleteOption> =
47
- TextInputOwnProps & {
48
- border?: boolean
49
- customValidity?: string
50
- filterOption?: (query: string, option: Option) => boolean
51
- icon?: ElementType | ReactNode
52
- /** @beta */
53
- listBox?: BoxOwnProps
54
- loading?: boolean
55
- onChange?: (value: string) => void
56
- onQueryChange?: (query: string | null) => void
57
- onSelect?: (value: string) => void
58
- /** @beta */
59
- openButton?: boolean | AutocompleteOpenButtonProps
60
- /** @beta */
61
- openOnFocus?: boolean
62
- /** The options to render. */
63
- options?: Option[]
64
- padding?: ResponsiveProp<Space>
65
- popover?: Omit<PopoverProps, 'content' | 'onMouseEnter' | 'onMouseLeave' | 'open'>
66
- prefix?: ReactNode
67
- radius?: Radius | Radius[]
68
- /** @beta */
69
- relatedElements?: HTMLElement[]
70
- /** The callback function for rendering each option. */
71
- renderOption?: (option: Option) => React.JSX.Element
72
- /** @beta */
73
- renderPopover?: (
74
- props: {
75
- content: React.JSX.Element | null
76
- hidden: boolean
77
- inputElement: HTMLInputElement | null
78
- onMouseEnter: () => void
79
- onMouseLeave: () => void
80
- },
81
- ref: ForwardedRef<HTMLDivElement>,
82
- ) => ReactNode
83
- renderValue?: (value: string, option?: Option) => string
84
- suffix?: ReactNode
85
- value?: string
86
- }
87
-
88
- /** @public */
89
- export type AutocompleteElementType = 'input' | ComponentType
90
-
91
- /** @public */
92
- export type AutocompleteProps<
93
- E extends AutocompleteElementType = AutocompleteElementType,
94
- Option extends BaseAutocompleteOption = BaseAutocompleteOption,
95
- > = Props<AutocompleteOwnProps<Option>, E>
96
-
97
- const DEFAULT_RENDER_VALUE = (value: string, option?: BaseAutocompleteOption) =>
98
- option ? option.value : value
99
-
100
- const DEFAULT_FILTER_OPTION = (query: string, option: BaseAutocompleteOption) =>
101
- option.value.toLowerCase().indexOf(query.toLowerCase()) > -1
102
-
103
- /**
104
- * The Autocomplete component is typically used for search components.
105
- * It consists of a text input for writing a query, and properties for rendering suggestions.
106
- *
107
- * @public
108
- */
109
- export function Autocomplete<
110
- E extends AutocompleteElementType = typeof DEFAULT_AUTOCOMPLETE_ELEMENT,
111
- Option extends BaseAutocompleteOption = BaseAutocompleteOption,
112
- >(props: AutocompleteProps<E, Option>): React.JSX.Element {
113
- const {
114
- as = DEFAULT_AUTOCOMPLETE_ELEMENT,
115
- border,
116
- customValidity,
117
- disabled,
118
- filterOption: filterOptionProp,
119
- flex,
120
- fontSize = 2,
121
- icon,
122
- id,
123
- listBox = EMPTY_RECORD,
124
- loading,
125
- onBlur,
126
- onChange,
127
- onFocus,
128
- onQueryChange,
129
- onSelect,
130
- openButton,
131
- openOnFocus,
132
- options: optionsProp,
133
- padding: paddingProp = 3,
134
- popover = EMPTY_RECORD,
135
- prefix,
136
- radius: radiusProp = 2,
137
- readOnly,
138
- ref: forwardedRef,
139
- relatedElements,
140
- renderOption: renderOptionProp,
141
- renderPopover,
142
- renderValue = DEFAULT_RENDER_VALUE,
143
- suffix,
144
- value: valueProp,
145
- ...rest
146
- } = props as AutocompleteProps<typeof DEFAULT_AUTOCOMPLETE_ELEMENT, Option>
147
-
148
- const [state, dispatch] = useReducer(autocompleteReducer, {
149
- activeValue: valueProp || null,
150
- focused: false,
151
- listFocused: false,
152
- query: null,
153
- value: valueProp || null,
154
- })
155
-
156
- const {activeValue, focused, listFocused, query, value} = state
157
-
158
- const radius = _getResponsiveProp(radiusProp)
159
-
160
- const innerRadius = _getResponsiveProp(
161
- radius.map((r): Radius => {
162
- if (r === undefined || r === 'full') return 'full'
163
- if (r === 0) return 0
164
- if (r === 1) return 1
165
- if (r === 2) return 1
166
- if (r === 3) return 2
167
- return (r - 1) as Radius
168
- }) as ResponsiveProp<Radius>,
169
- )
170
-
171
- const defaultRenderOption = ({value}: BaseAutocompleteOption) => (
172
- <Selectable as="button" padding={paddingProp} radius={innerRadius}>
173
- <Text size={fontSize} textOverflow="ellipsis">
174
- {value}
175
- </Text>
176
- </Selectable>
177
- )
178
-
179
- const renderOption =
180
- typeof renderOptionProp === 'function' ? renderOptionProp : defaultRenderOption
181
-
182
- const filterOption =
183
- typeof filterOptionProp === 'function' ? filterOptionProp : DEFAULT_FILTER_OPTION
184
-
185
- // Element refs
186
- const rootElementRef = useRef<HTMLDivElement | null>(null)
187
- const resultsPopoverElementRef = useRef<HTMLDivElement | null>(null)
188
- const inputElementRef = useRef<HTMLInputElement | null>(null)
189
- const listBoxElementRef = useRef<HTMLUListElement | null>(null)
190
-
191
- // Element refs that need to be accessed during render
192
- const [inputElement, setInputElement] = useState<HTMLInputElement | null>(null)
193
-
194
- // Value refs
195
- const listFocusedRef = useRef(false)
196
- const valueRef = useRef(value)
197
- const valuePropRef = useRef(valueProp)
198
- const popoverMouseWithinRef = useRef(false)
199
-
200
- // Forward inputElement state to inputElementRef
201
- useImperativeHandle<HTMLInputElement | null, HTMLInputElement | null>(
202
- inputElementRef,
203
- () => inputElement,
204
- [inputElement],
205
- )
206
- // Forward inputElement to parent
207
- useImperativeHandle<HTMLInputElement | null, HTMLInputElement | null>(
208
- forwardedRef,
209
- () => inputElement,
210
- [inputElement],
211
- )
212
-
213
- const listBoxId = `${id}-listbox`
214
- const options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY
215
- const padding = _getResponsiveProp(paddingProp)
216
- const currentOption = value !== null ? options.find((o) => o.value === value) : undefined
217
- const filteredOptions = options.filter((option) => (query ? filterOption(query, option) : true))
218
- const filteredOptionsLen = filteredOptions.length
219
- const activeItemId = activeValue ? `${id}-option-${activeValue}` : undefined
220
- const expanded = (query !== null && loading) || (focused && query !== null)
221
-
222
- const handleRootBlur = (event: FocusEvent<HTMLInputElement>) => {
223
- setTimeout(() => {
224
- // NOTE: This is a workaround for a bug that may happen in Chrome (clicking the scrollbar
225
- // closes the results in certain situations):
226
- // - Do not handle blur if the mouse is within the popover
227
- if (popoverMouseWithinRef.current) {
228
- return
229
- }
230
-
231
- const elements: HTMLElement[] = (relatedElements || []).concat(
232
- rootElementRef.current ? [rootElementRef.current] : [],
233
- resultsPopoverElementRef.current ? [resultsPopoverElementRef.current] : [],
234
- )
235
-
236
- let focusInside = false
237
-
238
- if (document.activeElement) {
239
- for (const e of elements) {
240
- if (e === document.activeElement || e.contains(document.activeElement)) {
241
- focusInside = true
242
- break
243
- }
244
- }
245
- }
246
-
247
- if (focusInside === false) {
248
- dispatch({type: 'root/blur'})
249
- popoverMouseWithinRef.current = false
250
- if (onQueryChange) onQueryChange(null)
251
- if (onBlur) onBlur(event)
252
- }
253
- }, 0)
254
- }
255
-
256
- const handleRootFocus = (event: FocusEvent<HTMLDivElement>) => {
257
- const listBoxElement = listBoxElementRef.current
258
- const focusedElement = event.target instanceof HTMLElement ? event.target : null
259
- const listFocused = listBoxElement?.contains(focusedElement) || false
260
-
261
- if (listFocused !== listFocusedRef.current) {
262
- listFocusedRef.current = listFocused
263
-
264
- dispatch({type: 'root/setListFocused', listFocused})
265
- }
266
- }
267
-
268
- const handleOptionSelect = (v: string) => {
269
- dispatch({type: 'value/change', value: v})
270
-
271
- popoverMouseWithinRef.current = false
272
-
273
- if (onSelect) onSelect(v)
274
-
275
- valueRef.current = v
276
-
277
- if (onChange) onChange(v)
278
- if (onQueryChange) onQueryChange(null)
279
-
280
- inputElementRef.current?.focus()
281
- }
282
-
283
- const handleRootKeyDown = (event: KeyboardEvent<HTMLElement>) => {
284
- if (event.key === 'ArrowDown') {
285
- event.preventDefault()
286
-
287
- if (!filteredOptionsLen) return
288
-
289
- const activeOption = filteredOptions.find((o) => o.value === activeValue)
290
- const activeIndex = activeOption ? filteredOptions.indexOf(activeOption) : -1
291
- const nextActiveOption = filteredOptions[(activeIndex + 1) % filteredOptionsLen]
292
-
293
- if (nextActiveOption) {
294
- dispatch({type: 'root/setActiveValue', value: nextActiveOption.value, listFocused: true})
295
- }
296
-
297
- return
298
- }
299
-
300
- if (event.key === 'ArrowUp') {
301
- event.preventDefault()
302
-
303
- if (!filteredOptionsLen) return
304
-
305
- const activeOption = filteredOptions.find((o) => o.value === activeValue)
306
- const activeIndex = activeOption ? filteredOptions.indexOf(activeOption) : -1
307
- const nextActiveOption =
308
- filteredOptions[
309
- activeIndex === -1
310
- ? filteredOptionsLen - 1
311
- : (filteredOptionsLen + activeIndex - 1) % filteredOptionsLen
312
- ]
313
-
314
- if (nextActiveOption) {
315
- dispatch({type: 'root/setActiveValue', value: nextActiveOption.value, listFocused: true})
316
- }
317
-
318
- return
319
- }
320
-
321
- if (event.key === 'Escape') {
322
- dispatch({type: 'root/escape'})
323
- popoverMouseWithinRef.current = false
324
- if (onQueryChange) onQueryChange(null)
325
- inputElementRef.current?.focus()
326
-
327
- return
328
- }
329
-
330
- const target = event.target as Node
331
- const listEl = listBoxElementRef.current
332
-
333
- if (
334
- (listEl === target || listEl?.contains(target)) &&
335
- !AUTOCOMPLETE_LISTBOX_IGNORE_KEYS.includes(event.key)
336
- ) {
337
- inputElementRef.current?.focus()
338
-
339
- return
340
- }
341
- }
342
-
343
- const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
344
- const nextQuery = event.currentTarget.value
345
-
346
- dispatch({type: 'input/change', query: nextQuery})
347
-
348
- if (onQueryChange) onQueryChange(nextQuery)
349
- }
350
-
351
- const dispatchOpen = () => {
352
- dispatch({
353
- type: 'root/open',
354
- query: value ? renderValue(value, currentOption) : '',
355
- })
356
- }
357
-
358
- const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
359
- if (!focused) {
360
- dispatch({type: 'input/focus'})
361
-
362
- if (onFocus) onFocus(event)
363
- if (openOnFocus) dispatchOpen()
364
- }
365
- }
366
-
367
- const handlePopoverMouseEnter = () => {
368
- popoverMouseWithinRef.current = true
369
- }
370
-
371
- const handlePopoverMouseLeave = () => {
372
- popoverMouseWithinRef.current = false
373
- }
374
-
375
- const handleClearButtonClick = () => {
376
- dispatch({type: 'root/clear'})
377
- valueRef.current = ''
378
- if (onChange) onChange('')
379
- if (onQueryChange) onQueryChange(null)
380
- inputElementRef.current?.focus()
381
- }
382
-
383
- const handleClearButtonFocus = () => {
384
- dispatch({type: 'input/focus'})
385
- }
386
-
387
- // Change the value when `value` prop changes
388
- useEffect(() => {
389
- // If `valueProp` changed
390
- if (valueProp !== valuePropRef.current) {
391
- valuePropRef.current = valueProp
392
-
393
- if (valueProp !== undefined) {
394
- dispatch({type: 'value/change', value: valueProp})
395
- valueRef.current = valueProp
396
- }
397
-
398
- return
399
- }
400
-
401
- // If `valueProp` is not equal to `value`
402
- if (valueProp !== valueRef.current) {
403
- valueRef.current = valueProp || null
404
-
405
- dispatch({type: 'value/change', value: valueProp || null})
406
- }
407
- }, [valueProp])
408
-
409
- // Reset active item when closing
410
- useEffect(() => {
411
- if (!focused && valueRef.current) {
412
- dispatch({type: 'root/setActiveValue', value: valueRef.current})
413
- }
414
- }, [focused])
415
-
416
- // Focus the selected item
417
- useEffect(() => {
418
- const listElement = listBoxElementRef.current
419
-
420
- if (!listElement) return
421
-
422
- const activeOption = filteredOptions.find((o) => o.value === activeValue)
423
-
424
- if (activeOption) {
425
- const activeIndex = filteredOptions.indexOf(activeOption)
426
- const activeItemElement = listElement.childNodes[activeIndex] as HTMLLIElement | undefined
427
-
428
- if (activeItemElement) {
429
- if (_hasFocus(activeItemElement)) {
430
- // already focused
431
- return
432
- }
433
-
434
- focusFirstDescendant(activeItemElement)
435
- }
436
- }
437
- }, [activeValue, filteredOptions])
438
-
439
- const clearButton = (() => {
440
- if (!loading && !disabled && value) {
441
- return {
442
- 'aria-label': 'Clear',
443
- 'onFocus': handleClearButtonFocus,
444
- }
445
- }
446
-
447
- return undefined
448
- })()
449
-
450
- const openButtonBoxPadding = padding.map((p) => {
451
- if (p === undefined) return 0
452
- if (p === 0) return 0
453
- if (p === 1) return 1
454
- if (p === 2) return 1
455
-
456
- return p - 2
457
- }) as ResponsiveProp<Space>
458
-
459
- const openButtonPadding = padding.map((v) =>
460
- v === undefined ? undefined : (Math.max(v - 1, 0) as Space),
461
- ) as ResponsiveProp<Space>
462
-
463
- const openButtonProps: AutocompleteOpenButtonProps =
464
- typeof openButton === 'object' ? openButton : EMPTY_RECORD
465
-
466
- const handleOpenClick = (event: MouseEvent<HTMLButtonElement>) => {
467
- dispatchOpen()
468
-
469
- if (openButtonProps['onClick']) openButtonProps['onClick'](event)
470
-
471
- _raf(() => inputElementRef.current?.focus())
472
- }
473
-
474
- const openButtonNode = (() => {
475
- if (disabled) return undefined
476
- if (readOnly) return undefined
477
- if (!openButton) return undefined
478
-
479
- return (
480
- <Box aria-hidden={expanded} padding={openButtonBoxPadding}>
481
- <Button
482
- aria-label="Open"
483
- fontSize={fontSize}
484
- icon={ChevronDownIcon}
485
- mode="bleed"
486
- padding={openButtonPadding}
487
- radius={innerRadius}
488
- selected={expanded}
489
- {...openButtonProps}
490
- onClick={handleOpenClick}
491
- />
492
- </Box>
493
- )
494
- })()
495
-
496
- const inputValue = (() => {
497
- if (query === null) {
498
- if (value !== null) {
499
- return renderValue(value, currentOption)
500
- }
501
-
502
- return ''
503
- }
504
-
505
- return query
506
- })()
507
-
508
- const handleListBoxKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
509
- // If the focus is currently in the list, move focus to the input element
510
- if (event.key === 'Tab') {
511
- if (listFocused) {
512
- inputElementRef.current?.focus()
513
- event.preventDefault()
514
- }
515
- }
516
- }
517
-
518
- const content = (() => {
519
- if (filteredOptions.length === 0) return null
520
-
521
- return (
522
- <Box data-ui="AutoComplete__results" onKeyDown={handleListBoxKeyDown} {...listBox}>
523
- <Stack
524
- ref={listBoxElementRef}
525
- aria-multiselectable={false}
526
- as="ul"
527
- data-ui="AutoComplete__resultsList"
528
- gap={1}
529
- id={listBoxId}
530
- padding={1}
531
- role="listbox"
532
- >
533
- {filteredOptions.map((option) => {
534
- const active =
535
- activeValue !== null ? option.value === activeValue : currentOption === option
536
-
537
- return (
538
- <AutocompleteOption
539
- key={option.value}
540
- id={`${id}-option-${option.value}`}
541
- selected={active}
542
- value={option.value}
543
- onSelect={handleOptionSelect}
544
- >
545
- {cloneElement(renderOption(option), {
546
- disabled: loading,
547
- selected: active,
548
- tabIndex: listFocused && active ? 0 : -1,
549
- })}
550
- </AutocompleteOption>
551
- )
552
- })}
553
- </Stack>
554
- </Box>
555
- )
556
- })()
557
-
558
- const results = (() => {
559
- if (renderPopover) {
560
- return (
561
- <RenderPopover
562
- content={content}
563
- hidden={!expanded}
564
- inputElement={inputElement}
565
- renderPopover={renderPopover}
566
- resultsPopoverElementRef={resultsPopoverElementRef}
567
- onMouseEnter={handlePopoverMouseEnter}
568
- onMouseLeave={handlePopoverMouseLeave}
569
- />
570
- )
571
- }
572
-
573
- if (filteredOptionsLen === 0) {
574
- return null
575
- }
576
-
577
- return (
578
- <Popover
579
- ref={resultsPopoverElementRef}
580
- constrainSize
581
- content={content}
582
- fallbackPlacements={AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS}
583
- matchReferenceWidth
584
- open={expanded}
585
- overflow="auto"
586
- placement={AUTOCOMPLETE_POPOVER_PLACEMENT}
587
- portal
588
- radius={radius}
589
- referenceElement={inputElement}
590
- onMouseEnter={handlePopoverMouseEnter}
591
- onMouseLeave={handlePopoverMouseLeave}
592
- {...popover}
593
- />
594
- )
595
- })()
596
-
597
- return (
598
- <Box
599
- ref={rootElementRef}
600
- data-ui="Autocomplete"
601
- flex={flex}
602
- onBlur={handleRootBlur}
603
- onFocus={handleRootFocus}
604
- onKeyDown={handleRootKeyDown}
605
- >
606
- <TextInput
607
- {...rest}
608
- ref={setInputElement}
609
- aria-activedescendant={activeItemId}
610
- aria-autocomplete="list"
611
- aria-expanded={expanded}
612
- aria-owns={listBoxId}
613
- as={as}
614
- autoCapitalize="off"
615
- autoComplete="off"
616
- autoCorrect="off"
617
- border={border}
618
- clearButton={clearButton}
619
- customValidity={customValidity}
620
- disabled={disabled}
621
- fontSize={fontSize}
622
- icon={icon}
623
- iconRight={loading && SpinnerAnimatedIcon}
624
- id={id}
625
- inputMode="search"
626
- padding={padding}
627
- prefix={prefix}
628
- radius={radius}
629
- readOnly={readOnly}
630
- role="combobox"
631
- spellCheck={false}
632
- suffix={suffix || openButtonNode}
633
- value={inputValue}
634
- onChange={handleInputChange}
635
- onClear={handleClearButtonClick}
636
- onFocus={handleInputFocus}
637
- />
638
- {results}
639
- </Box>
640
- )
641
- }
642
-
643
- function RenderPopover({
644
- renderPopover,
645
- content,
646
- hidden,
647
- inputElement,
648
- onMouseEnter,
649
- onMouseLeave,
650
- resultsPopoverElementRef,
651
- }: {
652
- renderPopover: Exclude<AutocompleteProps['renderPopover'], undefined>
653
- resultsPopoverElementRef: Parameters<Exclude<AutocompleteProps['renderPopover'], undefined>>[1]
654
- } & Parameters<Exclude<AutocompleteProps['renderPopover'], undefined>>[0]) {
655
- return renderPopover(
656
- {
657
- content,
658
- hidden,
659
- inputElement,
660
- onMouseEnter,
661
- onMouseLeave,
662
- },
663
- resultsPopoverElementRef,
664
- )
665
- }
@@ -1,42 +0,0 @@
1
- import {type KeyboardEvent, type ReactNode} from 'react'
2
-
3
- import {_isEnterToClickElement} from '../../core/helpers/element'
4
-
5
- export interface AutocompleteOptionProps {
6
- children: ReactNode
7
- id: string
8
- onSelect: (v: string) => void
9
- selected: boolean
10
- value: string
11
- }
12
-
13
- export function AutocompleteOption(props: AutocompleteOptionProps): React.JSX.Element {
14
- const {children, id, onSelect, selected, value} = props
15
-
16
- const handleClick = () => {
17
- // Calling the `onSelect` in a timeout is a fix to
18
- // allow the `click` event to propagate in some cases
19
- setTimeout(() => {
20
- onSelect(value)
21
- }, 0)
22
- }
23
-
24
- const handleKeyDown = (event: KeyboardEvent<HTMLLIElement>) => {
25
- if (event.key === 'Enter' && !_isEnterToClickElement(event.currentTarget)) {
26
- handleClick()
27
- }
28
- }
29
-
30
- return (
31
- <li
32
- aria-selected={selected}
33
- data-ui="AutocompleteOption"
34
- id={id}
35
- role="option"
36
- onClick={handleClick}
37
- onKeyDown={handleKeyDown}
38
- >
39
- {children}
40
- </li>
41
- )
42
- }