@sanity/ui 3.0.12-canary.2 → 3.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/_visual-editing.js +656 -852
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +658 -854
- 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 +144 -183
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -184
- package/dist/index.mjs.map +1 -1
- package/package.json +40 -26
- package/src/core/components/autocomplete/autocomplete.tsx +14 -10
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +2 -3
- package/src/core/components/dialog/dialog.tsx +14 -10
- 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 -5
- package/src/core/components/tree/tree.tsx +1 -0
- package/src/core/hooks/index.ts +1 -1
- package/src/core/hooks/useArrayProp.ts +17 -5
- package/src/core/hooks/useClickOutside.ts +1 -0
- package/src/core/primitives/avatar/avatar.tsx +17 -14
- package/src/core/primitives/avatar/avatarCounter.tsx +16 -14
- package/src/core/primitives/avatar/avatarStack.tsx +2 -2
- 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 -11
- package/src/core/primitives/card/card.tsx +8 -8
- package/src/core/primitives/code/code.tsx +2 -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 +6 -7
- package/src/core/primitives/select/select.tsx +5 -6
- 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 +5 -6
- package/src/core/primitives/textInput/textInput.tsx +5 -6
- package/src/core/primitives/tooltip/tooltip.tsx +3 -3
- package/src/core/utils/layer/layerProvider.tsx +2 -3
- package/src/core/utils/virtualList/virtualList.tsx +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"sanity",
|
|
6
6
|
"ui",
|
|
@@ -60,6 +60,32 @@
|
|
|
60
60
|
"exports",
|
|
61
61
|
"src"
|
|
62
62
|
],
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
65
|
+
"clean": "rimraf .workshop dist",
|
|
66
|
+
"commit": "cz",
|
|
67
|
+
"cypress:dev": "run-p dev cypress:open",
|
|
68
|
+
"cypress:open": "cypress open",
|
|
69
|
+
"cypress:run": "cypress run",
|
|
70
|
+
"dev": "run-p storybook:dev workshop:dev",
|
|
71
|
+
"figma:pkg:build": "cd figma && pnpm build",
|
|
72
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
73
|
+
"lint": "eslint .",
|
|
74
|
+
"prepack": "pnpm build",
|
|
75
|
+
"pkg:build": "pkg build --strict",
|
|
76
|
+
"pkg:check": "pkg --strict",
|
|
77
|
+
"prepare": "husky install",
|
|
78
|
+
"release": "semantic-release",
|
|
79
|
+
"storybook:build": "storybook build",
|
|
80
|
+
"storybook:dev": "storybook dev -p 6006",
|
|
81
|
+
"test": "jest",
|
|
82
|
+
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
83
|
+
"ts:check": "tsc",
|
|
84
|
+
"watch": "pkg watch --strict",
|
|
85
|
+
"workshop:build": "workshop build",
|
|
86
|
+
"workshop:dev": "workshop dev",
|
|
87
|
+
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
88
|
+
},
|
|
63
89
|
"commitlint": {
|
|
64
90
|
"extends": [
|
|
65
91
|
"@commitlint/config-conventional"
|
|
@@ -184,37 +210,25 @@
|
|
|
184
210
|
"react-is": "^18 || >=19.0.0-0",
|
|
185
211
|
"styled-components": "^5.2 || ^6"
|
|
186
212
|
},
|
|
213
|
+
"packageManager": "pnpm@9.15.9",
|
|
187
214
|
"engines": {
|
|
188
215
|
"node": ">=20.19 <22 || >=22.12"
|
|
189
216
|
},
|
|
190
217
|
"publishConfig": {
|
|
191
218
|
"access": "public"
|
|
192
219
|
},
|
|
220
|
+
"pnpm": {
|
|
221
|
+
"overrides": {
|
|
222
|
+
"@types/react": "$@types/react",
|
|
223
|
+
"@types/react-dom": "$@types/react-dom",
|
|
224
|
+
"@types/react-is": "$@types/react-is",
|
|
225
|
+
"conventional-changelog-conventionalcommits": ">= 8.0.0",
|
|
226
|
+
"react": "$react",
|
|
227
|
+
"react-dom": "$react-dom",
|
|
228
|
+
"react-is": "$react-is"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
193
231
|
"esm.sh": {
|
|
194
232
|
"bundle": false
|
|
195
|
-
},
|
|
196
|
-
"scripts": {
|
|
197
|
-
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
198
|
-
"clean": "rimraf .workshop dist",
|
|
199
|
-
"commit": "cz",
|
|
200
|
-
"cypress:dev": "run-p dev cypress:open",
|
|
201
|
-
"cypress:open": "cypress open",
|
|
202
|
-
"cypress:run": "cypress run",
|
|
203
|
-
"dev": "run-p storybook:dev workshop:dev",
|
|
204
|
-
"figma:pkg:build": "cd figma && pnpm build",
|
|
205
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
206
|
-
"lint": "eslint .",
|
|
207
|
-
"pkg:build": "pkg build --strict",
|
|
208
|
-
"pkg:check": "pkg --strict",
|
|
209
|
-
"release": "semantic-release",
|
|
210
|
-
"storybook:build": "storybook build",
|
|
211
|
-
"storybook:dev": "storybook dev -p 6006",
|
|
212
|
-
"test": "jest",
|
|
213
|
-
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
214
|
-
"ts:check": "tsc",
|
|
215
|
-
"watch": "pkg watch --strict",
|
|
216
|
-
"workshop:build": "workshop build",
|
|
217
|
-
"workshop:dev": "workshop dev",
|
|
218
|
-
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
219
233
|
}
|
|
220
|
-
}
|
|
234
|
+
}
|
|
@@ -21,6 +21,7 @@ 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'
|
|
24
25
|
import {
|
|
25
26
|
Box,
|
|
26
27
|
BoxProps,
|
|
@@ -32,7 +33,6 @@ import {
|
|
|
32
33
|
Text,
|
|
33
34
|
TextInput,
|
|
34
35
|
} 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 = useArrayProp(paddingProp)
|
|
218
218
|
const currentOption = useMemo(
|
|
219
219
|
() => (value !== null ? options.find((o) => o.value === value) : undefined),
|
|
220
220
|
[options, value],
|
|
@@ -470,14 +470,18 @@ 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
|
-
|
|
473
|
+
const openButtonBoxPadding = useMemo(
|
|
474
|
+
() =>
|
|
475
|
+
padding.map((v) => {
|
|
476
|
+
if (v === 0) return 0
|
|
477
|
+
if (v === 1) return 1
|
|
478
|
+
if (v === 2) return 1
|
|
479
|
+
|
|
480
|
+
return v - 2
|
|
481
|
+
}),
|
|
482
|
+
[padding],
|
|
483
|
+
)
|
|
484
|
+
const openButtonPadding = useMemo(() => padding.map((v) => Math.max(v - 1, 0)), [padding])
|
|
481
485
|
const openButtonProps: AutocompleteOpenButtonProps = useMemo(
|
|
482
486
|
() => (typeof openButton === 'object' ? openButton : EMPTY_RECORD),
|
|
483
487
|
[openButton],
|
|
@@ -9,9 +9,8 @@ import {
|
|
|
9
9
|
useState,
|
|
10
10
|
} from 'react'
|
|
11
11
|
|
|
12
|
-
import {useClickOutsideEvent} from '../../hooks'
|
|
12
|
+
import {useArrayProp, useClickOutsideEvent} from '../../hooks'
|
|
13
13
|
import {Box, Popover, Stack, Text} from '../../primitives'
|
|
14
|
-
import {_getArrayProp} from '../../styles'
|
|
15
14
|
import {ExpandButton, StyledBreadcrumbs} from './breadcrumbs.styles'
|
|
16
15
|
|
|
17
16
|
/**
|
|
@@ -31,7 +30,7 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
|
|
|
31
30
|
ref: React.ForwardedRef<HTMLOListElement>,
|
|
32
31
|
) {
|
|
33
32
|
const {children, maxLength, separator, space: spaceRaw = 2, ...restProps} = props
|
|
34
|
-
const space =
|
|
33
|
+
const space = useArrayProp(spaceRaw)
|
|
35
34
|
const [open, setOpen] = useState(false)
|
|
36
35
|
const expandElementRef = useRef<HTMLButtonElement | null>(null)
|
|
37
36
|
const popoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -9,10 +9,14 @@ import {
|
|
|
9
9
|
focusLastDescendant,
|
|
10
10
|
isHTMLElement,
|
|
11
11
|
} from '../../helpers'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
useArrayProp,
|
|
14
|
+
useClickOutsideEvent,
|
|
15
|
+
useGlobalKeyDown,
|
|
16
|
+
usePrefersReducedMotion,
|
|
17
|
+
} from '../../hooks'
|
|
13
18
|
import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
|
|
14
19
|
import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
|
|
15
|
-
import {_getArrayProp} from '../../styles'
|
|
16
20
|
import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
|
|
17
21
|
import {useTheme_v2} from '../../theme'
|
|
18
22
|
import {DialogPosition, Radius} from '../../types'
|
|
@@ -168,9 +172,9 @@ const DialogCard = forwardRef(function DialogCard(
|
|
|
168
172
|
const portal = usePortal()
|
|
169
173
|
const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
|
|
170
174
|
const boundaryElement = useBoundaryElement().element
|
|
171
|
-
const radius =
|
|
172
|
-
const shadow =
|
|
173
|
-
const width =
|
|
175
|
+
const radius = useArrayProp(radiusProp)
|
|
176
|
+
const shadow = useArrayProp(shadowProp)
|
|
177
|
+
const width = useArrayProp(widthProp)
|
|
174
178
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
175
179
|
const contentRef = useRef<HTMLDivElement | null>(null)
|
|
176
180
|
const layer = useLayer()
|
|
@@ -316,11 +320,11 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
316
320
|
const portal = usePortal()
|
|
317
321
|
const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
|
|
318
322
|
const boundaryElement = useBoundaryElement().element
|
|
319
|
-
const cardRadius =
|
|
320
|
-
const padding =
|
|
321
|
-
const position =
|
|
322
|
-
const width =
|
|
323
|
-
const zOffset =
|
|
323
|
+
const cardRadius = useArrayProp(cardRadiusProp)
|
|
324
|
+
const padding = useArrayProp(paddingProp)
|
|
325
|
+
const position = useArrayProp(positionProp)
|
|
326
|
+
const width = useArrayProp(widthProp)
|
|
327
|
+
const zOffset = useArrayProp(zOffsetProp)
|
|
324
328
|
const preDivRef = useRef<HTMLDivElement | null>(null)
|
|
325
329
|
const postDivRef = useRef<HTMLDivElement | null>(null)
|
|
326
330
|
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'
|
|
4
5
|
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 = useArrayProp(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'
|
|
5
6
|
import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
|
|
6
7
|
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={useArrayProp(radius)}
|
|
185
187
|
$tone={tone}
|
|
186
188
|
$scheme={scheme}
|
|
187
189
|
onClick={handleClick}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from 'react'
|
|
11
11
|
import {isValidElementType} from 'react-is'
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {useArrayProp} from '../../hooks'
|
|
14
14
|
import {Box, Flex, Text} from '../../primitives'
|
|
15
15
|
import {Selectable} from '../../primitives/_selectable'
|
|
16
16
|
import {ResponsivePaddingProps, ResponsiveRadiusProps} from '../../primitives/types'
|
|
@@ -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 = useArrayProp(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={useArrayProp(radius)}
|
|
128
|
+
$padding={useArrayProp(0)}
|
|
129
129
|
$tone={disabled ? 'default' : tone}
|
|
130
130
|
$scheme={scheme}
|
|
131
131
|
disabled={disabled}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {forwardRef, useEffect, useState} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {useArrayProp} from '../../hooks'
|
|
5
5
|
import {Box, BoxProps, ResponsiveRadiusProps} from '../../primitives'
|
|
6
6
|
import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
|
|
7
7
|
import {skeletonStyle} from './styles'
|
|
@@ -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={useArrayProp(radius)}
|
|
52
|
+
$visible={delay ? visible : true}
|
|
53
53
|
ref={ref}
|
|
54
54
|
/>
|
|
55
55
|
)
|
|
@@ -2,7 +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 {
|
|
5
|
+
import {useArrayProp} from '../../hooks'
|
|
6
6
|
import {_responsive, ThemeProps} from '../../styles'
|
|
7
7
|
import {Skeleton, SkeletonProps} from './skeleton'
|
|
8
8
|
|
|
@@ -68,7 +68,7 @@ export const TextSkeleton = forwardRef(function TextSkeleton(
|
|
|
68
68
|
ref: React.Ref<HTMLDivElement>,
|
|
69
69
|
) {
|
|
70
70
|
const {size = 2, ...restProps} = props
|
|
71
|
-
const $size =
|
|
71
|
+
const $size = useArrayProp(size)
|
|
72
72
|
|
|
73
73
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="text" />
|
|
74
74
|
})
|
|
@@ -84,7 +84,7 @@ export const LabelSkeleton = forwardRef(function TextSkeleton(
|
|
|
84
84
|
ref: React.Ref<HTMLDivElement>,
|
|
85
85
|
) {
|
|
86
86
|
const {size = 2, ...restProps} = props
|
|
87
|
-
const $size =
|
|
87
|
+
const $size = useArrayProp(size)
|
|
88
88
|
|
|
89
89
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="label" />
|
|
90
90
|
})
|
|
@@ -100,7 +100,7 @@ export const HeadingSkeleton = forwardRef(function TextSkeleton(
|
|
|
100
100
|
ref: React.Ref<HTMLDivElement>,
|
|
101
101
|
) {
|
|
102
102
|
const {size = 2, ...restProps} = props
|
|
103
|
-
const $size =
|
|
103
|
+
const $size = useArrayProp(size)
|
|
104
104
|
|
|
105
105
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="heading" />
|
|
106
106
|
})
|
|
@@ -116,7 +116,7 @@ export const CodeSkeleton = forwardRef(function TextSkeleton(
|
|
|
116
116
|
ref: React.Ref<HTMLDivElement>,
|
|
117
117
|
) {
|
|
118
118
|
const {size = 2, ...restProps} = props
|
|
119
|
-
const $size =
|
|
119
|
+
const $size = useArrayProp(size)
|
|
120
120
|
|
|
121
121
|
return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="code" />
|
|
122
122
|
})
|
package/src/core/hooks/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {useState} from 'react'
|
|
2
2
|
|
|
3
3
|
import {_getArrayProp} from '../styles'
|
|
4
4
|
|
|
@@ -6,14 +6,26 @@ import {_getArrayProp} from '../styles'
|
|
|
6
6
|
export type ArrayPropPrimitive = string | number | boolean | undefined | null
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
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
|
-
|
|
16
|
+
const [[cachedVal, cachedHash], setCache] = useState<[T[], string]>(() => [
|
|
17
|
+
_getArrayProp(val, defaultVal),
|
|
18
|
+
JSON.stringify(val ?? defaultVal),
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
const hash = JSON.stringify(val ?? defaultVal)
|
|
18
22
|
|
|
19
|
-
|
|
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
|
|
31
|
+
}
|
|
@@ -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, useState} from 'react'
|
|
2
|
+
import {forwardRef, useCallback, useEffect, useId, useMemo, useState} from 'react'
|
|
3
3
|
import ReactIs from 'react-is'
|
|
4
4
|
import {styled} from 'styled-components'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {useArrayProp} from '../../hooks'
|
|
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 = useArrayProp(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,6 +114,18 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
113
114
|
}
|
|
114
115
|
}, [onImageLoadError])
|
|
115
116
|
|
|
117
|
+
const initialsSize = useMemo(
|
|
118
|
+
() =>
|
|
119
|
+
size.map((s) => {
|
|
120
|
+
if (s === 1) return 1
|
|
121
|
+
if (s === 2) return 3
|
|
122
|
+
if (s === 3) return 5
|
|
123
|
+
|
|
124
|
+
return 0
|
|
125
|
+
}),
|
|
126
|
+
[size],
|
|
127
|
+
)
|
|
128
|
+
|
|
116
129
|
return (
|
|
117
130
|
<StyledAvatar
|
|
118
131
|
as={as}
|
|
@@ -169,17 +182,7 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
169
182
|
{(imageFailed || !src) && initials && (
|
|
170
183
|
<>
|
|
171
184
|
<Initials>
|
|
172
|
-
<InitialsLabel
|
|
173
|
-
forwardedAs="span"
|
|
174
|
-
size={size.map((s) => {
|
|
175
|
-
if (s === 1) return 1
|
|
176
|
-
if (s === 2) return 3
|
|
177
|
-
if (s === 3) return 5
|
|
178
|
-
|
|
179
|
-
return 0
|
|
180
|
-
})}
|
|
181
|
-
weight="medium"
|
|
182
|
-
>
|
|
185
|
+
<InitialsLabel forwardedAs="span" size={initialsSize} weight="medium">
|
|
183
186
|
{initials}
|
|
184
187
|
</InitialsLabel>
|
|
185
188
|
</Initials>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {getTheme_v2} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef} from 'react'
|
|
2
|
+
import {forwardRef, useMemo} from 'react'
|
|
3
3
|
import {css, styled} from 'styled-components'
|
|
4
4
|
|
|
5
5
|
import {EMPTY_RECORD} from '../../constants'
|
|
6
|
-
import {
|
|
6
|
+
import {useArrayProp} from '../../hooks'
|
|
7
7
|
import {_responsive, rem, ThemeProps} from '../../styles'
|
|
8
8
|
import {AvatarSize} from '../../types'
|
|
9
9
|
import {Label} from '../label'
|
|
@@ -69,21 +69,23 @@ export const AvatarCounter = forwardRef(function AvatarCounter(
|
|
|
69
69
|
ref: React.Ref<HTMLDivElement>,
|
|
70
70
|
) {
|
|
71
71
|
const {count, size: sizeProp = 1} = props
|
|
72
|
-
const size =
|
|
72
|
+
const size = useArrayProp(sizeProp)
|
|
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
|
+
)
|
|
73
85
|
|
|
74
86
|
return (
|
|
75
87
|
<StyledAvatarCounter $size={size} data-ui="AvatarCounter" ref={ref}>
|
|
76
|
-
<Label
|
|
77
|
-
as="span"
|
|
78
|
-
size={size.map((s) => {
|
|
79
|
-
if (s === 1) return 1
|
|
80
|
-
if (s === 2) return 3
|
|
81
|
-
if (s === 3) return 5
|
|
82
|
-
|
|
83
|
-
return 0
|
|
84
|
-
})}
|
|
85
|
-
weight="medium"
|
|
86
|
-
>
|
|
88
|
+
<Label as="span" size={fontSize} weight="medium">
|
|
87
89
|
{count}
|
|
88
90
|
</Label>
|
|
89
91
|
</StyledAvatarCounter>
|
|
@@ -3,7 +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 {
|
|
6
|
+
import {useArrayProp} from '../../hooks'
|
|
7
7
|
import {_responsive, rem, ThemeProps} from '../../styles'
|
|
8
8
|
import {AvatarSize} from '../../types'
|
|
9
9
|
import {AvatarCounter} from './avatarCounter'
|
|
@@ -71,7 +71,7 @@ export const AvatarStack = forwardRef(function AvatarStack(
|
|
|
71
71
|
} = props
|
|
72
72
|
const children: React.JSX.Element[] = Children.toArray(childrenProp).filter(isValidElement)
|
|
73
73
|
const maxLength = Math.max(maxLengthProp, 0)
|
|
74
|
-
const size =
|
|
74
|
+
const size = useArrayProp(sizeProp)
|
|
75
75
|
|
|
76
76
|
const len = children.length
|
|
77
77
|
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 {useArrayProp} from '../../hooks'
|
|
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={useArrayProp(radius)}
|
|
55
|
+
padding={useArrayProp(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 {useArrayProp} from '../../hooks'
|
|
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={useArrayProp(column)}
|
|
100
|
+
$columnStart={useArrayProp(columnStart)}
|
|
101
|
+
$columnEnd={useArrayProp(columnEnd)}
|
|
102
|
+
$display={useArrayProp(display)}
|
|
103
|
+
$flex={useArrayProp(flex)}
|
|
104
|
+
$height={useArrayProp(height)}
|
|
105
|
+
$margin={useArrayProp(margin)}
|
|
106
|
+
$marginX={useArrayProp(marginX)}
|
|
107
|
+
$marginY={useArrayProp(marginY)}
|
|
108
|
+
$marginTop={useArrayProp(marginTop)}
|
|
109
|
+
$marginRight={useArrayProp(marginRight)}
|
|
110
|
+
$marginBottom={useArrayProp(marginBottom)}
|
|
111
|
+
$marginLeft={useArrayProp(marginLeft)}
|
|
112
|
+
$overflow={useArrayProp(overflow)}
|
|
113
|
+
$padding={useArrayProp(padding)}
|
|
114
|
+
$paddingX={useArrayProp(paddingX)}
|
|
115
|
+
$paddingY={useArrayProp(paddingY)}
|
|
116
|
+
$paddingTop={useArrayProp(paddingTop)}
|
|
117
|
+
$paddingRight={useArrayProp(paddingRight)}
|
|
118
|
+
$paddingBottom={useArrayProp(paddingBottom)}
|
|
119
|
+
$paddingLeft={useArrayProp(paddingLeft)}
|
|
120
|
+
$row={useArrayProp(row)}
|
|
121
|
+
$rowStart={useArrayProp(rowStart)}
|
|
122
|
+
$rowEnd={useArrayProp(rowEnd)}
|
|
123
|
+
$sizing={useArrayProp(sizing)}
|
|
124
124
|
as={asProp}
|
|
125
125
|
ref={ref}
|
|
126
126
|
>
|