@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
@@ -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} 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,130 +36,128 @@ export interface PopoverCardProps extends CardProps {
33
36
  y: number | null
34
37
  }
35
38
 
36
- const MotionCard = motion.create(Card)
39
+ /** @internal */
40
+ export type PopoverCardElementType = CardElementType
37
41
 
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: schemeProp,
63
- shadow,
64
- strategy,
65
- style,
66
- tone = 'inherit',
67
- // width,
68
- x: xProp,
69
- y: yProp,
70
- ...restProps
71
- } = props
42
+ /** @internal */
43
+ export type PopoverCardProps<E extends PopoverCardElementType = PopoverCardElementType> = Props<
44
+ PopoverCardOwnProps,
45
+ E
46
+ >
72
47
 
73
- // const card = useCard()
48
+ const MotionCard = motion.create(Card)
74
49
 
75
- // const tone = toneProp ?? card?.tone ?? 'inherit'
76
- // const scheme = schemeProp ?? card?.scheme ?? 'light'
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>
77
79
 
78
- const layer = useLayer()
80
+ const layer = useLayer()
79
81
 
80
- // Get margins: [top, right, bottom, left]
81
- const margins: PopoverMargins = useMemo(
82
- () => marginsProp || DEFAULT_POPOVER_MARGINS,
83
- [marginsProp],
84
- )
82
+ // Get margins: [top, right, bottom, left]
83
+ const margins: PopoverMargins = useMemo(
84
+ () => marginsProp || DEFAULT_POPOVER_MARGINS,
85
+ [marginsProp],
86
+ )
85
87
 
86
- // Translate according to margins
87
- const x = (xProp ?? 0) + margins[3]
88
- const y = (yProp ?? 0) + margins[0]
88
+ // Translate according to margins
89
+ const x = (xProp ?? 0) + margins[3]
90
+ const y = (yProp ?? 0) + margins[0]
89
91
 
90
- const rootStyle: CSSProperties = useMemo(
91
- () => ({
92
- left: x,
93
- originX,
94
- originY,
95
- position: strategy,
96
- top: y,
97
- width: referenceWidth,
98
- zIndex: layer.zIndex ?? 100,
99
- willChange: animate ? 'transform' : undefined,
100
- ...style,
101
- }),
102
- [animate, layer.zIndex, originX, originY, referenceWidth, strategy, style, x, y],
103
- )
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
+ )
104
106
 
105
- const arrowStyle: CSSProperties = useMemo(
106
- () => ({
107
- left: arrowX !== null ? arrowX : undefined,
108
- top: arrowY !== null ? arrowY : undefined,
109
- right: undefined,
110
- bottom: undefined,
111
- }),
112
- [arrowX, arrowY],
113
- )
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
+ )
114
116
 
115
- return (
116
- <MotionCard
117
- className={popoverCard()}
118
- data-ui="Popover"
119
- {...(restProps as CardProps & MotionProps)}
120
- data-context-tone={tone}
121
- data-placement={placement}
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"
122
140
  direction="column"
123
- display="flex"
124
- radius={radius}
125
- ref={ref}
126
- // scheme={scheme}
127
- shadow={shadow}
128
- sizing="border"
129
- style={rootStyle}
130
- tone={tone}
131
- variants={POPOVER_MOTION_PROPS.card}
132
- transition={POPOVER_MOTION_PROPS.transition}
133
- initial={animate ? ['hidden', 'initial'] : undefined}
134
- animate={animate ? ['visible', 'scaleIn'] : undefined}
135
- exit={animate ? ['hidden', 'scaleOut'] : undefined}
141
+ flex={1}
142
+ maxWidth={maxWidth}
143
+ overflow={overflow}
136
144
  >
137
- <Flex
138
- data-ui="Popover__wrapper"
139
- direction="column"
140
- flex={1}
141
- maxWidth={maxWidth}
142
- overflow={overflow}
143
- >
144
- <Flex direction="column" flex={1} padding={padding}>
145
- {children}
146
- </Flex>
145
+ <Flex direction="column" flex={1} padding={padding}>
146
+ {children}
147
147
  </Flex>
148
+ </Flex>
149
+
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
+ }
148
162
 
149
- {arrow && (
150
- <Arrow
151
- ref={arrowRef}
152
- style={arrowStyle}
153
- width={DEFAULT_POPOVER_ARROW_WIDTH}
154
- height={DEFAULT_POPOVER_ARROW_HEIGHT}
155
- radius={DEFAULT_POPOVER_ARROW_RADIUS}
156
- />
157
- )}
158
- </MotionCard>
159
- )
160
- }),
161
- )
162
- 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'