@sanity/ui 3.0.0-static.10 → 3.0.0-static.12

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 (275) hide show
  1. package/dist/_chunks-cjs/_visual-editing.js +1300 -1269
  2. package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
  3. package/dist/_chunks-cjs/buildCommand.js +28 -10
  4. package/dist/_chunks-cjs/buildCommand.js.map +1 -1
  5. package/dist/_chunks-es/_visual-editing.mjs +1298 -1263
  6. package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
  7. package/dist/_visual-editing.d.mts +516 -360
  8. package/dist/_visual-editing.d.ts +516 -360
  9. package/dist/cli.js +1 -1
  10. package/dist/css.d.mts +258 -75
  11. package/dist/css.d.ts +258 -75
  12. package/dist/css.js +746 -752
  13. package/dist/css.js.map +1 -1
  14. package/dist/css.mjs +748 -754
  15. package/dist/css.mjs.map +1 -1
  16. package/dist/index.d.mts +1342 -871
  17. package/dist/index.d.ts +1342 -871
  18. package/dist/index.js +433 -325
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +429 -321
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/sanity-palette.css +105 -1
  23. package/dist/sanity-palette.min.css +1 -0
  24. package/dist/sanity-theme.css +4571 -1
  25. package/dist/sanity-theme.min.css +1 -0
  26. package/dist/system.css +22053 -21710
  27. package/dist/system.min.css +1 -0
  28. package/dist/theme.d.mts +51 -106
  29. package/dist/theme.d.ts +51 -106
  30. package/dist/theme.js +19 -20
  31. package/dist/theme.js.map +1 -1
  32. package/dist/theme.mjs +19 -20
  33. package/dist/theme.mjs.map +1 -1
  34. package/package.json +10 -5
  35. package/src/cli/buildCommand.ts +46 -19
  36. package/src/css/_comp.ts +2 -2
  37. package/src/css/{compile/compileStyle.ts → _compileStyle.ts} +7 -7
  38. package/src/css/_resp.ts +0 -1
  39. package/src/css/{system.style.ts → _system.style.ts} +3 -2
  40. package/src/css/aspects/display/display.ts +1 -0
  41. package/src/css/aspects/display/types.ts +2 -3
  42. package/src/css/aspects/flex/types.ts +4 -12
  43. package/src/css/aspects/flexItem/types.ts +1 -3
  44. package/src/css/aspects/font/font.style.ts +7 -66
  45. package/src/css/aspects/font/types.ts +1 -3
  46. package/src/css/aspects/grid/grid.ts +1 -0
  47. package/src/css/aspects/grid/types.ts +5 -9
  48. package/src/css/aspects/gridItem/gridItem.ts +1 -1
  49. package/src/css/aspects/gridItem/types.ts +7 -18
  50. package/src/css/aspects/height/height.ts +3 -4
  51. package/src/css/aspects/inset/inset.ts +1 -0
  52. package/src/css/aspects/margin/margin.ts +1 -0
  53. package/src/css/aspects/margin/types.ts +1 -0
  54. package/src/css/aspects/maxWidth/maxWidth.ts +1 -0
  55. package/src/css/aspects/maxWidth/types.ts +1 -0
  56. package/src/css/aspects/minWidth/minWidth.ts +1 -0
  57. package/src/css/aspects/minWidth/types.ts +2 -0
  58. package/src/css/aspects/overflow/overflow.ts +1 -0
  59. package/src/css/aspects/padding/padding.ts +1 -0
  60. package/src/css/aspects/pointerEvents/pointerEvents.ts +1 -0
  61. package/src/css/aspects/position/position.ts +1 -0
  62. package/src/css/aspects/shadow/shadow.style.ts +16 -41
  63. package/src/css/aspects/shadow/shadow.ts +1 -0
  64. package/src/css/aspects/textOverflow/textOverflow.ts +1 -0
  65. package/src/css/aspects/textOverflow/types.ts +1 -0
  66. package/src/css/aspects/width/types.ts +2 -0
  67. package/src/css/aspects/width/width.ts +1 -0
  68. package/src/css/compilePalette.ts +32 -0
  69. package/src/css/compileSystem.ts +7 -0
  70. package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
  71. package/src/css/compileTheme_v3.ts +434 -0
  72. package/src/css/components/breadcrumbs/breadcrumbs.ts +1 -0
  73. package/src/css/components/dialog/dialog.ts +7 -0
  74. package/src/css/components/menu/menu.ts +2 -0
  75. package/src/css/components/skeleton/skeleton.style.ts +8 -4
  76. package/src/css/components/skeleton/skeleton.ts +4 -0
  77. package/src/css/components/skeleton/types.ts +4 -0
  78. package/src/css/components/toast/toast.ts +5 -0
  79. package/src/css/components/tree/tree.ts +1 -0
  80. package/src/css/composeClassNames.ts +4 -2
  81. package/src/css/constants.ts +11 -0
  82. package/src/css/index.ts +4 -3
  83. package/src/css/primitives/_arrow/_arrow.style.ts +6 -8
  84. package/src/css/primitives/_arrow/_arrow.ts +7 -0
  85. package/src/css/primitives/_input/input.ts +2 -0
  86. package/src/css/primitives/_selectable/_selectable.style.ts +24 -25
  87. package/src/css/primitives/_selectable/selectable.ts +1 -2
  88. package/src/css/primitives/avatar/avatar.style.ts +5 -8
  89. package/src/css/primitives/avatar/avatar.ts +6 -0
  90. package/src/css/primitives/avatar/types.ts +1 -0
  91. package/src/css/primitives/box/types.ts +1 -3
  92. package/src/css/primitives/button/button.style.ts +48 -15
  93. package/src/css/primitives/button/button.ts +4 -21
  94. package/src/css/primitives/button/index.ts +1 -0
  95. package/src/css/primitives/button/types.ts +18 -0
  96. package/src/css/primitives/card/card.style.ts +4 -7
  97. package/src/css/primitives/card/card.ts +2 -2
  98. package/src/css/primitives/card/types.ts +2 -2
  99. package/src/css/primitives/checkbox/checkbox.ts +2 -0
  100. package/src/css/primitives/container/container.ts +1 -0
  101. package/src/css/primitives/container/types.ts +1 -0
  102. package/src/css/primitives/kbd/kbd.ts +1 -0
  103. package/src/css/primitives/label/types.ts +7 -2
  104. package/src/css/primitives/popover/popover.ts +2 -0
  105. package/src/css/primitives/radio/radio.ts +1 -0
  106. package/src/css/primitives/select/select.ts +2 -0
  107. package/src/css/primitives/spinner/spinner.ts +2 -0
  108. package/src/css/primitives/switch/switch.ts +5 -0
  109. package/src/css/primitives/text/types.ts +4 -0
  110. package/src/css/primitives/textArea/textArea.ts +1 -0
  111. package/src/css/primitives/textInput/textInput.ts +1 -0
  112. package/src/css/primitives/token/token.style.ts +37 -36
  113. package/src/css/primitives/tooltip/tooltip.ts +2 -0
  114. package/src/css/responsiveRules.ts +12 -19
  115. package/src/css/scopeClassName.ts +1 -0
  116. package/src/css/types.ts +115 -15
  117. package/src/css/util.ts +5 -0
  118. package/src/css/utils/srOnly/srOnly.ts +1 -0
  119. package/src/css/varNames.ts +230 -143
  120. package/src/css/vars.ts +53 -22
  121. package/src/theme/palette/constants.ts +2 -0
  122. package/src/theme/palette/types.ts +3 -0
  123. package/src/theme/types.ts +2 -6
  124. package/src/theme/v0/focusRing.ts +1 -3
  125. package/src/theme/v0/font.ts +6 -18
  126. package/src/theme/v0/layer.ts +1 -3
  127. package/src/theme/v0/shadow.ts +2 -6
  128. package/src/theme/v2/avatar.ts +1 -3
  129. package/src/theme/v2/color/_system.ts +1 -3
  130. package/src/theme/v2/color/avatar.ts +2 -6
  131. package/src/theme/v2/color/badge.ts +2 -6
  132. package/src/theme/v2/color/button.ts +3 -9
  133. package/src/theme/v2/color/color.ts +3 -9
  134. package/src/theme/v2/color/input.ts +3 -9
  135. package/src/theme/v2/color/kbd.ts +1 -3
  136. package/src/theme/v2/color/selectable.ts +2 -6
  137. package/src/theme/v2/color/state.ts +1 -3
  138. package/src/theme/v2/color/syntax.ts +1 -3
  139. package/src/theme/v2/input.ts +1 -3
  140. package/src/theme/v2/theme.ts +2 -6
  141. package/src/theme/v3/buildTheme_v3.ts +2 -1
  142. package/src/theme/v3/color/color.ts +6 -4
  143. package/src/theme/v3/color/renderColor.ts +4 -1
  144. package/src/theme/v3/{defaults.ts → defaultTokens.ts} +2 -2
  145. package/src/theme/v3/index.ts +1 -1
  146. package/src/theme/v3/resolveTokens.ts +18 -18
  147. package/src/ui/RootClassNames.tsx +44 -0
  148. package/src/ui/StyleTags.tsx +3 -1
  149. package/src/ui/_compat/helpers.ts +72 -0
  150. package/src/ui/_compat/index.ts +2 -6
  151. package/src/ui/_compat/studioTheme.ts +7 -0
  152. package/src/ui/_compat/theme/themeColorProvider.tsx +2 -6
  153. package/src/ui/_compat/theme/themeProvider.tsx +2 -6
  154. package/src/ui/_compat/theme/types.ts +1 -3
  155. package/src/ui/_compat/theme/useRootTheme.ts +1 -3
  156. package/src/ui/_compat/theme/useTheme.ts +2 -6
  157. package/src/ui/_compat/types.ts +0 -83
  158. package/src/ui/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
  159. package/src/ui/components/autocomplete/autocomplete.tsx +86 -114
  160. package/src/ui/components/autocomplete/autocompleteOption.tsx +2 -0
  161. package/src/ui/components/autocomplete/types.ts +3 -8
  162. package/src/ui/components/breadcrumbs/breadcrumbs.tsx +27 -21
  163. package/src/ui/components/dialog/dialog.tsx +89 -291
  164. package/src/ui/components/dialog/dialogCard.tsx +183 -0
  165. package/src/ui/components/dialog/isTargetWithinScope.ts +14 -0
  166. package/src/ui/components/hotkeys/hotkeys.tsx +33 -15
  167. package/src/ui/components/menu/__workshop__/asComponent.tsx +6 -6
  168. package/src/ui/components/menu/menu.tsx +27 -33
  169. package/src/ui/components/menu/menuButton.tsx +10 -14
  170. package/src/ui/components/menu/menuDivider.tsx +25 -13
  171. package/src/ui/components/menu/menuGroup.tsx +34 -26
  172. package/src/ui/components/menu/menuItem.tsx +51 -40
  173. package/src/ui/components/skeleton/codeSkeleton.tsx +53 -0
  174. package/src/ui/components/skeleton/headingSkeleton.tsx +52 -0
  175. package/src/ui/components/skeleton/index.ts +3 -0
  176. package/src/ui/components/skeleton/labelSkeleton.tsx +51 -0
  177. package/src/ui/components/skeleton/skeleton.tsx +39 -16
  178. package/src/ui/components/skeleton/textSkeleton.tsx +31 -110
  179. package/src/ui/components/tab/tab.tsx +23 -19
  180. package/src/ui/components/tab/tabList.tsx +34 -33
  181. package/src/ui/components/tab/tabPanel.tsx +25 -19
  182. package/src/ui/components/toast/toast.tsx +21 -16
  183. package/src/ui/components/toast/toastLayer.tsx +28 -10
  184. package/src/ui/components/toast/toastProvider.tsx +2 -6
  185. package/src/ui/components/toast/types.ts +2 -6
  186. package/src/ui/components/toast/useToast.ts +1 -3
  187. package/src/ui/components/tree/tree.tsx +194 -187
  188. package/src/ui/components/tree/treeGroup.tsx +25 -5
  189. package/src/ui/components/tree/treeItem.tsx +35 -23
  190. package/src/ui/hooks/useClickOutside.ts +2 -6
  191. package/src/ui/hooks/useClickOutsideEvent.ts +3 -9
  192. package/src/ui/index.ts +1 -0
  193. package/src/ui/primitives/_selectable/selectable.tsx +33 -20
  194. package/src/ui/primitives/avatar/avatar.tsx +28 -31
  195. package/src/ui/primitives/avatar/avatarCounter.tsx +33 -25
  196. package/src/ui/primitives/avatar/avatarStack.tsx +31 -24
  197. package/src/ui/primitives/avatar/types.ts +2 -0
  198. package/src/ui/primitives/badge/__workshop__/props.tsx +1 -9
  199. package/src/ui/primitives/badge/__workshop__/tones.tsx +1 -6
  200. package/src/ui/primitives/badge/badge.tsx +33 -32
  201. package/src/ui/primitives/badge/types.ts +2 -1
  202. package/src/ui/primitives/box/box.tsx +59 -29
  203. package/src/ui/primitives/button/__workshop__/sanityUploadButton.tsx +3 -3
  204. package/src/ui/primitives/button/__workshop__/uploadButton.tsx +2 -1
  205. package/src/ui/primitives/button/button.test.tsx +1 -15
  206. package/src/ui/primitives/button/button.tsx +63 -70
  207. package/src/ui/primitives/card/__workshop__/asComponent.tsx +3 -3
  208. package/src/ui/primitives/card/card.tsx +22 -22
  209. package/src/ui/primitives/card/cardProvider.tsx +2 -0
  210. package/src/ui/primitives/checkbox/checkbox.tsx +26 -15
  211. package/src/ui/primitives/code/code.tsx +24 -22
  212. package/src/ui/primitives/container/container.tsx +26 -15
  213. package/src/ui/primitives/flex/flex.tsx +21 -19
  214. package/src/ui/primitives/grid/grid.tsx +21 -16
  215. package/src/ui/primitives/heading/heading.tsx +42 -19
  216. package/src/ui/primitives/inline/inline.tsx +26 -23
  217. package/src/ui/primitives/kbd/kbd.tsx +25 -23
  218. package/src/ui/primitives/label/label.tsx +29 -26
  219. package/src/ui/primitives/popover/popover.tsx +293 -271
  220. package/src/ui/primitives/popover/popoverCard.tsx +122 -120
  221. package/src/ui/primitives/radio/radio.tsx +30 -14
  222. package/src/ui/primitives/select/select.tsx +24 -16
  223. package/src/ui/primitives/spinner/animatedSpinnerIcon.tsx +4 -2
  224. package/src/ui/primitives/spinner/spinner.tsx +24 -12
  225. package/src/ui/primitives/stack/stack.tsx +27 -18
  226. package/src/ui/primitives/switch/switch.tsx +31 -14
  227. package/src/ui/primitives/text/text.tsx +30 -24
  228. package/src/ui/primitives/textArea/textArea.tsx +33 -18
  229. package/src/ui/primitives/textInput/textInput.tsx +28 -40
  230. package/src/ui/primitives/tooltip/constants.ts +1 -1
  231. package/src/ui/primitives/tooltip/tooltip.tsx +85 -61
  232. package/src/ui/primitives/tooltip/tooltipCard.tsx +89 -82
  233. package/src/ui/primitives/types.ts +1 -3
  234. package/src/ui/types/avatar.ts +3 -6
  235. package/src/ui/types/badge.ts +1 -3
  236. package/src/ui/types/button.ts +1 -3
  237. package/src/ui/types/card.ts +1 -3
  238. package/src/ui/types/dialog.ts +1 -3
  239. package/src/ui/types/props.ts +20 -10
  240. package/src/ui/utils/arrow/arrow.tsx +43 -25
  241. package/src/ui/utils/boundaryElement/boundaryElementProvider.tsx +2 -6
  242. package/src/ui/utils/boundaryElement/types.ts +1 -3
  243. package/src/ui/utils/boundaryElement/useBoundaryElement.ts +1 -3
  244. package/src/ui/utils/elementQuery/elementQuery.tsx +43 -19
  245. package/src/ui/utils/errorBoundary.tsx +2 -0
  246. package/src/ui/utils/index.ts +0 -1
  247. package/src/ui/utils/layer/layer.tsx +23 -93
  248. package/src/ui/utils/layer/layerCard.tsx +92 -0
  249. package/src/ui/utils/layer/layerProvider.tsx +2 -6
  250. package/src/ui/utils/layer/useLayer.ts +1 -3
  251. package/src/ui/utils/portal/portal.ts +2 -6
  252. package/src/ui/utils/portal/portalProvider.tsx +2 -6
  253. package/src/ui/utils/portal/types.ts +1 -3
  254. package/src/ui/utils/portal/usePortal.ts +1 -3
  255. package/src/ui/utils/srOnly/srOnly.tsx +25 -20
  256. package/src/ui/utils/virtualList/virtualList.tsx +69 -50
  257. package/src/css/compile/compilePalette.ts +0 -27
  258. package/src/css/compile/compileRule.ts +0 -97
  259. package/src/css/compile/compileRules.test.ts +0 -36
  260. package/src/css/compile/compileRules.ts +0 -43
  261. package/src/css/compile/compileSystem.ts +0 -10
  262. package/src/css/compile/compileTheme_v3.ts +0 -401
  263. package/src/css/compile/types.ts +0 -6
  264. package/src/css/components/breadcrumbs/rules.ts +0 -25
  265. package/src/css/components/dialog/rules.ts +0 -78
  266. package/src/css/components/skeleton/rules.ts +0 -113
  267. package/src/css/components/toast/rules.ts +0 -18
  268. package/src/css/components/tree/rules.ts +0 -168
  269. package/src/css/primitives/_selectable/_contants.ts +0 -11
  270. package/src/css/primitives/card/_constants.ts +0 -13
  271. package/src/css/primitives/popover/rules.ts +0 -5
  272. package/src/css/primitives/spinner/rules.ts +0 -21
  273. package/src/css/primitives/token/rules.ts +0 -45
  274. package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
  275. package/src/ui/utils/conditionalWrapper/index.ts +0 -1
@@ -5,45 +5,45 @@ import {
5
5
  TextOverflowStyleProps,
6
6
  TextStyleProps,
7
7
  } from '@sanity/ui/css'
8
- import {ForwardedRef, forwardRef} from 'react'
9
8
 
10
- import {Props} from '../../types'
9
+ import {ComponentType, Props} from '../../types'
11
10
 
12
- /**
13
- * @public
14
- */
15
- export interface TextProps extends TextStyleProps, TextOverflowStyleProps {
16
- htmlFor?: string
17
- }
11
+ /** @public */
12
+ export const DEFAULT_TEXT_ELEMENT = 'div'
13
+
14
+ /** @public */
15
+ export type TextOwnProps = TextStyleProps & TextOverflowStyleProps
16
+
17
+ /** @public */
18
+ export type TextElementType = 'div' | 'label' | 'li' | 'span' | ComponentType
19
+
20
+ /** @public */
21
+ export type TextProps<E extends TextElementType = TextElementType> = Props<TextOwnProps, E>
18
22
 
19
23
  /**
20
24
  * The `Text` component is an agile, themed typographic element.
21
25
  *
22
26
  * @public
23
27
  */
24
- export const Text = forwardRef(function Text(
25
- props: Props<TextProps, 'div'>,
26
- ref: ForwardedRef<HTMLDivElement>,
27
- ) {
28
+ export function Text<E extends TextElementType = typeof DEFAULT_TEXT_ELEMENT>(props: TextProps<E>) {
28
29
  const {
29
- accent = false,
30
+ accent,
30
31
  align,
31
- as: As = 'div',
32
+ as: Element = DEFAULT_TEXT_ELEMENT,
32
33
  children,
33
34
  className,
34
35
  flex,
35
- muted = false,
36
+ muted,
36
37
  size = 2,
37
38
  textOverflow: textOverflowProp,
38
39
  weight,
39
- ...restProps
40
- } = props
40
+ ...rest
41
+ } = props as TextProps<typeof DEFAULT_TEXT_ELEMENT>
41
42
 
42
43
  return (
43
- <As
44
+ <Element
44
45
  data-ui="Text"
45
- {...restProps}
46
- ref={ref}
46
+ {...rest}
47
47
  className={composeClassNames(
48
48
  className,
49
49
  text({
@@ -56,9 +56,15 @@ export const Text = forwardRef(function Text(
56
56
  }),
57
57
  )}
58
58
  >
59
- <span className={textOverflow({textOverflow: textOverflowProp})}>{children}</span>
60
- </As>
59
+ <span
60
+ className={textOverflow({
61
+ textOverflow: textOverflowProp,
62
+ })}
63
+ >
64
+ {children}
65
+ </span>
66
+ </Element>
61
67
  )
62
- })
68
+ }
63
69
 
64
- Text.displayName = 'ForwardRef(Text)'
70
+ Text.displayName = 'Text'
@@ -3,18 +3,19 @@ import {
3
3
  _inputPresentation,
4
4
  ResponsiveProp,
5
5
  textArea,
6
- TextAreaStyleProps,
6
+ type TextAreaStyleProps,
7
7
  } from '@sanity/ui/css'
8
- import {Space, ThemeFontWeightKey} from '@sanity/ui/theme'
9
- import {ForwardedRef, forwardRef, useImperativeHandle, useRef} from 'react'
8
+ import type {Space, ThemeFontWeightKey} from '@sanity/ui/theme'
9
+ import {useImperativeHandle, useRef} from 'react'
10
10
 
11
11
  import {useCustomValidity} from '../../hooks'
12
- import {Props} from '../../types'
12
+ import type {ComponentType, Props} from '../../types'
13
13
 
14
- /**
15
- * @public
16
- */
17
- export interface TextAreaProps extends TextAreaStyleProps {
14
+ /** @public */
15
+ export const DEFAULT_TEXT_AREA_ELEMENT = 'textarea'
16
+
17
+ /** @public */
18
+ export type TextAreaOwnProps = TextAreaStyleProps & {
18
19
  /**
19
20
  * @beta
20
21
  */
@@ -25,16 +26,25 @@ export interface TextAreaProps extends TextAreaStyleProps {
25
26
  weight?: ThemeFontWeightKey
26
27
  }
27
28
 
29
+ /** @public */
30
+ export type TextAreaElementType = 'textarea' | ComponentType
31
+
32
+ /** @public */
33
+ export type TextAreaProps<E extends TextAreaElementType = TextAreaElementType> = Props<
34
+ TextAreaOwnProps,
35
+ E
36
+ >
37
+
28
38
  /**
29
39
  * A multiline text input.
30
40
  *
31
41
  * @public
32
42
  */
33
- export const TextArea = forwardRef(function TextArea(
34
- props: Props<TextAreaProps, 'textarea'>,
35
- forwardedRef: ForwardedRef<HTMLTextAreaElement>,
43
+ export function TextArea<E extends TextAreaElementType = typeof DEFAULT_TEXT_AREA_ELEMENT>(
44
+ props: TextAreaProps<E>,
36
45
  ) {
37
46
  const {
47
+ as: Element = DEFAULT_TEXT_AREA_ELEMENT,
38
48
  border = true,
39
49
  customValidity,
40
50
  disabled = false,
@@ -42,11 +52,16 @@ export const TextArea = forwardRef(function TextArea(
42
52
  gap,
43
53
  padding = 3,
44
54
  radius = 2,
55
+ ref: forwardedRef,
45
56
  space = 3,
46
- // weight,
47
- // __unstable_disableFocusRing,
48
- ...restProps
49
- } = props
57
+ // TODO: fix this
58
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
59
+ weight,
60
+ // TODO: fix this
61
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
+ __unstable_disableFocusRing,
63
+ ...rest
64
+ } = props as TextAreaProps<typeof DEFAULT_TEXT_AREA_ELEMENT>
50
65
 
51
66
  const ref = useRef<HTMLTextAreaElement | null>(null)
52
67
 
@@ -62,10 +77,10 @@ export const TextArea = forwardRef(function TextArea(
62
77
  className={textArea({border, fontSize, padding, radius, gap: gap ?? space})}
63
78
  data-ui="TextArea"
64
79
  >
65
- <textarea {...restProps} className={_inputElement()} disabled={disabled} ref={ref} />
80
+ <Element {...rest} className={_inputElement()} disabled={disabled} ref={ref} />
66
81
  <span className={_inputPresentation()} />
67
82
  </span>
68
83
  )
69
- })
84
+ }
70
85
 
71
- TextArea.displayName = 'ForwardRef(TextArea)'
86
+ TextArea.displayName = 'TextArea'
@@ -11,8 +11,6 @@ import {Space, ThemeFontWeightKey} from '@sanity/ui/theme'
11
11
  import {
12
12
  CSSProperties,
13
13
  ElementType,
14
- ForwardedRef,
15
- forwardRef,
16
14
  isValidElement,
17
15
  MouseEvent,
18
16
  ReactNode,
@@ -26,41 +24,22 @@ import {isValidElementType} from 'react-is'
26
24
  import {EMPTY_RECORD} from '../../constants'
27
25
  import {useArrayProp, useCustomValidity} from '../../hooks'
28
26
  import {isRecord} from '../../lib/isRecord'
29
- import {Props} from '../../types'
27
+ import {ComponentType, Props} from '../../types'
30
28
  import {Box} from '../box'
31
29
  import {Button, ButtonProps} from '../button'
32
30
  import {Text} from '../text'
33
31
 
34
- /**
35
- * @public
36
- */
32
+ /** @public */
33
+ export const DEFAULT_TEXT_INPUT_ELEMENT = 'input'
34
+
35
+ /** @public */
37
36
  export type TextInputClearButtonProps = Omit<
38
- Props<ButtonProps, 'button'>,
37
+ ButtonProps<'button'>,
39
38
  'as' | 'onClick' | 'onMouseDown'
40
39
  >
41
40
 
42
- /**
43
- * @public
44
- */
45
- export type TextInputType =
46
- | 'search'
47
- | 'date'
48
- | 'datetime-local'
49
- | 'email'
50
- | 'url'
51
- | 'month'
52
- | 'number'
53
- | 'password'
54
- | 'tel'
55
- | 'time'
56
- | 'text'
57
- | 'week'
58
- | 'color'
59
-
60
- /**
61
- * @public
62
- */
63
- export interface TextInputProps extends InputStyleProps {
41
+ /** @public */
42
+ export type TextInputOwnProps = InputStyleProps & {
64
43
  /**
65
44
  * @beta
66
45
  */
@@ -80,10 +59,18 @@ export interface TextInputProps extends InputStyleProps {
80
59
  /** @deprecated Use `gap` instead. */
81
60
  space?: ResponsiveProp<Space>
82
61
  suffix?: ReactNode
83
- type?: TextInputType
84
62
  weight?: ThemeFontWeightKey
85
63
  }
86
64
 
65
+ /** @public */
66
+ export type TextInputElementType = 'input' | ComponentType
67
+
68
+ /** @public */
69
+ export type TextInputProps<E extends TextInputElementType = TextInputElementType> = Props<
70
+ TextInputOwnProps,
71
+ E
72
+ >
73
+
87
74
  const CLEAR_BUTTON_BOX_STYLE: CSSProperties = {
88
75
  backgroundColor: 'transparent',
89
76
  top: 0,
@@ -96,12 +83,12 @@ const CLEAR_BUTTON_BOX_STYLE: CSSProperties = {
96
83
  *
97
84
  * @public
98
85
  */
99
- export const TextInput = forwardRef(function TextInput(
100
- props: Props<TextInputProps, 'input'>,
101
- forwardedRef: ForwardedRef<HTMLInputElement>,
86
+ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_INPUT_ELEMENT>(
87
+ props: TextInputProps<E>,
102
88
  ) {
103
89
  const {
104
90
  __unstable_disableFocusRing,
91
+ as: Element = DEFAULT_TEXT_INPUT_ELEMENT,
105
92
  border = true,
106
93
  className,
107
94
  clearButton,
@@ -115,14 +102,16 @@ export const TextInput = forwardRef(function TextInput(
115
102
  prefix,
116
103
  radius = 2,
117
104
  readOnly,
105
+ ref: forwardedRef,
118
106
  space = 3,
119
107
  suffix,
120
108
  customValidity,
121
109
  type = 'text',
122
110
  weight: _width, // eslint-disable-line @typescript-eslint/no-unused-vars
123
111
  width,
124
- ...restProps
125
- } = props
112
+ ...rest
113
+ } = props as TextInputProps<typeof DEFAULT_TEXT_INPUT_ELEMENT>
114
+
126
115
  const ref = useRef<HTMLInputElement | null>(null)
127
116
 
128
117
  const paddingArray = useArrayProp(padding)
@@ -213,9 +202,8 @@ export const TextInput = forwardRef(function TextInput(
213
202
  )}
214
203
 
215
204
  <Box as="span" flex={1} position="relative">
216
- <input
217
- // data-as="input"
218
- {...restProps}
205
+ <Element
206
+ {...rest}
219
207
  className={_inputElement()}
220
208
  disabled={disabled}
221
209
  readOnly={readOnly}
@@ -281,6 +269,6 @@ export const TextInput = forwardRef(function TextInput(
281
269
  )}
282
270
  </Box>
283
271
  )
284
- })
272
+ }
285
273
 
286
- TextInput.displayName = 'ForwardRef(TextInput)'
274
+ TextInput.displayName = 'TextInput'
@@ -1,4 +1,4 @@
1
- import {Placement} from '@floating-ui/react-dom'
1
+ import {Placement} from '../../types'
2
2
 
3
3
  export const DEFAULT_TOOLTIP_ARROW_WIDTH = 15
4
4
  export const DEFAULT_TOOLTIP_ARROW_HEIGHT = 6
@@ -13,10 +13,12 @@ import type {ThemeColorCardToneKey, ThemeColorSchemeKey} from '@sanity/ui/theme'
13
13
  import {AnimatePresence} from 'framer-motion'
14
14
  import {
15
15
  cloneElement,
16
- ForwardedRef,
17
- forwardRef,
18
- ReactElement,
19
- ReactNode,
16
+ type FocusEvent,
17
+ HTMLAttributes,
18
+ type MouseEvent as ReactMouseEvent,
19
+ type ReactElement,
20
+ type ReactNode,
21
+ RefAttributes,
20
22
  useCallback,
21
23
  useEffect,
22
24
  useId,
@@ -32,10 +34,11 @@ import {Z_OFFSETS} from '../../constants'
32
34
  import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
33
35
  import {useDelayedState} from '../../hooks/useDelayedState'
34
36
  import {origin} from '../../middleware/origin'
35
- import type {Placement, Props} from '../../types'
36
- import {Layer, type LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
37
+ import type {ComponentType, Placement, Props} from '../../types'
38
+ import {Layer, type LayerOwnProps, Portal, useBoundaryElement, usePortal} from '../../utils'
37
39
  import {getElementRef} from '../../utils/getElementRef'
38
- import type {Delay} from '../types'
40
+ import {CardProvider, useCard} from '../card'
41
+ import {Delay} from '../types'
39
42
  import {
40
43
  DEFAULT_FALLBACK_PLACEMENTS,
41
44
  DEFAULT_TOOLTIP_DISTANCE,
@@ -44,56 +47,69 @@ import {
44
47
  import {TooltipCard} from './tooltipCard'
45
48
  import {useTooltipDelayGroup} from './tooltipDelayGroup'
46
49
 
47
- /**
48
- * @public
49
- */
50
- export interface TooltipProps extends Omit<LayerProps, 'as'>, RadiusStyleProps, ShadowStyleProps {
51
- /** @deprecated Use `fallbackPlacements` instead. */
52
- allowedAutoPlacements?: Placement[]
53
- /**
54
- * Whether the tooltip should animate in and out.
55
- *
56
- * @beta
57
- * @defaultValue false
58
- */
59
- animate?: boolean
60
- arrow?: boolean
61
- boundaryElement?: HTMLElement | null
62
- children?: ReactElement<Props>
63
- content?: ReactNode
64
- /**
65
- * Adds a delay to open or close the tooltip.
66
- *
67
- * If only a `number` is passed, it will be used for both opening and closing.
68
- *
69
- * If an object `{open: number; close:number}` is passed, it can be used to set different delays for each action.
70
- *
71
- * @public
72
- * @defaultValue 0
73
- */
74
- delay?: Delay
75
- disabled?: boolean
76
- fallbackPlacements?: Placement[]
77
- placement?: Placement
78
- /** Whether or not to render the tooltip in a portal element. */
79
- portal?: boolean | string
80
- scheme?: ThemeColorSchemeKey
81
- tone?: ThemeColorCardToneKey
82
- }
50
+ /** @public */
51
+ export const DEFAULT_TOOLTIP_ELEMENT = 'div'
52
+
53
+ /** @public */
54
+ export type TooltipOwnProps = LayerOwnProps &
55
+ RadiusStyleProps &
56
+ ShadowStyleProps & {
57
+ /** @deprecated Use `fallbackPlacements` instead. */
58
+ allowedAutoPlacements?: Placement[]
59
+ /**
60
+ * Whether the tooltip should animate in and out.
61
+ *
62
+ * @beta
63
+ * @defaultValue false
64
+ */
65
+ animate?: boolean
66
+ arrow?: boolean
67
+ boundaryElement?: HTMLElement | null
68
+ children?: ReactElement<HTMLAttributes<HTMLElement> & RefAttributes<HTMLElement>>
69
+ content?: ReactNode
70
+ /**
71
+ * Adds a delay to open or close the tooltip.
72
+ *
73
+ * If only a `number` is passed, it will be used for both opening and closing.
74
+ *
75
+ * If an object `{open: number; close:number}` is passed, it can be used to set different delays for each action.
76
+ *
77
+ * @public
78
+ * @defaultValue 0
79
+ */
80
+ delay?: Delay
81
+ disabled?: boolean
82
+ fallbackPlacements?: Placement[]
83
+ placement?: Placement
84
+ /** Whether or not to render the tooltip in a portal element. */
85
+ portal?: boolean | string
86
+ scheme?: ThemeColorSchemeKey
87
+ tone?: ThemeColorCardToneKey
88
+ }
89
+
90
+ /** @public */
91
+ export type TooltipElementType = 'div' | 'span' | ComponentType
92
+
93
+ /** @public */
94
+ export type TooltipProps<E extends TooltipElementType = TooltipElementType> = Props<
95
+ TooltipOwnProps,
96
+ E
97
+ >
83
98
 
84
99
  /**
85
100
  * Tooltips display information when hovering, focusing or tapping.
86
101
  *
87
102
  * @public
88
103
  */
89
- export const Tooltip = forwardRef(function Tooltip(
90
- props: Props<TooltipProps, 'div'>,
91
- forwardedRef: ForwardedRef<HTMLDivElement>,
104
+ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_ELEMENT>(
105
+ props: TooltipProps<E>,
92
106
  ) {
93
107
  const boundaryElementContext = useBoundaryElement()
108
+
94
109
  const {
95
110
  animate: _animate = false,
96
111
  arrow: arrowProp = false,
112
+ as = DEFAULT_TOOLTIP_ELEMENT,
97
113
  boundaryElement = boundaryElementContext?.element,
98
114
  children: childProp,
99
115
  className,
@@ -106,12 +122,15 @@ export const Tooltip = forwardRef(function Tooltip(
106
122
  placement: placementProp = 'bottom',
107
123
  portal: portalProp,
108
124
  radius = 3,
125
+ ref: forwardedRef,
109
126
  scheme,
110
127
  shadow = 2,
111
128
  zOffset = Z_OFFSETS.tooltip,
112
- tone,
113
- ...restProps
114
- } = props
129
+ tone = 'inherit',
130
+ ...rest
131
+ } = props as TooltipProps<typeof DEFAULT_TOOLTIP_ELEMENT>
132
+
133
+ const card = useCard()
115
134
  const prefersReducedMotion = usePrefersReducedMotion()
116
135
  const animate = prefersReducedMotion ? false : _animate
117
136
  const fallbackPlacements = useArrayProp(fallbackPlacementsProp)
@@ -228,42 +247,42 @@ export const Tooltip = forwardRef(function Tooltip(
228
247
  )
229
248
 
230
249
  const handleBlur = useCallback(
231
- (e: FocusEvent) => {
250
+ (e: FocusEvent<HTMLElement>) => {
232
251
  handleIsOpenChange(false)
233
252
  childProp?.props?.onBlur?.(e)
234
253
  },
235
254
  [childProp?.props, handleIsOpenChange],
236
255
  )
237
256
  const handleClick = useCallback(
238
- (e: MouseEvent) => {
257
+ (e: ReactMouseEvent<HTMLElement>) => {
239
258
  handleIsOpenChange(false, true)
240
259
  childProp?.props.onClick?.(e)
241
260
  },
242
261
  [childProp?.props, handleIsOpenChange],
243
262
  )
244
263
  const handleContextMenu = useCallback(
245
- (e: MouseEvent) => {
264
+ (e: ReactMouseEvent<HTMLElement>) => {
246
265
  handleIsOpenChange(false, true)
247
266
  childProp?.props.onContextMenu?.(e)
248
267
  },
249
268
  [childProp?.props, handleIsOpenChange],
250
269
  )
251
270
  const handleFocus = useCallback(
252
- (e: FocusEvent) => {
271
+ (e: FocusEvent<HTMLElement>) => {
253
272
  handleIsOpenChange(true)
254
273
  childProp?.props?.onFocus?.(e)
255
274
  },
256
275
  [childProp?.props, handleIsOpenChange],
257
276
  )
258
277
  const handleMouseEnter = useCallback(
259
- (e: MouseEvent) => {
278
+ (e: ReactMouseEvent<HTMLElement>) => {
260
279
  handleIsOpenChange(true)
261
280
  childProp?.props?.onMouseEnter?.(e)
262
281
  },
263
282
  [childProp?.props, handleIsOpenChange],
264
283
  )
265
284
  const handleMouseLeave = useCallback(
266
- (e: MouseEvent) => {
285
+ (e: ReactMouseEvent<HTMLElement>) => {
267
286
  handleIsOpenChange(false)
268
287
  childProp?.props?.onMouseLeave?.(e)
269
288
  },
@@ -364,7 +383,6 @@ export const Tooltip = forwardRef(function Tooltip(
364
383
  const node = (
365
384
  <Layer
366
385
  data-ui="Tooltip"
367
- // {...restProps}
368
386
  className={composeClassNames(className, tooltip())}
369
387
  ref={setFloating}
370
388
  style={{
@@ -374,12 +392,13 @@ export const Tooltip = forwardRef(function Tooltip(
374
392
  zOffset={zOffset}
375
393
  >
376
394
  <TooltipCard
377
- {...restProps}
395
+ {...rest}
378
396
  animate={animate}
379
397
  arrow={arrowProp}
380
398
  arrowRef={setArrow}
381
399
  arrowX={arrowX}
382
400
  arrowY={arrowY}
401
+ as={as}
383
402
  originX={originX}
384
403
  originY={originY}
385
404
  padding={padding}
@@ -399,7 +418,12 @@ export const Tooltip = forwardRef(function Tooltip(
399
418
  showTooltip &&
400
419
  (portalProp ? (
401
420
  <Portal __unstable_name={typeof portalProp === 'string' ? portalProp : undefined}>
402
- {node}
421
+ <CardProvider
422
+ tone={tone === 'inherit' ? (card?.tone ?? 'default') : tone}
423
+ scheme={scheme ?? 'light'}
424
+ >
425
+ {node}
426
+ </CardProvider>
403
427
  </Portal>
404
428
  ) : (
405
429
  node
@@ -414,9 +438,7 @@ export const Tooltip = forwardRef(function Tooltip(
414
438
  {child}
415
439
  </>
416
440
  )
417
- })
418
-
419
- Tooltip.displayName = 'ForwardRef(Tooltip)'
441
+ }
420
442
 
421
443
  /**
422
444
  * As `useEffectEvent` should never be passed to other components or hooks, this custom hook groups together the `useEffectEvent` and the `useEffect` hook using it.
@@ -464,3 +486,5 @@ function useCloseOnMouseLeave({
464
486
  return () => window.removeEventListener('mousemove', handleMouseMove)
465
487
  }, [isInsideGroup, showTooltip])
466
488
  }
489
+
490
+ Tooltip.displayName = 'Tooltip'