@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,49 +1,51 @@
1
1
  import {code, composeClassNames, FontStyleProps} from '@sanity/ui/css'
2
- import {ForwardedRef, forwardRef, lazy, Suspense} from 'react'
2
+ import {lazy, Suspense} from 'react'
3
3
 
4
- import {Props} from '../../types'
4
+ import {ComponentType, Props} from '../../types'
5
5
 
6
6
  const LazyRefractor = lazy(() => import('./refractor'))
7
7
 
8
- /**
9
- * @public
10
- */
11
- export interface CodeProps extends Omit<FontStyleProps, 'align'> {
8
+ /** @public */
9
+ export const DEFAULT_CODE_ELEMENT = 'pre'
10
+
11
+ /** @public */
12
+ export type CodeOwnProps = Omit<FontStyleProps, 'align'> & {
12
13
  /** Define the language to use for syntax highlighting. */
13
14
  language?: string
14
15
  size?: number | number[]
15
16
  }
16
17
 
17
- /**
18
- * @public
19
- */
20
- export const Code = forwardRef(function Code(
21
- props: Props<CodeProps, 'pre'>,
22
- ref: ForwardedRef<HTMLPreElement>,
23
- ) {
18
+ /** @public */
19
+ export type CodeElementType = 'div' | 'pre' | ComponentType
20
+
21
+ /** @public */
22
+ export type CodeProps<E extends CodeElementType = CodeElementType> = Props<CodeOwnProps, E>
23
+
24
+ /** @public */
25
+ export function Code<E extends CodeElementType = typeof DEFAULT_CODE_ELEMENT>(props: CodeProps<E>) {
24
26
  const {
25
- as: As = 'pre',
27
+ as: Element = DEFAULT_CODE_ELEMENT,
26
28
  children,
27
29
  className,
28
30
  language: languageProp,
29
31
  size = 2,
30
32
  weight,
31
- ...restProps
32
- } = props
33
+ ...rest
34
+ } = props as CodeProps<typeof DEFAULT_CODE_ELEMENT>
35
+
33
36
  const language = typeof languageProp === 'string' ? languageProp : undefined
34
37
 
35
38
  return (
36
- <As
39
+ <Element
37
40
  data-ui="Code"
38
- {...restProps}
41
+ {...rest}
39
42
  className={composeClassNames(className, code({size, weight}))}
40
- ref={ref}
41
43
  >
42
44
  <Suspense fallback={<code>{children}</code>}>
43
45
  <LazyRefractor language={language} value={children} />
44
46
  </Suspense>
45
- </As>
47
+ </Element>
46
48
  )
47
- })
49
+ }
48
50
 
49
- Code.displayName = 'ForwardRef(Code)'
51
+ Code.displayName = 'Code'
@@ -1,35 +1,46 @@
1
1
  import {composeClassNames, container, ContainerStyleProps} from '@sanity/ui/css'
2
- import {ForwardedRef, forwardRef} from 'react'
3
2
 
4
3
  import {Props} from '../../types'
5
- import {Box, BoxProps} from '../box'
4
+ import {Box, BoxElementType, BoxOwnProps} from '../box'
6
5
 
7
- /**
8
- * @public
9
- */
10
- export interface ContainerProps extends Omit<BoxProps, 'width'>, ContainerStyleProps {}
6
+ /** @public */
7
+ export const DEFAULT_CONTAINER_ELEMENT = 'div'
8
+
9
+ /** @public */
10
+ export type ContainerOwnProps = Omit<BoxOwnProps, 'width'> & ContainerStyleProps
11
+
12
+ /** @public */
13
+ export type ContainerElementType = BoxElementType
14
+
15
+ /** @public */
16
+ export type ContainerProps<E extends ContainerElementType = ContainerElementType> = Props<
17
+ ContainerOwnProps,
18
+ E
19
+ >
11
20
 
12
21
  /**
13
22
  * The `Container` component wraps content layout in a defined set of widths.
14
23
  *
15
24
  * @public
16
25
  */
17
- export const Container = forwardRef(function Container(
18
- props: Props<ContainerProps, 'div'>,
19
- ref: ForwardedRef<HTMLDivElement>,
26
+ export function Container<E extends ContainerElementType = typeof DEFAULT_CONTAINER_ELEMENT>(
27
+ props: ContainerProps<E>,
20
28
  ) {
21
- const {as, className, sizing = 'border', width = 2, ...restProps} = props
29
+ const {
30
+ as = DEFAULT_CONTAINER_ELEMENT,
31
+ className,
32
+ width = 2,
33
+ ...rest
34
+ } = props as ContainerProps<typeof DEFAULT_CONTAINER_ELEMENT>
22
35
 
23
36
  return (
24
37
  <Box
25
38
  data-ui="Container"
26
- {...restProps}
39
+ {...rest}
27
40
  as={as}
28
41
  className={composeClassNames(className, container({width}))}
29
- ref={ref}
30
- sizing={sizing}
31
42
  />
32
43
  )
33
- })
44
+ }
34
45
 
35
- Container.displayName = 'ForwardRef(Container)'
46
+ Container.displayName = 'Container'
@@ -1,29 +1,31 @@
1
- import {ForwardedRef, forwardRef} from 'react'
2
-
3
1
  import {Props} from '../../types'
4
- import {Box, BoxProps} from '../box'
2
+ import {Box, BoxElementType, BoxOwnProps} from '../box'
5
3
 
6
- /**
7
- * @public
8
- */
9
- export interface FlexProps extends Omit<BoxProps, 'display'> {
10
- htmlFor?: string
11
- }
4
+ /** @public */
5
+ export const DEFAULT_FLEX_ELEMENT = 'div'
6
+
7
+ /** @public */
8
+ export type FlexOwnProps = Omit<BoxOwnProps, 'display'>
9
+
10
+ /** @public */
11
+ export type FlexElementType = BoxElementType
12
+
13
+ /** @public */
14
+ export type FlexProps<E extends FlexElementType = FlexElementType> = Props<FlexOwnProps, E>
12
15
 
13
16
  /**
14
17
  * The `Flex` component is a wrapper component for flexible elements (`Box`, `Card` and `Flex`).
15
18
  *
16
19
  * @public
17
20
  */
18
- export const Flex = forwardRef(function Flex(
19
- props: Props<FlexProps, 'div'>,
20
- ref: ForwardedRef<HTMLDivElement>,
21
- ) {
22
- const {as, direction = 'row', ...restProps} = props
21
+ export function Flex<E extends FlexElementType = typeof DEFAULT_FLEX_ELEMENT>(props: FlexProps<E>) {
22
+ const {
23
+ as = DEFAULT_FLEX_ELEMENT,
24
+ direction = 'row',
25
+ ...rest
26
+ } = props as FlexProps<typeof DEFAULT_FLEX_ELEMENT>
23
27
 
24
- return (
25
- <Box data-ui="Flex" {...restProps} as={as} direction={direction} display="flex" ref={ref} />
26
- )
27
- })
28
+ return <Box data-ui="Flex" {...rest} as={as} direction={direction} display="flex" />
29
+ }
28
30
 
29
- Flex.displayName = 'ForwardRef(Flex)'
31
+ Flex.displayName = 'Flex'
@@ -1,30 +1,35 @@
1
- import {ForwardedRef, forwardRef} from 'react'
1
+ import type {Props} from '../../types'
2
+ import {Box, type BoxElementType, type BoxOwnProps} from '../box'
2
3
 
3
- import {Props} from '../../types'
4
- import {Box, BoxProps} from '../box'
4
+ /** @public */
5
+ export const DEFAULT_GRID_ELEMENT = 'div'
5
6
 
6
- /**
7
- * @public
8
- */
9
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
10
- export interface GridProps extends Omit<BoxProps, 'display'> {}
7
+ /** @public */
8
+ export type GridOwnProps = Omit<BoxOwnProps, 'display'>
9
+
10
+ /** @public */
11
+ export type GridElementType = BoxElementType
12
+
13
+ /** @public */
14
+ export type GridProps<E extends GridElementType = GridElementType> = Props<GridOwnProps, E>
11
15
 
12
16
  /**
13
17
  * The `Grid` component is for building 2-dimensional layers (based on CSS grid).
14
18
  *
15
19
  * @public
16
20
  */
17
- export const Grid = forwardRef(function Grid(
18
- props: Props<GridProps, 'div'>,
19
- ref: ForwardedRef<HTMLDivElement>,
20
- ) {
21
- const {as, children, ...restProps} = props
21
+ export function Grid<E extends GridElementType = typeof DEFAULT_GRID_ELEMENT>(props: GridProps<E>) {
22
+ const {
23
+ as = DEFAULT_GRID_ELEMENT,
24
+ children,
25
+ ...rest
26
+ } = props as GridProps<typeof DEFAULT_GRID_ELEMENT>
22
27
 
23
28
  return (
24
- <Box data-ui="Grid" {...restProps} as={as} display="grid" ref={ref}>
29
+ <Box data-ui="Grid" {...rest} as={as} display="grid">
25
30
  {children}
26
31
  </Box>
27
32
  )
28
- })
33
+ }
29
34
 
30
- Grid.displayName = 'ForwardRef(Grid)'
35
+ Grid.displayName = 'Grid'
@@ -5,28 +5,46 @@ import {
5
5
  textOverflow,
6
6
  type TextOverflowStyleProps,
7
7
  } from '@sanity/ui/css'
8
- import {ForwardedRef, forwardRef} from 'react'
9
8
 
10
- import {Props} from '../../types'
9
+ import type {ComponentType, Props} from '../../types'
11
10
 
12
- /**
13
- * @public
14
- */
15
- export interface HeadingProps extends HeadingStyleProps, TextOverflowStyleProps {}
11
+ /** @public */
12
+ export const DEFAULT_HEADING_ELEMENT = 'div'
13
+
14
+ /** @public */
15
+ export type HeadingOwnProps = HeadingStyleProps & TextOverflowStyleProps
16
+
17
+ /** @public */
18
+ export type HeadingElementType =
19
+ | 'div'
20
+ | 'h1'
21
+ | 'h2'
22
+ | 'h3'
23
+ | 'h4'
24
+ | 'h5'
25
+ | 'h6'
26
+ | 'label'
27
+ | 'span'
28
+ | ComponentType
29
+
30
+ /** @public */
31
+ export type HeadingProps<E extends HeadingElementType = HeadingElementType> = Props<
32
+ HeadingOwnProps,
33
+ E
34
+ >
16
35
 
17
36
  /**
18
37
  * Typographic headings.
19
38
  *
20
39
  * @public
21
40
  */
22
- export const Heading = forwardRef(function Heading(
23
- props: Props<HeadingProps, 'div'>,
24
- ref: ForwardedRef<HTMLElement>,
41
+ export function Heading<E extends HeadingElementType = typeof DEFAULT_HEADING_ELEMENT>(
42
+ props: HeadingProps<E>,
25
43
  ) {
26
44
  const {
27
45
  accent = false,
28
46
  align,
29
- as: As = 'div',
47
+ as: Element = DEFAULT_HEADING_ELEMENT,
30
48
  children,
31
49
  className,
32
50
  flex,
@@ -34,13 +52,13 @@ export const Heading = forwardRef(function Heading(
34
52
  size = 2,
35
53
  textOverflow: textOverflowProp,
36
54
  weight,
37
- ...restProps
38
- } = props
55
+ ...rest
56
+ } = props as HeadingProps<typeof DEFAULT_HEADING_ELEMENT>
39
57
 
40
58
  return (
41
- <As
59
+ <Element
42
60
  data-ui="Heading"
43
- {...restProps}
61
+ {...rest}
44
62
  className={composeClassNames(
45
63
  className,
46
64
  heading({
@@ -52,11 +70,16 @@ export const Heading = forwardRef(function Heading(
52
70
  weight,
53
71
  }),
54
72
  )}
55
- ref={ref}
56
73
  >
57
- <span className={textOverflow({textOverflow: textOverflowProp})}>{children}</span>
58
- </As>
74
+ <span
75
+ className={textOverflow({
76
+ textOverflow: textOverflowProp,
77
+ })}
78
+ >
79
+ {children}
80
+ </span>
81
+ </Element>
59
82
  )
60
- })
83
+ }
61
84
 
62
- Heading.displayName = 'ForwardRef(Heading)'
85
+ Heading.displayName = 'Heading'
@@ -1,50 +1,53 @@
1
- import {ResponsiveProp} from '@sanity/ui/css'
1
+ import {FlexStyleProps, GridStyleProps, ResponsiveProp} from '@sanity/ui/css'
2
2
  import {Space} from '@sanity/ui/theme'
3
- import {Children, ForwardedRef, forwardRef, useMemo} from 'react'
4
3
 
5
- import {Props} from '../../types'
6
- import {Box, BoxProps} from '../box'
4
+ import type {Props} from '../../types'
5
+ import {Box, type BoxElementType, type BoxOwnProps} from '../box'
7
6
 
8
- /**
9
- * @public
10
- */
11
- export interface InlineProps extends Omit<BoxProps, 'align' | 'display' | 'justify'> {
7
+ /** @public */
8
+ export const DEFAULT_INLINE_ELEMENT = 'div'
9
+
10
+ /** @public */
11
+ export type InlineOwnProps = Omit<BoxOwnProps, keyof FlexStyleProps | keyof GridStyleProps> & {
12
12
  /** @deprecated Use `gap` instead. */
13
13
  space?: ResponsiveProp<Space>
14
14
  }
15
15
 
16
+ /** @public */
17
+ export type InlineElementType = BoxElementType
18
+
19
+ /** @public */
20
+ export type InlineProps<E extends InlineElementType = InlineElementType> = Props<InlineOwnProps, E>
21
+
16
22
  /**
17
23
  * The `Inline` component is a layout utility for aligning and spacing items horizontally.
18
24
  *
19
25
  * @public
20
26
  */
21
- export const Inline = forwardRef(function Inline(
22
- props: Props<InlineProps, 'div'>,
23
- ref: ForwardedRef<HTMLDivElement>,
27
+ export function Inline<E extends InlineElementType = typeof DEFAULT_INLINE_ELEMENT>(
28
+ props: InlineProps<E>,
24
29
  ) {
25
- const {as, children: childrenProp, gap, gapX, gapY, space, ...restProps} = props
26
-
27
- const children = useMemo(
28
- () => Children.map(childrenProp, (child) => child && <Box maxWidth="fill">{child}</Box>),
29
- [childrenProp],
30
- )
30
+ const {
31
+ as = DEFAULT_INLINE_ELEMENT,
32
+ children,
33
+ gap,
34
+ space,
35
+ ...rest
36
+ } = props as InlineProps<typeof DEFAULT_INLINE_ELEMENT>
31
37
 
32
38
  return (
33
39
  <Box
34
40
  data-ui="Inline"
35
- {...restProps}
41
+ {...rest}
36
42
  align="center"
37
43
  as={as}
38
44
  display="flex"
39
45
  gap={gap ?? space}
40
- gapX={gapX}
41
- gapY={gapY}
42
- ref={ref}
43
46
  wrap="wrap"
44
47
  >
45
48
  {children}
46
49
  </Box>
47
50
  )
48
- })
51
+ }
49
52
 
50
- Inline.displayName = 'ForwardRef(Inline)'
53
+ Inline.displayName = 'Inline'
@@ -1,55 +1,57 @@
1
1
  import {composeClassNames, kbd, RadiusStyleProps, ResponsiveProp} from '@sanity/ui/css'
2
- import {FontTextSize, Space} from '@sanity/ui/theme'
3
- import {ForwardedRef, forwardRef} from 'react'
2
+ import {FontTextSize} from '@sanity/ui/theme'
4
3
 
5
- import {Props} from '../../types'
6
- import {Box, BoxProps} from '../box'
4
+ import {ComponentType, Props} from '../../types'
5
+ import {Box, BoxElementType, BoxOwnProps} from '../box'
7
6
  import {Text} from '../text'
8
7
 
9
- /**
10
- * @public
11
- */
12
- export interface KBDProps extends BoxProps, RadiusStyleProps {
13
- fontSize?: ResponsiveProp<FontTextSize>
14
- padding?: ResponsiveProp<Space>
15
- }
8
+ /** @public */
9
+ export const DEFAULT_KBD_ELEMENT = 'kbd'
10
+
11
+ /** @public */
12
+ export type KBDOwnProps = BoxOwnProps &
13
+ RadiusStyleProps & {
14
+ fontSize?: ResponsiveProp<FontTextSize>
15
+ }
16
+
17
+ /** @public */
18
+ export type KBDElementType = 'kbd' | ComponentType
19
+
20
+ /** @public */
21
+ export type KBDProps<E extends KBDElementType = KBDElementType> = Props<KBDOwnProps, E>
16
22
 
17
23
  /**
18
24
  * Used to define some text as keyboard input.
19
25
  *
20
26
  * @public
21
27
  */
22
- export const KBD = forwardRef(function KBD(
23
- props: Props<KBDProps, 'div'>,
24
- ref: ForwardedRef<HTMLDivElement>,
25
- ) {
28
+ export function KBD<E extends KBDElementType = typeof DEFAULT_KBD_ELEMENT>(props: KBDProps<E>) {
26
29
  const {
27
- as = 'kbd',
30
+ as = DEFAULT_KBD_ELEMENT,
28
31
  children,
29
32
  className,
30
33
  display = 'inline-block',
31
34
  fontSize = 0,
32
35
  padding = 1,
33
36
  radius = 2,
34
- ...restProps
35
- } = props
37
+ ...rest
38
+ } = props as KBDProps<typeof DEFAULT_KBD_ELEMENT>
36
39
 
37
40
  return (
38
41
  <Box
39
42
  data-ui="KBD"
40
- {...restProps}
41
- as={as}
43
+ {...rest}
44
+ as={as as BoxElementType}
42
45
  className={composeClassNames(className, kbd({radius}))}
43
46
  display={display}
44
47
  muted
45
48
  padding={padding}
46
- ref={ref}
47
49
  >
48
50
  <Text as="span" muted size={fontSize} weight="semibold">
49
51
  {children}
50
52
  </Text>
51
53
  </Box>
52
54
  )
53
- })
55
+ }
54
56
 
55
- KBD.displayName = 'ForwardRef(KBD)'
57
+ KBD.displayName = 'KBD'
@@ -1,52 +1,50 @@
1
1
  import {
2
2
  composeClassNames,
3
- FontStyleProps,
4
3
  label,
5
- LabelSize,
6
- ResponsiveProp,
4
+ LabelStyleProps,
7
5
  textOverflow,
8
6
  TextOverflowStyleProps,
9
7
  } from '@sanity/ui/css'
10
- import {ForwardedRef, forwardRef} from 'react'
11
8
 
12
- import {Props} from '../../types'
9
+ import {ComponentType, Props} from '../../types'
13
10
 
14
- /**
15
- * @public
16
- */
17
- export interface LabelProps extends FontStyleProps, TextOverflowStyleProps {
18
- accent?: boolean
19
- htmlFor?: string
20
- muted?: boolean
21
- size?: ResponsiveProp<LabelSize>
22
- }
11
+ /** @public */
12
+ export const DEFAULT_LABEL_ELEMENT = 'div'
13
+
14
+ /** @public */
15
+ export type LabelOwnProps = LabelStyleProps & TextOverflowStyleProps
16
+
17
+ /** @public */
18
+ export type LabelElementType = 'div' | 'label' | 'span' | ComponentType
19
+
20
+ /** @public */
21
+ export type LabelProps<E extends LabelElementType = LabelElementType> = Props<LabelOwnProps, E>
23
22
 
24
23
  /**
25
24
  * Typographic labels.
26
25
  *
27
26
  * @public
28
27
  */
29
- export const Label = forwardRef(function Label(
30
- props: Props<LabelProps, 'div'>,
31
- ref: ForwardedRef<HTMLDivElement>,
28
+ export function Label<E extends LabelElementType = typeof DEFAULT_LABEL_ELEMENT>(
29
+ props: LabelProps<E>,
32
30
  ) {
33
31
  const {
34
32
  accent,
35
33
  align,
36
- as: As = 'div',
34
+ as: Element = DEFAULT_LABEL_ELEMENT,
37
35
  children,
38
36
  className,
39
37
  muted = false,
40
38
  size = 1,
41
39
  textOverflow: textOverflowProp,
42
40
  weight = 'medium',
43
- ...restProps
41
+ ...rest
44
42
  } = props
45
43
 
46
44
  return (
47
- <As
45
+ <Element
48
46
  data-ui="Label"
49
- {...restProps}
47
+ {...rest}
50
48
  className={composeClassNames(
51
49
  className,
52
50
  label({
@@ -57,11 +55,16 @@ export const Label = forwardRef(function Label(
57
55
  weight,
58
56
  }),
59
57
  )}
60
- ref={ref}
61
58
  >
62
- <span className={textOverflow({textOverflow: textOverflowProp})}>{children}</span>
63
- </As>
59
+ <span
60
+ className={textOverflow({
61
+ textOverflow: textOverflowProp,
62
+ })}
63
+ >
64
+ {children}
65
+ </span>
66
+ </Element>
64
67
  )
65
- })
68
+ }
66
69
 
67
- Label.displayName = 'ForwardRef(Label)'
70
+ Label.displayName = 'Label'