@sanity/ui 3.0.12 → 3.0.14

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 (47) hide show
  1. package/dist/_chunks-cjs/_visual-editing.js +805 -609
  2. package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
  3. package/dist/_chunks-es/_visual-editing.mjs +807 -611
  4. package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
  5. package/dist/index.d.mts +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +184 -144
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +185 -145
  10. package/dist/index.mjs.map +1 -1
  11. package/package.json +1 -1
  12. package/src/core/components/autocomplete/autocomplete.tsx +10 -14
  13. package/src/core/components/breadcrumbs/breadcrumbs.tsx +3 -2
  14. package/src/core/components/dialog/dialog.tsx +10 -14
  15. package/src/core/components/hotkeys/hotkeys.tsx +2 -2
  16. package/src/core/components/menu/menuGroup.tsx +4 -2
  17. package/src/core/components/menu/menuItem.tsx +4 -4
  18. package/src/core/components/skeleton/skeleton.tsx +4 -4
  19. package/src/core/components/skeleton/textSkeleton.tsx +5 -6
  20. package/src/core/components/tree/tree.tsx +1 -0
  21. package/src/core/hooks/index.ts +1 -1
  22. package/src/core/hooks/useArrayProp.ts +3 -17
  23. package/src/core/hooks/useClickOutside.ts +1 -0
  24. package/src/core/primitives/avatar/avatar.tsx +15 -16
  25. package/src/core/primitives/avatar/avatarCounter.tsx +14 -17
  26. package/src/core/primitives/avatar/avatarStack.tsx +2 -3
  27. package/src/core/primitives/badge/badge.tsx +3 -3
  28. package/src/core/primitives/box/box.tsx +26 -26
  29. package/src/core/primitives/button/button.tsx +11 -12
  30. package/src/core/primitives/card/card.tsx +8 -8
  31. package/src/core/primitives/code/code.tsx +8 -2
  32. package/src/core/primitives/container/container.tsx +2 -2
  33. package/src/core/primitives/flex/flex.tsx +6 -6
  34. package/src/core/primitives/grid/grid.tsx +9 -9
  35. package/src/core/primitives/heading/heading.tsx +3 -3
  36. package/src/core/primitives/inline/inline.tsx +2 -2
  37. package/src/core/primitives/kbd/kbd.tsx +2 -2
  38. package/src/core/primitives/label/label.tsx +3 -3
  39. package/src/core/primitives/popover/popover.tsx +7 -6
  40. package/src/core/primitives/select/select.tsx +6 -5
  41. package/src/core/primitives/stack/stack.tsx +2 -2
  42. package/src/core/primitives/text/text.tsx +3 -3
  43. package/src/core/primitives/textArea/textArea.tsx +6 -5
  44. package/src/core/primitives/textInput/textInput.tsx +6 -5
  45. package/src/core/primitives/tooltip/tooltip.tsx +4 -2
  46. package/src/core/utils/layer/layerProvider.tsx +3 -2
  47. package/src/core/utils/virtualList/virtualList.tsx +2 -0
@@ -1,7 +1,7 @@
1
1
  import {forwardRef, lazy, Suspense} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {responsiveCodeFontStyle, ResponsiveFontStyleProps} from '../../styles/internal'
6
6
  import {codeBaseStyle} from './styles'
7
7
 
@@ -30,7 +30,13 @@ export const Code = forwardRef(function Code(
30
30
  const {children, language, size = 2, weight, ...restProps} = props
31
31
 
32
32
  return (
33
- <StyledCode data-ui="Code" {...restProps} $size={useArrayProp(size)} $weight={weight} ref={ref}>
33
+ <StyledCode
34
+ data-ui="Code"
35
+ {...restProps}
36
+ $size={_getArrayProp(size)}
37
+ $weight={weight}
38
+ ref={ref}
39
+ >
34
40
  <Suspense fallback={<code>{children}</code>}>
35
41
  <LazyRefractor language={language} value={children} />
36
42
  </Suspense>
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {ResponsiveWidthProps} from '../types'
7
7
  import {containerBaseStyle, responsiveContainerWidthStyle} from './styles'
@@ -32,7 +32,7 @@ export const Container = forwardRef(function Container(
32
32
  <StyledContainer
33
33
  data-ui="Container"
34
34
  {...restProps}
35
- $width={useArrayProp(width)}
35
+ $width={_getArrayProp(width)}
36
36
  forwardedAs={as}
37
37
  ref={ref}
38
38
  />
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {
6
6
  flexItemStyle,
7
7
  FlexItemStyleProps,
@@ -41,11 +41,11 @@ export const Flex = forwardRef(function Flex(
41
41
  <StyledFlex
42
42
  data-ui="Flex"
43
43
  {...restProps}
44
- $align={useArrayProp(align)}
45
- $direction={useArrayProp(direction)}
46
- $gap={useArrayProp(gap)}
47
- $justify={useArrayProp(justify)}
48
- $wrap={useArrayProp(wrap)}
44
+ $align={_getArrayProp(align)}
45
+ $direction={_getArrayProp(direction)}
46
+ $gap={_getArrayProp(gap)}
47
+ $justify={_getArrayProp(justify)}
48
+ $wrap={_getArrayProp(wrap)}
49
49
  forwardedAs={as}
50
50
  ref={ref}
51
51
  />
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {responsiveGridStyle, ResponsiveGridStyleProps} from '../../styles/internal'
6
6
  import {Box, BoxProps} from '../box'
7
7
  import {ResponsiveGridProps} from '../types'
@@ -30,14 +30,14 @@ export const Grid = forwardRef(function Grid(
30
30
  data-as={typeof as === 'string' ? as : undefined}
31
31
  data-ui="Grid"
32
32
  {...restProps}
33
- $autoRows={useArrayProp(autoRows)}
34
- $autoCols={useArrayProp(autoCols)}
35
- $autoFlow={useArrayProp(autoFlow)}
36
- $columns={useArrayProp(columns)}
37
- $gap={useArrayProp(gap)}
38
- $gapX={useArrayProp(gapX)}
39
- $gapY={useArrayProp(gapY)}
40
- $rows={useArrayProp(rows)}
33
+ $autoRows={_getArrayProp(autoRows)}
34
+ $autoCols={_getArrayProp(autoCols)}
35
+ $autoFlow={_getArrayProp(autoFlow)}
36
+ $columns={_getArrayProp(columns)}
37
+ $gap={_getArrayProp(gap)}
38
+ $gapX={_getArrayProp(gapX)}
39
+ $gapY={_getArrayProp(gapY)}
40
+ $rows={_getArrayProp(rows)}
41
41
  forwardedAs={as}
42
42
  ref={ref}
43
43
  >
@@ -2,7 +2,7 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp} from '../../hooks'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {
7
7
  ResponsiveFontStyleProps,
8
8
  responsiveHeadingFont,
@@ -67,9 +67,9 @@ export const Heading = forwardRef(function Heading(
67
67
  data-ui="Heading"
68
68
  {...restProps}
69
69
  $accent={accent}
70
- $align={useArrayProp(align)}
70
+ $align={_getArrayProp(align)}
71
71
  $muted={muted}
72
- $size={useArrayProp(size)}
72
+ $size={_getArrayProp(size)}
73
73
  $weight={weight}
74
74
  ref={ref}
75
75
  >
@@ -1,7 +1,7 @@
1
1
  import {Children, forwardRef, useMemo} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {inlineBaseStyle, inlineSpaceStyle} from './styles'
7
7
  import {ResponsiveInlineSpaceStyleProps} from './types'
@@ -36,7 +36,7 @@ export const Inline = forwardRef(function Inline(
36
36
  <StyledInline
37
37
  data-ui="Inline"
38
38
  {...restProps}
39
- $space={useArrayProp(space)}
39
+ $space={_getArrayProp(space)}
40
40
  forwardedAs={as}
41
41
  ref={ref as any}
42
42
  >
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {css, styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
6
6
  import {Radius} from '../../types'
7
7
  import {Box} from '../box'
@@ -49,7 +49,7 @@ export const KBD = forwardRef(function KBD(
49
49
  const {children, fontSize = 0, padding = 1, radius = 2, ...restProps} = props
50
50
 
51
51
  return (
52
- <StyledKBD data-ui="KBD" {...restProps} $radius={useArrayProp(radius)} ref={ref}>
52
+ <StyledKBD data-ui="KBD" {...restProps} $radius={_getArrayProp(radius)} ref={ref}>
53
53
  <Box as="span" padding={padding}>
54
54
  <Text as="span" size={fontSize} weight="semibold">
55
55
  {children}
@@ -2,7 +2,7 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp} from '../../hooks'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {responsiveLabelFont, responsiveTextAlignStyle} from '../../styles/internal'
7
7
  import {TextAlign} from '../../types'
8
8
  import {SpanWithTextOverflow} from '../../utils/spanWithTextOverflow'
@@ -66,9 +66,9 @@ export const Label = forwardRef(function Label(
66
66
  data-ui="Label"
67
67
  {...restProps}
68
68
  $accent={accent}
69
- $align={useArrayProp(align)}
69
+ $align={_getArrayProp(align)}
70
70
  $muted={muted}
71
- $size={useArrayProp(size)}
71
+ $size={_getArrayProp(size)}
72
72
  $weight={weight}
73
73
  ref={ref}
74
74
  >
@@ -24,8 +24,9 @@ import {
24
24
  useState,
25
25
  } from 'react'
26
26
 
27
- import {useArrayProp, useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
27
+ import {useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
28
28
  import {origin} from '../../middleware/origin'
29
+ import {_getArrayProp} from '../../styles'
29
30
  import {useTheme_v2} from '../../theme'
30
31
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
31
32
  import {LayerProps, LayerProvider, Portal, useBoundaryElement, useLayer} from '../../utils'
@@ -185,11 +186,11 @@ export const Popover = forwardRef(function Popover(
185
186
  const prefersReducedMotion = usePrefersReducedMotion()
186
187
  const animate = prefersReducedMotion ? false : _animate
187
188
  const boundarySize = useElementSize(boundaryElement)?.border
188
- const padding = useArrayProp(paddingProp)
189
- const radius = useArrayProp(radiusProp)
190
- const shadow = useArrayProp(shadowProp)
191
- const widthArrayProp = useArrayProp(widthProp)
192
- const zOffset = useArrayProp(zOffsetProp)
189
+ const padding = _getArrayProp(paddingProp)
190
+ const radius = _getArrayProp(radiusProp)
191
+ const shadow = _getArrayProp(shadowProp)
192
+ const widthArrayProp = _getArrayProp(widthProp)
193
+ const zOffset = _getArrayProp(zOffsetProp)
193
194
  const ref = useRef<HTMLDivElement | null>(null)
194
195
  const arrowRef = useRef<HTMLDivElement | null>(null)
195
196
  const rootBoundary: RootBoundary = 'viewport'
@@ -2,7 +2,8 @@ import {ChevronDownIcon} from '@sanity/icons'
2
2
  import {forwardRef, useImperativeHandle, useRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp, useCustomValidity} from '../../hooks'
5
+ import {useCustomValidity} from '../../hooks'
6
+ import {_getArrayProp} from '../../styles'
6
7
  import {Radius} from '../../types'
7
8
  import {Box} from '../box'
8
9
  import {Text} from '../text'
@@ -66,10 +67,10 @@ export const Select = forwardRef(function Select(
66
67
  data-read-only={!disabled && readOnly ? '' : undefined}
67
68
  data-ui="Select"
68
69
  {...restProps}
69
- $fontSize={useArrayProp(fontSize)}
70
- $padding={useArrayProp(padding)}
71
- $radius={useArrayProp(radius)}
72
- $space={useArrayProp(space)}
70
+ $fontSize={_getArrayProp(fontSize)}
71
+ $padding={_getArrayProp(padding)}
72
+ $radius={_getArrayProp(radius)}
73
+ $space={_getArrayProp(space)}
73
74
  disabled={disabled || readOnly}
74
75
  ref={ref}
75
76
  >
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps, stackBaseStyle} from './styles'
7
7
 
@@ -34,7 +34,7 @@ export const Stack = forwardRef(function Stack(
34
34
  data-as={typeof as === 'string' ? as : undefined}
35
35
  data-ui="Stack"
36
36
  {...restProps}
37
- $space={useArrayProp(space)}
37
+ $space={_getArrayProp(space)}
38
38
  forwardedAs={as}
39
39
  ref={ref}
40
40
  />
@@ -2,7 +2,7 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp} from '../../hooks'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {
7
7
  ResponsiveFontStyleProps,
8
8
  responsiveTextAlignStyle,
@@ -68,10 +68,10 @@ export const Text = forwardRef(function Text(
68
68
  data-ui="Text"
69
69
  {...restProps}
70
70
  $accent={accent}
71
- $align={useArrayProp(align)}
71
+ $align={_getArrayProp(align)}
72
72
  $muted={muted}
73
73
  ref={ref}
74
- $size={useArrayProp(size)}
74
+ $size={_getArrayProp(size)}
75
75
  $weight={weight}
76
76
  >
77
77
  <span>{children}</span>
@@ -2,7 +2,8 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef, useImperativeHandle, useRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp, useCustomValidity} from '../../hooks'
5
+ import {useCustomValidity} from '../../hooks'
6
+ import {_getArrayProp} from '../../styles'
6
7
  import {
7
8
  responsiveInputPaddingStyle,
8
9
  responsiveRadiusStyle,
@@ -94,17 +95,17 @@ export const TextArea = forwardRef(function TextArea(
94
95
  data-scheme={rootTheme.scheme}
95
96
  data-tone={rootTheme.tone}
96
97
  {...restProps}
97
- $fontSize={useArrayProp(fontSize)}
98
- $padding={useArrayProp(padding)}
98
+ $fontSize={_getArrayProp(fontSize)}
99
+ $padding={_getArrayProp(padding)}
99
100
  $scheme={rootTheme.scheme}
100
- $space={useArrayProp(0)}
101
+ $space={_getArrayProp(0)}
101
102
  $tone={rootTheme.tone}
102
103
  $weight={weight}
103
104
  disabled={disabled}
104
105
  ref={ref}
105
106
  />
106
107
  <Presentation
107
- $radius={useArrayProp(radius)}
108
+ $radius={_getArrayProp(radius)}
108
109
  $unstableDisableFocusRing={__unstable_disableFocusRing}
109
110
  $scheme={rootTheme.scheme}
110
111
  $tone={rootTheme.tone}
@@ -5,7 +5,8 @@ import {isValidElementType} from 'react-is'
5
5
  import {styled} from 'styled-components'
6
6
 
7
7
  import {EMPTY_RECORD} from '../../constants'
8
- import {useArrayProp, useCustomValidity} from '../../hooks'
8
+ import {useCustomValidity} from '../../hooks'
9
+ import {_getArrayProp} from '../../styles'
9
10
  import {
10
11
  responsiveInputPaddingStyle,
11
12
  responsiveRadiusStyle,
@@ -179,10 +180,10 @@ export const TextInput = forwardRef(function TextInput(
179
180
 
180
181
  const rootTheme = useRootTheme()
181
182
 
182
- const fontSize = useArrayProp(fontSizeProp)
183
- const padding = useArrayProp(paddingProp)
184
- const radius = useArrayProp(radiusProp)
185
- const space = useArrayProp(spaceProp)
183
+ const fontSize = _getArrayProp(fontSizeProp)
184
+ const padding = _getArrayProp(paddingProp)
185
+ const radius = _getArrayProp(radiusProp)
186
+ const space = _getArrayProp(spaceProp)
186
187
 
187
188
  // Transient properties
188
189
  const $hasClearButton = Boolean(clearButton)
@@ -25,9 +25,10 @@ import {
25
25
  import {styled} from 'styled-components'
26
26
  import {useEffectEvent} from 'use-effect-event'
27
27
 
28
- import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
28
+ import {usePrefersReducedMotion} from '../../hooks'
29
29
  import {useDelayedState} from '../../hooks/useDelayedState'
30
30
  import {origin} from '../../middleware/origin'
31
+ import {_getArrayProp} from '../../styles'
31
32
  import {useTheme_v2} from '../../theme'
32
33
  import type {Placement} from '../../types'
33
34
  import {Layer, type LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
@@ -119,7 +120,7 @@ export const Tooltip = forwardRef(function Tooltip(
119
120
  const zOffset = _zOffset ?? layer.tooltip.zOffset
120
121
  const prefersReducedMotion = usePrefersReducedMotion()
121
122
  const animate = prefersReducedMotion ? false : _animate
122
- const fallbackPlacements = useArrayProp(fallbackPlacementsProp)
123
+ const fallbackPlacements = _getArrayProp(fallbackPlacementsProp)
123
124
  const ref = useRef<HTMLDivElement | null>(null)
124
125
  const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null)
125
126
  const arrowRef = useRef<HTMLDivElement | null>(null)
@@ -285,6 +286,7 @@ export const Tooltip = forwardRef(function Tooltip(
285
286
  portalElement?.offsetWidth || document.body.offsetWidth,
286
287
  ]
287
288
 
289
+ // eslint-disable-next-line react-hooks/set-state-in-effect
288
290
  setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2)
289
291
  }, [boundaryElement, portalElement])
290
292
 
@@ -1,6 +1,7 @@
1
1
  import {useCallback, useContext, useEffect, useMemo, useState} from 'react'
2
2
 
3
- import {useArrayProp, useMediaIndex} from '../../hooks'
3
+ import {useMediaIndex} from '../../hooks'
4
+ import {_getArrayProp} from '../../styles'
4
5
  import {getLayerContext} from './getLayerContext'
5
6
  import {LayerContext} from './layerContext'
6
7
  import {LayerContextValue} from './types'
@@ -29,7 +30,7 @@ export function LayerProvider(props: LayerProviderProps): React.JSX.Element {
29
30
  const level = parentLevel + 1
30
31
 
31
32
  // Get z-index offset
32
- const zOffset = useArrayProp(zOffsetProp)
33
+ const zOffset = _getArrayProp(zOffsetProp)
33
34
 
34
35
  // Get responsive z-index value
35
36
  const maxMediaIndex = zOffset.length - 1
@@ -66,6 +66,7 @@ export const VirtualList = forwardRef(function VirtualList(
66
66
  const firstElement = wrapperRef.current.firstChild
67
67
 
68
68
  if (firstElement instanceof HTMLElement) {
69
+ // eslint-disable-next-line react-hooks/set-state-in-effect
69
70
  setItemHeight(firstElement.offsetHeight)
70
71
  }
71
72
  }, [renderItem])
@@ -111,6 +112,7 @@ export const VirtualList = forwardRef(function VirtualList(
111
112
  window.addEventListener('scroll', handleScroll, {passive: true})
112
113
  window.addEventListener('resize', handleResize)
113
114
 
115
+ // eslint-disable-next-line react-hooks/set-state-in-effect
114
116
  setScrollHeight(window.innerHeight)
115
117
 
116
118
  handleScroll()