@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,132 +1,53 @@
1
- import {
2
- codeSkeleton,
3
- composeClassNames,
4
- headingSkeleton,
5
- labelSkeleton,
6
- ResponsiveProp,
7
- textSkeleton,
8
- } from '@sanity/ui/css'
9
- import {FontCodeSize, FontHeadingSize, FontLabelSize, FontTextSize} from '@sanity/ui/theme'
10
- import {ForwardedRef, forwardRef} from 'react'
1
+ import {composeClassNames, ResponsiveProp, textSkeleton} from '@sanity/ui/css'
2
+ import {FontTextSize} from '@sanity/ui/theme'
11
3
 
12
4
  import {Props} from '../../types'
13
- import {Skeleton, SkeletonProps} from './skeleton'
5
+ import {Skeleton, SkeletonElementType, SkeletonOwnProps} from './skeleton'
14
6
 
15
- /**
16
- * This API might change. DO NOT USE IN PRODUCTION.
17
- * @beta
18
- */
19
- export interface TextSkeletonProps extends SkeletonProps {
20
- size?: ResponsiveProp<FontTextSize>
21
- }
7
+ /** @public */
8
+ export const DEFAULT_TEXT_SKELETON_ELEMENT = 'div'
22
9
 
23
- /**
24
- * This API might change. DO NOT USE IN PRODUCTION.
25
- * @beta
26
- */
27
- export interface LabelSkeletonProps extends SkeletonProps {
28
- size?: ResponsiveProp<FontLabelSize>
10
+ /** @beta */
11
+ export type TextSkeletonOwnProps = SkeletonOwnProps & {
12
+ size?: ResponsiveProp<FontTextSize>
29
13
  }
30
14
 
31
- /**
32
- * This API might change. DO NOT USE IN PRODUCTION.
33
- * @beta
34
- */
35
- export interface HeadingSkeletonProps extends SkeletonProps {
36
- size?: ResponsiveProp<FontHeadingSize>
37
- }
15
+ /** @public */
16
+ export type TextSkeletonElementType = SkeletonElementType
38
17
 
39
18
  /**
40
19
  * This API might change. DO NOT USE IN PRODUCTION.
41
20
  * @beta
42
21
  */
43
- export interface CodeSkeletonProps extends SkeletonProps {
44
- size?: ResponsiveProp<FontCodeSize>
45
- }
22
+ export type TextSkeletonProps<E extends TextSkeletonElementType = TextSkeletonElementType> = Props<
23
+ TextSkeletonOwnProps,
24
+ E
25
+ >
46
26
 
47
27
  /**
48
28
  * This API might change. DO NOT USE IN PRODUCTION.
49
29
  * @beta
50
30
  */
51
- export const TextSkeleton = forwardRef(function TextSkeleton(
52
- props: Props<TextSkeletonProps, 'div'>,
53
- ref: ForwardedRef<HTMLDivElement>,
54
- ) {
55
- const {className, size = 2, ...restProps} = props
31
+ export function TextSkeleton<
32
+ E extends TextSkeletonElementType = typeof DEFAULT_TEXT_SKELETON_ELEMENT,
33
+ >(props: TextSkeletonProps<E>) {
34
+ const {
35
+ className,
36
+ size = 2,
37
+ ...rest
38
+ } = props as TextSkeletonProps<typeof DEFAULT_TEXT_SKELETON_ELEMENT>
56
39
 
57
40
  return (
58
41
  <Skeleton
59
- data-ui="TextSkeleton"
60
- {...restProps}
61
- className={composeClassNames(className, textSkeleton({size}))}
62
- ref={ref}
42
+ {...rest}
43
+ className={composeClassNames(
44
+ className,
45
+ textSkeleton({
46
+ size,
47
+ }),
48
+ )}
63
49
  />
64
50
  )
65
- })
66
-
67
- TextSkeleton.displayName = 'ForwardRef(TextSkeleton)'
68
-
69
- /**
70
- * This API might change. DO NOT USE IN PRODUCTION.
71
- * @beta
72
- */
73
- export const LabelSkeleton = forwardRef(function TextSkeleton(
74
- props: Props<LabelSkeletonProps, 'div'>,
75
- ref: ForwardedRef<HTMLDivElement>,
76
- ) {
77
- const {className, size = 2, ...restProps} = props
78
-
79
- return (
80
- <Skeleton
81
- data-ui="LabelSkeleton"
82
- {...restProps}
83
- className={composeClassNames(className, labelSkeleton({size}))}
84
- ref={ref}
85
- />
86
- )
87
- })
88
-
89
- LabelSkeleton.displayName = 'ForwardRef(LabelSkeleton)'
90
-
91
- /**
92
- * This API might change. DO NOT USE IN PRODUCTION.
93
- * @beta
94
- */
95
- export const HeadingSkeleton = forwardRef(function TextSkeleton(
96
- props: Props<HeadingSkeletonProps, 'div'>,
97
- ref: ForwardedRef<HTMLDivElement>,
98
- ) {
99
- const {className, size = 2, ...restProps} = props
100
-
101
- return (
102
- <Skeleton
103
- {...restProps}
104
- className={composeClassNames(className, headingSkeleton({size}))}
105
- ref={ref}
106
- />
107
- )
108
- })
109
-
110
- HeadingSkeleton.displayName = 'ForwardRef(HeadingSkeleton)'
111
-
112
- /**
113
- * This API might change. DO NOT USE IN PRODUCTION.
114
- * @beta
115
- */
116
- export const CodeSkeleton = forwardRef(function TextSkeleton(
117
- props: Props<CodeSkeletonProps, 'div'>,
118
- ref: ForwardedRef<HTMLDivElement>,
119
- ) {
120
- const {className, size = 2, ...restProps} = props
121
-
122
- return (
123
- <Skeleton
124
- // root
125
- {...restProps}
126
- className={composeClassNames(className, codeSkeleton({size}))}
127
- ref={ref}
128
- />
129
- )
130
- })
51
+ }
131
52
 
132
- CodeSkeleton.displayName = 'ForwardRef(CodeSkeleton)'
53
+ TextSkeleton.displayName = 'TextSkeleton'
@@ -3,8 +3,6 @@ import {FontTextSize, Space} from '@sanity/ui/theme'
3
3
  import {
4
4
  ElementType,
5
5
  FocusEvent,
6
- ForwardedRef,
7
- forwardRef,
8
6
  ReactNode,
9
7
  useCallback,
10
8
  useEffect,
@@ -13,12 +11,13 @@ import {
13
11
  } from 'react'
14
12
 
15
13
  import {Button} from '../../primitives'
16
- import {ButtonTone, Props} from '../../types'
14
+ import {ButtonTone, ComponentType, Props} from '../../types'
17
15
 
18
- /**
19
- * @public
20
- */
21
- export interface TabProps {
16
+ /** @public */
17
+ export const DEFAULT_TAB_ELEMENT = 'button'
18
+
19
+ /** @public */
20
+ export type TabOwnProps = {
22
21
  /**
23
22
  * The `id` of the corresponding `TabPanel` component.
24
23
  */
@@ -33,14 +32,16 @@ export interface TabProps {
33
32
  'tone'?: ButtonTone
34
33
  }
35
34
 
36
- /**
37
- * @public
38
- */
39
- export const Tab = forwardRef(function Tab(
40
- props: Props<TabProps, 'button'>,
41
- forwardedRef: ForwardedRef<HTMLButtonElement>,
42
- ) {
35
+ /** @public */
36
+ export type TabElementType = 'button' | ComponentType
37
+
38
+ /** @public */
39
+ export type TabProps<E extends TabElementType = TabElementType> = Props<TabOwnProps, E>
40
+
41
+ /** @public */
42
+ export function Tab<E extends TabElementType = typeof DEFAULT_TAB_ELEMENT>(props: TabProps<E>) {
43
43
  const {
44
+ as = DEFAULT_TAB_ELEMENT,
44
45
  icon,
45
46
  id,
46
47
  focused,
@@ -49,9 +50,11 @@ export const Tab = forwardRef(function Tab(
49
50
  onClick,
50
51
  onFocus,
51
52
  padding = 2,
53
+ ref: forwardedRef,
52
54
  selected,
53
- ...restProps
54
- } = props
55
+ ...rest
56
+ } = props as TabProps<typeof DEFAULT_TAB_ELEMENT>
57
+
55
58
  const ref = useRef<HTMLButtonElement | null>(null)
56
59
  const focusedRef = useRef(false)
57
60
 
@@ -82,8 +85,9 @@ export const Tab = forwardRef(function Tab(
82
85
  return (
83
86
  <Button
84
87
  data-ui="Tab"
85
- {...restProps}
88
+ {...rest}
86
89
  aria-selected={selected ? 'true' : 'false'}
90
+ as={as}
87
91
  fontSize={fontSize}
88
92
  icon={icon}
89
93
  id={id}
@@ -100,6 +104,6 @@ export const Tab = forwardRef(function Tab(
100
104
  type="button"
101
105
  />
102
106
  )
103
- })
107
+ }
104
108
 
105
- Tab.displayName = 'ForwardRef(Tab)'
109
+ Tab.displayName = 'Tab'
@@ -1,42 +1,39 @@
1
- import {
2
- Children,
3
- cloneElement,
4
- ForwardedRef,
5
- forwardRef,
6
- KeyboardEvent,
7
- ReactElement,
8
- useCallback,
9
- useState,
10
- } from 'react'
11
-
12
- import {Inline, InlineProps} from '../../primitives'
13
- import {Props} from '../../types'
1
+ import {Children, cloneElement, KeyboardEvent, ReactElement, useCallback, useState} from 'react'
2
+
3
+ import {Inline, InlineOwnProps} from '../../primitives'
4
+ import {ComponentType, Props} from '../../types'
14
5
  import {TabProps} from './tab'
15
6
 
16
- /**
17
- * @public
18
- */
7
+ /** @public */
8
+ export const DEFAULT_TAB_LIST_ELEMENT = 'div'
9
+
10
+ /** @public */
19
11
  export type TabListChild = ReactElement<Props<TabProps, 'button'>> | null | undefined | false
20
12
 
21
- /**
22
- * @public
23
- */
24
- export interface TabListProps extends Omit<InlineProps, 'as' | 'height'> {
13
+ /** @public */
14
+ export type TabListOwnProps = Omit<InlineOwnProps, 'as' | 'height'> & {
25
15
  children: TabListChild[]
26
16
  }
27
17
 
28
- function _isReactElement(node: unknown): node is ReactElement<Props<TabProps, 'button'>> {
29
- return Boolean(node)
30
- }
18
+ /** @public */
19
+ export type TabListElementType = 'div' | 'span' | ComponentType
20
+
21
+ /** @public */
22
+ export type TabListProps<E extends TabListElementType = TabListElementType> = Props<
23
+ TabListOwnProps,
24
+ E
25
+ >
31
26
 
32
- /**
33
- * @public
34
- */
35
- export const TabList = forwardRef(function TabList(
36
- props: Props<TabListProps, 'div'>,
37
- ref: ForwardedRef<HTMLDivElement>,
27
+ /** @public */
28
+ export function TabList<E extends TabListElementType = typeof DEFAULT_TAB_LIST_ELEMENT>(
29
+ props: TabListProps<E>,
38
30
  ) {
39
- const {children: childrenProp, ...restProps} = props
31
+ const {
32
+ as = DEFAULT_TAB_LIST_ELEMENT,
33
+ children: childrenProp,
34
+ ...rest
35
+ } = props as TabListProps<typeof DEFAULT_TAB_LIST_ELEMENT>
36
+
40
37
  const [focusedIndex, setFocusedIndex] = useState(-1)
41
38
 
42
39
  const children = Children.toArray(childrenProp).filter(_isReactElement)
@@ -65,10 +62,14 @@ export const TabList = forwardRef(function TabList(
65
62
  )
66
63
 
67
64
  return (
68
- <Inline data-ui="TabList" {...restProps} onKeyDown={handleKeyDown} ref={ref} role="tablist">
65
+ <Inline data-ui="TabList" {...rest} as={as} onKeyDown={handleKeyDown} role="tablist">
69
66
  {tabs}
70
67
  </Inline>
71
68
  )
72
- })
69
+ }
70
+
71
+ TabList.displayName = 'TabList'
73
72
 
74
- TabList.displayName = 'ForwardRef(TabList)'
73
+ function _isReactElement(node: unknown): node is ReactElement<Props<TabProps, 'button'>> {
74
+ return Boolean(node)
75
+ }
@@ -1,12 +1,11 @@
1
- import {ForwardedRef, forwardRef} from 'react'
1
+ import {Box, BoxOwnProps} from '../../primitives'
2
+ import {ComponentType, Props} from '../../types'
2
3
 
3
- import {Box, BoxProps} from '../../primitives'
4
- import {Props} from '../../types'
4
+ /** @public */
5
+ export const DEFAULT_TAB_PANEL_ELEMENT = 'div'
5
6
 
6
- /**
7
- * @public
8
- */
9
- export interface TabPanelProps extends BoxProps {
7
+ /** @public */
8
+ export type TabPanelOwnProps = BoxOwnProps & {
10
9
  /**
11
10
  * The `id` of the correlating `Tab` component.
12
11
  */
@@ -14,27 +13,34 @@ export interface TabPanelProps extends BoxProps {
14
13
  'id': string
15
14
  }
16
15
 
17
- /**
18
- * @public
19
- */
20
- export const TabPanel = forwardRef(function TabPanel(
21
- props: Props<TabPanelProps, 'div'>,
22
- ref: ForwardedRef<HTMLDivElement>,
16
+ /** @public */
17
+ export type TabPanelElementType = 'div' | 'span' | ComponentType
18
+
19
+ /** @public */
20
+ export type TabPanelProps<E extends TabPanelElementType = TabPanelElementType> = Props<
21
+ TabPanelOwnProps,
22
+ E
23
+ >
24
+
25
+ /** @public */
26
+ export function TabPanel<E extends TabPanelElementType = typeof DEFAULT_TAB_PANEL_ELEMENT>(
27
+ props: TabPanelProps<E>,
23
28
  ) {
24
- const {flex, ...restProps} = props
29
+ const {as = DEFAULT_TAB_PANEL_ELEMENT, ...rest} = props as TabPanelProps<
30
+ typeof DEFAULT_TAB_PANEL_ELEMENT
31
+ >
25
32
 
26
33
  return (
27
34
  <Box
28
35
  data-ui="TabPanel"
29
- {...restProps}
30
- flex={flex}
31
- ref={ref}
36
+ {...rest}
37
+ as={as}
32
38
  role="tabpanel"
33
39
  tabIndex={props.tabIndex === undefined ? 0 : props.tabIndex}
34
40
  >
35
41
  {props.children}
36
42
  </Box>
37
43
  )
38
- })
44
+ }
39
45
 
40
- TabPanel.displayName = 'ForwardRef(TabPanel)'
46
+ TabPanel.displayName = 'TabPanel'
@@ -8,16 +8,17 @@ import {
8
8
  } from '@sanity/ui/css'
9
9
  import {ThemeColorStateToneKey} from '@sanity/ui/theme'
10
10
  import {motion, type Variant, type Variants} from 'framer-motion'
11
- import {ReactElement, ReactNode} from 'react'
11
+ import {ReactNode} from 'react'
12
12
 
13
13
  import {usePrefersReducedMotion} from '../../hooks/usePrefersReducedMotion'
14
14
  import {Box, Button, Card, Flex, Stack, Text} from '../../primitives'
15
- import {ButtonTone, Props} from '../../types'
15
+ import {ButtonTone, ComponentType, Props} from '../../types'
16
16
 
17
- /**
18
- * @public
19
- */
20
- export interface ToastProps extends RadiusStyleProps {
17
+ /** @public */
18
+ export const DEFAULT_TOAST_ELEMENT = 'li'
19
+
20
+ /** @public */
21
+ export type ToastOwnProps = RadiusStyleProps & {
21
22
  closable?: boolean
22
23
  description?: ReactNode
23
24
  onClose?: () => void
@@ -27,6 +28,12 @@ export interface ToastProps extends RadiusStyleProps {
27
28
  updatedAt?: number
28
29
  }
29
30
 
31
+ /** @public */
32
+ export type ToastElementType = 'li' | ComponentType
33
+
34
+ /** @public */
35
+ export type ToastProps<E extends ToastElementType = ToastElementType> = Props<ToastOwnProps, E>
36
+
30
37
  const ROLES = {
31
38
  error: 'alert',
32
39
  warning: 'alert',
@@ -59,13 +66,11 @@ const LONG_ENOUGH_BUT_NOT_TOO_LONG = 1000 * 60 * 60 * 24 * 24
59
66
  *
60
67
  * @public
61
68
  */
62
- export function Toast(
63
- props: Omit<
64
- Props<ToastProps, 'div'>,
65
- 'onDrag' | 'onDragEnd' | 'onDragStart' | 'onAnimationStart'
66
- >,
67
- ): ReactElement {
69
+ export function Toast<E extends ToastElementType = typeof DEFAULT_TOAST_ELEMENT>(
70
+ props: ToastProps<E>,
71
+ ) {
68
72
  const {
73
+ as = DEFAULT_TOAST_ELEMENT,
69
74
  closable,
70
75
  description,
71
76
  duration,
@@ -74,8 +79,8 @@ export function Toast(
74
79
  title,
75
80
  status,
76
81
  updatedAt,
77
- ...restProps
78
- } = props
82
+ ...rest
83
+ } = props as ToastProps<typeof DEFAULT_TOAST_ELEMENT>
79
84
 
80
85
  const cardTone = status ? STATUS_CARD_TONE[status] : 'default'
81
86
  const buttonTone = status ? BUTTON_TONE[status] : 'default'
@@ -93,11 +98,11 @@ export function Toast(
93
98
 
94
99
  return (
95
100
  <MotionCard
96
- as="li"
101
+ as={as}
97
102
  className={toast()}
98
103
  data-ui="Toast"
99
104
  role={role}
100
- {...restProps}
105
+ {...rest}
101
106
  data-has-duration={hasDuration ? '' : undefined}
102
107
  custom={visualDuration}
103
108
  radius={radius}
@@ -1,26 +1,44 @@
1
1
  import {GapStyleProps, PaddingStyleProps, toastLayer} from '@sanity/ui/css'
2
- import {ReactNode} from 'react'
3
2
 
4
3
  import {Grid} from '../../primitives/grid'
4
+ import {ComponentType, Props} from '../../types'
5
5
  import {useLayer} from '../../utils'
6
6
 
7
- /**
8
- * @public
9
- */
10
- export interface ToastLayerProps extends GapStyleProps, PaddingStyleProps {
11
- children: ReactNode
12
- }
7
+ /** @internal */
8
+ export const DEFAULT_TOAST_LAYER_ELEMENT = 'ul'
9
+
10
+ /** @internal */
11
+ export type ToastLayerOwnProps = GapStyleProps & PaddingStyleProps
12
+
13
+ /** @internal */
14
+ export type ToastLayerElementType = 'ul' | ComponentType
15
+
16
+ /** @internal */
17
+ export type ToastLayerProps<E extends ToastLayerElementType = ToastLayerElementType> = Props<
18
+ ToastLayerOwnProps,
19
+ E
20
+ >
13
21
 
14
22
  /**
15
23
  * @internal
16
24
  */
17
- export function ToastLayer(props: ToastLayerProps): React.JSX.Element {
18
- const {children, padding = 4, paddingX, paddingY, gap = 3} = props
25
+ export function ToastLayer<E extends ToastLayerElementType = typeof DEFAULT_TOAST_LAYER_ELEMENT>(
26
+ props: ToastLayerProps<E>,
27
+ ) {
28
+ const {
29
+ as = DEFAULT_TOAST_LAYER_ELEMENT,
30
+ children,
31
+ padding = 4,
32
+ paddingX,
33
+ paddingY,
34
+ gap = 3,
35
+ } = props as ToastLayerProps<typeof DEFAULT_TOAST_LAYER_ELEMENT>
36
+
19
37
  const {zIndex} = useLayer()
20
38
 
21
39
  return (
22
40
  <Grid
23
- as="ul"
41
+ as={as}
24
42
  className={toastLayer()}
25
43
  data-ui="ToastProvider"
26
44
  padding={padding}
@@ -16,17 +16,13 @@ type ToastState = {
16
16
  params: ToastParams
17
17
  }[]
18
18
 
19
- /**
20
- * @public
21
- */
19
+ /** @public */
22
20
  export interface ToastProviderProps extends Omit<ToastLayerProps, 'children'> {
23
21
  children?: React.ReactNode
24
22
  zOffset?: number | number[]
25
23
  }
26
24
 
27
- /**
28
- * @public
29
- */
25
+ /** @public */
30
26
  export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
31
27
  const {children, padding, paddingX, paddingY, gap, zOffset = 1} = props
32
28
  const [state, setState] = useState<ToastState>([])
@@ -1,8 +1,6 @@
1
1
  import {ReactNode} from 'react'
2
2
 
3
- /**
4
- * @public
5
- */
3
+ /** @public */
6
4
  export interface ToastParams {
7
5
  closable?: boolean
8
6
  description?: ReactNode
@@ -13,9 +11,7 @@ export interface ToastParams {
13
11
  status?: 'error' | 'warning' | 'success' | 'info'
14
12
  }
15
13
 
16
- /**
17
- * @public
18
- */
14
+ /** @public */
19
15
  export interface ToastContextValue {
20
16
  version: 0.0
21
17
  /**
@@ -4,9 +4,7 @@ import {isRecord} from '../../lib/isRecord'
4
4
  import {ToastContext} from './toastContext'
5
5
  import {ToastContextValue} from './types'
6
6
 
7
- /**
8
- * @public
9
- */
7
+ /** @public */
10
8
  export function useToast(): ToastContextValue {
11
9
  const value = useContext(ToastContext)
12
10