@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
@@ -1,12 +1,12 @@
1
1
  import {Strategy} from '@floating-ui/react-dom'
2
2
  import {popoverCard} from '@sanity/ui/css'
3
- import {motion, MotionProps} from 'framer-motion'
4
- import {CSSProperties, ForwardedRef, forwardRef, memo, useMemo} from 'react'
3
+ import {motion} from 'framer-motion'
4
+ import {CSSProperties, ForwardedRef, useMemo} from 'react'
5
5
 
6
6
  import {POPOVER_MOTION_PROPS} from '../../constants'
7
7
  import {Placement, PopoverMargins, Props} from '../../types'
8
8
  import {Arrow, useLayer} from '../../utils'
9
- import {Card, CardProps, CardProvider, useCard} from '../card'
9
+ import {Card, CardElementType, CardOwnProps} from '../card'
10
10
  import {Flex} from '../flex'
11
11
  import {
12
12
  DEFAULT_POPOVER_ARROW_HEIGHT,
@@ -16,7 +16,10 @@ import {
16
16
  } from './constants'
17
17
 
18
18
  /** @internal */
19
- export interface PopoverCardProps extends CardProps {
19
+ export const DEFAULT_POPOVER_CARD_ELEMENT = 'div'
20
+
21
+ /** @internal */
22
+ export type PopoverCardOwnProps = CardOwnProps & {
20
23
  /** @beta*/
21
24
  __unstable_margins?: PopoverMargins
22
25
  animate?: boolean
@@ -33,129 +36,128 @@ export interface PopoverCardProps extends CardProps {
33
36
  y: number | null
34
37
  }
35
38
 
39
+ /** @internal */
40
+ export type PopoverCardElementType = CardElementType
41
+
42
+ /** @internal */
43
+ export type PopoverCardProps<E extends PopoverCardElementType = PopoverCardElementType> = Props<
44
+ PopoverCardOwnProps,
45
+ E
46
+ >
47
+
36
48
  const MotionCard = motion.create(Card)
37
49
 
38
- /**
39
- * @internal
40
- */
41
- export const PopoverCard = memo(
42
- forwardRef(function PopoverCard(
43
- props: Props<PopoverCardProps, 'div'>,
44
- ref: ForwardedRef<HTMLDivElement>,
45
- ) {
46
- const {
47
- __unstable_margins: marginsProp,
48
- animate,
49
- arrow,
50
- arrowRef,
51
- arrowX,
52
- arrowY,
53
- children,
54
- maxWidth,
55
- padding,
56
- placement,
57
- originX,
58
- originY,
59
- overflow,
60
- radius,
61
- referenceWidth,
62
- scheme,
63
- shadow,
64
- strategy,
65
- style,
66
- tone,
67
- // width,
68
- x: xProp,
69
- y: yProp,
70
- ...restProps
71
- } = props
50
+ /** @internal */
51
+ export function PopoverCard<E extends PopoverCardElementType = typeof DEFAULT_POPOVER_CARD_ELEMENT>(
52
+ props: PopoverCardProps<E>,
53
+ ) {
54
+ const {
55
+ __unstable_margins: marginsProp,
56
+ animate,
57
+ arrow,
58
+ arrowRef,
59
+ arrowX,
60
+ arrowY,
61
+ as = DEFAULT_POPOVER_CARD_ELEMENT,
62
+ children,
63
+ maxWidth,
64
+ padding,
65
+ placement,
66
+ originX,
67
+ originY,
68
+ overflow,
69
+ radius,
70
+ referenceWidth,
71
+ shadow,
72
+ strategy,
73
+ style,
74
+ tone = 'inherit',
75
+ x: xProp,
76
+ y: yProp,
77
+ ...rest
78
+ } = props as PopoverCardProps<typeof DEFAULT_POPOVER_CARD_ELEMENT>
72
79
 
73
- const card = useCard()
80
+ const layer = useLayer()
74
81
 
75
- const layer = useLayer()
82
+ // Get margins: [top, right, bottom, left]
83
+ const margins: PopoverMargins = useMemo(
84
+ () => marginsProp || DEFAULT_POPOVER_MARGINS,
85
+ [marginsProp],
86
+ )
76
87
 
77
- // Get margins: [top, right, bottom, left]
78
- const margins: PopoverMargins = useMemo(
79
- () => marginsProp || DEFAULT_POPOVER_MARGINS,
80
- [marginsProp],
81
- )
88
+ // Translate according to margins
89
+ const x = (xProp ?? 0) + margins[3]
90
+ const y = (yProp ?? 0) + margins[0]
82
91
 
83
- // Translate according to margins
84
- const x = (xProp ?? 0) + margins[3]
85
- const y = (yProp ?? 0) + margins[0]
92
+ const rootStyle: CSSProperties = useMemo(
93
+ () => ({
94
+ left: x,
95
+ originX,
96
+ originY,
97
+ position: strategy,
98
+ top: y,
99
+ width: referenceWidth,
100
+ zIndex: layer.zIndex ?? 100,
101
+ willChange: animate ? 'transform' : undefined,
102
+ ...style,
103
+ }),
104
+ [animate, layer.zIndex, originX, originY, referenceWidth, strategy, style, x, y],
105
+ )
86
106
 
87
- const rootStyle: CSSProperties = useMemo(
88
- () => ({
89
- left: x,
90
- originX,
91
- originY,
92
- position: strategy,
93
- top: y,
94
- width: referenceWidth,
95
- zIndex: layer.zIndex ?? 100,
96
- willChange: animate ? 'transform' : undefined,
97
- ...style,
98
- }),
99
- [animate, layer.zIndex, originX, originY, referenceWidth, strategy, style, x, y],
100
- )
107
+ const arrowStyle: CSSProperties = useMemo(
108
+ () => ({
109
+ left: arrowX !== null ? arrowX : undefined,
110
+ top: arrowY !== null ? arrowY : undefined,
111
+ right: undefined,
112
+ bottom: undefined,
113
+ }),
114
+ [arrowX, arrowY],
115
+ )
101
116
 
102
- const arrowStyle: CSSProperties = useMemo(
103
- () => ({
104
- left: arrowX !== null ? arrowX : undefined,
105
- top: arrowY !== null ? arrowY : undefined,
106
- right: undefined,
107
- bottom: undefined,
108
- }),
109
- [arrowX, arrowY],
110
- )
117
+ return (
118
+ <MotionCard
119
+ className={popoverCard()}
120
+ data-ui="Popover"
121
+ {...rest}
122
+ as={as}
123
+ data-context-tone={tone}
124
+ data-placement={placement}
125
+ direction="column"
126
+ display="flex"
127
+ radius={radius}
128
+ shadow={shadow}
129
+ sizing="border"
130
+ style={rootStyle}
131
+ tone={tone}
132
+ variants={POPOVER_MOTION_PROPS.card}
133
+ transition={POPOVER_MOTION_PROPS.transition}
134
+ initial={animate ? ['hidden', 'initial'] : undefined}
135
+ animate={animate ? ['visible', 'scaleIn'] : undefined}
136
+ exit={animate ? ['hidden', 'scaleOut'] : undefined}
137
+ >
138
+ <Flex
139
+ data-ui="Popover__wrapper"
140
+ direction="column"
141
+ flex={1}
142
+ maxWidth={maxWidth}
143
+ overflow={overflow}
144
+ >
145
+ <Flex direction="column" flex={1} padding={padding}>
146
+ {children}
147
+ </Flex>
148
+ </Flex>
111
149
 
112
- return (
113
- <CardProvider tone={card?.tone ?? 'transparent'} scheme={card?.scheme ?? 'light'}>
114
- <MotionCard
115
- className={popoverCard()}
116
- data-ui="Popover"
117
- {...(restProps as CardProps & MotionProps)}
118
- data-context-tone={card?.tone ?? 'transparent'}
119
- data-placement={placement}
120
- direction="column"
121
- display="flex"
122
- radius={radius}
123
- ref={ref}
124
- scheme={scheme}
125
- shadow={shadow}
126
- sizing="border"
127
- style={rootStyle}
128
- tone={tone}
129
- variants={POPOVER_MOTION_PROPS.card}
130
- transition={POPOVER_MOTION_PROPS.transition}
131
- initial={animate ? ['hidden', 'initial'] : undefined}
132
- animate={animate ? ['visible', 'scaleIn'] : undefined}
133
- exit={animate ? ['hidden', 'scaleOut'] : undefined}
134
- >
135
- <Flex
136
- data-ui="Popover__wrapper"
137
- direction="column"
138
- flex={1}
139
- maxWidth={maxWidth}
140
- overflow={overflow}
141
- >
142
- <Flex direction="column" flex={1} padding={padding}>
143
- {children}
144
- </Flex>
145
- </Flex>
150
+ {arrow && (
151
+ <Arrow
152
+ ref={arrowRef}
153
+ style={arrowStyle}
154
+ width={DEFAULT_POPOVER_ARROW_WIDTH}
155
+ height={DEFAULT_POPOVER_ARROW_HEIGHT}
156
+ radius={DEFAULT_POPOVER_ARROW_RADIUS}
157
+ />
158
+ )}
159
+ </MotionCard>
160
+ )
161
+ }
146
162
 
147
- {arrow && (
148
- <Arrow
149
- ref={arrowRef}
150
- style={arrowStyle}
151
- width={DEFAULT_POPOVER_ARROW_WIDTH}
152
- height={DEFAULT_POPOVER_ARROW_HEIGHT}
153
- radius={DEFAULT_POPOVER_ARROW_RADIUS}
154
- />
155
- )}
156
- </MotionCard>
157
- </CardProvider>
158
- )
159
- }),
160
- )
161
- PopoverCard.displayName = 'Memo(ForwardRef(PopoverCard))'
163
+ PopoverCard.displayName = 'PopoverCard'
@@ -1,26 +1,42 @@
1
1
  import {composeClassNames, radio} from '@sanity/ui/css'
2
- import {ForwardedRef, forwardRef, useImperativeHandle, useRef} from 'react'
2
+ import {useImperativeHandle, useRef} from 'react'
3
3
 
4
4
  import {useCustomValidity} from '../../hooks'
5
- import {Props} from '../../types'
5
+ import {ComponentType, Props} from '../../types'
6
6
 
7
- /**
8
- * @public
9
- */
10
- export interface RadioProps {
7
+ /** @public */
8
+ export const DEFAULT_RADIO_ELEMENT = 'input'
9
+
10
+ /** @public */
11
+ export type RadioOwnProps = {
11
12
  customValidity?: string
12
13
  }
13
14
 
15
+ /** @public */
16
+ export type RadioElementType = 'input' | ComponentType
17
+
18
+ /** @public */
19
+ export type RadioProps<E extends RadioElementType = RadioElementType> = Props<RadioOwnProps, E>
20
+
14
21
  /**
15
22
  * The `Radio` component allows the user to select one option from a set.
16
23
  *
17
24
  * @public
18
25
  */
19
- export const Radio = forwardRef(function Radio(
20
- props: Props<RadioProps, 'input'>,
21
- forwardedRef: ForwardedRef<HTMLInputElement>,
26
+ export function Radio<E extends RadioElementType = typeof DEFAULT_RADIO_ELEMENT>(
27
+ props: RadioProps<E>,
22
28
  ) {
23
- const {className, disabled, style, customValidity, readOnly, ...restProps} = props
29
+ const {
30
+ as: Element = DEFAULT_RADIO_ELEMENT,
31
+ className,
32
+ disabled,
33
+ style,
34
+ customValidity,
35
+ readOnly,
36
+ ref: forwardedRef,
37
+ ...rest
38
+ } = props as RadioProps<typeof DEFAULT_RADIO_ELEMENT>
39
+
24
40
  const ref = useRef<HTMLInputElement | null>(null)
25
41
 
26
42
  useImperativeHandle<HTMLInputElement | null, HTMLInputElement | null>(
@@ -32,10 +48,10 @@ export const Radio = forwardRef(function Radio(
32
48
 
33
49
  return (
34
50
  <div className={composeClassNames(className, radio())} data-ui="Radio" style={style}>
35
- <input
51
+ <Element
36
52
  data-read-only={!disabled && readOnly ? '' : undefined}
37
53
  data-error={customValidity ? '' : undefined}
38
- {...restProps}
54
+ {...rest}
39
55
  disabled={disabled || readOnly}
40
56
  readOnly={readOnly}
41
57
  ref={ref}
@@ -44,6 +60,6 @@ export const Radio = forwardRef(function Radio(
44
60
  <span />
45
61
  </div>
46
62
  )
47
- })
63
+ }
48
64
 
49
- Radio.displayName = 'ForwardRef(Radio)'
65
+ Radio.displayName = 'Radio'
@@ -7,33 +7,40 @@ import {
7
7
  SelectStyleProps,
8
8
  } from '@sanity/ui/css'
9
9
  import {Space} from '@sanity/ui/theme'
10
- import {ForwardedRef, forwardRef, useImperativeHandle, useRef} from 'react'
10
+ import {useImperativeHandle, useRef} from 'react'
11
11
 
12
12
  import {useCustomValidity} from '../../hooks'
13
- import {Props} from '../../types'
13
+ import type {ComponentType, Props} from '../../types'
14
14
  import {Box} from '../box'
15
15
  import {Text} from '../text'
16
16
 
17
- /**
18
- * @public
19
- */
20
- export interface SelectProps extends SelectStyleProps {
17
+ /** @public */
18
+ export const DEFAULT_SELECT_ELEMENT = 'select'
19
+
20
+ /** @public */
21
+ export type SelectOwnProps = SelectStyleProps & {
21
22
  customValidity?: string
22
23
  readOnly?: boolean
23
24
  /** @deprecated Use `gap` instead. */
24
25
  space?: ResponsiveProp<Space>
25
26
  }
26
27
 
28
+ /** @public */
29
+ export type SelectElementType = 'select' | ComponentType
30
+
31
+ /** @public */
32
+ export type SelectProps<E extends SelectElementType = SelectElementType> = Props<SelectOwnProps, E>
33
+
27
34
  /**
28
35
  * The `Select` component provides control of options.
29
36
  *
30
37
  * @public
31
38
  */
32
- export const Select = forwardRef(function Select(
33
- props: Props<SelectProps, 'select'>,
34
- forwardedRef: ForwardedRef<HTMLSelectElement>,
39
+ export function Select<E extends SelectElementType = typeof DEFAULT_SELECT_ELEMENT>(
40
+ props: SelectProps<E>,
35
41
  ) {
36
42
  const {
43
+ as: Element = DEFAULT_SELECT_ELEMENT,
37
44
  border = true,
38
45
  children,
39
46
  customValidity,
@@ -43,9 +50,10 @@ export const Select = forwardRef(function Select(
43
50
  padding = 3,
44
51
  radius = 1,
45
52
  readOnly,
53
+ ref: forwardedRef,
46
54
  space = 2,
47
- ...restProps
48
- } = props
55
+ ...rest
56
+ } = props as SelectProps<typeof DEFAULT_SELECT_ELEMENT>
49
57
 
50
58
  const ref = useRef<HTMLSelectElement | null>(null)
51
59
 
@@ -62,15 +70,15 @@ export const Select = forwardRef(function Select(
62
70
  className={select({border, fontSize, padding, radius, gap: gap ?? space})}
63
71
  data-icon-right=""
64
72
  >
65
- <select
73
+ <Element
66
74
  data-read-only={!disabled && readOnly ? '' : undefined}
67
- {...restProps}
75
+ {...rest}
68
76
  className={_inputElement()}
69
77
  disabled={disabled || readOnly}
70
78
  ref={ref}
71
79
  >
72
80
  {children}
73
- </select>
81
+ </Element>
74
82
  <span className={selectPresentation()}>
75
83
  <Box as="span" display="inline-block" padding={padding}>
76
84
  <Text size={fontSize}>
@@ -80,6 +88,6 @@ export const Select = forwardRef(function Select(
80
88
  </span>
81
89
  </div>
82
90
  )
83
- })
91
+ }
84
92
 
85
- Select.displayName = 'ForwardRef(Select)'
93
+ Select.displayName = 'Select'
@@ -4,13 +4,15 @@ import {ReactElement, SVGProps} from 'react'
4
4
 
5
5
  /** @internal */
6
6
  export function AnimatedSpinnerIcon(props: SVGProps<SVGSVGElement>): ReactElement {
7
- const {className, ...restProps} = props
7
+ const {className, ...rest} = props
8
8
 
9
9
  return (
10
10
  <SpinnerIcon
11
- {...restProps}
11
+ {...rest}
12
12
  data-sanity-icon="animated-spinner"
13
13
  className={composeClassNames(className, animatedSpinnerIcon())}
14
14
  />
15
15
  )
16
16
  }
17
+
18
+ AnimatedSpinnerIcon.displayName = 'AnimatedSpinnerIcon'
@@ -1,33 +1,45 @@
1
1
  import {ResponsiveProp, spinner} from '@sanity/ui/css'
2
2
  import {FontTextSize} from '@sanity/ui/theme'
3
- import {ForwardedRef, forwardRef} from 'react'
4
3
 
5
- import {Props} from '../../types'
4
+ import {ComponentType, Props} from '../../types'
6
5
  import {Text} from '../text'
7
6
  import {AnimatedSpinnerIcon} from './animatedSpinnerIcon'
8
7
 
9
- /**
10
- * @public
11
- */
12
- export interface SpinnerProps {
8
+ /** @public */
9
+ export const DEFAULT_SPINNER_ELEMENT = 'div'
10
+
11
+ /** @public */
12
+ export type SpinnerOwnProps = {
13
13
  muted?: boolean
14
14
  size?: ResponsiveProp<FontTextSize>
15
15
  }
16
16
 
17
+ /** @public */
18
+ export type SpinnerElementType = 'div' | 'span' | ComponentType
19
+
20
+ /** @public */
21
+ export type SpinnerProps<E extends SpinnerElementType = SpinnerElementType> = Props<
22
+ SpinnerOwnProps,
23
+ E
24
+ >
25
+
17
26
  /**
18
27
  * Indicate that something is loading for an indeterminate amount of time.
19
28
  *
20
29
  * @public
21
30
  */
22
- export const Spinner = forwardRef(function Spinner(
23
- props: Props<SpinnerProps, 'div'>,
24
- ref: ForwardedRef<HTMLDivElement>,
31
+ export function Spinner<E extends SpinnerElementType = typeof DEFAULT_SPINNER_ELEMENT>(
32
+ props: SpinnerProps<E>,
25
33
  ) {
34
+ const {as = DEFAULT_SPINNER_ELEMENT, ...rest} = props as SpinnerProps<
35
+ typeof DEFAULT_SPINNER_ELEMENT
36
+ >
37
+
26
38
  return (
27
- <Text data-ui="Spinner" {...props} className={spinner()} ref={ref}>
39
+ <Text as={as} data-ui="Spinner" {...rest} className={spinner()}>
28
40
  <AnimatedSpinnerIcon />
29
41
  </Text>
30
42
  )
31
- })
43
+ }
32
44
 
33
- Spinner.displayName = 'ForwardRef(Spinner)'
45
+ Spinner.displayName = 'Spinner'
@@ -1,45 +1,54 @@
1
1
  import {composeClassNames, ResponsiveProp, stack} from '@sanity/ui/css'
2
2
  import {Space} from '@sanity/ui/theme'
3
- import {ForwardedRef, forwardRef} from 'react'
4
3
 
5
4
  import {Props} from '../../types'
6
- import {Box, BoxProps} from '../box'
5
+ import {Box, BoxElementType, BoxOwnProps} from '../box'
7
6
 
8
- /**
9
- * @public
10
- */
11
- export interface StackProps
12
- extends Omit<
13
- BoxProps,
14
- 'align' | 'columns' | 'direction' | 'display' | 'gapX' | 'gapY' | 'justify'
15
- > {
7
+ /** @public */
8
+ export const DEFAULT_STACK_ELEMENT = 'div'
9
+
10
+ /** @public */
11
+ export type StackOwnProps = Omit<
12
+ BoxOwnProps,
13
+ 'align' | 'columns' | 'direction' | 'display' | 'gapX' | 'gapY' | 'justify'
14
+ > & {
16
15
  /** @deprecated Use `gap` instead. */
17
16
  space?: ResponsiveProp<Space>
18
17
  }
19
18
 
19
+ /** @public */
20
+ export type StackElementType = BoxElementType
21
+
22
+ /** @public */
23
+ export type StackProps<E extends StackElementType = StackElementType> = Props<StackOwnProps, E>
24
+
20
25
  /**
21
26
  * The `Stack` component is used to place elements on top of each other.
22
27
  *
23
28
  * @public
24
29
  */
25
- export const Stack = forwardRef(function Stack(
26
- props: Props<StackProps, 'div'>,
27
- ref: ForwardedRef<HTMLDivElement>,
30
+ export function Stack<E extends StackElementType = typeof DEFAULT_STACK_ELEMENT>(
31
+ props: StackProps<E>,
28
32
  ) {
29
- const {as, className, gap, space, ...restProps} = props
33
+ const {
34
+ as = DEFAULT_STACK_ELEMENT,
35
+ className,
36
+ gap,
37
+ space,
38
+ ...rest
39
+ } = props as StackProps<typeof DEFAULT_STACK_ELEMENT>
30
40
 
31
41
  return (
32
42
  <Box
33
43
  data-ui="Stack"
34
- {...restProps}
44
+ {...rest}
35
45
  as={as}
36
46
  autoRows="min"
37
47
  className={composeClassNames(className, stack())}
38
48
  display="grid"
39
49
  gap={gap ?? space}
40
- ref={ref}
41
50
  />
42
51
  )
43
- })
52
+ }
44
53
 
45
- Stack.displayName = 'ForwardRef(Stack)'
54
+ Stack.displayName = 'Stack'
@@ -6,18 +6,25 @@ import {
6
6
  _switchTrack,
7
7
  composeClassNames,
8
8
  } from '@sanity/ui/css'
9
- import {ForwardedRef, forwardRef, useEffect, useImperativeHandle, useRef} from 'react'
9
+ import {useEffect, useImperativeHandle, useRef} from 'react'
10
10
 
11
- import {Props} from '../../types'
11
+ import {ComponentType, Props} from '../../types'
12
12
  import {Box} from '../box'
13
13
 
14
- /**
15
- * @public
16
- */
17
- export interface SwitchProps {
14
+ /** @public */
15
+ export const DEFAULT_SWITCH_ELEMENT = 'input'
16
+
17
+ /** @public */
18
+ export type SwitchOwnProps = {
18
19
  indeterminate?: boolean
19
20
  }
20
21
 
22
+ /** @public */
23
+ export type SwitchElementType = 'input' | ComponentType
24
+
25
+ /** @public */
26
+ export type SwitchProps<E extends SwitchElementType = SwitchElementType> = Props<SwitchOwnProps, E>
27
+
21
28
  /**
22
29
  * The `Switch` component allows the user to toggle a setting on and off.
23
30
  *
@@ -25,11 +32,21 @@ export interface SwitchProps {
25
32
  *
26
33
  * @public
27
34
  */
28
- export const Switch = forwardRef(function Switch(
29
- props: Props<SwitchProps, 'input'>,
30
- forwardedRef: ForwardedRef<HTMLInputElement>,
35
+ export function Switch<E extends SwitchElementType = typeof DEFAULT_SWITCH_ELEMENT>(
36
+ props: SwitchProps<E>,
31
37
  ) {
32
- const {checked, className, disabled, indeterminate, readOnly, style, ...restProps} = props
38
+ const {
39
+ as: Element = DEFAULT_SWITCH_ELEMENT,
40
+ checked,
41
+ className,
42
+ disabled,
43
+ indeterminate,
44
+ readOnly,
45
+ ref: forwardedRef,
46
+ style,
47
+ ...rest
48
+ } = props as SwitchProps<typeof DEFAULT_SWITCH_ELEMENT>
49
+
33
50
  const ref = useRef<HTMLInputElement | null>(null)
34
51
 
35
52
  useImperativeHandle<HTMLInputElement | null, HTMLInputElement | null>(
@@ -54,8 +71,8 @@ export const Switch = forwardRef(function Switch(
54
71
  position="relative"
55
72
  style={style}
56
73
  >
57
- <input
58
- {...restProps}
74
+ <Element
75
+ {...rest}
59
76
  checked={indeterminate !== true && checked}
60
77
  className={_switchElement()}
61
78
  data-disabled={disabled ? '' : undefined}
@@ -70,6 +87,6 @@ export const Switch = forwardRef(function Switch(
70
87
  </span>
71
88
  </Box>
72
89
  )
73
- })
90
+ }
74
91
 
75
- Switch.displayName = 'ForwardRef(Switch)'
92
+ Switch.displayName = 'Switch'