@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.
- package/dist/_chunks-cjs/_visual-editing.js +805 -609
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +807 -611
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +184 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +185 -145
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/components/autocomplete/autocomplete.tsx +10 -14
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +3 -2
- package/src/core/components/dialog/dialog.tsx +10 -14
- package/src/core/components/hotkeys/hotkeys.tsx +2 -2
- package/src/core/components/menu/menuGroup.tsx +4 -2
- package/src/core/components/menu/menuItem.tsx +4 -4
- package/src/core/components/skeleton/skeleton.tsx +4 -4
- package/src/core/components/skeleton/textSkeleton.tsx +5 -6
- package/src/core/components/tree/tree.tsx +1 -0
- package/src/core/hooks/index.ts +1 -1
- package/src/core/hooks/useArrayProp.ts +3 -17
- package/src/core/hooks/useClickOutside.ts +1 -0
- package/src/core/primitives/avatar/avatar.tsx +15 -16
- package/src/core/primitives/avatar/avatarCounter.tsx +14 -17
- package/src/core/primitives/avatar/avatarStack.tsx +2 -3
- package/src/core/primitives/badge/badge.tsx +3 -3
- package/src/core/primitives/box/box.tsx +26 -26
- package/src/core/primitives/button/button.tsx +11 -12
- package/src/core/primitives/card/card.tsx +8 -8
- package/src/core/primitives/code/code.tsx +8 -2
- package/src/core/primitives/container/container.tsx +2 -2
- package/src/core/primitives/flex/flex.tsx +6 -6
- package/src/core/primitives/grid/grid.tsx +9 -9
- package/src/core/primitives/heading/heading.tsx +3 -3
- package/src/core/primitives/inline/inline.tsx +2 -2
- package/src/core/primitives/kbd/kbd.tsx +2 -2
- package/src/core/primitives/label/label.tsx +3 -3
- package/src/core/primitives/popover/popover.tsx +7 -6
- package/src/core/primitives/select/select.tsx +6 -5
- package/src/core/primitives/stack/stack.tsx +2 -2
- package/src/core/primitives/text/text.tsx +3 -3
- package/src/core/primitives/textArea/textArea.tsx +6 -5
- package/src/core/primitives/textInput/textInput.tsx +6 -5
- package/src/core/primitives/tooltip/tooltip.tsx +4 -2
- package/src/core/utils/layer/layerProvider.tsx +3 -2
- package/src/core/utils/virtualList/virtualList.tsx +2 -0
package/package.json
CHANGED
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
|
|
22
22
|
import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
|
|
23
23
|
import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
|
|
24
|
-
import {useArrayProp} from '../../hooks'
|
|
25
24
|
import {
|
|
26
25
|
Box,
|
|
27
26
|
BoxProps,
|
|
@@ -33,6 +32,7 @@ import {
|
|
|
33
32
|
Text,
|
|
34
33
|
TextInput,
|
|
35
34
|
} from '../../primitives'
|
|
35
|
+
import {_getArrayProp} from '../../styles'
|
|
36
36
|
import {Radius} from '../../types'
|
|
37
37
|
import {AnimatedSpinnerIcon, ListBox, StyledAutocomplete} from './autocomplete.styles'
|
|
38
38
|
import {AutocompleteOption} from './autocompleteOption'
|
|
@@ -214,7 +214,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
214
214
|
|
|
215
215
|
const listBoxId = `${id}-listbox`
|
|
216
216
|
const options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY
|
|
217
|
-
const padding =
|
|
217
|
+
const padding = _getArrayProp(paddingProp)
|
|
218
218
|
const currentOption = useMemo(
|
|
219
219
|
() => (value !== null ? options.find((o) => o.value === value) : undefined),
|
|
220
220
|
[options, value],
|
|
@@ -470,18 +470,14 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
470
470
|
return undefined
|
|
471
471
|
}, [disabled, handleClearButtonFocus, loading, value])
|
|
472
472
|
|
|
473
|
-
const openButtonBoxPadding =
|
|
474
|
-
()
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}),
|
|
482
|
-
[padding],
|
|
483
|
-
)
|
|
484
|
-
const openButtonPadding = useMemo(() => padding.map((v) => Math.max(v - 1, 0)), [padding])
|
|
473
|
+
const openButtonBoxPadding = padding.map((v) => {
|
|
474
|
+
if (v === 0) return 0
|
|
475
|
+
if (v === 1) return 1
|
|
476
|
+
if (v === 2) return 1
|
|
477
|
+
|
|
478
|
+
return v - 2
|
|
479
|
+
})
|
|
480
|
+
const openButtonPadding = padding.map((v) => Math.max(v - 1, 0))
|
|
485
481
|
const openButtonProps: AutocompleteOpenButtonProps = useMemo(
|
|
486
482
|
() => (typeof openButton === 'object' ? openButton : EMPTY_RECORD),
|
|
487
483
|
[openButton],
|
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
useState,
|
|
10
10
|
} from 'react'
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {useClickOutsideEvent} from '../../hooks'
|
|
13
13
|
import {Box, Popover, Stack, Text} from '../../primitives'
|
|
14
|
+
import {_getArrayProp} from '../../styles'
|
|
14
15
|
import {ExpandButton, StyledBreadcrumbs} from './breadcrumbs.styles'
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -30,7 +31,7 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
|
|
|
30
31
|
ref: React.ForwardedRef<HTMLOListElement>,
|
|
31
32
|
) {
|
|
32
33
|
const {children, maxLength, separator, space: spaceRaw = 2, ...restProps} = props
|
|
33
|
-
const space =
|
|
34
|
+
const space = _getArrayProp(spaceRaw)
|
|
34
35
|
const [open, setOpen] = useState(false)
|
|
35
36
|
const expandElementRef = useRef<HTMLButtonElement | null>(null)
|
|
36
37
|
const popoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -9,14 +9,10 @@ import {
|
|
|
9
9
|
focusLastDescendant,
|
|
10
10
|
isHTMLElement,
|
|
11
11
|
} from '../../helpers'
|
|
12
|
-
import {
|
|
13
|
-
useArrayProp,
|
|
14
|
-
useClickOutsideEvent,
|
|
15
|
-
useGlobalKeyDown,
|
|
16
|
-
usePrefersReducedMotion,
|
|
17
|
-
} from '../../hooks'
|
|
12
|
+
import {useClickOutsideEvent, useGlobalKeyDown, usePrefersReducedMotion} from '../../hooks'
|
|
18
13
|
import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
|
|
19
14
|
import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
|
|
15
|
+
import {_getArrayProp} from '../../styles'
|
|
20
16
|
import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
|
|
21
17
|
import {useTheme_v2} from '../../theme'
|
|
22
18
|
import {DialogPosition, Radius} from '../../types'
|
|
@@ -172,9 +168,9 @@ const DialogCard = forwardRef(function DialogCard(
|
|
|
172
168
|
const portal = usePortal()
|
|
173
169
|
const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
|
|
174
170
|
const boundaryElement = useBoundaryElement().element
|
|
175
|
-
const radius =
|
|
176
|
-
const shadow =
|
|
177
|
-
const width =
|
|
171
|
+
const radius = _getArrayProp(radiusProp)
|
|
172
|
+
const shadow = _getArrayProp(shadowProp)
|
|
173
|
+
const width = _getArrayProp(widthProp)
|
|
178
174
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
179
175
|
const contentRef = useRef<HTMLDivElement | null>(null)
|
|
180
176
|
const layer = useLayer()
|
|
@@ -320,11 +316,11 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
320
316
|
const portal = usePortal()
|
|
321
317
|
const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
|
|
322
318
|
const boundaryElement = useBoundaryElement().element
|
|
323
|
-
const cardRadius =
|
|
324
|
-
const padding =
|
|
325
|
-
const position =
|
|
326
|
-
const width =
|
|
327
|
-
const zOffset =
|
|
319
|
+
const cardRadius = _getArrayProp(cardRadiusProp)
|
|
320
|
+
const padding = _getArrayProp(paddingProp)
|
|
321
|
+
const position = _getArrayProp(positionProp)
|
|
322
|
+
const width = _getArrayProp(widthProp)
|
|
323
|
+
const zOffset = _getArrayProp(zOffsetProp)
|
|
328
324
|
const preDivRef = useRef<HTMLDivElement | null>(null)
|
|
329
325
|
const postDivRef = useRef<HTMLDivElement | null>(null)
|
|
330
326
|
const cardRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {forwardRef} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
import {useArrayProp} from '../../hooks'
|
|
5
4
|
import {Inline, KBD} from '../../primitives'
|
|
5
|
+
import {_getArrayProp} from '../../styles'
|
|
6
6
|
import {Radius} from '../../types'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -41,7 +41,7 @@ export const Hotkeys = forwardRef(function Hotkeys(
|
|
|
41
41
|
ref: React.Ref<HTMLElement>,
|
|
42
42
|
) {
|
|
43
43
|
const {fontSize, keys, padding, radius, space: spaceProp = 0.5, ...restProps} = props
|
|
44
|
-
const space =
|
|
44
|
+
const space = _getArrayProp(spaceProp)
|
|
45
45
|
|
|
46
46
|
if (!keys || keys.length === 0) {
|
|
47
47
|
return <></>
|
|
@@ -2,9 +2,9 @@ import {ChevronRightIcon} from '@sanity/icons'
|
|
|
2
2
|
import {isValidElement, useCallback, useEffect, useState} from 'react'
|
|
3
3
|
import {isValidElementType} from 'react-is'
|
|
4
4
|
|
|
5
|
-
import {useArrayProp} from '../../hooks'
|
|
6
5
|
import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
|
|
7
6
|
import {Selectable} from '../../primitives/_selectable'
|
|
7
|
+
import {_getArrayProp} from '../../styles'
|
|
8
8
|
import {useRootTheme} from '../../theme'
|
|
9
9
|
import {Radius, SelectableTone} from '../../types'
|
|
10
10
|
import {Menu, MenuProps} from './menu'
|
|
@@ -122,11 +122,13 @@ export function MenuGroup(
|
|
|
122
122
|
|
|
123
123
|
// Close child menu when a sibling item becomes active
|
|
124
124
|
useEffect(() => {
|
|
125
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
125
126
|
if (!active) setOpen(false)
|
|
126
127
|
}, [active])
|
|
127
128
|
|
|
128
129
|
// Update state when child menu is no longer open
|
|
129
130
|
useEffect(() => {
|
|
131
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
130
132
|
if (!open) setWithinMenu(false)
|
|
131
133
|
}, [open])
|
|
132
134
|
|
|
@@ -181,7 +183,7 @@ export function MenuGroup(
|
|
|
181
183
|
aria-pressed={as === 'button' ? withinMenu : undefined}
|
|
182
184
|
data-pressed={as !== 'button' ? withinMenu : undefined}
|
|
183
185
|
data-selected={!withinMenu && active ? '' : undefined}
|
|
184
|
-
$radius={
|
|
186
|
+
$radius={_getArrayProp(radius)}
|
|
185
187
|
$tone={tone}
|
|
186
188
|
$scheme={scheme}
|
|
187
189
|
onClick={handleClick}
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
} from 'react'
|
|
11
11
|
import {isValidElementType} from 'react-is'
|
|
12
12
|
|
|
13
|
-
import {useArrayProp} from '../../hooks'
|
|
14
13
|
import {Box, Flex, Text} from '../../primitives'
|
|
15
14
|
import {Selectable} from '../../primitives/_selectable'
|
|
16
15
|
import {ResponsivePaddingProps, ResponsiveRadiusProps} from '../../primitives/types'
|
|
16
|
+
import {_getArrayProp} from '../../styles'
|
|
17
17
|
import {useRootTheme} from '../../theme'
|
|
18
18
|
import {SelectableTone} from '../../types/selectable'
|
|
19
19
|
import {Hotkeys} from '../hotkeys'
|
|
@@ -108,7 +108,7 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
108
108
|
[padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft],
|
|
109
109
|
)
|
|
110
110
|
|
|
111
|
-
const hotkeysFontSize =
|
|
111
|
+
const hotkeysFontSize = _getArrayProp(fontSize).map((s) => s - 1)
|
|
112
112
|
|
|
113
113
|
const setRef = useCallback((el: HTMLDivElement | null) => {
|
|
114
114
|
ref.current = el
|
|
@@ -124,8 +124,8 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
124
124
|
data-selected={active ? '' : undefined}
|
|
125
125
|
data-disabled={disabled ? '' : undefined}
|
|
126
126
|
forwardedAs={as}
|
|
127
|
-
$radius={
|
|
128
|
-
$padding={
|
|
127
|
+
$radius={_getArrayProp(radius)}
|
|
128
|
+
$padding={_getArrayProp(0)}
|
|
129
129
|
$tone={disabled ? 'default' : tone}
|
|
130
130
|
$scheme={scheme}
|
|
131
131
|
disabled={disabled}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {forwardRef, useEffect, useState} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
import {useArrayProp} from '../../hooks'
|
|
5
4
|
import {Box, 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
|
|
|
@@ -32,7 +32,7 @@ export const Skeleton = forwardRef(function Skeleton(
|
|
|
32
32
|
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
if (!delay) {
|
|
35
|
-
return
|
|
35
|
+
return undefined
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const timeout = setTimeout(() => {
|
|
@@ -48,8 +48,8 @@ export const Skeleton = forwardRef(function Skeleton(
|
|
|
48
48
|
<StyledSkeleton
|
|
49
49
|
{...restProps}
|
|
50
50
|
$animated={animated}
|
|
51
|
-
$radius={
|
|
52
|
-
$visible={visible}
|
|
51
|
+
$radius={_getArrayProp(radius)}
|
|
52
|
+
$visible={delay ? visible : true}
|
|
53
53
|
ref={ref}
|
|
54
54
|
/>
|
|
55
55
|
)
|
|
@@ -2,8 +2,7 @@ import {getTheme_v2, ThemeFontKey} from '@sanity/ui/theme'
|
|
|
2
2
|
import {forwardRef} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {_responsive, ThemeProps} from '../../styles'
|
|
5
|
+
import {_getArrayProp, _responsive, ThemeProps} from '../../styles'
|
|
7
6
|
import {Skeleton, SkeletonProps} from './skeleton'
|
|
8
7
|
|
|
9
8
|
const StyledSkeleton = styled(Skeleton)<{$size: number[]; $style: ThemeFontKey}>((
|
|
@@ -68,7 +67,7 @@ export const TextSkeleton = forwardRef(function TextSkeleton(
|
|
|
68
67
|
ref: React.Ref<HTMLDivElement>,
|
|
69
68
|
) {
|
|
70
69
|
const {size = 2, ...restProps} = props
|
|
71
|
-
const $size =
|
|
70
|
+
const $size = _getArrayProp(size)
|
|
72
71
|
|
|
73
72
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="text" />
|
|
74
73
|
})
|
|
@@ -84,7 +83,7 @@ export const LabelSkeleton = forwardRef(function TextSkeleton(
|
|
|
84
83
|
ref: React.Ref<HTMLDivElement>,
|
|
85
84
|
) {
|
|
86
85
|
const {size = 2, ...restProps} = props
|
|
87
|
-
const $size =
|
|
86
|
+
const $size = _getArrayProp(size)
|
|
88
87
|
|
|
89
88
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="label" />
|
|
90
89
|
})
|
|
@@ -100,7 +99,7 @@ export const HeadingSkeleton = forwardRef(function TextSkeleton(
|
|
|
100
99
|
ref: React.Ref<HTMLDivElement>,
|
|
101
100
|
) {
|
|
102
101
|
const {size = 2, ...restProps} = props
|
|
103
|
-
const $size =
|
|
102
|
+
const $size = _getArrayProp(size)
|
|
104
103
|
|
|
105
104
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="heading" />
|
|
106
105
|
})
|
|
@@ -116,7 +115,7 @@ export const CodeSkeleton = forwardRef(function TextSkeleton(
|
|
|
116
115
|
ref: React.Ref<HTMLDivElement>,
|
|
117
116
|
) {
|
|
118
117
|
const {size = 2, ...restProps} = props
|
|
119
|
-
const $size =
|
|
118
|
+
const $size = _getArrayProp(size)
|
|
120
119
|
|
|
121
120
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="code" />
|
|
122
121
|
})
|
package/src/core/hooks/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
2
|
|
|
3
3
|
import {_getArrayProp} from '../styles'
|
|
4
4
|
|
|
@@ -6,26 +6,12 @@ import {_getArrayProp} from '../styles'
|
|
|
6
6
|
export type ArrayPropPrimitive = string | number | boolean | undefined | null
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* @deprecated instead of `useArrayProp(width)` use `Array.isArray(width) ? width : [width]` instead
|
|
10
10
|
* @beta
|
|
11
11
|
*/
|
|
12
12
|
export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
|
|
13
13
|
val: T | T[] | undefined,
|
|
14
14
|
defaultVal?: T[],
|
|
15
15
|
): T[] {
|
|
16
|
-
|
|
17
|
-
_getArrayProp(val, defaultVal),
|
|
18
|
-
JSON.stringify(val ?? defaultVal),
|
|
19
|
-
])
|
|
20
|
-
|
|
21
|
-
const hash = JSON.stringify(val ?? defaultVal)
|
|
22
|
-
|
|
23
|
-
if (hash !== cachedHash) {
|
|
24
|
-
// If the cached hash has changed, update the cache right away.
|
|
25
|
-
// Calling setState during render is fine in this case, and preferred over a useEffect loop
|
|
26
|
-
// https://19.react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
|
|
27
|
-
setCache([_getArrayProp(val, defaultVal), hash])
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return cachedVal
|
|
16
|
+
return useMemo(() => _getArrayProp(val, defaultVal), [val, defaultVal])
|
|
31
17
|
}
|
|
@@ -58,6 +58,7 @@ export function useClickOutside(
|
|
|
58
58
|
const nextElements = _getElements(element, elementsArg)
|
|
59
59
|
|
|
60
60
|
if (prevElements.length !== nextElements.length) {
|
|
61
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
61
62
|
setElements(nextElements)
|
|
62
63
|
elementsRef.current = nextElements
|
|
63
64
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {ThemeColorAvatarColorKey} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef, useCallback, useEffect, useId,
|
|
2
|
+
import {forwardRef, useCallback, useEffect, useId, useState} from 'react'
|
|
3
3
|
import ReactIs from 'react-is'
|
|
4
4
|
import {styled} from 'styled-components'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {_getArrayProp} from '../../styles'
|
|
7
7
|
import {useTheme_v2} from '../../theme'
|
|
8
8
|
import {AvatarPosition, AvatarSize, AvatarStatus} from '../../types'
|
|
9
9
|
import {Label} from '../label'
|
|
@@ -75,7 +75,7 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
75
75
|
} = props
|
|
76
76
|
const {avatar} = useTheme_v2()
|
|
77
77
|
const as = ReactIs.isValidElementType(asProp) ? asProp : 'div'
|
|
78
|
-
const size =
|
|
78
|
+
const size = _getArrayProp(sizeProp)
|
|
79
79
|
|
|
80
80
|
// eslint-disable-next-line no-warning-comments
|
|
81
81
|
// @todo: remove this
|
|
@@ -102,6 +102,7 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
102
102
|
}, [arrowPosition, arrowPositionProp])
|
|
103
103
|
|
|
104
104
|
useEffect(() => {
|
|
105
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
105
106
|
if (src) setImageFailed(false)
|
|
106
107
|
}, [src])
|
|
107
108
|
|
|
@@ -113,18 +114,6 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
113
114
|
}
|
|
114
115
|
}, [onImageLoadError])
|
|
115
116
|
|
|
116
|
-
const initialsSize = useMemo(
|
|
117
|
-
() =>
|
|
118
|
-
size.map((s) => {
|
|
119
|
-
if (s === 1) return 1
|
|
120
|
-
if (s === 2) return 3
|
|
121
|
-
if (s === 3) return 5
|
|
122
|
-
|
|
123
|
-
return 0
|
|
124
|
-
}),
|
|
125
|
-
[size],
|
|
126
|
-
)
|
|
127
|
-
|
|
128
117
|
return (
|
|
129
118
|
<StyledAvatar
|
|
130
119
|
as={as}
|
|
@@ -181,7 +170,17 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
181
170
|
{(imageFailed || !src) && initials && (
|
|
182
171
|
<>
|
|
183
172
|
<Initials>
|
|
184
|
-
<InitialsLabel
|
|
173
|
+
<InitialsLabel
|
|
174
|
+
forwardedAs="span"
|
|
175
|
+
size={size.map((s) => {
|
|
176
|
+
if (s === 1) return 1
|
|
177
|
+
if (s === 2) return 3
|
|
178
|
+
if (s === 3) return 5
|
|
179
|
+
|
|
180
|
+
return 0
|
|
181
|
+
})}
|
|
182
|
+
weight="medium"
|
|
183
|
+
>
|
|
185
184
|
{initials}
|
|
186
185
|
</InitialsLabel>
|
|
187
186
|
</Initials>
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {getTheme_v2} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef
|
|
2
|
+
import {forwardRef} from 'react'
|
|
3
3
|
import {css, styled} from 'styled-components'
|
|
4
4
|
|
|
5
5
|
import {EMPTY_RECORD} from '../../constants'
|
|
6
|
-
import {
|
|
7
|
-
import {_responsive, rem, ThemeProps} from '../../styles'
|
|
6
|
+
import {_getArrayProp, _responsive, rem, ThemeProps} from '../../styles'
|
|
8
7
|
import {AvatarSize} from '../../types'
|
|
9
8
|
import {Label} from '../label'
|
|
10
9
|
|
|
@@ -69,23 +68,21 @@ export const AvatarCounter = forwardRef(function AvatarCounter(
|
|
|
69
68
|
ref: React.Ref<HTMLDivElement>,
|
|
70
69
|
) {
|
|
71
70
|
const {count, size: sizeProp = 1} = props
|
|
72
|
-
const size =
|
|
73
|
-
|
|
74
|
-
const fontSize = useMemo(
|
|
75
|
-
() =>
|
|
76
|
-
size.map((s) => {
|
|
77
|
-
if (s === 1) return 1
|
|
78
|
-
if (s === 2) return 3
|
|
79
|
-
if (s === 3) return 5
|
|
80
|
-
|
|
81
|
-
return 0
|
|
82
|
-
}),
|
|
83
|
-
[size],
|
|
84
|
-
)
|
|
71
|
+
const size = _getArrayProp(sizeProp)
|
|
85
72
|
|
|
86
73
|
return (
|
|
87
74
|
<StyledAvatarCounter $size={size} data-ui="AvatarCounter" ref={ref}>
|
|
88
|
-
<Label
|
|
75
|
+
<Label
|
|
76
|
+
as="span"
|
|
77
|
+
size={size.map((s) => {
|
|
78
|
+
if (s === 1) return 1
|
|
79
|
+
if (s === 2) return 3
|
|
80
|
+
if (s === 3) return 5
|
|
81
|
+
|
|
82
|
+
return 0
|
|
83
|
+
})}
|
|
84
|
+
weight="medium"
|
|
85
|
+
>
|
|
89
86
|
{count}
|
|
90
87
|
</Label>
|
|
91
88
|
</StyledAvatarCounter>
|
|
@@ -3,8 +3,7 @@ import {Children, cloneElement, forwardRef, isValidElement} from 'react'
|
|
|
3
3
|
import {css, styled} from 'styled-components'
|
|
4
4
|
|
|
5
5
|
import {EMPTY_RECORD} from '../../constants'
|
|
6
|
-
import {
|
|
7
|
-
import {_responsive, rem, ThemeProps} from '../../styles'
|
|
6
|
+
import {_getArrayProp, _responsive, rem, ThemeProps} from '../../styles'
|
|
8
7
|
import {AvatarSize} from '../../types'
|
|
9
8
|
import {AvatarCounter} from './avatarCounter'
|
|
10
9
|
|
|
@@ -71,7 +70,7 @@ export const AvatarStack = forwardRef(function AvatarStack(
|
|
|
71
70
|
} = props
|
|
72
71
|
const children: React.JSX.Element[] = Children.toArray(childrenProp).filter(isValidElement)
|
|
73
72
|
const maxLength = Math.max(maxLengthProp, 0)
|
|
74
|
-
const size =
|
|
73
|
+
const size = _getArrayProp(sizeProp)
|
|
75
74
|
|
|
76
75
|
const len = children.length
|
|
77
76
|
const visibleCount = maxLength - 1
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {forwardRef} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {_getArrayProp} from '../../styles'
|
|
5
5
|
import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
|
|
6
6
|
import {BadgeMode, BadgeTone} from '../../types'
|
|
7
7
|
import {Box, BoxProps} from '../box'
|
|
@@ -51,8 +51,8 @@ export const Badge = forwardRef(function Badge(
|
|
|
51
51
|
data-ui="Badge"
|
|
52
52
|
{...restProps}
|
|
53
53
|
$tone={tone}
|
|
54
|
-
$radius={
|
|
55
|
-
padding={
|
|
54
|
+
$radius={_getArrayProp(radius)}
|
|
55
|
+
padding={_getArrayProp(padding)}
|
|
56
56
|
ref={ref}
|
|
57
57
|
>
|
|
58
58
|
<Text size={fontSize}>{children}</Text>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {forwardRef} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {_getArrayProp} from '../../styles'
|
|
5
5
|
import {
|
|
6
6
|
boxStyle,
|
|
7
7
|
flexItemStyle,
|
|
@@ -96,31 +96,31 @@ export const Box = forwardRef(function Box(
|
|
|
96
96
|
data-as={typeof asProp === 'string' ? asProp : undefined}
|
|
97
97
|
data-ui="Box"
|
|
98
98
|
{...restProps}
|
|
99
|
-
$column={
|
|
100
|
-
$columnStart={
|
|
101
|
-
$columnEnd={
|
|
102
|
-
$display={
|
|
103
|
-
$flex={
|
|
104
|
-
$height={
|
|
105
|
-
$margin={
|
|
106
|
-
$marginX={
|
|
107
|
-
$marginY={
|
|
108
|
-
$marginTop={
|
|
109
|
-
$marginRight={
|
|
110
|
-
$marginBottom={
|
|
111
|
-
$marginLeft={
|
|
112
|
-
$overflow={
|
|
113
|
-
$padding={
|
|
114
|
-
$paddingX={
|
|
115
|
-
$paddingY={
|
|
116
|
-
$paddingTop={
|
|
117
|
-
$paddingRight={
|
|
118
|
-
$paddingBottom={
|
|
119
|
-
$paddingLeft={
|
|
120
|
-
$row={
|
|
121
|
-
$rowStart={
|
|
122
|
-
$rowEnd={
|
|
123
|
-
$sizing={
|
|
99
|
+
$column={_getArrayProp(column)}
|
|
100
|
+
$columnStart={_getArrayProp(columnStart)}
|
|
101
|
+
$columnEnd={_getArrayProp(columnEnd)}
|
|
102
|
+
$display={_getArrayProp(display)}
|
|
103
|
+
$flex={_getArrayProp(flex)}
|
|
104
|
+
$height={_getArrayProp(height)}
|
|
105
|
+
$margin={_getArrayProp(margin)}
|
|
106
|
+
$marginX={_getArrayProp(marginX)}
|
|
107
|
+
$marginY={_getArrayProp(marginY)}
|
|
108
|
+
$marginTop={_getArrayProp(marginTop)}
|
|
109
|
+
$marginRight={_getArrayProp(marginRight)}
|
|
110
|
+
$marginBottom={_getArrayProp(marginBottom)}
|
|
111
|
+
$marginLeft={_getArrayProp(marginLeft)}
|
|
112
|
+
$overflow={_getArrayProp(overflow)}
|
|
113
|
+
$padding={_getArrayProp(padding)}
|
|
114
|
+
$paddingX={_getArrayProp(paddingX)}
|
|
115
|
+
$paddingY={_getArrayProp(paddingY)}
|
|
116
|
+
$paddingTop={_getArrayProp(paddingTop)}
|
|
117
|
+
$paddingRight={_getArrayProp(paddingRight)}
|
|
118
|
+
$paddingBottom={_getArrayProp(paddingBottom)}
|
|
119
|
+
$paddingLeft={_getArrayProp(paddingLeft)}
|
|
120
|
+
$row={_getArrayProp(row)}
|
|
121
|
+
$rowStart={_getArrayProp(rowStart)}
|
|
122
|
+
$rowEnd={_getArrayProp(rowEnd)}
|
|
123
|
+
$sizing={_getArrayProp(sizing)}
|
|
124
124
|
as={asProp}
|
|
125
125
|
ref={ref}
|
|
126
126
|
>
|
|
@@ -3,8 +3,7 @@ import {forwardRef, isValidElement, useMemo} from 'react'
|
|
|
3
3
|
import {isValidElementType} from 'react-is'
|
|
4
4
|
import {styled} from 'styled-components'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {ThemeProps} from '../../styles'
|
|
6
|
+
import {_getArrayProp, ThemeProps} from '../../styles'
|
|
8
7
|
import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
|
|
9
8
|
import {useTheme_v2} from '../../theme'
|
|
10
9
|
import {ButtonMode, ButtonTextAlign, ButtonTone, ButtonWidth, FlexJustify} from '../../types'
|
|
@@ -97,16 +96,16 @@ export const Button = forwardRef(function Button(
|
|
|
97
96
|
} = props
|
|
98
97
|
const {button} = useTheme_v2()
|
|
99
98
|
|
|
100
|
-
const justify =
|
|
101
|
-
const padding =
|
|
102
|
-
const paddingX =
|
|
103
|
-
const paddingY =
|
|
104
|
-
const paddingTop =
|
|
105
|
-
const paddingBottom =
|
|
106
|
-
const paddingLeft =
|
|
107
|
-
const paddingRight =
|
|
108
|
-
const radius =
|
|
109
|
-
const space =
|
|
99
|
+
const justify = _getArrayProp(justifyProp)
|
|
100
|
+
const padding = _getArrayProp(paddingProp)
|
|
101
|
+
const paddingX = _getArrayProp(paddingXProp)
|
|
102
|
+
const paddingY = _getArrayProp(paddingYProp)
|
|
103
|
+
const paddingTop = _getArrayProp(paddingTopProp)
|
|
104
|
+
const paddingBottom = _getArrayProp(paddingBottomProp)
|
|
105
|
+
const paddingLeft = _getArrayProp(paddingLeftProp)
|
|
106
|
+
const paddingRight = _getArrayProp(paddingRightProp)
|
|
107
|
+
const radius = _getArrayProp(radiusProp)
|
|
108
|
+
const space = _getArrayProp(spaceProp)
|
|
110
109
|
|
|
111
110
|
const boxProps = useMemo(
|
|
112
111
|
() => ({
|
|
@@ -3,7 +3,7 @@ import {forwardRef} from 'react'
|
|
|
3
3
|
import {isValidElementType} from 'react-is'
|
|
4
4
|
import {styled} from 'styled-components'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {_getArrayProp} from '../../styles'
|
|
7
7
|
import {
|
|
8
8
|
responsiveBorderStyle,
|
|
9
9
|
ResponsiveBorderStyleProps,
|
|
@@ -93,16 +93,16 @@ export const Card = forwardRef(function Card(
|
|
|
93
93
|
data-ui="Card"
|
|
94
94
|
data-tone={tone}
|
|
95
95
|
{...restProps}
|
|
96
|
-
$border={
|
|
97
|
-
$borderTop={
|
|
98
|
-
$borderRight={
|
|
99
|
-
$borderBottom={
|
|
100
|
-
$borderLeft={
|
|
96
|
+
$border={_getArrayProp(border)}
|
|
97
|
+
$borderTop={_getArrayProp(borderTop)}
|
|
98
|
+
$borderRight={_getArrayProp(borderRight)}
|
|
99
|
+
$borderBottom={_getArrayProp(borderBottom)}
|
|
100
|
+
$borderLeft={_getArrayProp(borderLeft)}
|
|
101
101
|
$checkered={checkered}
|
|
102
102
|
$focusRing={focusRing}
|
|
103
103
|
$muted={muted}
|
|
104
|
-
$radius={
|
|
105
|
-
$shadow={
|
|
104
|
+
$radius={_getArrayProp(radius)}
|
|
105
|
+
$shadow={_getArrayProp(shadow)}
|
|
106
106
|
$tone={tone}
|
|
107
107
|
data-checkered={checkered ? '' : undefined}
|
|
108
108
|
data-pressed={pressed ? '' : undefined}
|