@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,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,62 @@
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 =
19
+ | 'div'
20
+ | 'h1'
21
+ | 'h2'
22
+ | 'h3'
23
+ | 'h4'
24
+ | 'h5'
25
+ | 'h6'
26
+ | 'label'
27
+ | 'li'
28
+ | 'p'
29
+ | 'span'
30
+ | ComponentType
31
+
32
+ /** @public */
33
+ export type LabelProps<E extends LabelElementType = LabelElementType> = Props<LabelOwnProps, E>
23
34
 
24
35
  /**
25
36
  * Typographic labels.
26
37
  *
27
38
  * @public
28
39
  */
29
- export const Label = forwardRef(function Label(
30
- props: Props<LabelProps, 'div'>,
31
- ref: ForwardedRef<HTMLDivElement>,
40
+ export function Label<E extends LabelElementType = typeof DEFAULT_LABEL_ELEMENT>(
41
+ props: LabelProps<E>,
32
42
  ) {
33
43
  const {
34
44
  accent,
35
45
  align,
36
- as: As = 'div',
46
+ as: Element = DEFAULT_LABEL_ELEMENT,
37
47
  children,
38
48
  className,
39
49
  muted = false,
40
50
  size = 1,
41
51
  textOverflow: textOverflowProp,
42
52
  weight = 'medium',
43
- ...restProps
53
+ ...rest
44
54
  } = props
45
55
 
46
56
  return (
47
- <As
57
+ <Element
48
58
  data-ui="Label"
49
- {...restProps}
59
+ {...rest}
50
60
  className={composeClassNames(
51
61
  className,
52
62
  label({
@@ -57,11 +67,16 @@ export const Label = forwardRef(function Label(
57
67
  weight,
58
68
  }),
59
69
  )}
60
- ref={ref}
61
70
  >
62
- <span className={textOverflow({textOverflow: textOverflowProp})}>{children}</span>
63
- </As>
71
+ <span
72
+ className={textOverflow({
73
+ textOverflow: textOverflowProp,
74
+ })}
75
+ >
76
+ {children}
77
+ </span>
78
+ </Element>
64
79
  )
65
- })
80
+ }
66
81
 
67
- Label.displayName = 'ForwardRef(Label)'
82
+ Label.displayName = 'Label'