@sanity/ui 2.3.6-0 → 2.3.6-canary.1

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 (44) hide show
  1. package/dist/index.compiled.mjs +7073 -0
  2. package/dist/index.compiled.mjs.map +1 -0
  3. package/dist/index.d.mts +10 -0
  4. package/dist/index.d.ts +10 -0
  5. package/dist/index.esm.js +966 -982
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.js +971 -987
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +966 -982
  10. package/dist/index.mjs.map +1 -1
  11. package/package.json +6 -2
  12. package/src/core/components/autocomplete/autocomplete.tsx +2 -2
  13. package/src/core/components/breadcrumbs/breadcrumbs.tsx +3 -2
  14. package/src/core/components/dialog/dialog.tsx +19 -10
  15. package/src/core/components/hotkeys/hotkeys.tsx +3 -3
  16. package/src/core/components/menu/menuGroup.tsx +5 -4
  17. package/src/core/components/menu/menuItem.tsx +6 -4
  18. package/src/core/components/skeleton/skeleton.tsx +5 -11
  19. package/src/core/components/skeleton/textSkeleton.tsx +6 -7
  20. package/src/core/hooks/useArrayProp.ts +11 -10
  21. package/src/core/primitives/avatar/avatar.tsx +4 -4
  22. package/src/core/primitives/avatar/avatarCounter.tsx +2 -3
  23. package/src/core/primitives/avatar/avatarStack.tsx +2 -3
  24. package/src/core/primitives/badge/badge.tsx +7 -4
  25. package/src/core/primitives/box/box.tsx +53 -27
  26. package/src/core/primitives/button/button.tsx +11 -12
  27. package/src/core/primitives/card/card.tsx +17 -9
  28. package/src/core/primitives/code/code.tsx +4 -3
  29. package/src/core/primitives/container/container.tsx +4 -11
  30. package/src/core/primitives/flex/flex.tsx +13 -7
  31. package/src/core/primitives/grid/grid.tsx +19 -10
  32. package/src/core/primitives/heading/heading.tsx +7 -4
  33. package/src/core/primitives/inline/inline.tsx +3 -2
  34. package/src/core/primitives/kbd/kbd.tsx +4 -3
  35. package/src/core/primitives/label/label.tsx +7 -4
  36. package/src/core/primitives/popover/popover.tsx +7 -6
  37. package/src/core/primitives/select/select.tsx +12 -6
  38. package/src/core/primitives/stack/stack.tsx +4 -3
  39. package/src/core/primitives/text/text.tsx +7 -4
  40. package/src/core/primitives/textArea/textArea.tsx +12 -6
  41. package/src/core/primitives/textInput/textInput.tsx +6 -5
  42. package/src/core/primitives/tooltip/tooltip.tsx +6 -6
  43. package/src/core/theme/themeProvider.tsx +2 -1
  44. package/src/core/utils/layer/layerProvider.tsx +3 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.3.6-0",
3
+ "version": "2.3.6-canary.1",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -23,6 +23,10 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "source": "./exports/index.ts",
26
+ "react-compiler": {
27
+ "source": "./exports/index.ts",
28
+ "default": "./dist/index.compiled.mjs"
29
+ },
26
30
  "import": "./dist/index.mjs",
27
31
  "require": "./dist/index.js",
28
32
  "default": "./dist/index.js"
@@ -93,7 +97,7 @@
93
97
  "@commitlint/cli": "^19.3.0",
94
98
  "@commitlint/config-conventional": "^19.2.2",
95
99
  "@juggle/resize-observer": "^3.4.0",
96
- "@sanity/pkg-utils": "^6.9.3",
100
+ "@sanity/pkg-utils": "6.9.4-canary.1",
97
101
  "@sanity/semantic-release-preset": "^4.1.8",
98
102
  "@sanity/ui-workshop": "^2.0.15",
99
103
  "@storybook/addon-a11y": "^8.0.8",
@@ -20,7 +20,6 @@ import {
20
20
  } from 'react'
21
21
  import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
22
22
  import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
23
- import {useArrayProp} from '../../hooks'
24
23
  import {
25
24
  Box,
26
25
  BoxProps,
@@ -32,6 +31,7 @@ import {
32
31
  Text,
33
32
  TextInput,
34
33
  } from '../../primitives'
34
+ import {_getArrayProp} from '../../styles'
35
35
  import {Radius} from '../../types'
36
36
  import {AnimatedSpinnerIcon, ListBox, Root} from './autocomplete.styles'
37
37
  import {AutocompleteOption} from './autocompleteOption'
@@ -200,7 +200,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
200
200
 
201
201
  const listBoxId = `${id}-listbox`
202
202
  const options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY
203
- const padding = useArrayProp(paddingProp)
203
+ const padding = useMemo(() => _getArrayProp(paddingProp), [paddingProp])
204
204
  const currentOption = useMemo(
205
205
  () => (value !== null ? options.find((o) => o.value === value) : undefined),
206
206
  [options, value],
@@ -1,6 +1,7 @@
1
1
  import {Children, forwardRef, Fragment, isValidElement, useCallback, useMemo, useState} from 'react'
2
- import {useArrayProp, useClickOutside} from '../../hooks'
2
+ import {useClickOutside} from '../../hooks'
3
3
  import {Box, Popover, Stack, Text} from '../../primitives'
4
+ import {_getArrayProp} from '../../styles'
4
5
  import {ExpandButton, Root} from './breadcrumbs.styles'
5
6
 
6
7
  /**
@@ -20,7 +21,7 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
20
21
  ref: React.ForwardedRef<HTMLOListElement>,
21
22
  ) {
22
23
  const {children, maxLength, separator, space: spaceRaw = 2, ...restProps} = props
23
- const space = useArrayProp(spaceRaw)
24
+ const space = useMemo(() => _getArrayProp(spaceRaw), [spaceRaw])
24
25
  const [open, setOpen] = useState(false)
25
26
  const [expandElement, setExpandElement] = useState<HTMLButtonElement | null>(null)
26
27
  const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
@@ -1,6 +1,14 @@
1
1
  import {CloseIcon} from '@sanity/icons'
2
2
  import {ThemeColorSchemeKey} from '@sanity/ui/theme'
3
- import {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'
3
+ import {
4
+ forwardRef,
5
+ useCallback,
6
+ useEffect,
7
+ useImperativeHandle,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from 'react'
4
12
  import {styled} from 'styled-components'
5
13
  import {
6
14
  containsOrEqualsElement,
@@ -8,9 +16,10 @@ import {
8
16
  focusLastDescendant,
9
17
  isHTMLElement,
10
18
  } from '../../helpers'
11
- import {useArrayProp, useClickOutside, useGlobalKeyDown, usePrefersReducedMotion} from '../../hooks'
19
+ import {useClickOutside, useGlobalKeyDown, usePrefersReducedMotion} from '../../hooks'
12
20
  import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
13
21
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
22
+ import {_getArrayProp} from '../../styles'
14
23
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
15
24
  import {useTheme_v2} from '../../theme'
16
25
  import {DialogPosition, Radius} from '../../types'
@@ -166,9 +175,9 @@ const DialogCard = forwardRef(function DialogCard(
166
175
  const portal = usePortal()
167
176
  const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
168
177
  const boundaryElement = useBoundaryElement().element
169
- const radius = useArrayProp(radiusProp)
170
- const shadow = useArrayProp(shadowProp)
171
- const width = useArrayProp(widthProp)
178
+ const radius = useMemo(() => _getArrayProp(radiusProp), [radiusProp])
179
+ const shadow = useMemo(() => _getArrayProp(shadowProp), [shadowProp])
180
+ const width = useMemo(() => _getArrayProp(widthProp), [widthProp])
172
181
  const ref = useRef<HTMLDivElement | null>(null)
173
182
  const [rootElement, setRootElement] = useState<HTMLDivElement | null>(null)
174
183
  const contentRef = useRef<HTMLDivElement | null>(null)
@@ -319,11 +328,11 @@ export const Dialog = forwardRef(function Dialog(
319
328
  const portal = usePortal()
320
329
  const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
321
330
  const boundaryElement = useBoundaryElement().element
322
- const cardRadius = useArrayProp(cardRadiusProp)
323
- const padding = useArrayProp(paddingProp)
324
- const position = useArrayProp(positionProp)
325
- const width = useArrayProp(widthProp)
326
- const zOffset = useArrayProp(zOffsetProp)
331
+ const cardRadius = useMemo(() => _getArrayProp(cardRadiusProp), [cardRadiusProp])
332
+ const padding = useMemo(() => _getArrayProp(paddingProp), [paddingProp])
333
+ const position = useMemo(() => _getArrayProp(positionProp), [positionProp])
334
+ const width = useMemo(() => _getArrayProp(widthProp), [widthProp])
335
+ const zOffset = useMemo(() => _getArrayProp(zOffsetProp), [zOffsetProp])
327
336
  const preDivRef = useRef<HTMLDivElement | null>(null)
328
337
  const postDivRef = useRef<HTMLDivElement | null>(null)
329
338
  const cardRef = useRef<HTMLDivElement | null>(null)
@@ -1,7 +1,7 @@
1
- import {forwardRef} from 'react'
1
+ import {forwardRef, useMemo} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
4
3
  import {Inline, KBD} from '../../primitives'
4
+ import {_getArrayProp} from '../../styles'
5
5
  import {Radius} from '../../types'
6
6
 
7
7
  /**
@@ -40,7 +40,7 @@ export const Hotkeys = forwardRef(function Hotkeys(
40
40
  ref: React.Ref<HTMLElement>,
41
41
  ) {
42
42
  const {fontSize, keys, padding, radius, space: spaceProp = 0.5, ...restProps} = props
43
- const space = useArrayProp(spaceProp)
43
+ const space = useMemo(() => _getArrayProp(spaceProp), [spaceProp])
44
44
 
45
45
  if (!keys || keys.length === 0) {
46
46
  return <></>
@@ -1,9 +1,9 @@
1
1
  import {ChevronRightIcon} from '@sanity/icons'
2
- import {isValidElement, useCallback, useEffect, useRef, useState} from 'react'
2
+ import {isValidElement, useCallback, useEffect, useMemo, useRef, useState} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
- import {useArrayProp} from '../../hooks'
5
4
  import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
6
5
  import {Selectable} from '../../primitives/_selectable'
6
+ import {_getArrayProp} from '../../styles'
7
7
  import {useRootTheme} from '../../theme'
8
8
  import {Radius, SelectableTone} from '../../types'
9
9
  import {Menu} from './menu'
@@ -39,7 +39,7 @@ export function MenuGroup(
39
39
  onClick,
40
40
  padding = 3,
41
41
  popover,
42
- radius = 2,
42
+ radius: radiusProp = 2,
43
43
  space = 3,
44
44
  text,
45
45
  tone = 'default',
@@ -61,6 +61,7 @@ export function MenuGroup(
61
61
  const shouldFocusRef = useRef<'first' | 'last' | null>(null)
62
62
  const active = Boolean(activeElement) && activeElement === rootElement
63
63
  const [withinMenu, setWithinMenu] = useState(false)
64
+ const radius = useMemo(() => _getArrayProp(radiusProp), [radiusProp])
64
65
 
65
66
  const handleMouseEnter = useCallback(
66
67
  (event: React.MouseEvent<HTMLElement>) => {
@@ -166,7 +167,7 @@ export function MenuGroup(
166
167
  aria-pressed={as === 'button' ? withinMenu : undefined}
167
168
  data-pressed={as !== 'button' ? withinMenu : undefined}
168
169
  data-selected={!withinMenu && active ? '' : undefined}
169
- $radius={useArrayProp(radius)}
170
+ $radius={radius}
170
171
  $tone={tone}
171
172
  $scheme={scheme}
172
173
  onClick={handleClick}
@@ -9,10 +9,10 @@ import {
9
9
  useState,
10
10
  } from 'react'
11
11
  import {isValidElementType} from 'react-is'
12
- import {useArrayProp} from '../../hooks'
13
12
  import {Box, Flex, Text} from '../../primitives'
14
13
  import {Selectable} from '../../primitives/_selectable'
15
14
  import {ResponsivePaddingProps, ResponsiveRadiusProps} from '../../primitives/types'
15
+ import {_getArrayProp} from '../../styles'
16
16
  import {useRootTheme} from '../../theme'
17
17
  import {SelectableTone} from '../../types/selectable'
18
18
  import {Hotkeys} from '../hotkeys'
@@ -105,7 +105,9 @@ export const MenuItem = forwardRef(function MenuItem(
105
105
  [padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft],
106
106
  )
107
107
 
108
- const hotkeysFontSize = useArrayProp(fontSize).map((s) => s - 1)
108
+ const hotkeysFontSize = useMemo(() => _getArrayProp(fontSize).map((s) => s - 1), [fontSize])
109
+ const $radius = useMemo(() => _getArrayProp(radius), [radius])
110
+ const $padding = useMemo(() => _getArrayProp(0), [])
109
111
 
110
112
  const setRef = useCallback((el: HTMLDivElement | null) => {
111
113
  ref.current = el
@@ -121,8 +123,8 @@ export const MenuItem = forwardRef(function MenuItem(
121
123
  data-selected={active ? '' : undefined}
122
124
  data-disabled={disabled ? '' : undefined}
123
125
  forwardedAs={as}
124
- $radius={useArrayProp(radius)}
125
- $padding={useArrayProp(0)}
126
+ $radius={$radius}
127
+ $padding={$padding}
126
128
  $tone={disabled ? 'default' : tone}
127
129
  $scheme={scheme}
128
130
  disabled={disabled}
@@ -1,8 +1,8 @@
1
- import {forwardRef, useEffect, useState} from 'react'
1
+ import {forwardRef, useEffect, useMemo, useState} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
4
3
  import {Box} from '../../primitives'
5
4
  import {BoxProps, ResponsiveRadiusProps} from '../../primitives'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
7
7
  import {skeletonStyle} from './styles'
8
8
 
@@ -45,13 +45,7 @@ export const Skeleton = forwardRef(function Skeleton(
45
45
  }
46
46
  }, [delay])
47
47
 
48
- return (
49
- <Root
50
- {...restProps}
51
- $animated={animated}
52
- $radius={useArrayProp(radius)}
53
- $visible={visible}
54
- ref={ref}
55
- />
56
- )
48
+ const $radius = useMemo(() => _getArrayProp(radius), [radius])
49
+
50
+ return <Root {...restProps} $animated={animated} $radius={$radius} $visible={visible} ref={ref} />
57
51
  })
@@ -1,8 +1,7 @@
1
1
  import {ThemeFontKey, getTheme_v2} from '@sanity/ui/theme'
2
- import {forwardRef} from 'react'
2
+ import {forwardRef, useMemo} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks'
5
- import {ThemeProps, _responsive} from '../../styles'
4
+ import {ThemeProps, _getArrayProp, _responsive} from '../../styles'
6
5
  import {Skeleton, SkeletonProps} from './skeleton'
7
6
 
8
7
  const Root = styled(Skeleton)<{$size: number[]; $style: ThemeFontKey}>((
@@ -67,7 +66,7 @@ export const TextSkeleton = forwardRef(function TextSkeleton(
67
66
  ref: React.Ref<HTMLDivElement>,
68
67
  ) {
69
68
  const {size = 2, ...restProps} = props
70
- const $size = useArrayProp(size)
69
+ const $size = useMemo(() => _getArrayProp(size), [size])
71
70
 
72
71
  return <Root {...restProps} $size={$size} ref={ref} $style="text" />
73
72
  })
@@ -82,7 +81,7 @@ export const LabelSkeleton = forwardRef(function TextSkeleton(
82
81
  ref: React.Ref<HTMLDivElement>,
83
82
  ) {
84
83
  const {size = 2, ...restProps} = props
85
- const $size = useArrayProp(size)
84
+ const $size = useMemo(() => _getArrayProp(size), [size])
86
85
 
87
86
  return <Root {...restProps} $size={$size} ref={ref} $style="label" />
88
87
  })
@@ -97,7 +96,7 @@ export const HeadingSkeleton = forwardRef(function TextSkeleton(
97
96
  ref: React.Ref<HTMLDivElement>,
98
97
  ) {
99
98
  const {size = 2, ...restProps} = props
100
- const $size = useArrayProp(size)
99
+ const $size = useMemo(() => _getArrayProp(size), [size])
101
100
 
102
101
  return <Root {...restProps} $size={$size} ref={ref} $style="heading" />
103
102
  })
@@ -112,7 +111,7 @@ export const CodeSkeleton = forwardRef(function TextSkeleton(
112
111
  ref: React.Ref<HTMLDivElement>,
113
112
  ) {
114
113
  const {size = 2, ...restProps} = props
115
- const $size = useArrayProp(size)
114
+ const $size = useMemo(() => _getArrayProp(size), [size])
116
115
 
117
116
  return <Root {...restProps} $size={$size} ref={ref} $style="code" />
118
117
  })
@@ -7,19 +7,20 @@ export type ArrayPropPrimitive = string | number | boolean | undefined | null
7
7
  /**
8
8
  * This API might change. DO NOT USE IN PRODUCTION.
9
9
  * @beta
10
+ * @deprecated use `_getArrayProp` and `useMemo` directly instead
11
+ * @example
12
+ * ```diff
13
+ * -import {useArrayProp} from '@sanity/ui'
14
+ * +import {_getArrayProp} from '@sanity/ui'
15
+ * +import {useMemo} from 'react'
16
+ *
17
+ * -const width = useArrayProp(props.width)
18
+ * +const width = useMemo(() => _getArrayProp(props.width), [props.width])
19
+ * ```
10
20
  */
11
21
  export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
12
22
  val: T | T[] | undefined,
13
23
  defaultVal?: T[],
14
24
  ): T[] {
15
- // JSON.stringify is fast, but it's not faster than useMemo's referencial equality check
16
- const __perf_hash__ = useMemo(() => JSON.stringify(val ?? defaultVal), [defaultVal, val])
17
-
18
- return useMemo(
19
- () => _getArrayProp(val, defaultVal),
20
-
21
- // Improve performance: Keep object identify for a given hash of the value
22
- // eslint-disable-next-line react-hooks/exhaustive-deps
23
- [__perf_hash__],
24
- )
25
+ return useMemo(() => _getArrayProp(val, defaultVal), [defaultVal, val])
25
26
  }
@@ -1,8 +1,8 @@
1
1
  import {ThemeColorAvatarColorKey} from '@sanity/ui/theme'
2
2
  import {forwardRef, useCallback, useEffect, useId, useMemo, useState} from 'react'
3
- import ReactIs from 'react-is'
3
+ import {isValidElementType} from 'react-is'
4
4
  import {styled} from 'styled-components'
5
- import {useArrayProp} from '../../hooks'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {useTheme_v2} from '../../theme'
7
7
  import {AvatarPosition, AvatarSize, AvatarStatus} from '../../types'
8
8
  import {Label} from '../label'
@@ -73,8 +73,8 @@ export const Avatar = forwardRef(function Avatar(
73
73
  ...restProps
74
74
  } = props
75
75
  const {avatar} = useTheme_v2()
76
- const as = ReactIs.isValidElementType(asProp) ? asProp : 'div'
77
- const size = useArrayProp(sizeProp)
76
+ const as = isValidElementType(asProp) ? asProp : 'div'
77
+ const size = useMemo(() => _getArrayProp(sizeProp), [sizeProp])
78
78
 
79
79
  // @todo: remove this
80
80
  const avatarSize = avatar.sizes[size[0]] || avatar.sizes[0]
@@ -2,8 +2,7 @@ import {getTheme_v2} from '@sanity/ui/theme'
2
2
  import {forwardRef, useMemo} from 'react'
3
3
  import {styled, css} from 'styled-components'
4
4
  import {EMPTY_RECORD} from '../../constants'
5
- import {useArrayProp} from '../../hooks'
6
- import {rem, _responsive, ThemeProps} from '../../styles'
5
+ import {rem, _responsive, ThemeProps, _getArrayProp} from '../../styles'
7
6
  import {AvatarSize} from '../../types'
8
7
  import {Label} from '../label'
9
8
 
@@ -68,7 +67,7 @@ export const AvatarCounter = forwardRef(function AvatarCounter(
68
67
  ref: React.Ref<HTMLDivElement>,
69
68
  ) {
70
69
  const {count, size: sizeProp = 1} = props
71
- const size = useArrayProp(sizeProp)
70
+ const size = useMemo(() => _getArrayProp(sizeProp), [sizeProp])
72
71
 
73
72
  const fontSize = useMemo(
74
73
  () =>
@@ -2,8 +2,7 @@ import {getTheme_v2} from '@sanity/ui/theme'
2
2
  import {Children, cloneElement, forwardRef, isValidElement, useMemo} from 'react'
3
3
  import {styled, css} from 'styled-components'
4
4
  import {EMPTY_RECORD} from '../../constants'
5
- import {useArrayProp} from '../../hooks'
6
- import {rem, _responsive, ThemeProps} from '../../styles'
5
+ import {rem, _responsive, ThemeProps, _getArrayProp} from '../../styles'
7
6
  import {AvatarSize} from '../../types'
8
7
  import {AvatarCounter} from './avatarCounter'
9
8
 
@@ -70,7 +69,7 @@ export const AvatarStack = forwardRef(function AvatarStack(
70
69
  [childrenProp],
71
70
  )
72
71
  const maxLength = Math.max(maxLengthProp, 0)
73
- const size = useArrayProp(sizeProp)
72
+ const size = useMemo(() => _getArrayProp(sizeProp), [sizeProp])
74
73
 
75
74
  const len = children.length
76
75
  const visibleCount = maxLength - 1
@@ -1,6 +1,6 @@
1
- import {forwardRef} from 'react'
1
+ import {forwardRef, useMemo} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
3
+ import {_getArrayProp} from '../../styles'
4
4
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
5
5
  import {BadgeMode, BadgeTone} from '../../types'
6
6
  import {Box, BoxProps} from '../box'
@@ -45,13 +45,16 @@ export const Badge = forwardRef(function Badge(
45
45
  ...restProps
46
46
  } = props
47
47
 
48
+ const $radius = useMemo(() => _getArrayProp(radius), [radius])
49
+ const $padding = useMemo(() => _getArrayProp(padding), [padding])
50
+
48
51
  return (
49
52
  <Root
50
53
  data-ui="Badge"
51
54
  {...restProps}
52
55
  $tone={tone}
53
- $radius={useArrayProp(radius)}
54
- padding={useArrayProp(padding)}
56
+ $radius={$radius}
57
+ padding={$padding}
55
58
  ref={ref}
56
59
  >
57
60
  <Text size={fontSize}>{children}</Text>
@@ -1,6 +1,6 @@
1
- import {forwardRef} from 'react'
1
+ import {forwardRef, useMemo} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
3
+ import {_getArrayProp} from '../../styles'
4
4
  import {
5
5
  boxStyle,
6
6
  flexItemStyle,
@@ -90,36 +90,62 @@ export const Box = forwardRef(function Box(
90
90
  ...restProps
91
91
  } = props
92
92
 
93
+ const $column = useMemo(() => _getArrayProp(column), [column])
94
+ const $columnStart = useMemo(() => _getArrayProp(columnStart), [columnStart])
95
+ const $columnEnd = useMemo(() => _getArrayProp(columnEnd), [columnEnd])
96
+ const $display = useMemo(() => _getArrayProp(display), [display])
97
+ const $flex = useMemo(() => _getArrayProp(flex), [flex])
98
+ const $height = useMemo(() => _getArrayProp(height), [height])
99
+ const $margin = useMemo(() => _getArrayProp(margin), [margin])
100
+ const $marginX = useMemo(() => _getArrayProp(marginX), [marginX])
101
+ const $marginY = useMemo(() => _getArrayProp(marginY), [marginY])
102
+ const $marginTop = useMemo(() => _getArrayProp(marginTop), [marginTop])
103
+ const $marginRight = useMemo(() => _getArrayProp(marginRight), [marginRight])
104
+ const $marginBottom = useMemo(() => _getArrayProp(marginBottom), [marginBottom])
105
+ const $marginLeft = useMemo(() => _getArrayProp(marginLeft), [marginLeft])
106
+ const $overflow = useMemo(() => _getArrayProp(overflow), [overflow])
107
+ const $padding = useMemo(() => _getArrayProp(padding), [padding])
108
+ const $paddingX = useMemo(() => _getArrayProp(paddingX), [paddingX])
109
+ const $paddingY = useMemo(() => _getArrayProp(paddingY), [paddingY])
110
+ const $paddingTop = useMemo(() => _getArrayProp(paddingTop), [paddingTop])
111
+ const $paddingRight = useMemo(() => _getArrayProp(paddingRight), [paddingRight])
112
+ const $paddingBottom = useMemo(() => _getArrayProp(paddingBottom), [paddingBottom])
113
+ const $paddingLeft = useMemo(() => _getArrayProp(paddingLeft), [paddingLeft])
114
+ const $row = useMemo(() => _getArrayProp(row), [row])
115
+ const $rowStart = useMemo(() => _getArrayProp(rowStart), [rowStart])
116
+ const $rowEnd = useMemo(() => _getArrayProp(rowEnd), [rowEnd])
117
+ const $sizing = useMemo(() => _getArrayProp(sizing), [sizing])
118
+
93
119
  return (
94
120
  <Root
95
121
  data-as={typeof asProp === 'string' ? asProp : undefined}
96
122
  data-ui="Box"
97
123
  {...restProps}
98
- $column={useArrayProp(column)}
99
- $columnStart={useArrayProp(columnStart)}
100
- $columnEnd={useArrayProp(columnEnd)}
101
- $display={useArrayProp(display)}
102
- $flex={useArrayProp(flex)}
103
- $height={useArrayProp(height)}
104
- $margin={useArrayProp(margin)}
105
- $marginX={useArrayProp(marginX)}
106
- $marginY={useArrayProp(marginY)}
107
- $marginTop={useArrayProp(marginTop)}
108
- $marginRight={useArrayProp(marginRight)}
109
- $marginBottom={useArrayProp(marginBottom)}
110
- $marginLeft={useArrayProp(marginLeft)}
111
- $overflow={useArrayProp(overflow)}
112
- $padding={useArrayProp(padding)}
113
- $paddingX={useArrayProp(paddingX)}
114
- $paddingY={useArrayProp(paddingY)}
115
- $paddingTop={useArrayProp(paddingTop)}
116
- $paddingRight={useArrayProp(paddingRight)}
117
- $paddingBottom={useArrayProp(paddingBottom)}
118
- $paddingLeft={useArrayProp(paddingLeft)}
119
- $row={useArrayProp(row)}
120
- $rowStart={useArrayProp(rowStart)}
121
- $rowEnd={useArrayProp(rowEnd)}
122
- $sizing={useArrayProp(sizing)}
124
+ $column={$column}
125
+ $columnStart={$columnStart}
126
+ $columnEnd={$columnEnd}
127
+ $display={$display}
128
+ $flex={$flex}
129
+ $height={$height}
130
+ $margin={$margin}
131
+ $marginX={$marginX}
132
+ $marginY={$marginY}
133
+ $marginTop={$marginTop}
134
+ $marginRight={$marginRight}
135
+ $marginBottom={$marginBottom}
136
+ $marginLeft={$marginLeft}
137
+ $overflow={$overflow}
138
+ $padding={$padding}
139
+ $paddingX={$paddingX}
140
+ $paddingY={$paddingY}
141
+ $paddingTop={$paddingTop}
142
+ $paddingRight={$paddingRight}
143
+ $paddingBottom={$paddingBottom}
144
+ $paddingLeft={$paddingLeft}
145
+ $row={$row}
146
+ $rowStart={$rowStart}
147
+ $rowEnd={$rowEnd}
148
+ $sizing={$sizing}
123
149
  as={asProp}
124
150
  ref={ref}
125
151
  >
@@ -1,8 +1,7 @@
1
1
  import {forwardRef, isValidElement, useMemo} from 'react'
2
2
  import {isValidElementType} from 'react-is'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks'
5
- import {ThemeProps} from '../../styles'
4
+ import {ThemeProps, _getArrayProp} from '../../styles'
6
5
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
7
6
  import {useTheme_v2} from '../../theme'
8
7
  import {ButtonMode, ButtonTextAlign, ButtonTone, ButtonWidth, FlexJustify} from '../../types'
@@ -93,16 +92,16 @@ export const Button = forwardRef(function Button(
93
92
  } = props
94
93
  const {button} = useTheme_v2()
95
94
 
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)
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])
106
105
 
107
106
  const boxProps = useMemo(
108
107
  () => ({
@@ -1,8 +1,8 @@
1
1
  import {ThemeColorSchemeKey} from '@sanity/ui/theme'
2
- import {forwardRef} from 'react'
2
+ import {forwardRef, useMemo} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
4
  import {styled} from 'styled-components'
5
- import {useArrayProp} from '../../hooks'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {
7
7
  responsiveBorderStyle,
8
8
  ResponsiveBorderStyleProps,
@@ -82,6 +82,14 @@ 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
+
85
93
  // todo: Consider adding the wrapper approach for nested cards in which the tones are not changing, avoid unnecessary ThemeColorProvider
86
94
  return (
87
95
  <ThemeColorProvider scheme={scheme} tone={tone}>
@@ -91,16 +99,16 @@ export const Card = forwardRef(function Card(
91
99
  data-ui="Card"
92
100
  data-tone={tone}
93
101
  {...restProps}
94
- $border={useArrayProp(border)}
95
- $borderTop={useArrayProp(borderTop)}
96
- $borderRight={useArrayProp(borderRight)}
97
- $borderBottom={useArrayProp(borderBottom)}
98
- $borderLeft={useArrayProp(borderLeft)}
102
+ $border={$border}
103
+ $borderTop={$borderTop}
104
+ $borderRight={$borderRight}
105
+ $borderBottom={$borderBottom}
106
+ $borderLeft={$borderLeft}
107
+ $radius={$radius}
108
+ $shadow={$shadow}
99
109
  $checkered={checkered}
100
110
  $focusRing={focusRing}
101
111
  $muted={muted}
102
- $radius={useArrayProp(radius)}
103
- $shadow={useArrayProp(shadow)}
104
112
  $tone={tone}
105
113
  data-checkered={checkered ? '' : undefined}
106
114
  data-pressed={pressed ? '' : undefined}
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import {forwardRef} from 'react'
2
+ import {forwardRef, useMemo} from 'react'
3
3
  import Refractor from 'react-refractor'
4
4
  import {styled} from 'styled-components'
5
- import {useArrayProp} from '../../hooks'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {responsiveCodeFontStyle, ResponsiveFontStyleProps} from '../../styles/internal'
7
7
  import {codeBaseStyle} from './styles'
8
8
 
@@ -29,9 +29,10 @@ 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])
32
33
 
33
34
  return (
34
- <Root data-ui="Code" {...restProps} $size={useArrayProp(size)} $weight={weight} ref={ref}>
35
+ <Root data-ui="Code" {...restProps} $size={$size} $weight={weight} ref={ref}>
35
36
  {!(language && registered) && <code>{children}</code>}
36
37
  {language && registered && <Refractor inline language={language} value={String(children)} />}
37
38
  </Root>