@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,31 +1,44 @@
1
1
  import {_selectable, composeClassNames, SelectableStyleProps} from '@sanity/ui/css'
2
- import {ForwardedRef, forwardRef} from 'react'
3
2
 
4
- import {Props, SelectableTone} from '../../types'
5
- import {Box, BoxProps} from '../box'
3
+ import type {ComponentType, Props, SelectableTone} from '../../types'
4
+ import {Box, BoxOwnProps} from '../box'
6
5
 
7
6
  /** @internal */
8
- export interface SelectableProps extends BoxProps, SelectableStyleProps {
9
- disabled?: boolean
10
- href?: string
11
- tone?: SelectableTone
12
- type?: 'button'
13
- }
7
+ export const DEFAULT_SELECTABLE_ELEMENT = 'button'
8
+
9
+ /** @internal */
10
+ export type SelectableOwnProps = BoxOwnProps &
11
+ SelectableStyleProps & {
12
+ disabled?: boolean
13
+ href?: string
14
+ tone?: SelectableTone
15
+ type?: 'button'
16
+ }
17
+
18
+ /** @internal */
19
+ export type SelectableElementType = 'button' | 'a' | ComponentType
20
+
21
+ /** @internal */
22
+ export type SelectableProps<E extends SelectableElementType = SelectableElementType> = Props<
23
+ SelectableOwnProps,
24
+ E
25
+ >
14
26
 
15
27
  /** @internal */
16
- export const Selectable = forwardRef(function Selectable(
17
- props: Props<SelectableProps, 'div'>,
18
- ref: ForwardedRef<HTMLDivElement>,
28
+ export function Selectable<E extends SelectableElementType = typeof DEFAULT_SELECTABLE_ELEMENT>(
29
+ props: SelectableProps<E>,
19
30
  ) {
20
- const {className, radius, tone, ...restProps} = props
31
+ const {
32
+ as = DEFAULT_SELECTABLE_ELEMENT,
33
+ className,
34
+ radius,
35
+ tone,
36
+ ...rest
37
+ } = props as SelectableProps<typeof DEFAULT_SELECTABLE_ELEMENT>
21
38
 
22
39
  return (
23
- <Box
24
- {...restProps}
25
- className={composeClassNames(className, _selectable({radius, tone}))}
26
- ref={ref}
27
- />
40
+ <Box {...rest} as={as} className={composeClassNames(className, _selectable({radius, tone}))} />
28
41
  )
29
- })
42
+ }
30
43
 
31
- Selectable.displayName = 'ForwardRef(Selectable)'
44
+ Selectable.displayName = 'Selectable'
@@ -6,19 +6,19 @@ import {
6
6
  composeClassNames,
7
7
  ResponsiveProp,
8
8
  } from '@sanity/ui/css'
9
- import {AvatarSize, ThemeColorAvatarColorKey} from '@sanity/ui/theme'
10
- import {ForwardedRef, forwardRef, useCallback, useEffect, useMemo, useState} from 'react'
11
- import ReactIs from 'react-is'
9
+ import {ThemeColorAvatarColorKey} from '@sanity/ui/theme'
10
+ import {useCallback, useEffect, useMemo, useState} from 'react'
12
11
 
13
12
  import {useArrayProp} from '../../hooks'
14
- import {AvatarPosition, AvatarStatus, Props} from '../../types'
13
+ import type {AvatarPosition, AvatarSize, AvatarStatus, ComponentType, Props} from '../../types'
15
14
  import {Box} from '../box'
16
15
  import {Label} from '../label'
17
16
 
18
- /**
19
- * @public
20
- */
21
- export interface AvatarProps {
17
+ /** @public */
18
+ export const DEFAULT_AVATAR_ELEMENT = 'div'
19
+
20
+ /** @public */
21
+ export interface AvatarOwnProps {
22
22
  /** @beta */
23
23
  __unstable_hideInnerStroke?: boolean
24
24
  animateArrowFrom?: AvatarPosition
@@ -30,24 +30,29 @@ export interface AvatarProps {
30
30
  src?: string
31
31
  /**
32
32
  * The status of the entity this Avatar represents.
33
- * @alpha
33
+ * @deprecated Will be removed in next major version.
34
34
  */
35
35
  status?: AvatarStatus
36
36
  title?: string
37
37
  }
38
38
 
39
+ /** @public */
40
+ export type AvatarElementType = 'a' | 'button' | 'div' | 'span' | ComponentType
41
+
42
+ /** @public */
43
+ export type AvatarProps<E extends AvatarElementType = AvatarElementType> = Props<AvatarOwnProps, E>
44
+
39
45
  /**
40
46
  * Avatars are used to represent people and other agents (e.g. bots).
41
47
  *
42
48
  * @public
43
49
  */
44
- export const Avatar = forwardRef(function Avatar(
45
- props: Props<AvatarProps, 'div'>,
46
- ref: ForwardedRef<HTMLDivElement>,
50
+ export function Avatar<E extends AvatarElementType = typeof DEFAULT_AVATAR_ELEMENT>(
51
+ props: AvatarProps<E>,
47
52
  ) {
48
53
  const {
49
54
  __unstable_hideInnerStroke,
50
- as: asProp,
55
+ as: Element = DEFAULT_AVATAR_ELEMENT,
51
56
  className,
52
57
  color = 'gray',
53
58
  src,
@@ -56,11 +61,12 @@ export const Avatar = forwardRef(function Avatar(
56
61
  onImageLoadError,
57
62
  arrowPosition: arrowPositionProp,
58
63
  animateArrowFrom,
64
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
59
65
  status = 'online',
60
66
  size: sizeProp = 1,
61
- ...restProps
62
- } = props
63
- const As = ReactIs.isValidElementType(asProp) ? asProp : 'div'
67
+ ...rest
68
+ } = props as AvatarProps<typeof DEFAULT_AVATAR_ELEMENT>
69
+
64
70
  const size = useArrayProp(sizeProp)
65
71
 
66
72
  const [arrowPosition, setArrowPosition] = useState<AvatarPosition | undefined>(
@@ -103,17 +109,14 @@ export const Avatar = forwardRef(function Avatar(
103
109
  )
104
110
 
105
111
  return (
106
- <As
107
- // data-as={typeof As === 'string' ? As : undefined}
112
+ <Element
108
113
  data-hide-inner-stroke={__unstable_hideInnerStroke ? '' : undefined}
109
114
  data-ui="Avatar"
110
- {...restProps}
115
+ {...rest}
111
116
  aria-label={title}
112
117
  className={composeClassNames(className, avatar({color, size: sizeProp}))}
113
118
  data-arrow-position={arrowPosition}
114
119
  data-image-error={imageError ? '' : undefined}
115
- data-status={status}
116
- ref={ref}
117
120
  title={title}
118
121
  >
119
122
  <span className={avatarArrow()}>
@@ -134,13 +137,7 @@ export const Avatar = forwardRef(function Avatar(
134
137
  position="absolute"
135
138
  inset={0}
136
139
  >
137
- <Label
138
- align="center"
139
- as="span"
140
- size={initialsSize}
141
- style={{color: 'inherit'}}
142
- weight="medium"
143
- >
140
+ <Label align="center" as="span" size={initialsSize} weight="medium">
144
141
  {initials}
145
142
  </Label>
146
143
  </Box>
@@ -151,8 +148,8 @@ export const Avatar = forwardRef(function Avatar(
151
148
  <span />
152
149
  </Box>
153
150
  )}
154
- </As>
151
+ </Element>
155
152
  )
156
- })
153
+ }
157
154
 
158
- Avatar.displayName = 'ForwardRef(Avatar)'
155
+ Avatar.displayName = 'Avatar'
@@ -1,34 +1,42 @@
1
1
  import {avatarCounter, composeClassNames, ResponsiveProp} from '@sanity/ui/css'
2
- import {AvatarSize} from '@sanity/ui/theme'
3
- import {ForwardedRef, forwardRef, useMemo} from 'react'
2
+ import type {AvatarSize, FontLabelSize} from '@sanity/ui/theme'
3
+ import {useMemo} from 'react'
4
4
 
5
5
  import {useArrayProp} from '../../hooks'
6
- import {Props} from '../../types'
7
- import {Box, BoxProps} from '../box'
6
+ import {ComponentType, Props} from '../../types'
7
+ import {Box} from '../box'
8
8
  import {Label} from '../label'
9
9
 
10
- /**
11
- * @public
12
- */
13
- export interface AvatarCounterProps
14
- extends Omit<BoxProps, 'align' | 'className' | 'display' | 'justify' | 'paddingX' | 'sizing'> {
10
+ /** @public */
11
+ export const DEFAULT_AVATAR_COUNTER_ELEMENT = 'div'
12
+
13
+ /** @public */
14
+ export interface AvatarCounterOwnProps {
15
15
  count: number
16
16
  size?: ResponsiveProp<AvatarSize>
17
- /** @deprecated No longer supported. */
18
- tone?: 'navbar'
19
17
  }
20
18
 
21
- /**
22
- * @public
23
- */
24
- export const AvatarCounter = forwardRef(function AvatarCounter(
25
- props: Props<AvatarCounterProps, 'div'>,
26
- ref: ForwardedRef<HTMLDivElement>,
27
- ) {
28
- const {className, count, size: sizeProp = 1, ...restProps} = props
19
+ /** @public */
20
+ export type AvatarCounterElementType = 'button' | 'div' | 'span' | ComponentType
21
+
22
+ /** @public */
23
+ export type AvatarCounterProps<E extends AvatarCounterElementType = AvatarCounterElementType> =
24
+ Props<AvatarCounterOwnProps, E>
25
+
26
+ /** @public */
27
+ export function AvatarCounter<
28
+ E extends AvatarCounterElementType = typeof DEFAULT_AVATAR_COUNTER_ELEMENT,
29
+ >(props: AvatarCounterProps<E>) {
30
+ const {
31
+ as = DEFAULT_AVATAR_COUNTER_ELEMENT,
32
+ className,
33
+ count,
34
+ size: sizeProp = 1,
35
+ ...rest
36
+ } = props as AvatarCounterProps<typeof DEFAULT_AVATAR_COUNTER_ELEMENT>
29
37
  const size = useArrayProp(sizeProp)
30
38
 
31
- const fontSize = useMemo(
39
+ const labelSize: FontLabelSize[] = useMemo(
32
40
  () =>
33
41
  size.map((s) => {
34
42
  if (s === 1) return 1
@@ -43,20 +51,20 @@ export const AvatarCounter = forwardRef(function AvatarCounter(
43
51
  return (
44
52
  <Box
45
53
  data-ui="AvatarCounter"
46
- {...restProps}
54
+ {...rest}
47
55
  align="center"
56
+ as={as}
48
57
  className={composeClassNames(className, avatarCounter({size}))}
49
58
  display="flex"
50
59
  justify="center"
51
60
  paddingX={2}
52
- ref={ref}
53
61
  sizing="border"
54
62
  >
55
- <Label align="center" as="span" size={fontSize} weight="medium">
63
+ <Label align="center" as="span" size={labelSize} weight="medium">
56
64
  {count}
57
65
  </Label>
58
66
  </Box>
59
67
  )
60
- })
68
+ }
61
69
 
62
- AvatarCounter.displayName = 'ForwardRef(AvatarCounter)'
70
+ AvatarCounter.displayName = 'AvatarCounter'
@@ -1,22 +1,21 @@
1
1
  import {avatarStack, composeClassNames, ResponsiveProp} from '@sanity/ui/css'
2
2
  import {AvatarSize} from '@sanity/ui/theme'
3
- import {Children, cloneElement, ForwardedRef, forwardRef, isValidElement, ReactElement} from 'react'
3
+ import {Children, cloneElement, isValidElement, ReactElement} from 'react'
4
4
 
5
5
  import {useArrayProp} from '../../hooks'
6
- import {Props} from '../../types'
7
- import {Box, BoxProps} from '../box'
6
+ import {ComponentType, Props} from '../../types'
7
+ import {Box, BoxOwnProps} from '../box'
8
8
  import {AvatarProps} from './avatar'
9
9
  import {AvatarCounter} from './avatarCounter'
10
10
 
11
- /**
12
- * @public
13
- */
14
- export type AvatarStackChild = ReactElement<Props<AvatarProps, 'div'>> | null | undefined | false
11
+ /** @public */
12
+ export const DEFAULT_AVATAR_STACK_ELEMENT = 'div'
15
13
 
16
- /**
17
- * @public
18
- */
19
- export interface AvatarStackProps extends Omit<BoxProps, 'align' | 'className' | 'display'> {
14
+ /** @public */
15
+ export type AvatarStackChild = ReactElement<AvatarProps<'div'>> | null | undefined | false
16
+
17
+ /** @public */
18
+ export type AvatarStackOwnProps = Omit<BoxOwnProps, 'align' | 'display'> & {
20
19
  children: AvatarStackChild | AvatarStackChild[]
21
20
  maxLength?: number
22
21
  size?: ResponsiveProp<AvatarSize>
@@ -24,22 +23,30 @@ export interface AvatarStackProps extends Omit<BoxProps, 'align' | 'className' |
24
23
  tone?: 'navbar'
25
24
  }
26
25
 
27
- /**
28
- * @public
29
- */
30
- export const AvatarStack = forwardRef(function AvatarStack(
31
- props: Props<AvatarStackProps, 'div'>,
32
- ref: ForwardedRef<HTMLDivElement>,
26
+ /** @public */
27
+ export type AvatarStackElementType = 'div' | 'span' | ComponentType
28
+
29
+ /** @public */
30
+ export type AvatarStackProps<E extends AvatarStackElementType = AvatarStackElementType> = Props<
31
+ AvatarStackOwnProps,
32
+ E
33
+ >
34
+
35
+ /** @public */
36
+ export function AvatarStack<E extends AvatarStackElementType = typeof DEFAULT_AVATAR_STACK_ELEMENT>(
37
+ props: AvatarStackProps<E>,
33
38
  ) {
34
39
  const {
40
+ as = DEFAULT_AVATAR_STACK_ELEMENT,
35
41
  children: childrenProp,
36
42
  className,
37
43
  maxLength: maxLengthProp = 4,
38
44
  size: sizeProp = 1,
39
- ...restProps
40
- } = props
45
+ ...rest
46
+ } = props as AvatarStackProps<typeof DEFAULT_AVATAR_STACK_ELEMENT>
47
+
41
48
  const children = Children.toArray(childrenProp).filter(isValidElement) as ReactElement<
42
- Props<AvatarProps, 'div'>
49
+ AvatarProps<'div'>
43
50
  >[]
44
51
  const maxLength = Math.max(maxLengthProp, 0)
45
52
  const size = useArrayProp(sizeProp)
@@ -52,11 +59,11 @@ export const AvatarStack = forwardRef(function AvatarStack(
52
59
  return (
53
60
  <Box
54
61
  data-ui="AvatarStack"
55
- {...restProps}
62
+ {...rest}
56
63
  align="center"
64
+ as={as}
57
65
  className={composeClassNames(className, avatarStack({size}))}
58
66
  display="flex"
59
- ref={ref}
60
67
  >
61
68
  {len === 0 && (
62
69
  <Box flex="none">
@@ -77,6 +84,6 @@ export const AvatarStack = forwardRef(function AvatarStack(
77
84
  ))}
78
85
  </Box>
79
86
  )
80
- })
87
+ }
81
88
 
82
- AvatarStack.displayName = 'ForwardRef(AvatarStack)'
89
+ AvatarStack.displayName = 'AvatarStack'
@@ -4,6 +4,7 @@ import {AvatarSize} from '../../types'
4
4
 
5
5
  /**
6
6
  * @internal
7
+ * @deprecated This will be removed in next major version.
7
8
  */
8
9
  export interface AvatarRootStyleProps {
9
10
  $color: ThemeColorAvatarColorKey
@@ -11,6 +12,7 @@ export interface AvatarRootStyleProps {
11
12
 
12
13
  /**
13
14
  * @internal
15
+ * @deprecated This will be removed in next major version.
14
16
  */
15
17
  export interface ResponsiveAvatarSizeStyleProps {
16
18
  $size: AvatarSize[]
@@ -2,13 +2,11 @@ import {Badge, Flex} from '@sanity/ui'
2
2
  import {useAction, useSelect, useText} from '@sanity/ui-workshop'
3
3
 
4
4
  import {
5
- WORKSHOP_BADGE_MODE_OPTIONS,
6
5
  WORKSHOP_BADGE_TONE_OPTIONS,
7
6
  WORKSHOP_SPACE_OPTIONS,
8
7
  } from '../../../../../workshop/constants'
9
8
 
10
9
  export default function PropsStory() {
11
- const mode = useSelect('Mode (deprecated)', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
12
10
  const paddingX = useSelect('Padding X', WORKSHOP_SPACE_OPTIONS, 1, 'Props')
13
11
  const paddingY = useSelect('Padding Y', WORKSHOP_SPACE_OPTIONS, 1, 'Props')
14
12
  const tone = useSelect('Tone', WORKSHOP_BADGE_TONE_OPTIONS, 'default', 'Props')
@@ -16,13 +14,7 @@ export default function PropsStory() {
16
14
 
17
15
  return (
18
16
  <Flex align="center" height="fill" justify="center">
19
- <Badge
20
- mode={mode}
21
- onClick={useAction('onClick')}
22
- paddingX={paddingX}
23
- paddingY={paddingY}
24
- tone={tone}
25
- >
17
+ <Badge onClick={useAction('onClick')} paddingX={paddingX} paddingY={paddingY} tone={tone}>
26
18
  {textProp}
27
19
  </Badge>
28
20
  </Flex>
@@ -1,17 +1,12 @@
1
1
  import {Badge, Flex} from '@sanity/ui'
2
2
  import {THEME_COLOR_STATE_TONES} from '@sanity/ui/theme'
3
- import {useSelect} from '@sanity/ui-workshop'
4
-
5
- import {WORKSHOP_BADGE_MODE_OPTIONS} from '../../../../../workshop/constants'
6
3
 
7
4
  export default function Tones() {
8
- const mode = useSelect('Mode (deprecated)', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
9
-
10
5
  return (
11
6
  <Flex align="center" height="fill" justify="center" padding={4} sizing="border">
12
7
  <Flex align="center" direction="column" gap={2}>
13
8
  {THEME_COLOR_STATE_TONES.map((tone) => (
14
- <Badge key={tone} mode={mode} tone={tone}>
9
+ <Badge key={tone} tone={tone}>
15
10
  {tone}
16
11
  </Badge>
17
12
  ))}
@@ -1,48 +1,51 @@
1
- import {badge, composeClassNames, RadiusStyleProps} from '@sanity/ui/css'
2
- import {ForwardedRef, forwardRef} from 'react'
1
+ import type {PaddingStyleProps, RadiusStyleProps, ResponsiveProp} from '@sanity/ui/css'
2
+ import {badge, composeClassNames} from '@sanity/ui/css'
3
+ import {FontTextSize} from '@sanity/ui/theme'
3
4
 
4
- import {BadgeMode, BadgeTone, Props} from '../../types'
5
- import {Box, BoxProps} from '../box'
6
- import {Text, TextProps} from '../text'
5
+ import type {BadgeTone, ComponentType, Props} from '../../types'
6
+ import {Box} from '../box'
7
+ import {Text} from '../text'
7
8
 
8
- /**
9
- * @public
10
- */
11
- export interface BadgeProps extends BoxProps, RadiusStyleProps {
12
- fontSize?: number | number[]
13
- /** @deprecated No longer used. */
14
- mode?: BadgeMode
15
- textAlign?: TextProps['align']
16
- tone?: BadgeTone
17
- }
9
+ /** @public */
10
+ export const DEFAULT_BADGE_ELEMENT = 'span'
11
+
12
+ /** @public */
13
+ export type BadgeOwnProps = PaddingStyleProps &
14
+ RadiusStyleProps & {
15
+ fontSize?: ResponsiveProp<FontTextSize>
16
+ tone?: BadgeTone
17
+ }
18
+
19
+ /** @public */
20
+ export type BadgeElementType = 'div' | 'span' | ComponentType
21
+
22
+ /** @public */
23
+ export type BadgeProps<E extends BadgeElementType = BadgeElementType> = Props<BadgeOwnProps, E>
18
24
 
19
25
  /**
20
26
  * Badges are used to tag resources.
21
27
  *
22
28
  * @public
23
29
  */
24
- export const Badge = forwardRef(function Badge(
25
- props: Props<BadgeProps, 'div'>,
26
- ref: ForwardedRef<HTMLDivElement>,
30
+ export function Badge<E extends BadgeElementType = typeof DEFAULT_BADGE_ELEMENT>(
31
+ props: BadgeProps<E>,
27
32
  ) {
28
33
  const {
34
+ as = DEFAULT_BADGE_ELEMENT,
29
35
  children,
30
36
  className,
31
- display = 'inline-block',
32
37
  fontSize = 1,
33
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
- mode: _deprecated_mode,
35
38
  padding = 1,
36
39
  radius = 2,
37
- textAlign,
38
40
  tone = 'default',
39
- ...restProps
40
- } = props
41
+ ...rest
42
+ } = props as BadgeProps<typeof DEFAULT_BADGE_ELEMENT>
41
43
 
42
44
  return (
43
45
  <Box
44
46
  data-ui="Badge"
45
- {...restProps}
47
+ {...rest}
48
+ as={as}
46
49
  className={composeClassNames(
47
50
  className,
48
51
  badge({
@@ -50,15 +53,13 @@ export const Badge = forwardRef(function Badge(
50
53
  tone,
51
54
  }),
52
55
  )}
53
- display={display}
56
+ display="inline-flex"
57
+ maxWidth="fill"
54
58
  padding={padding}
55
- ref={ref}
56
59
  >
57
- <Text align={textAlign} size={fontSize}>
58
- {children}
59
- </Text>
60
+ <Text size={fontSize}>{children}</Text>
60
61
  </Box>
61
62
  )
62
- })
63
+ }
63
64
 
64
- Badge.displayName = 'ForwardRef(Badge)'
65
+ Badge.displayName = 'Badge'
@@ -1,7 +1,8 @@
1
- import {BadgeTone} from '../../types'
1
+ import type {BadgeTone} from '../../types'
2
2
 
3
3
  /**
4
4
  * @internal
5
+ * @deprecated
5
6
  */
6
7
  export interface BadgeStyleProps {
7
8
  $tone: BadgeTone