@sanity/ui 3.0.0-static.11 → 3.0.0-static.13

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 (251) hide show
  1. package/dist/_chunks-cjs/_visual-editing.js +1293 -1215
  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 +1284 -1202
  6. package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
  7. package/dist/_visual-editing.d.mts +528 -358
  8. package/dist/_visual-editing.d.ts +528 -358
  9. package/dist/cli.js +1 -1
  10. package/dist/css.d.mts +143 -73
  11. package/dist/css.d.ts +143 -73
  12. package/dist/css.js +329 -472
  13. package/dist/css.js.map +1 -1
  14. package/dist/css.mjs +330 -473
  15. package/dist/css.mjs.map +1 -1
  16. package/dist/index.d.mts +1362 -869
  17. package/dist/index.d.ts +1362 -869
  18. package/dist/index.js +383 -308
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +387 -312
  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 -21946
  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 +9 -9
  31. package/dist/theme.js.map +1 -1
  32. package/dist/theme.mjs +9 -9
  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/{system.style.ts → _system.style.ts} +3 -2
  39. package/src/css/aspects/display/display.ts +1 -0
  40. package/src/css/aspects/display/types.ts +2 -3
  41. package/src/css/aspects/flex/types.ts +4 -12
  42. package/src/css/aspects/flexItem/types.ts +1 -3
  43. package/src/css/aspects/font/types.ts +1 -3
  44. package/src/css/aspects/grid/grid.ts +1 -0
  45. package/src/css/aspects/grid/types.ts +5 -9
  46. package/src/css/aspects/gridItem/gridItem.ts +1 -1
  47. package/src/css/aspects/gridItem/types.ts +7 -18
  48. package/src/css/aspects/height/height.ts +3 -4
  49. package/src/css/aspects/inset/inset.ts +1 -0
  50. package/src/css/aspects/margin/margin.ts +1 -0
  51. package/src/css/aspects/margin/types.ts +1 -0
  52. package/src/css/aspects/maxWidth/maxWidth.ts +1 -0
  53. package/src/css/aspects/maxWidth/types.ts +1 -0
  54. package/src/css/aspects/minWidth/minWidth.ts +1 -0
  55. package/src/css/aspects/minWidth/types.ts +2 -0
  56. package/src/css/aspects/overflow/overflow.ts +1 -0
  57. package/src/css/aspects/padding/padding.ts +1 -0
  58. package/src/css/aspects/pointerEvents/pointerEvents.ts +1 -0
  59. package/src/css/aspects/position/position.ts +1 -0
  60. package/src/css/aspects/shadow/shadow.ts +1 -0
  61. package/src/css/aspects/textOverflow/textOverflow.ts +1 -0
  62. package/src/css/aspects/textOverflow/types.ts +1 -0
  63. package/src/css/aspects/width/types.ts +2 -0
  64. package/src/css/aspects/width/width.ts +1 -0
  65. package/src/css/{compile/compilePalette.ts → compilePalette.ts} +14 -10
  66. package/src/css/compileSystem.ts +7 -0
  67. package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
  68. package/src/css/{compile/compileTheme_v3.ts → compileTheme_v3.ts} +123 -104
  69. package/src/css/components/breadcrumbs/breadcrumbs.ts +1 -0
  70. package/src/css/components/dialog/dialog.ts +7 -0
  71. package/src/css/components/menu/menu.ts +2 -0
  72. package/src/css/components/skeleton/skeleton.ts +4 -0
  73. package/src/css/components/skeleton/types.ts +4 -0
  74. package/src/css/components/toast/toast.ts +5 -0
  75. package/src/css/components/tree/tree.ts +1 -0
  76. package/src/css/composeClassNames.ts +4 -2
  77. package/src/css/constants.ts +2 -0
  78. package/src/css/index.ts +3 -3
  79. package/src/css/primitives/_arrow/_arrow.ts +3 -0
  80. package/src/css/primitives/_input/input.ts +2 -0
  81. package/src/css/primitives/_selectable/_selectable.style.ts +1 -2
  82. package/src/css/primitives/_selectable/selectable.ts +1 -2
  83. package/src/css/primitives/avatar/avatar.style.ts +5 -8
  84. package/src/css/primitives/avatar/avatar.ts +6 -0
  85. package/src/css/primitives/avatar/types.ts +1 -0
  86. package/src/css/primitives/box/types.ts +1 -3
  87. package/src/css/primitives/button/button.ts +4 -21
  88. package/src/css/primitives/button/index.ts +1 -0
  89. package/src/css/primitives/button/types.ts +18 -0
  90. package/src/css/primitives/card/card.style.ts +3 -6
  91. package/src/css/primitives/card/card.ts +2 -2
  92. package/src/css/primitives/card/types.ts +2 -2
  93. package/src/css/primitives/checkbox/checkbox.ts +2 -0
  94. package/src/css/primitives/container/container.ts +1 -0
  95. package/src/css/primitives/container/types.ts +1 -0
  96. package/src/css/primitives/kbd/kbd.ts +1 -0
  97. package/src/css/primitives/label/types.ts +7 -2
  98. package/src/css/primitives/popover/popover.ts +2 -0
  99. package/src/css/primitives/radio/radio.ts +1 -0
  100. package/src/css/primitives/select/select.ts +2 -0
  101. package/src/css/primitives/spinner/spinner.ts +2 -0
  102. package/src/css/primitives/switch/switch.ts +5 -0
  103. package/src/css/primitives/text/types.ts +4 -0
  104. package/src/css/primitives/textArea/textArea.ts +1 -0
  105. package/src/css/primitives/textInput/textInput.ts +1 -0
  106. package/src/css/primitives/tooltip/tooltip.ts +2 -0
  107. package/src/css/scopeClassName.ts +1 -0
  108. package/src/css/types.ts +9 -12
  109. package/src/css/util.ts +5 -0
  110. package/src/css/utils/srOnly/srOnly.ts +3 -1
  111. package/src/css/varNames.ts +131 -141
  112. package/src/css/vars.ts +1 -6
  113. package/src/theme/palette/constants.ts +2 -0
  114. package/src/theme/palette/types.ts +3 -0
  115. package/src/theme/types.ts +2 -6
  116. package/src/theme/v0/focusRing.ts +1 -3
  117. package/src/theme/v0/font.ts +6 -18
  118. package/src/theme/v0/layer.ts +1 -3
  119. package/src/theme/v0/shadow.ts +2 -6
  120. package/src/theme/v2/avatar.ts +1 -3
  121. package/src/theme/v2/color/_system.ts +1 -3
  122. package/src/theme/v2/color/avatar.ts +2 -6
  123. package/src/theme/v2/color/badge.ts +2 -6
  124. package/src/theme/v2/color/button.ts +3 -9
  125. package/src/theme/v2/color/color.ts +3 -9
  126. package/src/theme/v2/color/input.ts +3 -9
  127. package/src/theme/v2/color/kbd.ts +1 -3
  128. package/src/theme/v2/color/selectable.ts +2 -6
  129. package/src/theme/v2/color/state.ts +1 -3
  130. package/src/theme/v2/color/syntax.ts +1 -3
  131. package/src/theme/v2/input.ts +1 -3
  132. package/src/theme/v2/theme.ts +2 -6
  133. package/src/theme/v3/buildTheme_v3.ts +1 -0
  134. package/src/theme/v3/color/color.ts +6 -4
  135. package/src/theme/v3/color/renderColor.ts +4 -1
  136. package/src/theme/v3/defaultTokens.ts +1 -0
  137. package/src/theme/v3/resolveTokens.ts +9 -9
  138. package/src/ui/RootClassNames.tsx +3 -0
  139. package/src/ui/StyleTags.tsx +3 -1
  140. package/src/ui/_compat/theme/themeColorProvider.tsx +2 -6
  141. package/src/ui/_compat/theme/themeProvider.tsx +2 -6
  142. package/src/ui/_compat/theme/types.ts +1 -3
  143. package/src/ui/_compat/theme/useRootTheme.ts +1 -3
  144. package/src/ui/_compat/theme/useTheme.ts +2 -6
  145. package/src/ui/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
  146. package/src/ui/components/autocomplete/autocomplete.tsx +86 -114
  147. package/src/ui/components/autocomplete/autocompleteOption.tsx +2 -0
  148. package/src/ui/components/autocomplete/types.ts +3 -8
  149. package/src/ui/components/breadcrumbs/breadcrumbs.tsx +27 -21
  150. package/src/ui/components/dialog/dialog.tsx +89 -291
  151. package/src/ui/components/dialog/dialogCard.tsx +183 -0
  152. package/src/ui/components/dialog/isTargetWithinScope.ts +14 -0
  153. package/src/ui/components/hotkeys/hotkeys.tsx +33 -15
  154. package/src/ui/components/menu/__workshop__/asComponent.tsx +6 -6
  155. package/src/ui/components/menu/menu.tsx +27 -33
  156. package/src/ui/components/menu/menuButton.tsx +10 -14
  157. package/src/ui/components/menu/menuDivider.tsx +25 -13
  158. package/src/ui/components/menu/menuGroup.tsx +34 -26
  159. package/src/ui/components/menu/menuItem.tsx +51 -40
  160. package/src/ui/components/skeleton/codeSkeleton.tsx +53 -0
  161. package/src/ui/components/skeleton/headingSkeleton.tsx +52 -0
  162. package/src/ui/components/skeleton/index.ts +3 -0
  163. package/src/ui/components/skeleton/labelSkeleton.tsx +51 -0
  164. package/src/ui/components/skeleton/skeleton.tsx +39 -16
  165. package/src/ui/components/skeleton/textSkeleton.tsx +31 -110
  166. package/src/ui/components/tab/tab.tsx +23 -19
  167. package/src/ui/components/tab/tabList.tsx +34 -33
  168. package/src/ui/components/tab/tabPanel.tsx +25 -19
  169. package/src/ui/components/toast/toast.tsx +21 -16
  170. package/src/ui/components/toast/toastLayer.tsx +28 -10
  171. package/src/ui/components/toast/toastProvider.tsx +2 -6
  172. package/src/ui/components/toast/types.ts +2 -6
  173. package/src/ui/components/toast/useToast.ts +1 -3
  174. package/src/ui/components/tree/tree.tsx +194 -187
  175. package/src/ui/components/tree/treeGroup.tsx +25 -5
  176. package/src/ui/components/tree/treeItem.tsx +35 -23
  177. package/src/ui/hooks/useClickOutside.ts +2 -6
  178. package/src/ui/hooks/useClickOutsideEvent.ts +3 -9
  179. package/src/ui/primitives/_selectable/selectable.tsx +33 -20
  180. package/src/ui/primitives/avatar/avatar.tsx +28 -31
  181. package/src/ui/primitives/avatar/avatarCounter.tsx +33 -25
  182. package/src/ui/primitives/avatar/avatarStack.tsx +31 -24
  183. package/src/ui/primitives/avatar/types.ts +2 -0
  184. package/src/ui/primitives/badge/__workshop__/props.tsx +1 -9
  185. package/src/ui/primitives/badge/__workshop__/tones.tsx +1 -6
  186. package/src/ui/primitives/badge/badge.tsx +33 -32
  187. package/src/ui/primitives/badge/types.ts +2 -1
  188. package/src/ui/primitives/box/box.tsx +59 -29
  189. package/src/ui/primitives/button/__workshop__/sanityUploadButton.tsx +3 -3
  190. package/src/ui/primitives/button/__workshop__/uploadButton.tsx +2 -1
  191. package/src/ui/primitives/button/button.test.tsx +1 -15
  192. package/src/ui/primitives/button/button.tsx +64 -70
  193. package/src/ui/primitives/card/__workshop__/asComponent.tsx +3 -3
  194. package/src/ui/primitives/card/card.tsx +22 -22
  195. package/src/ui/primitives/card/cardProvider.tsx +2 -0
  196. package/src/ui/primitives/checkbox/checkbox.tsx +26 -15
  197. package/src/ui/primitives/code/code.tsx +24 -22
  198. package/src/ui/primitives/container/container.tsx +26 -15
  199. package/src/ui/primitives/flex/flex.tsx +21 -19
  200. package/src/ui/primitives/grid/grid.tsx +21 -16
  201. package/src/ui/primitives/heading/heading.tsx +42 -19
  202. package/src/ui/primitives/inline/inline.tsx +26 -23
  203. package/src/ui/primitives/kbd/kbd.tsx +25 -23
  204. package/src/ui/primitives/label/label.tsx +41 -26
  205. package/src/ui/primitives/popover/popover.tsx +281 -277
  206. package/src/ui/primitives/popover/popoverCard.tsx +119 -118
  207. package/src/ui/primitives/radio/radio.tsx +30 -14
  208. package/src/ui/primitives/select/select.tsx +24 -16
  209. package/src/ui/primitives/spinner/animatedSpinnerIcon.tsx +4 -2
  210. package/src/ui/primitives/spinner/spinner.tsx +24 -12
  211. package/src/ui/primitives/stack/stack.tsx +27 -18
  212. package/src/ui/primitives/switch/switch.tsx +31 -14
  213. package/src/ui/primitives/text/text.tsx +42 -24
  214. package/src/ui/primitives/textArea/textArea.tsx +33 -18
  215. package/src/ui/primitives/textInput/textInput.tsx +28 -40
  216. package/src/ui/primitives/tooltip/constants.ts +1 -1
  217. package/src/ui/primitives/tooltip/tooltip.tsx +76 -59
  218. package/src/ui/primitives/tooltip/tooltipCard.tsx +89 -82
  219. package/src/ui/primitives/types.ts +1 -3
  220. package/src/ui/types/avatar.ts +3 -6
  221. package/src/ui/types/badge.ts +1 -3
  222. package/src/ui/types/button.ts +1 -3
  223. package/src/ui/types/card.ts +1 -3
  224. package/src/ui/types/dialog.ts +1 -3
  225. package/src/ui/types/props.ts +20 -10
  226. package/src/ui/utils/arrow/arrow.tsx +40 -14
  227. package/src/ui/utils/boundaryElement/boundaryElementProvider.tsx +2 -6
  228. package/src/ui/utils/boundaryElement/types.ts +1 -3
  229. package/src/ui/utils/boundaryElement/useBoundaryElement.ts +1 -3
  230. package/src/ui/utils/elementQuery/elementQuery.tsx +36 -14
  231. package/src/ui/utils/errorBoundary.tsx +2 -0
  232. package/src/ui/utils/index.ts +0 -1
  233. package/src/ui/utils/layer/layer.tsx +23 -93
  234. package/src/ui/utils/layer/layerCard.tsx +92 -0
  235. package/src/ui/utils/layer/layerProvider.tsx +2 -6
  236. package/src/ui/utils/layer/useLayer.ts +1 -3
  237. package/src/ui/utils/portal/portal.ts +2 -6
  238. package/src/ui/utils/portal/portalProvider.tsx +2 -6
  239. package/src/ui/utils/portal/types.ts +1 -3
  240. package/src/ui/utils/portal/usePortal.ts +1 -3
  241. package/src/ui/utils/srOnly/srOnly.tsx +25 -20
  242. package/src/ui/utils/virtualList/virtualList.tsx +36 -24
  243. package/src/css/compile/compileRule.ts +0 -97
  244. package/src/css/compile/compileRules.test.ts +0 -36
  245. package/src/css/compile/compileRules.ts +0 -43
  246. package/src/css/compile/compileSystem.ts +0 -7
  247. package/src/css/compile/types.ts +0 -6
  248. package/src/css/primitives/_selectable/_contants.ts +0 -11
  249. package/src/css/primitives/card/_constants.ts +0 -13
  250. package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
  251. package/src/ui/utils/conditionalWrapper/index.ts +0 -1
@@ -5,45 +5,57 @@ 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 =
19
+ | 'div'
20
+ | 'h1'
21
+ | 'h2'
22
+ | 'h3'
23
+ | 'h4'
24
+ | 'h5'
25
+ | 'h6'
26
+ | 'label'
27
+ | 'li'
28
+ | 'p'
29
+ | 'span'
30
+ | ComponentType
31
+
32
+ /** @public */
33
+ export type TextProps<E extends TextElementType = TextElementType> = Props<TextOwnProps, E>
18
34
 
19
35
  /**
20
36
  * The `Text` component is an agile, themed typographic element.
21
37
  *
22
38
  * @public
23
39
  */
24
- export const Text = forwardRef(function Text(
25
- props: Props<TextProps, 'div'>,
26
- ref: ForwardedRef<HTMLDivElement>,
27
- ) {
40
+ export function Text<E extends TextElementType = typeof DEFAULT_TEXT_ELEMENT>(props: TextProps<E>) {
28
41
  const {
29
- accent = false,
42
+ accent,
30
43
  align,
31
- as: As = 'div',
44
+ as: Element = DEFAULT_TEXT_ELEMENT,
32
45
  children,
33
46
  className,
34
47
  flex,
35
- muted = false,
48
+ muted,
36
49
  size = 2,
37
50
  textOverflow: textOverflowProp,
38
51
  weight,
39
- ...restProps
40
- } = props
52
+ ...rest
53
+ } = props as TextProps<typeof DEFAULT_TEXT_ELEMENT>
41
54
 
42
55
  return (
43
- <As
56
+ <Element
44
57
  data-ui="Text"
45
- {...restProps}
46
- ref={ref}
58
+ {...rest}
47
59
  className={composeClassNames(
48
60
  className,
49
61
  text({
@@ -56,9 +68,15 @@ export const Text = forwardRef(function Text(
56
68
  }),
57
69
  )}
58
70
  >
59
- <span className={textOverflow({textOverflow: textOverflowProp})}>{children}</span>
60
- </As>
71
+ <span
72
+ className={textOverflow({
73
+ textOverflow: textOverflowProp,
74
+ })}
75
+ >
76
+ {children}
77
+ </span>
78
+ </Element>
61
79
  )
62
- })
80
+ }
63
81
 
64
- Text.displayName = 'ForwardRef(Text)'
82
+ 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,11 +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
40
  import {CardProvider, useCard} from '../card'
39
- import type {Delay} from '../types'
41
+ import {Delay} from '../types'
40
42
  import {
41
43
  DEFAULT_FALLBACK_PLACEMENTS,
42
44
  DEFAULT_TOOLTIP_DISTANCE,
@@ -45,56 +47,69 @@ import {
45
47
  import {TooltipCard} from './tooltipCard'
46
48
  import {useTooltipDelayGroup} from './tooltipDelayGroup'
47
49
 
48
- /**
49
- * @public
50
- */
51
- export interface TooltipProps extends Omit<LayerProps, 'as'>, RadiusStyleProps, ShadowStyleProps {
52
- /** @deprecated Use `fallbackPlacements` instead. */
53
- allowedAutoPlacements?: Placement[]
54
- /**
55
- * Whether the tooltip should animate in and out.
56
- *
57
- * @beta
58
- * @defaultValue false
59
- */
60
- animate?: boolean
61
- arrow?: boolean
62
- boundaryElement?: HTMLElement | null
63
- children?: ReactElement<Props>
64
- content?: ReactNode
65
- /**
66
- * Adds a delay to open or close the tooltip.
67
- *
68
- * If only a `number` is passed, it will be used for both opening and closing.
69
- *
70
- * If an object `{open: number; close:number}` is passed, it can be used to set different delays for each action.
71
- *
72
- * @public
73
- * @defaultValue 0
74
- */
75
- delay?: Delay
76
- disabled?: boolean
77
- fallbackPlacements?: Placement[]
78
- placement?: Placement
79
- /** Whether or not to render the tooltip in a portal element. */
80
- portal?: boolean | string
81
- scheme?: ThemeColorSchemeKey
82
- tone?: ThemeColorCardToneKey
83
- }
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
+ >
84
98
 
85
99
  /**
86
100
  * Tooltips display information when hovering, focusing or tapping.
87
101
  *
88
102
  * @public
89
103
  */
90
- export const Tooltip = forwardRef(function Tooltip(
91
- props: Props<TooltipProps, 'div'>,
92
- forwardedRef: ForwardedRef<HTMLDivElement>,
104
+ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_ELEMENT>(
105
+ props: TooltipProps<E>,
93
106
  ) {
94
107
  const boundaryElementContext = useBoundaryElement()
108
+
95
109
  const {
96
110
  animate: _animate = false,
97
111
  arrow: arrowProp = false,
112
+ as = DEFAULT_TOOLTIP_ELEMENT,
98
113
  boundaryElement = boundaryElementContext?.element,
99
114
  children: childProp,
100
115
  className,
@@ -107,12 +122,14 @@ export const Tooltip = forwardRef(function Tooltip(
107
122
  placement: placementProp = 'bottom',
108
123
  portal: portalProp,
109
124
  radius = 3,
125
+ ref: forwardedRef,
110
126
  scheme,
111
127
  shadow = 2,
112
128
  zOffset = Z_OFFSETS.tooltip,
113
129
  tone = 'inherit',
114
- ...restProps
115
- } = props
130
+ ...rest
131
+ } = props as TooltipProps<typeof DEFAULT_TOOLTIP_ELEMENT>
132
+
116
133
  const card = useCard()
117
134
  const prefersReducedMotion = usePrefersReducedMotion()
118
135
  const animate = prefersReducedMotion ? false : _animate
@@ -230,42 +247,42 @@ export const Tooltip = forwardRef(function Tooltip(
230
247
  )
231
248
 
232
249
  const handleBlur = useCallback(
233
- (e: FocusEvent) => {
250
+ (e: FocusEvent<HTMLElement>) => {
234
251
  handleIsOpenChange(false)
235
252
  childProp?.props?.onBlur?.(e)
236
253
  },
237
254
  [childProp?.props, handleIsOpenChange],
238
255
  )
239
256
  const handleClick = useCallback(
240
- (e: MouseEvent) => {
257
+ (e: ReactMouseEvent<HTMLElement>) => {
241
258
  handleIsOpenChange(false, true)
242
259
  childProp?.props.onClick?.(e)
243
260
  },
244
261
  [childProp?.props, handleIsOpenChange],
245
262
  )
246
263
  const handleContextMenu = useCallback(
247
- (e: MouseEvent) => {
264
+ (e: ReactMouseEvent<HTMLElement>) => {
248
265
  handleIsOpenChange(false, true)
249
266
  childProp?.props.onContextMenu?.(e)
250
267
  },
251
268
  [childProp?.props, handleIsOpenChange],
252
269
  )
253
270
  const handleFocus = useCallback(
254
- (e: FocusEvent) => {
271
+ (e: FocusEvent<HTMLElement>) => {
255
272
  handleIsOpenChange(true)
256
273
  childProp?.props?.onFocus?.(e)
257
274
  },
258
275
  [childProp?.props, handleIsOpenChange],
259
276
  )
260
277
  const handleMouseEnter = useCallback(
261
- (e: MouseEvent) => {
278
+ (e: ReactMouseEvent<HTMLElement>) => {
262
279
  handleIsOpenChange(true)
263
280
  childProp?.props?.onMouseEnter?.(e)
264
281
  },
265
282
  [childProp?.props, handleIsOpenChange],
266
283
  )
267
284
  const handleMouseLeave = useCallback(
268
- (e: MouseEvent) => {
285
+ (e: ReactMouseEvent<HTMLElement>) => {
269
286
  handleIsOpenChange(false)
270
287
  childProp?.props?.onMouseLeave?.(e)
271
288
  },
@@ -366,7 +383,6 @@ export const Tooltip = forwardRef(function Tooltip(
366
383
  const node = (
367
384
  <Layer
368
385
  data-ui="Tooltip"
369
- // {...restProps}
370
386
  className={composeClassNames(className, tooltip())}
371
387
  ref={setFloating}
372
388
  style={{
@@ -376,12 +392,13 @@ export const Tooltip = forwardRef(function Tooltip(
376
392
  zOffset={zOffset}
377
393
  >
378
394
  <TooltipCard
379
- {...restProps}
395
+ {...rest}
380
396
  animate={animate}
381
397
  arrow={arrowProp}
382
398
  arrowRef={setArrow}
383
399
  arrowX={arrowX}
384
400
  arrowY={arrowY}
401
+ as={as}
385
402
  originX={originX}
386
403
  originY={originY}
387
404
  padding={padding}
@@ -421,9 +438,7 @@ export const Tooltip = forwardRef(function Tooltip(
421
438
  {child}
422
439
  </>
423
440
  )
424
- })
425
-
426
- Tooltip.displayName = 'ForwardRef(Tooltip)'
441
+ }
427
442
 
428
443
  /**
429
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.
@@ -471,3 +486,5 @@ function useCloseOnMouseLeave({
471
486
  return () => window.removeEventListener('mousemove', handleMouseMove)
472
487
  }, [isInsideGroup, showTooltip])
473
488
  }
489
+
490
+ Tooltip.displayName = 'Tooltip'