@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
@@ -0,0 +1,92 @@
1
+ import {type FocusEvent, useCallback, useEffect, useImperativeHandle, useRef} from 'react'
2
+
3
+ import {EMPTY_RECORD} from '../../constants'
4
+ import {containsOrEqualsElement, isHTMLElement} from '../../helpers'
5
+ import {Card, CardElementType} from '../../primitives'
6
+ import {Props} from '../../types'
7
+ import {LayerElementType, LayerOwnProps} from './layer'
8
+ import {useLayer} from './useLayer'
9
+
10
+ /** @internal */
11
+ export const DEFAULT_LAYER_CARD_ELEMENT = 'div'
12
+
13
+ /** @internal */
14
+ export type LayerCardOwnProps = Omit<LayerOwnProps, 'zOffset'>
15
+
16
+ /** @internal */
17
+ export type LayerCardElementType = LayerElementType
18
+
19
+ /** @internal */
20
+ export type LayerCardProps<E extends LayerCardElementType = LayerCardElementType> = Props<
21
+ LayerCardOwnProps,
22
+ E
23
+ >
24
+
25
+ /** @internal */
26
+ export function LayerCard<E extends LayerCardElementType = typeof DEFAULT_LAYER_CARD_ELEMENT>(
27
+ props: LayerCardProps<E>,
28
+ ) {
29
+ const {
30
+ as = DEFAULT_LAYER_CARD_ELEMENT,
31
+ children,
32
+ onActivate,
33
+ onFocus,
34
+ position = 'relative',
35
+ ref: forwardedRef,
36
+ style = EMPTY_RECORD,
37
+ ...rest
38
+ } = props as LayerCardProps<typeof DEFAULT_LAYER_CARD_ELEMENT>
39
+
40
+ const {zIndex, isTopLayer} = useLayer()
41
+ const lastFocusedRef = useRef<HTMLElement | null>(null)
42
+ const ref = useRef<HTMLDivElement | null>(null)
43
+ const isTopLayerRef = useRef<boolean>(isTopLayer)
44
+
45
+ useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
46
+
47
+ // When the layer very first mounts, it will be the top layer, but we don't want to fire
48
+ // the callback in that case. We use a ref to track the previous value of isTopLayer to
49
+ // determine if the layer has become the top layer since the last render.
50
+ useEffect(() => {
51
+ const becameTopLayer = isTopLayerRef.current !== isTopLayer && isTopLayer
52
+
53
+ if (becameTopLayer) {
54
+ onActivate?.({activeElement: lastFocusedRef.current})
55
+ }
56
+
57
+ isTopLayerRef.current = isTopLayer
58
+ }, [isTopLayer, onActivate])
59
+
60
+ const handleFocus = useCallback(
61
+ (event: FocusEvent<HTMLDivElement, Element>) => {
62
+ // Call the user-provided onFocus handler if any
63
+ onFocus?.(event)
64
+
65
+ const rootElement = ref.current
66
+ const target = document.activeElement
67
+
68
+ if (!isTopLayer || !rootElement || !target) return
69
+
70
+ if (isHTMLElement(target) && containsOrEqualsElement(rootElement, target)) {
71
+ lastFocusedRef.current = target
72
+ }
73
+ },
74
+ [isTopLayer, onFocus],
75
+ )
76
+
77
+ return (
78
+ <Card
79
+ data-ui="Layer"
80
+ {...rest}
81
+ as={as as CardElementType}
82
+ onFocus={handleFocus}
83
+ position={position}
84
+ ref={ref}
85
+ style={{...style, zIndex}}
86
+ >
87
+ {children}
88
+ </Card>
89
+ )
90
+ }
91
+
92
+ LayerCard.displayName = 'LayerCard'
@@ -5,17 +5,13 @@ import {getLayerContext} from './getLayerContext'
5
5
  import {LayerContext} from './layerContext'
6
6
  import {LayerContextValue} from './types'
7
7
 
8
- /**
9
- * @public
10
- */
8
+ /** @public */
11
9
  export interface LayerProviderProps {
12
10
  children?: ReactNode
13
11
  zOffset?: number | number[]
14
12
  }
15
13
 
16
- /**
17
- * @public
18
- */
14
+ /** @public */
19
15
  export function LayerProvider(props: LayerProviderProps): ReactElement {
20
16
  const {children, zOffset: zOffsetProp = 0} = props
21
17
 
@@ -4,9 +4,7 @@ import {getLayerContext} from './getLayerContext'
4
4
  import {LayerContext} from './layerContext'
5
5
  import {LayerContextValue} from './types'
6
6
 
7
- /**
8
- * @public
9
- */
7
+ /** @public */
10
8
  export function useLayer(): LayerContextValue {
11
9
  const value = useContext(LayerContext)
12
10
 
@@ -4,9 +4,7 @@ import {createPortal} from 'react-dom'
4
4
  import {CardProvider, useCard} from '../../primitives'
5
5
  import {usePortal} from './usePortal'
6
6
 
7
- /**
8
- * @public
9
- */
7
+ /** @public */
10
8
  export interface PortalProps {
11
9
  children: ReactNode
12
10
  /**
@@ -15,9 +13,7 @@ export interface PortalProps {
15
13
  __unstable_name?: string
16
14
  }
17
15
 
18
- /**
19
- * @public
20
- */
16
+ /** @public */
21
17
  export function Portal(props: PortalProps): ReactPortal | null {
22
18
  const {children, __unstable_name: name} = props
23
19
  const card = useCard()
@@ -3,9 +3,7 @@ import {ReactElement, ReactNode, useMemo, useRef, useSyncExternalStore} from 're
3
3
  import {PortalContext} from './portalContext'
4
4
  import {PortalContextValue} from './types'
5
5
 
6
- /**
7
- * @public
8
- */
6
+ /** @public */
9
7
  export interface PortalProviderProps {
10
8
  /**
11
9
  * @deprecated Use `<BoundaryElementProvider element={...} />` instead
@@ -19,9 +17,7 @@ export interface PortalProviderProps {
19
17
  __unstable_elements?: Record<string, HTMLElement | null | undefined>
20
18
  }
21
19
 
22
- /**
23
- * @public
24
- */
20
+ /** @public */
25
21
  export function PortalProvider(props: PortalProviderProps): ReactElement {
26
22
  const {boundaryElement, children, element, __unstable_elements: elementsProp} = props
27
23
  const elements = useUnique(elementsProp)
@@ -1,6 +1,4 @@
1
- /**
2
- * @public
3
- */
1
+ /** @public */
4
2
  export interface PortalContextValue {
5
3
  version: 0.0
6
4
  boundaryElement: HTMLElement | null
@@ -4,9 +4,7 @@ import {isRecord} from '../../lib/isRecord'
4
4
  import {PortalContext} from './portalContext'
5
5
  import {PortalContextValue} from './types'
6
6
 
7
- /**
8
- * @public
9
- */
7
+ /** @public */
10
8
  export function usePortal(): PortalContextValue {
11
9
  const value = useContext(PortalContext)
12
10
 
@@ -1,35 +1,40 @@
1
1
  import {composeClassNames, srOnly} from '@sanity/ui/css'
2
- import {ForwardedRef, forwardRef, ReactNode} from 'react'
3
2
 
4
- import {Props} from '../../types'
3
+ import {ComponentType, Props} from '../../types'
5
4
 
6
- /**
7
- * @public
8
- */
9
- export interface SrOnlyProps {
10
- children?: ReactNode
11
- }
5
+ /** @public */
6
+ export const DEFAULT_SR_ONLY_ELEMENT = 'span'
7
+
8
+ /** @public */
9
+ export type SrOnlyOwnProps = {} // eslint-disable-line @typescript-eslint/no-empty-object-type
10
+
11
+ /** @public */
12
+ export type SrOnlyElementType = 'span' | ComponentType
12
13
 
13
- /**
14
- * @public
15
- */
16
- export const SrOnly = forwardRef(function SrOnly(
17
- props: Props<SrOnlyProps, 'div'>,
18
- ref: ForwardedRef<HTMLDivElement>,
14
+ /** @public */
15
+ export type SrOnlyProps<E extends SrOnlyElementType = SrOnlyElementType> = Props<SrOnlyOwnProps, E>
16
+
17
+ /** @public */
18
+ export function SrOnly<E extends SrOnlyElementType = typeof DEFAULT_SR_ONLY_ELEMENT>(
19
+ props: SrOnlyProps<E>,
19
20
  ) {
20
- const {as: As = 'div', children, className, ...rest} = props
21
+ const {
22
+ as: Element = DEFAULT_SR_ONLY_ELEMENT,
23
+ children,
24
+ className,
25
+ ...rest
26
+ } = props as SrOnlyProps<typeof DEFAULT_SR_ONLY_ELEMENT>
21
27
 
22
28
  return (
23
- <As
29
+ <Element
24
30
  data-ui="SrOnly"
25
31
  {...rest}
26
32
  aria-hidden
27
33
  className={composeClassNames(className, srOnly())}
28
- ref={ref}
29
34
  >
30
35
  {children}
31
- </As>
36
+ </Element>
32
37
  )
33
- })
38
+ }
34
39
 
35
- SrOnly.displayName = 'ForwardRef(SrOnly)'
40
+ SrOnly.displayName = 'SrOnly'
@@ -1,10 +1,7 @@
1
1
  import {vars} from '@sanity/ui/css'
2
2
  import {Space} from '@sanity/ui/theme'
3
3
  import {
4
- CSSProperties,
5
- ForwardedRef,
6
- forwardRef,
7
- ReactElement,
4
+ type CSSProperties,
8
5
  ReactNode,
9
6
  useEffect,
10
7
  useImperativeHandle,
@@ -15,12 +12,13 @@ import {
15
12
 
16
13
  import {_isScrollable} from '../../helpers'
17
14
  import {_ResizeObserver} from '../../observers'
18
- import {Box, StackProps} from '../../primitives'
19
- import {Props} from '../../types'
15
+ import {Box} from '../../primitives'
16
+ import {ComponentType, Props} from '../../types'
20
17
 
21
- /**
22
- * @beta
23
- */
18
+ /** @beta */
19
+ export const DEFAULT_VIRTUAL_LIST_ELEMENT = 'div'
20
+
21
+ /** @beta */
24
22
  export interface VirtualListChangeOpts {
25
23
  fromIndex: number
26
24
  gap: number
@@ -30,10 +28,8 @@ export interface VirtualListChangeOpts {
30
28
  toIndex: number
31
29
  }
32
30
 
33
- /**
34
- * @beta
35
- */
36
- export interface VirtualListProps<Item = any> extends Omit<StackProps, 'gap'> {
31
+ /** @beta */
32
+ export type VirtualListOwnProps<Item = any> = {
37
33
  gap?: Space
38
34
  getItemKey?: (item: Item, itemIndex: number) => string
39
35
  items?: Item[]
@@ -41,14 +37,30 @@ export interface VirtualListProps<Item = any> extends Omit<StackProps, 'gap'> {
41
37
  renderItem?: (item: Item) => ReactNode
42
38
  }
43
39
 
44
- /**
45
- * @beta
46
- */
47
- export const VirtualList = forwardRef(function VirtualList(
48
- props: Props<VirtualListProps, 'div'>,
49
- forwardedRef: ForwardedRef<HTMLDivElement>,
50
- ): ReactElement {
51
- const {gap = 0, getItemKey, items = [], onChange, renderItem, ...restProps} = props
40
+ /** @beta */
41
+ export type VirtualListElementType = 'div' | ComponentType
42
+
43
+ /** @beta */
44
+ export type VirtualListProps<E extends VirtualListElementType = VirtualListElementType> = Props<
45
+ VirtualListOwnProps,
46
+ E
47
+ >
48
+
49
+ /** @beta */
50
+ export function VirtualList<E extends VirtualListElementType = typeof DEFAULT_VIRTUAL_LIST_ELEMENT>(
51
+ props: VirtualListProps<E>,
52
+ ) {
53
+ const {
54
+ as = DEFAULT_VIRTUAL_LIST_ELEMENT,
55
+ gap = 0,
56
+ getItemKey,
57
+ items = [],
58
+ onChange,
59
+ renderItem,
60
+ ref: forwardedRef,
61
+ ...rest
62
+ } = props as VirtualListProps<typeof DEFAULT_VIRTUAL_LIST_ELEMENT>
63
+
52
64
  const ref = useRef<HTMLDivElement | null>(null)
53
65
  const wrapperRef = useRef<HTMLDivElement | null>(null)
54
66
  const [scrollTop, setScrollTop] = useState(0)
@@ -173,15 +185,15 @@ export const VirtualList = forwardRef(function VirtualList(
173
185
  const wrapperStyle: CSSProperties = useMemo(() => ({height}), [height])
174
186
 
175
187
  return (
176
- <Box data-ui="VirtualList" {...restProps} position="relative" ref={ref}>
188
+ <Box data-ui="VirtualList" {...rest} as={as} position="relative" ref={ref}>
177
189
  <div ref={wrapperRef} style={wrapperStyle}>
178
190
  {children}
179
191
  </div>
180
192
  </Box>
181
193
  )
182
- })
194
+ }
183
195
 
184
- VirtualList.displayName = 'ForwardRef(VirtualList)'
196
+ VirtualList.displayName = 'VirtualList'
185
197
 
186
198
  function findScrollable(parentNode: ParentNode | null) {
187
199
  let _scrollEl = parentNode
@@ -1,97 +0,0 @@
1
- import {PREFIX} from '../constants'
2
- import {type Properties} from '../types'
3
- import {CompileRulesContext} from './types'
4
-
5
- // TODO: remove this
6
- export function compileRule(
7
- selector: string,
8
- props: Properties,
9
- context: CompileRulesContext,
10
- ): string {
11
- let css = compileProperties(selector, props)
12
-
13
- if (props['@nest']) {
14
- css += compileNestedRules(selector, props['@nest'], context)
15
- }
16
-
17
- // @ts-expect-error - TODO: fix this
18
- if (props['@keyframes']) {
19
- // @ts-expect-error - TODO: fix this
20
- for (const name in props['@keyframes']) {
21
- // @ts-expect-error - TODO: fix this
22
- context.keyframes[name] = props['@keyframes'][name]
23
- }
24
- }
25
-
26
- if (props['@media']) {
27
- for (const key in props['@media']) {
28
- if (!context.media[key]) {
29
- context.media[key] = {}
30
- }
31
-
32
- context.media[key][selector] = props['@media'][key]
33
- }
34
- }
35
-
36
- return css
37
- }
38
-
39
- function compileProperties(selector: string, props: Properties) {
40
- let css = '{'
41
-
42
- for (const key in props) {
43
- if (key === '@keyframes') continue // ignore
44
- if (key === '@media') continue // ignore
45
- if (key === '@nest') continue // ignore
46
-
47
- const value = (props as Record<string, string>)[key]
48
-
49
- const valueArr = Array.isArray(value) ? value : [value]
50
-
51
- for (const v of valueArr) {
52
- css += toSnakeCase(key) + ':' + v + ';'
53
- }
54
- }
55
-
56
- if (css === '{') return ''
57
-
58
- return selector + css + '}'
59
- }
60
-
61
- function compileNestedRules(
62
- selector: string,
63
- props: Record<string, Properties>,
64
- context: CompileRulesContext,
65
- ) {
66
- if (!props) return ''
67
-
68
- let css = ''
69
-
70
- for (const [_selector, _props] of Object.entries(props)) {
71
- css +=
72
- '\n' +
73
- compileRule(_selector.replace(/\./g, `.${PREFIX}`).replace(/&/g, selector), _props, context)
74
- }
75
-
76
- return css
77
- }
78
-
79
- export function compileMediaQueryRule(query: string, rules: Record<string, Properties>): string {
80
- let css = `@media ${query}{`
81
-
82
- for (const [selector, props] of Object.entries(rules)) {
83
- // console.log('compileMediaQueryRule', {selector, props})
84
-
85
- css += '\n ' + compileProperties(selector, props)
86
-
87
- if (props['@nest']) {
88
- css += compileNestedRules(selector, props['@nest'], {keyframes: {}, media: {}})
89
- }
90
- }
91
-
92
- return css + '\n}'
93
- }
94
-
95
- function toSnakeCase(value: string) {
96
- return value.replace(/[A-Z]/g, (match) => '-' + match.toLowerCase())
97
- }
@@ -1,36 +0,0 @@
1
- import {responsiveRules} from '../responsiveRules'
2
- import {Rules} from '../types'
3
- import {compileRules} from './compileRules'
4
-
5
- it('should compile deeply nested rules', () => {
6
- const rules: Rules = {
7
- card: {
8
- '@nest': {
9
- '&:is(a)': {
10
- // @ts-expect-error - TODO: fix this
11
- '@media': {
12
- '(hover: hover)': {
13
- background: 'red',
14
- },
15
- },
16
- },
17
- },
18
- },
19
- }
20
-
21
- // eslint-disable-next-line no-console
22
- console.log(compileRules(rules))
23
- })
24
-
25
- it.only('should compile responsive rules', () => {
26
- const rules = responsiveRules('block', {
27
- '@nest': {
28
- '&:not([hidden])': {
29
- display: 'block',
30
- },
31
- },
32
- })
33
-
34
- // eslint-disable-next-line no-console
35
- console.log(compileRules(rules))
36
- })
@@ -1,43 +0,0 @@
1
- import {scopeClassName} from '../scopeClassName'
2
- import {type Rules} from '../types'
3
- import {compileMediaQueryRule, compileRule} from './compileRule'
4
- import {CompileRulesContext} from './types'
5
-
6
- /** @public */
7
- export function compileRules(rules: Rules): string {
8
- let css = ''
9
-
10
- const context: CompileRulesContext = {
11
- keyframes: {},
12
- media: {},
13
- }
14
-
15
- for (const [className, props] of Object.entries(rules)) {
16
- const ruleCss = compileRule(
17
- `.${scopeClassName(className)}`.replace(/:/g, '\\:'),
18
- props,
19
- context,
20
- )
21
-
22
- css += ruleCss ? `${ruleCss}\n` : ''
23
- }
24
-
25
- for (const [name, value] of Object.entries(context.keyframes)) {
26
- let keyframesCss = `@keyframes ${name} {\n`
27
-
28
- for (const [key, props] of Object.entries(value)) {
29
- keyframesCss += ` ${key}`
30
- keyframesCss += compileRule('', props, context).replace(/\n/g, '\n ') + '\n'
31
- }
32
-
33
- keyframesCss += `\n}\n`
34
-
35
- css += keyframesCss
36
- }
37
-
38
- for (const [query, queryRules] of Object.entries(context.media)) {
39
- css += compileMediaQueryRule(query, queryRules) + '\n'
40
- }
41
-
42
- return css.replace(/\n{2,}/g, '\n').trimStart()
43
- }
@@ -1,7 +0,0 @@
1
- import {systemStyle} from '../system.style'
2
- import {compileStyle} from './compileStyle'
3
-
4
- /** @public */
5
- export function compileSystem(): string {
6
- return compileStyle(systemStyle)
7
- }
@@ -1,6 +0,0 @@
1
- import {Properties} from '../types'
2
-
3
- export interface CompileRulesContext {
4
- keyframes: Record<string, Record<string, Properties>>
5
- media: Record<string, Record<string, Properties>>
6
- }
@@ -1,11 +0,0 @@
1
- import {ThemeColorStateToneKey} from '@sanity/ui/theme'
2
-
3
- export const toneMap: Record<ThemeColorStateToneKey, string | undefined> = {
4
- default: 'default',
5
- neutral: 'neutral',
6
- suggest: 'suggest',
7
- primary: 'accent',
8
- positive: 'positive',
9
- caution: 'caution',
10
- critical: 'critical',
11
- } as const
@@ -1,13 +0,0 @@
1
- import {ThemeColorCardToneKey} from '@sanity/ui/theme'
2
-
3
- export const toneMap: Record<ThemeColorCardToneKey | 'inherit', string | undefined> = {
4
- transparent: 'transparent',
5
- default: 'default',
6
- neutral: 'neutral',
7
- suggest: 'suggest',
8
- primary: 'accent',
9
- positive: 'positive',
10
- caution: 'caution',
11
- critical: 'critical',
12
- inherit: undefined,
13
- } as const
@@ -1,23 +0,0 @@
1
- import {ReactNode} from 'react'
2
-
3
- /**
4
- * @internal
5
- * @deprecated this component will be removed in the next major release
6
- */
7
- export function ConditionalWrapper({
8
- children,
9
- condition,
10
- wrapper,
11
- }: {
12
- children: ReactNode
13
- condition: boolean
14
- wrapper: (children: ReactNode) => ReactNode
15
- }): ReactNode {
16
- if (!condition) {
17
- return children
18
- }
19
-
20
- return wrapper(children)
21
- }
22
-
23
- ConditionalWrapper.displayName = 'ConditionalWrapper'
@@ -1 +0,0 @@
1
- export * from './conditionalWrapper'