@sanity/ui 2.3.7-canary.0 → 2.5.0

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 (67) hide show
  1. package/dist/_chunks-cjs/getTheme_v2.js +319 -0
  2. package/dist/_chunks-cjs/getTheme_v2.js.map +1 -0
  3. package/dist/_chunks-es/getTheme_v2.mjs +320 -0
  4. package/dist/_chunks-es/getTheme_v2.mjs.map +1 -0
  5. package/dist/_legacy/getTheme_v2.esm.js +320 -0
  6. package/dist/_legacy/getTheme_v2.esm.js.map +1 -0
  7. package/dist/index.d.mts +4 -13
  8. package/dist/index.d.ts +4 -13
  9. package/dist/index.esm.js +2311 -2244
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.js +2314 -2248
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +2311 -2244
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/theme.esm.js +4 -315
  16. package/dist/theme.esm.js.map +1 -1
  17. package/dist/theme.js +36 -349
  18. package/dist/theme.js.map +1 -1
  19. package/dist/theme.mjs +4 -315
  20. package/dist/theme.mjs.map +1 -1
  21. package/package.json +35 -31
  22. package/src/core/components/autocomplete/autocomplete.tsx +48 -37
  23. package/src/core/components/breadcrumbs/breadcrumbs.tsx +2 -3
  24. package/src/core/components/dialog/dialog.tsx +12 -23
  25. package/src/core/components/hotkeys/hotkeys.tsx +3 -3
  26. package/src/core/components/menu/menu.tsx +1 -5
  27. package/src/core/components/menu/menuButton.tsx +32 -17
  28. package/src/core/components/menu/menuGroup.tsx +5 -7
  29. package/src/core/components/menu/menuItem.tsx +6 -10
  30. package/src/core/components/skeleton/skeleton.tsx +11 -5
  31. package/src/core/components/skeleton/textSkeleton.tsx +7 -6
  32. package/src/core/components/toast/styles.ts +61 -0
  33. package/src/core/components/toast/toast.tsx +11 -16
  34. package/src/core/components/toast/toastProvider.tsx +25 -26
  35. package/src/core/components/tree/treeItem.tsx +44 -31
  36. package/src/core/hooks/useArrayProp.ts +10 -11
  37. package/src/core/primitives/avatar/avatar.tsx +15 -11
  38. package/src/core/primitives/avatar/avatarCounter.tsx +17 -11
  39. package/src/core/primitives/avatar/avatarStack.tsx +7 -3
  40. package/src/core/primitives/badge/badge.tsx +4 -7
  41. package/src/core/primitives/box/box.tsx +27 -53
  42. package/src/core/primitives/button/button.tsx +12 -11
  43. package/src/core/primitives/card/card.tsx +9 -17
  44. package/src/core/primitives/code/code.tsx +3 -4
  45. package/src/core/primitives/container/container.tsx +11 -4
  46. package/src/core/primitives/flex/flex.tsx +7 -13
  47. package/src/core/primitives/grid/grid.tsx +10 -19
  48. package/src/core/primitives/heading/heading.tsx +4 -7
  49. package/src/core/primitives/inline/inline.tsx +2 -3
  50. package/src/core/primitives/kbd/kbd.tsx +3 -4
  51. package/src/core/primitives/label/label.tsx +4 -7
  52. package/src/core/primitives/popover/popover.tsx +49 -49
  53. package/src/core/primitives/select/select.tsx +6 -12
  54. package/src/core/primitives/stack/stack.tsx +3 -4
  55. package/src/core/primitives/text/text.tsx +4 -7
  56. package/src/core/primitives/textArea/textArea.tsx +6 -12
  57. package/src/core/primitives/textInput/textInput.tsx +5 -6
  58. package/src/core/primitives/tooltip/tooltip.tsx +7 -14
  59. package/src/core/theme/themeProvider.tsx +6 -4
  60. package/src/core/utils/elementQuery/elementQuery.tsx +3 -4
  61. package/src/core/utils/layer/getLayerContext.test.ts +4 -0
  62. package/src/core/utils/layer/layer.test.tsx +2 -0
  63. package/src/core/utils/layer/layerProvider.tsx +43 -35
  64. package/src/core/utils/layer/types.ts +1 -0
  65. package/dist/index.compiled.mjs +0 -7488
  66. package/dist/index.compiled.mjs.map +0 -1
  67. package/src/core/components/tree/treeItem.styles.ts +0 -21
@@ -1,7 +1,8 @@
1
1
  import {forwardRef, isValidElement, useMemo} from 'react'
2
2
  import {isValidElementType} from 'react-is'
3
3
  import {styled} from 'styled-components'
4
- import {ThemeProps, _getArrayProp} from '../../styles'
4
+ import {useArrayProp} from '../../hooks'
5
+ import {ThemeProps} from '../../styles'
5
6
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
6
7
  import {useTheme_v2} from '../../theme'
7
8
  import {ButtonMode, ButtonTextAlign, ButtonTone, ButtonWidth, FlexJustify} from '../../types'
@@ -92,16 +93,16 @@ export const Button = forwardRef(function Button(
92
93
  } = props
93
94
  const {button} = useTheme_v2()
94
95
 
95
- const justify = useMemo(() => _getArrayProp(justifyProp), [justifyProp])
96
- const padding = useMemo(() => _getArrayProp(paddingProp), [paddingProp])
97
- const paddingX = useMemo(() => _getArrayProp(paddingXProp), [paddingXProp])
98
- const paddingY = useMemo(() => _getArrayProp(paddingYProp), [paddingYProp])
99
- const paddingTop = useMemo(() => _getArrayProp(paddingTopProp), [paddingTopProp])
100
- const paddingBottom = useMemo(() => _getArrayProp(paddingBottomProp), [paddingBottomProp])
101
- const paddingLeft = useMemo(() => _getArrayProp(paddingLeftProp), [paddingLeftProp])
102
- const paddingRight = useMemo(() => _getArrayProp(paddingRightProp), [paddingRightProp])
103
- const radius = useMemo(() => _getArrayProp(radiusProp), [radiusProp])
104
- const space = useMemo(() => _getArrayProp(spaceProp), [spaceProp])
96
+ const justify = useArrayProp(justifyProp)
97
+ const padding = useArrayProp(paddingProp)
98
+ const paddingX = useArrayProp(paddingXProp)
99
+ const paddingY = useArrayProp(paddingYProp)
100
+ const paddingTop = useArrayProp(paddingTopProp)
101
+ const paddingBottom = useArrayProp(paddingBottomProp)
102
+ const paddingLeft = useArrayProp(paddingLeftProp)
103
+ const paddingRight = useArrayProp(paddingRightProp)
104
+ const radius = useArrayProp(radiusProp)
105
+ const space = useArrayProp(spaceProp)
105
106
 
106
107
  const boxProps = useMemo(
107
108
  () => ({
@@ -1,8 +1,8 @@
1
1
  import {ThemeColorSchemeKey} from '@sanity/ui/theme'
2
- import {forwardRef, useMemo} from 'react'
2
+ import {forwardRef} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
4
  import {styled} from 'styled-components'
5
- import {_getArrayProp} from '../../styles'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {
7
7
  responsiveBorderStyle,
8
8
  ResponsiveBorderStyleProps,
@@ -82,14 +82,6 @@ export const Card = forwardRef(function Card(
82
82
  const rootTheme = useRootTheme()
83
83
  const tone = toneProp === 'inherit' ? rootTheme.tone : toneProp
84
84
 
85
- const $border = useMemo(() => _getArrayProp(border), [border])
86
- const $borderTop = useMemo(() => _getArrayProp(borderTop), [borderTop])
87
- const $borderRight = useMemo(() => _getArrayProp(borderRight), [borderRight])
88
- const $borderBottom = useMemo(() => _getArrayProp(borderBottom), [borderBottom])
89
- const $borderLeft = useMemo(() => _getArrayProp(borderLeft), [borderLeft])
90
- const $radius = useMemo(() => _getArrayProp(radius), [radius])
91
- const $shadow = useMemo(() => _getArrayProp(shadow), [shadow])
92
-
93
85
  // todo: Consider adding the wrapper approach for nested cards in which the tones are not changing, avoid unnecessary ThemeColorProvider
94
86
  return (
95
87
  <ThemeColorProvider scheme={scheme} tone={tone}>
@@ -99,16 +91,16 @@ export const Card = forwardRef(function Card(
99
91
  data-ui="Card"
100
92
  data-tone={tone}
101
93
  {...restProps}
102
- $border={$border}
103
- $borderTop={$borderTop}
104
- $borderRight={$borderRight}
105
- $borderBottom={$borderBottom}
106
- $borderLeft={$borderLeft}
107
- $radius={$radius}
108
- $shadow={$shadow}
94
+ $border={useArrayProp(border)}
95
+ $borderTop={useArrayProp(borderTop)}
96
+ $borderRight={useArrayProp(borderRight)}
97
+ $borderBottom={useArrayProp(borderBottom)}
98
+ $borderLeft={useArrayProp(borderLeft)}
109
99
  $checkered={checkered}
110
100
  $focusRing={focusRing}
111
101
  $muted={muted}
102
+ $radius={useArrayProp(radius)}
103
+ $shadow={useArrayProp(shadow)}
112
104
  $tone={tone}
113
105
  data-checkered={checkered ? '' : undefined}
114
106
  data-pressed={pressed ? '' : undefined}
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import {forwardRef, useMemo} from 'react'
2
+ import {forwardRef} from 'react'
3
3
  import Refractor from 'react-refractor'
4
4
  import {styled} from 'styled-components'
5
- import {_getArrayProp} from '../../styles'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {responsiveCodeFontStyle, ResponsiveFontStyleProps} from '../../styles/internal'
7
7
  import {codeBaseStyle} from './styles'
8
8
 
@@ -29,10 +29,9 @@ export const Code = forwardRef(function Code(
29
29
  const {children, language: languageProp, size = 2, weight, ...restProps} = props
30
30
  const language = typeof languageProp === 'string' ? languageProp : undefined
31
31
  const registered = language ? Refractor.hasLanguage(language as any) : false
32
- const $size = useMemo(() => _getArrayProp(size), [size])
33
32
 
34
33
  return (
35
- <Root data-ui="Code" {...restProps} $size={$size} $weight={weight} ref={ref}>
34
+ <Root data-ui="Code" {...restProps} $size={useArrayProp(size)} $weight={weight} ref={ref}>
36
35
  {!(language && registered) && <code>{children}</code>}
37
36
  {language && registered && <Refractor inline language={language} value={String(children)} />}
38
37
  </Root>
@@ -1,6 +1,6 @@
1
- import {forwardRef, useMemo} from 'react'
1
+ import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {_getArrayProp} from '../../styles'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box, BoxProps} from '../box'
5
5
  import {ResponsiveWidthProps} from '../types'
6
6
  import {containerBaseStyle, responsiveContainerWidthStyle} from './styles'
@@ -26,7 +26,14 @@ export const Container = forwardRef(function Container(
26
26
  ref: React.ForwardedRef<HTMLDivElement>,
27
27
  ) {
28
28
  const {as, width = 2, ...restProps} = props
29
- const $width = useMemo(() => _getArrayProp(width), [width])
30
29
 
31
- return <Root data-ui="Container" {...restProps} $width={$width} forwardedAs={as} ref={ref} />
30
+ return (
31
+ <Root
32
+ data-ui="Container"
33
+ {...restProps}
34
+ $width={useArrayProp(width)}
35
+ forwardedAs={as}
36
+ ref={ref}
37
+ />
38
+ )
32
39
  })
@@ -1,6 +1,6 @@
1
- import {forwardRef, useMemo} from 'react'
1
+ import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {_getArrayProp} from '../../styles'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {
5
5
  flexItemStyle,
6
6
  FlexItemStyleProps,
@@ -36,21 +36,15 @@ export const Flex = forwardRef(function Flex(
36
36
  ) {
37
37
  const {align, as, direction = 'row', gap, justify, wrap, ...restProps} = props
38
38
 
39
- const $align = useMemo(() => _getArrayProp(align), [align])
40
- const $direction = useMemo(() => _getArrayProp(direction), [direction])
41
- const $gap = useMemo(() => _getArrayProp(gap), [gap])
42
- const $justify = useMemo(() => _getArrayProp(justify), [justify])
43
- const $wrap = useMemo(() => _getArrayProp(wrap), [wrap])
44
-
45
39
  return (
46
40
  <Root
47
41
  data-ui="Flex"
48
42
  {...restProps}
49
- $align={$align}
50
- $direction={$direction}
51
- $gap={$gap}
52
- $justify={$justify}
53
- $wrap={$wrap}
43
+ $align={useArrayProp(align)}
44
+ $direction={useArrayProp(direction)}
45
+ $gap={useArrayProp(gap)}
46
+ $justify={useArrayProp(justify)}
47
+ $wrap={useArrayProp(wrap)}
54
48
  forwardedAs={as}
55
49
  ref={ref}
56
50
  />
@@ -1,6 +1,6 @@
1
- import {forwardRef, useMemo} from 'react'
1
+ import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {_getArrayProp} from '../../styles'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {responsiveGridStyle, ResponsiveGridStyleProps} from '../../styles/internal'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {ResponsiveGridProps} from '../types'
@@ -24,28 +24,19 @@ export const Grid = forwardRef(function Grid(
24
24
  const {as, autoRows, autoCols, autoFlow, columns, gap, gapX, gapY, rows, children, ...restProps} =
25
25
  props
26
26
 
27
- const $autoRows = useMemo(() => _getArrayProp(autoRows), [autoRows])
28
- const $autoCols = useMemo(() => _getArrayProp(autoCols), [autoCols])
29
- const $autoFlow = useMemo(() => _getArrayProp(autoFlow), [autoFlow])
30
- const $columns = useMemo(() => _getArrayProp(columns), [columns])
31
- const $gap = useMemo(() => _getArrayProp(gap), [gap])
32
- const $gapX = useMemo(() => _getArrayProp(gapX), [gapX])
33
- const $gapY = useMemo(() => _getArrayProp(gapY), [gapY])
34
- const $rows = useMemo(() => _getArrayProp(rows), [rows])
35
-
36
27
  return (
37
28
  <Root
38
29
  data-as={typeof as === 'string' ? as : undefined}
39
30
  data-ui="Grid"
40
31
  {...restProps}
41
- $autoRows={$autoRows}
42
- $autoCols={$autoCols}
43
- $autoFlow={$autoFlow}
44
- $columns={$columns}
45
- $gap={$gap}
46
- $gapX={$gapX}
47
- $gapY={$gapY}
48
- $rows={$rows}
32
+ $autoRows={useArrayProp(autoRows)}
33
+ $autoCols={useArrayProp(autoCols)}
34
+ $autoFlow={useArrayProp(autoFlow)}
35
+ $columns={useArrayProp(columns)}
36
+ $gap={useArrayProp(gap)}
37
+ $gapX={useArrayProp(gapX)}
38
+ $gapY={useArrayProp(gapY)}
39
+ $rows={useArrayProp(rows)}
49
40
  forwardedAs={as}
50
41
  ref={ref}
51
42
  >
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
- import {forwardRef, useMemo} from 'react'
2
+ import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {_getArrayProp} from '../../styles'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {
6
6
  ResponsiveFontStyleProps,
7
7
  responsiveHeadingFont,
@@ -62,9 +62,6 @@ export const Heading = forwardRef(function Heading(
62
62
  ...restProps
63
63
  } = props
64
64
 
65
- const $size = useMemo(() => _getArrayProp(size), [size])
66
- const $align = useMemo(() => _getArrayProp(align), [align])
67
-
68
65
  let children = childrenProp
69
66
 
70
67
  if (textOverflow === 'ellipsis') {
@@ -76,9 +73,9 @@ export const Heading = forwardRef(function Heading(
76
73
  data-ui="Heading"
77
74
  {...restProps}
78
75
  $accent={accent}
79
- $align={$align}
80
- $size={$size}
76
+ $align={useArrayProp(align)}
81
77
  $muted={muted}
78
+ $size={useArrayProp(size)}
82
79
  $weight={weight}
83
80
  ref={ref}
84
81
  >
@@ -1,6 +1,6 @@
1
1
  import {forwardRef, useMemo, Children} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {_getArrayProp} from '../../styles'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box, BoxProps} from '../box'
5
5
  import {inlineBaseStyle, inlineSpaceStyle} from './styles'
6
6
  import {ResponsiveInlineSpaceStyleProps} from './types'
@@ -26,7 +26,6 @@ export const Inline = forwardRef(function Inline(
26
26
  ) {
27
27
  const {as, children: childrenProp, space, ...restProps} = props
28
28
 
29
- const $space = useMemo(() => _getArrayProp(space), [space])
30
29
  const children = useMemo(
31
30
  () => Children.map(childrenProp, (child) => child && <div>{child}</div>),
32
31
  [childrenProp],
@@ -36,7 +35,7 @@ export const Inline = forwardRef(function Inline(
36
35
  <Root
37
36
  data-ui="Inline"
38
37
  {...restProps}
39
- $space={$space}
38
+ $space={useArrayProp(space)}
40
39
  forwardedAs={as}
41
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
41
  ref={ref as any}
@@ -1,6 +1,6 @@
1
- import {forwardRef, useMemo} from 'react'
1
+ import {forwardRef} from 'react'
2
2
  import {styled, css} from 'styled-components'
3
- import {_getArrayProp} from '../../styles'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
5
5
  import {Radius} from '../../types'
6
6
  import {Box} from '../box'
@@ -46,10 +46,9 @@ export const KBD = forwardRef(function KBD(
46
46
  ref: React.ForwardedRef<HTMLDivElement>,
47
47
  ) {
48
48
  const {children, fontSize = 0, padding = 1, radius = 2, ...restProps} = props
49
- const $radius = useMemo(() => _getArrayProp(radius), [radius])
50
49
 
51
50
  return (
52
- <Root data-ui="KBD" {...restProps} $radius={$radius} ref={ref}>
51
+ <Root data-ui="KBD" {...restProps} $radius={useArrayProp(radius)} ref={ref}>
53
52
  <Box as="span" padding={padding}>
54
53
  <Text as="span" size={fontSize} weight="semibold">
55
54
  {children}
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
- import {forwardRef, useMemo} from 'react'
2
+ import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {_getArrayProp} from '../../styles'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {responsiveLabelFont, responsiveTextAlignStyle} from '../../styles/internal'
6
6
  import {TextAlign} from '../../types'
7
7
  import {labelBaseStyle} from './styles'
@@ -59,9 +59,6 @@ export const Label = forwardRef(function Label(
59
59
  ...restProps
60
60
  } = props
61
61
 
62
- const $size = useMemo(() => _getArrayProp(size), [size])
63
- const $align = useMemo(() => _getArrayProp(align), [align])
64
-
65
62
  let children = childrenProp
66
63
 
67
64
  if (textOverflow === 'ellipsis') {
@@ -75,9 +72,9 @@ export const Label = forwardRef(function Label(
75
72
  data-ui="Label"
76
73
  {...restProps}
77
74
  $accent={accent}
78
- $align={$align}
79
- $size={$size}
75
+ $align={useArrayProp(align)}
80
76
  $muted={muted}
77
+ $size={useArrayProp(size)}
81
78
  $weight={weight}
82
79
  ref={ref}
83
80
  >
@@ -23,9 +23,8 @@ import {
23
23
  useMemo,
24
24
  useRef,
25
25
  } from 'react'
26
- import {useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
26
+ import {useArrayProp, useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
27
27
  import {origin} from '../../middleware/origin'
28
- import {_getArrayProp} from '../../styles'
29
28
  import {useTheme_v2} from '../../theme'
30
29
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
31
30
  import {
@@ -66,7 +65,6 @@ export interface PopoverProps
66
65
  arrow?: boolean
67
66
  /** @deprecated Use `floatingBoundary` and/or `referenceBoundary` instead */
68
67
  boundaryElement?: HTMLElement | null
69
- /** @deprecated Use `referenceElement` instead */
70
68
  children?: React.ReactElement
71
69
  /**
72
70
  * When `true`, prevent overflow within the current boundary:
@@ -133,14 +131,15 @@ export const Popover = memo(
133
131
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
134
132
  animate: _animate = false,
135
133
  arrow: arrowProp = false,
136
- boundaryElement: _boundaryElement,
137
- children: _children,
134
+ boundaryElement = boundaryElementContext.element,
135
+ children: childProp,
138
136
  constrainSize = false,
139
137
  content,
140
138
  disabled,
141
- fallbackPlacements: _fallbackPlacements,
139
+ fallbackPlacements = props.fallbackPlacements ??
140
+ DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
142
141
  matchReferenceWidth,
143
- floatingBoundary: _floatingBoundary,
142
+ floatingBoundary = props.boundaryElement ?? boundaryElementContext.element,
144
143
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
145
144
  onActivate,
146
145
  open,
@@ -150,32 +149,24 @@ export const Popover = memo(
150
149
  portal,
151
150
  preventOverflow = true,
152
151
  radius: radiusProp = 3,
153
- referenceBoundary: _referenceBoundary,
152
+ referenceBoundary = props.boundaryElement ?? boundaryElementContext.element,
154
153
  referenceElement,
155
154
  scheme,
156
155
  shadow: shadowProp = 3,
157
156
  tone = 'inherit',
158
157
  width: widthProp = 'auto',
159
- zOffset: _zOffset,
158
+ zOffset: zOffsetProp = layer.popover.zOffset,
160
159
  updateRef,
161
160
  ...restProps
162
161
  } = props
163
- const boundaryElement = _boundaryElement ?? boundaryElementContext.element
164
- const referenceBoundary =
165
- _referenceBoundary ?? props.boundaryElement ?? boundaryElementContext.element
166
- const floatingBoundary =
167
- _floatingBoundary ?? props.boundaryElement ?? boundaryElementContext.element
168
- const fallbackPlacements =
169
- _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom']
170
- const zOffsetProp = _zOffset ?? layer.popover.zOffset
171
162
  const prefersReducedMotion = usePrefersReducedMotion()
172
163
  const animate = prefersReducedMotion ? false : _animate
173
164
  const boundarySize = useElementSize(boundaryElement)?.border
174
- const padding = useMemo(() => _getArrayProp(paddingProp), [paddingProp])
175
- const radius = useMemo(() => _getArrayProp(radiusProp), [radiusProp])
176
- const shadow = useMemo(() => _getArrayProp(shadowProp), [shadowProp])
177
- const widthArrayProp = _getArrayProp(widthProp)
178
- const zOffset = useMemo(() => _getArrayProp(zOffsetProp), [zOffsetProp])
165
+ const padding = useArrayProp(paddingProp)
166
+ const radius = useArrayProp(radiusProp)
167
+ const shadow = useArrayProp(shadowProp)
168
+ const widthArrayProp = useArrayProp(widthProp)
169
+ const zOffset = useArrayProp(zOffsetProp)
179
170
  const ref = useRef<HTMLDivElement | null>(null)
180
171
  const arrowRef = useRef<HTMLDivElement | null>(null)
181
172
  const rootBoundary: RootBoundary = 'viewport'
@@ -364,26 +355,45 @@ export const Popover = memo(
364
355
  [refs],
365
356
  )
366
357
 
367
- useImperativeHandle(updateRef, () => update, [update])
358
+ const setReference = useCallback(
359
+ (node: HTMLElement | null) => {
360
+ refs.setReference(node)
368
361
 
369
- useEffect(() => {
370
- if (_children) return
371
- refs.setReference(referenceElement || null)
372
- }, [_children, referenceElement, refs])
362
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
363
+ const childRef = (childProp as any)?.ref
364
+
365
+ if (typeof childRef === 'function') {
366
+ childRef(node)
367
+ } else if (childRef) {
368
+ childRef.current = node
369
+ }
370
+ },
371
+ [childProp, refs],
372
+ )
373
+
374
+ const child = useMemo(() => {
375
+ if (!childProp || referenceElement) return null
376
+
377
+ return cloneElement(childProp, {ref: setReference})
378
+ }, [childProp, referenceElement, setReference])
373
379
 
374
- const children = useMemo(() => {
375
- if (!_children || referenceElement) return null
380
+ useEffect(() => {
381
+ if (updateRef) {
382
+ if (typeof updateRef === 'function') {
383
+ updateRef(update)
384
+ } else if (updateRef) {
385
+ updateRef.current = update
386
+ }
387
+ }
388
+ }, [update, updateRef])
376
389
 
377
- return cloneElement(_children, {
378
- ref: (node: HTMLDivElement | null): void => {
379
- logDeprecatedWarning()
380
- refs.setReference(node)
381
- },
382
- })
383
- }, [_children, referenceElement, refs])
390
+ useEffect(() => {
391
+ if (child) return
392
+ refs.setReference(referenceElement || null)
393
+ }, [referenceElement, refs, child])
384
394
 
385
395
  if (disabled) {
386
- return _children || <></>
396
+ return childProp || <></>
387
397
  }
388
398
 
389
399
  const popover = (
@@ -438,21 +448,11 @@ export const Popover = memo(
438
448
  )}
439
449
  </ConditionalWrapper>
440
450
 
441
- {/* the referred element (legacy, use referenceElement instead) */}
442
- {children}
451
+ {/* the referred element */}
452
+ {child}
443
453
  </>
444
454
  )
445
455
  }),
446
456
  )
447
457
 
448
458
  Popover.displayName = 'Popover'
449
-
450
- let didWarn = false
451
-
452
- function logDeprecatedWarning() {
453
- if (!didWarn) {
454
- // eslint-disable-next-line no-console
455
- console.warn('Popover: Please use the `referenceElement` prop instead of passing a children.')
456
- didWarn = true
457
- }
458
- }
@@ -1,8 +1,7 @@
1
1
  import {ChevronDownIcon} from '@sanity/icons'
2
- import {forwardRef, useImperativeHandle, useMemo, useRef} from 'react'
2
+ import {forwardRef, useImperativeHandle, useRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useCustomValidity} from '../../hooks'
5
- import {_getArrayProp} from '../../styles'
4
+ import {useCustomValidity, useArrayProp} from '../../hooks'
6
5
  import {Radius} from '../../types'
7
6
  import {Box} from '../box'
8
7
  import {Text} from '../text'
@@ -60,21 +59,16 @@ export const Select = forwardRef(function Select(
60
59
 
61
60
  useCustomValidity(ref, customValidity)
62
61
 
63
- const $fontSize = useMemo(() => _getArrayProp(fontSize), [fontSize])
64
- const $padding = useMemo(() => _getArrayProp(padding), [padding])
65
- const $radius = useMemo(() => _getArrayProp(radius), [radius])
66
- const $space = useMemo(() => _getArrayProp(space), [space])
67
-
68
62
  return (
69
63
  <Root data-ui="Select">
70
64
  <Input
71
65
  data-read-only={!disabled && readOnly ? '' : undefined}
72
66
  data-ui="Select"
73
67
  {...restProps}
74
- $fontSize={$fontSize}
75
- $padding={$padding}
76
- $radius={$radius}
77
- $space={$space}
68
+ $fontSize={useArrayProp(fontSize)}
69
+ $padding={useArrayProp(padding)}
70
+ $radius={useArrayProp(radius)}
71
+ $space={useArrayProp(space)}
78
72
  disabled={disabled || readOnly}
79
73
  ref={ref}
80
74
  >
@@ -1,6 +1,6 @@
1
- import {forwardRef, useMemo} from 'react'
1
+ import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {_getArrayProp} from '../../styles'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box, BoxProps} from '../box'
5
5
  import {stackBaseStyle, responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps} from './styles'
6
6
 
@@ -24,14 +24,13 @@ export const Stack = forwardRef(function Stack(
24
24
  ref: React.ForwardedRef<HTMLDivElement>,
25
25
  ) {
26
26
  const {as, space, ...restProps} = props
27
- const $space = useMemo(() => _getArrayProp(space), [space])
28
27
 
29
28
  return (
30
29
  <Root
31
30
  data-as={typeof as === 'string' ? as : undefined}
32
31
  data-ui="Stack"
33
32
  {...restProps}
34
- $space={$space}
33
+ $space={useArrayProp(space)}
35
34
  forwardedAs={as}
36
35
  ref={ref}
37
36
  />
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
- import {forwardRef, useMemo} from 'react'
2
+ import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {_getArrayProp} from '../../styles'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {
6
6
  ResponsiveFontStyleProps,
7
7
  responsiveTextAlignStyle,
@@ -63,9 +63,6 @@ export const Text = forwardRef(function Text(
63
63
  ...restProps
64
64
  } = props
65
65
 
66
- const $size = useMemo(() => _getArrayProp(size), [size])
67
- const $align = useMemo(() => _getArrayProp(align), [align])
68
-
69
66
  let children = childrenProp
70
67
 
71
68
  if (textOverflow === 'ellipsis') {
@@ -77,10 +74,10 @@ export const Text = forwardRef(function Text(
77
74
  data-ui="Text"
78
75
  {...restProps}
79
76
  $accent={accent}
80
- $align={$align}
81
- $size={$size}
77
+ $align={useArrayProp(align)}
82
78
  $muted={muted}
83
79
  ref={ref}
80
+ $size={useArrayProp(size)}
84
81
  $weight={weight}
85
82
  >
86
83
  <span>{children}</span>
@@ -1,8 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
- import {forwardRef, useImperativeHandle, useMemo, useRef} from 'react'
2
+ import {forwardRef, useImperativeHandle, useRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useCustomValidity} from '../../hooks'
5
- import {_getArrayProp} from '../../styles'
4
+ import {useCustomValidity, useArrayProp} from '../../hooks'
6
5
  import {
7
6
  responsiveInputPaddingStyle,
8
7
  responsiveRadiusStyle,
@@ -81,11 +80,6 @@ export const TextArea = forwardRef(function TextArea(
81
80
 
82
81
  useCustomValidity(ref, customValidity)
83
82
 
84
- const $radius = useMemo(() => _getArrayProp(radius), [radius])
85
- const $fontSize = useMemo(() => _getArrayProp(fontSize), [fontSize])
86
- const $padding = useMemo(() => _getArrayProp(padding), [padding])
87
- const $space = useMemo(() => _getArrayProp(0), [])
88
-
89
83
  return (
90
84
  <Root data-ui="TextArea">
91
85
  <InputRoot>
@@ -94,17 +88,17 @@ export const TextArea = forwardRef(function TextArea(
94
88
  data-scheme={rootTheme.scheme}
95
89
  data-tone={rootTheme.tone}
96
90
  {...restProps}
97
- $fontSize={$fontSize}
98
- $padding={$padding}
99
- $space={$space}
91
+ $fontSize={useArrayProp(fontSize)}
92
+ $padding={useArrayProp(padding)}
100
93
  $scheme={rootTheme.scheme}
94
+ $space={useArrayProp(0)}
101
95
  $tone={rootTheme.tone}
102
96
  $weight={weight}
103
97
  disabled={disabled}
104
98
  ref={ref}
105
99
  />
106
100
  <Presentation
107
- $radius={$radius}
101
+ $radius={useArrayProp(radius)}
108
102
  $scheme={rootTheme.scheme}
109
103
  $tone={rootTheme.tone}
110
104
  data-border={border ? '' : undefined}
@@ -4,8 +4,7 @@ import {forwardRef, isValidElement, useCallback, useImperativeHandle, useMemo, u
4
4
  import {isValidElementType} from 'react-is'
5
5
  import {styled} from 'styled-components'
6
6
  import {EMPTY_RECORD} from '../../constants'
7
- import {useCustomValidity} from '../../hooks'
8
- import {_getArrayProp} from '../../styles'
7
+ import {useArrayProp, useCustomValidity} from '../../hooks'
9
8
  import {
10
9
  responsiveRadiusStyle,
11
10
  ResponsiveRadiusStyleProps,
@@ -178,10 +177,10 @@ export const TextInput = forwardRef(function TextInput(
178
177
 
179
178
  const rootTheme = useRootTheme()
180
179
 
181
- const fontSize = useMemo(() => _getArrayProp(fontSizeProp), [fontSizeProp])
182
- const padding = useMemo(() => _getArrayProp(paddingProp), [paddingProp])
183
- const radius = useMemo(() => _getArrayProp(radiusProp), [radiusProp])
184
- const space = useMemo(() => _getArrayProp(spaceProp), [spaceProp])
180
+ const fontSize = useArrayProp(fontSizeProp)
181
+ const padding = useArrayProp(paddingProp)
182
+ const radius = useArrayProp(radiusProp)
183
+ const space = useArrayProp(spaceProp)
185
184
 
186
185
  // Transient properties
187
186
  const $hasClearButton = Boolean(clearButton)