@sanity/ui 2.3.6 → 2.3.7-canary.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.
- package/dist/index.compiled.mjs +7488 -0
- package/dist/index.compiled.mjs.map +1 -0
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.esm.js +1047 -1072
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1054 -1079
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1047 -1072
- package/dist/index.mjs.map +1 -1
- package/package.json +31 -35
- package/src/core/components/autocomplete/autocomplete.tsx +31 -34
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +3 -2
- package/src/core/components/dialog/dialog.tsx +23 -12
- package/src/core/components/hotkeys/hotkeys.tsx +3 -3
- package/src/core/components/menu/menu.tsx +5 -1
- package/src/core/components/menu/menuButton.tsx +17 -32
- package/src/core/components/menu/menuGroup.tsx +7 -5
- package/src/core/components/menu/menuItem.tsx +10 -6
- package/src/core/components/skeleton/skeleton.tsx +5 -11
- package/src/core/components/skeleton/textSkeleton.tsx +6 -7
- package/src/core/components/toast/toastProvider.tsx +26 -24
- package/src/core/components/tree/treeItem.styles.ts +21 -0
- package/src/core/components/tree/treeItem.tsx +31 -44
- package/src/core/hooks/useArrayProp.ts +11 -10
- package/src/core/primitives/avatar/avatar.tsx +11 -15
- package/src/core/primitives/avatar/avatarCounter.tsx +11 -17
- package/src/core/primitives/avatar/avatarStack.tsx +3 -7
- package/src/core/primitives/badge/badge.tsx +7 -4
- package/src/core/primitives/box/box.tsx +53 -27
- package/src/core/primitives/button/button.tsx +11 -12
- package/src/core/primitives/card/card.tsx +17 -9
- package/src/core/primitives/code/code.tsx +4 -3
- package/src/core/primitives/container/container.tsx +4 -11
- package/src/core/primitives/flex/flex.tsx +13 -7
- package/src/core/primitives/grid/grid.tsx +19 -10
- package/src/core/primitives/heading/heading.tsx +7 -4
- package/src/core/primitives/inline/inline.tsx +3 -2
- package/src/core/primitives/kbd/kbd.tsx +4 -3
- package/src/core/primitives/label/label.tsx +7 -4
- package/src/core/primitives/popover/popover.tsx +49 -49
- package/src/core/primitives/select/select.tsx +12 -6
- package/src/core/primitives/stack/stack.tsx +4 -3
- package/src/core/primitives/text/text.tsx +7 -4
- package/src/core/primitives/textArea/textArea.tsx +12 -6
- package/src/core/primitives/textInput/textInput.tsx +6 -5
- package/src/core/primitives/tooltip/tooltip.tsx +14 -7
- package/src/core/theme/themeProvider.tsx +4 -6
- package/src/core/utils/elementQuery/elementQuery.tsx +4 -3
- package/src/core/utils/layer/getLayerContext.test.ts +0 -4
- package/src/core/utils/layer/layer.test.tsx +0 -2
- package/src/core/utils/layer/layerProvider.tsx +35 -43
- package/src/core/utils/layer/types.ts +0 -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 {
|
|
3
|
+
import {_getArrayProp} from '../../styles'
|
|
4
4
|
import {responsiveGridStyle, ResponsiveGridStyleProps} from '../../styles/internal'
|
|
5
5
|
import {Box, BoxProps} from '../box'
|
|
6
6
|
import {ResponsiveGridProps} from '../types'
|
|
@@ -24,19 +24,28 @@ 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
|
+
|
|
27
36
|
return (
|
|
28
37
|
<Root
|
|
29
38
|
data-as={typeof as === 'string' ? as : undefined}
|
|
30
39
|
data-ui="Grid"
|
|
31
40
|
{...restProps}
|
|
32
|
-
$autoRows={
|
|
33
|
-
$autoCols={
|
|
34
|
-
$autoFlow={
|
|
35
|
-
$columns={
|
|
36
|
-
$gap={
|
|
37
|
-
$gapX={
|
|
38
|
-
$gapY={
|
|
39
|
-
$rows={
|
|
41
|
+
$autoRows={$autoRows}
|
|
42
|
+
$autoCols={$autoCols}
|
|
43
|
+
$autoFlow={$autoFlow}
|
|
44
|
+
$columns={$columns}
|
|
45
|
+
$gap={$gap}
|
|
46
|
+
$gapX={$gapX}
|
|
47
|
+
$gapY={$gapY}
|
|
48
|
+
$rows={$rows}
|
|
40
49
|
forwardedAs={as}
|
|
41
50
|
ref={ref}
|
|
42
51
|
>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef} from 'react'
|
|
2
|
+
import {forwardRef, useMemo} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
|
-
import {
|
|
4
|
+
import {_getArrayProp} from '../../styles'
|
|
5
5
|
import {
|
|
6
6
|
ResponsiveFontStyleProps,
|
|
7
7
|
responsiveHeadingFont,
|
|
@@ -62,6 +62,9 @@ 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
|
+
|
|
65
68
|
let children = childrenProp
|
|
66
69
|
|
|
67
70
|
if (textOverflow === 'ellipsis') {
|
|
@@ -73,9 +76,9 @@ export const Heading = forwardRef(function Heading(
|
|
|
73
76
|
data-ui="Heading"
|
|
74
77
|
{...restProps}
|
|
75
78
|
$accent={accent}
|
|
76
|
-
$align={
|
|
79
|
+
$align={$align}
|
|
80
|
+
$size={$size}
|
|
77
81
|
$muted={muted}
|
|
78
|
-
$size={useArrayProp(size)}
|
|
79
82
|
$weight={weight}
|
|
80
83
|
ref={ref}
|
|
81
84
|
>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {forwardRef, useMemo, Children} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
|
-
import {
|
|
3
|
+
import {_getArrayProp} from '../../styles'
|
|
4
4
|
import {Box, BoxProps} from '../box'
|
|
5
5
|
import {inlineBaseStyle, inlineSpaceStyle} from './styles'
|
|
6
6
|
import {ResponsiveInlineSpaceStyleProps} from './types'
|
|
@@ -26,6 +26,7 @@ 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])
|
|
29
30
|
const children = useMemo(
|
|
30
31
|
() => Children.map(childrenProp, (child) => child && <div>{child}</div>),
|
|
31
32
|
[childrenProp],
|
|
@@ -35,7 +36,7 @@ export const Inline = forwardRef(function Inline(
|
|
|
35
36
|
<Root
|
|
36
37
|
data-ui="Inline"
|
|
37
38
|
{...restProps}
|
|
38
|
-
$space={
|
|
39
|
+
$space={$space}
|
|
39
40
|
forwardedAs={as}
|
|
40
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
42
|
ref={ref as any}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {forwardRef} from 'react'
|
|
1
|
+
import {forwardRef, useMemo} from 'react'
|
|
2
2
|
import {styled, css} from 'styled-components'
|
|
3
|
-
import {
|
|
3
|
+
import {_getArrayProp} from '../../styles'
|
|
4
4
|
import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
|
|
5
5
|
import {Radius} from '../../types'
|
|
6
6
|
import {Box} from '../box'
|
|
@@ -46,9 +46,10 @@ 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])
|
|
49
50
|
|
|
50
51
|
return (
|
|
51
|
-
<Root data-ui="KBD" {...restProps} $radius={
|
|
52
|
+
<Root data-ui="KBD" {...restProps} $radius={$radius} ref={ref}>
|
|
52
53
|
<Box as="span" padding={padding}>
|
|
53
54
|
<Text as="span" size={fontSize} weight="semibold">
|
|
54
55
|
{children}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef} from 'react'
|
|
2
|
+
import {forwardRef, useMemo} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
|
-
import {
|
|
4
|
+
import {_getArrayProp} from '../../styles'
|
|
5
5
|
import {responsiveLabelFont, responsiveTextAlignStyle} from '../../styles/internal'
|
|
6
6
|
import {TextAlign} from '../../types'
|
|
7
7
|
import {labelBaseStyle} from './styles'
|
|
@@ -59,6 +59,9 @@ 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
|
+
|
|
62
65
|
let children = childrenProp
|
|
63
66
|
|
|
64
67
|
if (textOverflow === 'ellipsis') {
|
|
@@ -72,9 +75,9 @@ export const Label = forwardRef(function Label(
|
|
|
72
75
|
data-ui="Label"
|
|
73
76
|
{...restProps}
|
|
74
77
|
$accent={accent}
|
|
75
|
-
$align={
|
|
78
|
+
$align={$align}
|
|
79
|
+
$size={$size}
|
|
76
80
|
$muted={muted}
|
|
77
|
-
$size={useArrayProp(size)}
|
|
78
81
|
$weight={weight}
|
|
79
82
|
ref={ref}
|
|
80
83
|
>
|
|
@@ -23,8 +23,9 @@ import {
|
|
|
23
23
|
useMemo,
|
|
24
24
|
useRef,
|
|
25
25
|
} from 'react'
|
|
26
|
-
import {
|
|
26
|
+
import {useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
|
|
27
27
|
import {origin} from '../../middleware/origin'
|
|
28
|
+
import {_getArrayProp} from '../../styles'
|
|
28
29
|
import {useTheme_v2} from '../../theme'
|
|
29
30
|
import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
|
|
30
31
|
import {
|
|
@@ -65,6 +66,7 @@ export interface PopoverProps
|
|
|
65
66
|
arrow?: boolean
|
|
66
67
|
/** @deprecated Use `floatingBoundary` and/or `referenceBoundary` instead */
|
|
67
68
|
boundaryElement?: HTMLElement | null
|
|
69
|
+
/** @deprecated Use `referenceElement` instead */
|
|
68
70
|
children?: React.ReactElement
|
|
69
71
|
/**
|
|
70
72
|
* When `true`, prevent overflow within the current boundary:
|
|
@@ -131,15 +133,14 @@ export const Popover = memo(
|
|
|
131
133
|
__unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
|
|
132
134
|
animate: _animate = false,
|
|
133
135
|
arrow: arrowProp = false,
|
|
134
|
-
boundaryElement
|
|
135
|
-
children:
|
|
136
|
+
boundaryElement: _boundaryElement,
|
|
137
|
+
children: _children,
|
|
136
138
|
constrainSize = false,
|
|
137
139
|
content,
|
|
138
140
|
disabled,
|
|
139
|
-
fallbackPlacements
|
|
140
|
-
DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
|
|
141
|
+
fallbackPlacements: _fallbackPlacements,
|
|
141
142
|
matchReferenceWidth,
|
|
142
|
-
floatingBoundary
|
|
143
|
+
floatingBoundary: _floatingBoundary,
|
|
143
144
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
144
145
|
onActivate,
|
|
145
146
|
open,
|
|
@@ -149,24 +150,32 @@ export const Popover = memo(
|
|
|
149
150
|
portal,
|
|
150
151
|
preventOverflow = true,
|
|
151
152
|
radius: radiusProp = 3,
|
|
152
|
-
referenceBoundary
|
|
153
|
+
referenceBoundary: _referenceBoundary,
|
|
153
154
|
referenceElement,
|
|
154
155
|
scheme,
|
|
155
156
|
shadow: shadowProp = 3,
|
|
156
157
|
tone = 'inherit',
|
|
157
158
|
width: widthProp = 'auto',
|
|
158
|
-
zOffset:
|
|
159
|
+
zOffset: _zOffset,
|
|
159
160
|
updateRef,
|
|
160
161
|
...restProps
|
|
161
162
|
} = 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
|
|
162
171
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
163
172
|
const animate = prefersReducedMotion ? false : _animate
|
|
164
173
|
const boundarySize = useElementSize(boundaryElement)?.border
|
|
165
|
-
const padding =
|
|
166
|
-
const radius =
|
|
167
|
-
const shadow =
|
|
168
|
-
const widthArrayProp =
|
|
169
|
-
const zOffset =
|
|
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])
|
|
170
179
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
171
180
|
const arrowRef = useRef<HTMLDivElement | null>(null)
|
|
172
181
|
const rootBoundary: RootBoundary = 'viewport'
|
|
@@ -355,45 +364,26 @@ export const Popover = memo(
|
|
|
355
364
|
[refs],
|
|
356
365
|
)
|
|
357
366
|
|
|
358
|
-
|
|
359
|
-
(node: HTMLElement | null) => {
|
|
360
|
-
refs.setReference(node)
|
|
361
|
-
|
|
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])
|
|
379
|
-
|
|
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])
|
|
367
|
+
useImperativeHandle(updateRef, () => update, [update])
|
|
389
368
|
|
|
390
369
|
useEffect(() => {
|
|
391
|
-
if (
|
|
370
|
+
if (_children) return
|
|
392
371
|
refs.setReference(referenceElement || null)
|
|
393
|
-
}, [referenceElement, refs
|
|
372
|
+
}, [_children, referenceElement, refs])
|
|
373
|
+
|
|
374
|
+
const children = useMemo(() => {
|
|
375
|
+
if (!_children || referenceElement) return null
|
|
376
|
+
|
|
377
|
+
return cloneElement(_children, {
|
|
378
|
+
ref: (node: HTMLDivElement | null): void => {
|
|
379
|
+
logDeprecatedWarning()
|
|
380
|
+
refs.setReference(node)
|
|
381
|
+
},
|
|
382
|
+
})
|
|
383
|
+
}, [_children, referenceElement, refs])
|
|
394
384
|
|
|
395
385
|
if (disabled) {
|
|
396
|
-
return
|
|
386
|
+
return _children || <></>
|
|
397
387
|
}
|
|
398
388
|
|
|
399
389
|
const popover = (
|
|
@@ -448,11 +438,21 @@ export const Popover = memo(
|
|
|
448
438
|
)}
|
|
449
439
|
</ConditionalWrapper>
|
|
450
440
|
|
|
451
|
-
{/* the referred element */}
|
|
452
|
-
{
|
|
441
|
+
{/* the referred element (legacy, use referenceElement instead) */}
|
|
442
|
+
{children}
|
|
453
443
|
</>
|
|
454
444
|
)
|
|
455
445
|
}),
|
|
456
446
|
)
|
|
457
447
|
|
|
458
448
|
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,7 +1,8 @@
|
|
|
1
1
|
import {ChevronDownIcon} from '@sanity/icons'
|
|
2
|
-
import {forwardRef, useImperativeHandle, useRef} from 'react'
|
|
2
|
+
import {forwardRef, useImperativeHandle, useMemo, useRef} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
|
-
import {useCustomValidity
|
|
4
|
+
import {useCustomValidity} from '../../hooks'
|
|
5
|
+
import {_getArrayProp} from '../../styles'
|
|
5
6
|
import {Radius} from '../../types'
|
|
6
7
|
import {Box} from '../box'
|
|
7
8
|
import {Text} from '../text'
|
|
@@ -59,16 +60,21 @@ export const Select = forwardRef(function Select(
|
|
|
59
60
|
|
|
60
61
|
useCustomValidity(ref, customValidity)
|
|
61
62
|
|
|
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
|
+
|
|
62
68
|
return (
|
|
63
69
|
<Root data-ui="Select">
|
|
64
70
|
<Input
|
|
65
71
|
data-read-only={!disabled && readOnly ? '' : undefined}
|
|
66
72
|
data-ui="Select"
|
|
67
73
|
{...restProps}
|
|
68
|
-
$fontSize={
|
|
69
|
-
$padding={
|
|
70
|
-
$radius={
|
|
71
|
-
$space={
|
|
74
|
+
$fontSize={$fontSize}
|
|
75
|
+
$padding={$padding}
|
|
76
|
+
$radius={$radius}
|
|
77
|
+
$space={$space}
|
|
72
78
|
disabled={disabled || readOnly}
|
|
73
79
|
ref={ref}
|
|
74
80
|
>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {forwardRef} from 'react'
|
|
1
|
+
import {forwardRef, useMemo} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
|
-
import {
|
|
3
|
+
import {_getArrayProp} from '../../styles'
|
|
4
4
|
import {Box, BoxProps} from '../box'
|
|
5
5
|
import {stackBaseStyle, responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps} from './styles'
|
|
6
6
|
|
|
@@ -24,13 +24,14 @@ 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])
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
30
|
<Root
|
|
30
31
|
data-as={typeof as === 'string' ? as : undefined}
|
|
31
32
|
data-ui="Stack"
|
|
32
33
|
{...restProps}
|
|
33
|
-
$space={
|
|
34
|
+
$space={$space}
|
|
34
35
|
forwardedAs={as}
|
|
35
36
|
ref={ref}
|
|
36
37
|
/>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef} from 'react'
|
|
2
|
+
import {forwardRef, useMemo} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
|
-
import {
|
|
4
|
+
import {_getArrayProp} from '../../styles'
|
|
5
5
|
import {
|
|
6
6
|
ResponsiveFontStyleProps,
|
|
7
7
|
responsiveTextAlignStyle,
|
|
@@ -63,6 +63,9 @@ 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
|
+
|
|
66
69
|
let children = childrenProp
|
|
67
70
|
|
|
68
71
|
if (textOverflow === 'ellipsis') {
|
|
@@ -74,10 +77,10 @@ export const Text = forwardRef(function Text(
|
|
|
74
77
|
data-ui="Text"
|
|
75
78
|
{...restProps}
|
|
76
79
|
$accent={accent}
|
|
77
|
-
$align={
|
|
80
|
+
$align={$align}
|
|
81
|
+
$size={$size}
|
|
78
82
|
$muted={muted}
|
|
79
83
|
ref={ref}
|
|
80
|
-
$size={useArrayProp(size)}
|
|
81
84
|
$weight={weight}
|
|
82
85
|
>
|
|
83
86
|
<span>{children}</span>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
2
|
-
import {forwardRef, useImperativeHandle, useRef} from 'react'
|
|
2
|
+
import {forwardRef, useImperativeHandle, useMemo, useRef} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
|
-
import {useCustomValidity
|
|
4
|
+
import {useCustomValidity} from '../../hooks'
|
|
5
|
+
import {_getArrayProp} from '../../styles'
|
|
5
6
|
import {
|
|
6
7
|
responsiveInputPaddingStyle,
|
|
7
8
|
responsiveRadiusStyle,
|
|
@@ -80,6 +81,11 @@ export const TextArea = forwardRef(function TextArea(
|
|
|
80
81
|
|
|
81
82
|
useCustomValidity(ref, customValidity)
|
|
82
83
|
|
|
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
|
+
|
|
83
89
|
return (
|
|
84
90
|
<Root data-ui="TextArea">
|
|
85
91
|
<InputRoot>
|
|
@@ -88,17 +94,17 @@ export const TextArea = forwardRef(function TextArea(
|
|
|
88
94
|
data-scheme={rootTheme.scheme}
|
|
89
95
|
data-tone={rootTheme.tone}
|
|
90
96
|
{...restProps}
|
|
91
|
-
$fontSize={
|
|
92
|
-
$padding={
|
|
97
|
+
$fontSize={$fontSize}
|
|
98
|
+
$padding={$padding}
|
|
99
|
+
$space={$space}
|
|
93
100
|
$scheme={rootTheme.scheme}
|
|
94
|
-
$space={useArrayProp(0)}
|
|
95
101
|
$tone={rootTheme.tone}
|
|
96
102
|
$weight={weight}
|
|
97
103
|
disabled={disabled}
|
|
98
104
|
ref={ref}
|
|
99
105
|
/>
|
|
100
106
|
<Presentation
|
|
101
|
-
$radius={
|
|
107
|
+
$radius={$radius}
|
|
102
108
|
$scheme={rootTheme.scheme}
|
|
103
109
|
$tone={rootTheme.tone}
|
|
104
110
|
data-border={border ? '' : undefined}
|
|
@@ -4,7 +4,8 @@ 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 {
|
|
7
|
+
import {useCustomValidity} from '../../hooks'
|
|
8
|
+
import {_getArrayProp} from '../../styles'
|
|
8
9
|
import {
|
|
9
10
|
responsiveRadiusStyle,
|
|
10
11
|
ResponsiveRadiusStyleProps,
|
|
@@ -177,10 +178,10 @@ export const TextInput = forwardRef(function TextInput(
|
|
|
177
178
|
|
|
178
179
|
const rootTheme = useRootTheme()
|
|
179
180
|
|
|
180
|
-
const fontSize =
|
|
181
|
-
const padding =
|
|
182
|
-
const radius =
|
|
183
|
-
const space =
|
|
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])
|
|
184
185
|
|
|
185
186
|
// Transient properties
|
|
186
187
|
const $hasClearButton = Boolean(clearButton)
|
|
@@ -24,9 +24,10 @@ import {
|
|
|
24
24
|
useImperativeHandle,
|
|
25
25
|
} from 'react'
|
|
26
26
|
import {styled} from 'styled-components'
|
|
27
|
-
import {
|
|
27
|
+
import {usePrefersReducedMotion} from '../../hooks'
|
|
28
28
|
import {useDelayedState} from '../../hooks/useDelayedState'
|
|
29
29
|
import {origin} from '../../middleware/origin'
|
|
30
|
+
import {_getArrayProp} from '../../styles'
|
|
30
31
|
import {useTheme_v2} from '../../theme'
|
|
31
32
|
import type {Placement} from '../../types'
|
|
32
33
|
import {
|
|
@@ -104,25 +105,31 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
104
105
|
const {
|
|
105
106
|
animate: _animate = false,
|
|
106
107
|
arrow: arrowProp = false,
|
|
107
|
-
boundaryElement
|
|
108
|
+
boundaryElement: _boundaryElement,
|
|
108
109
|
children: childProp,
|
|
109
110
|
content,
|
|
110
111
|
disabled,
|
|
111
|
-
fallbackPlacements:
|
|
112
|
-
DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
|
|
112
|
+
fallbackPlacements: _fallbackPlacements,
|
|
113
113
|
padding = 2,
|
|
114
114
|
placement: placementProp = 'bottom',
|
|
115
115
|
portal: portalProp,
|
|
116
116
|
radius = 2,
|
|
117
117
|
scheme,
|
|
118
118
|
shadow = 2,
|
|
119
|
-
zOffset
|
|
119
|
+
zOffset: _zOffset,
|
|
120
120
|
delay,
|
|
121
121
|
...restProps
|
|
122
122
|
} = props
|
|
123
|
+
const zOffset = _zOffset ?? layer.tooltip.zOffset
|
|
124
|
+
const fallbackPlacementsProp =
|
|
125
|
+
_fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom']
|
|
126
|
+
const boundaryElement = _boundaryElement ?? boundaryElementContext?.element
|
|
123
127
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
124
128
|
const animate = prefersReducedMotion ? false : _animate
|
|
125
|
-
const fallbackPlacements =
|
|
129
|
+
const fallbackPlacements = useMemo(
|
|
130
|
+
() => _getArrayProp(fallbackPlacementsProp),
|
|
131
|
+
[fallbackPlacementsProp],
|
|
132
|
+
)
|
|
126
133
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
127
134
|
const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null)
|
|
128
135
|
const arrowRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -291,7 +298,7 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
291
298
|
useEffect(() => {
|
|
292
299
|
if (!showTooltip) return
|
|
293
300
|
|
|
294
|
-
|
|
301
|
+
const handleWindowMouseMove = (event: MouseEvent) => {
|
|
295
302
|
if (!referenceElement) return
|
|
296
303
|
|
|
297
304
|
const isHoveringReference =
|
|
@@ -24,13 +24,11 @@ export interface ThemeProviderProps {
|
|
|
24
24
|
* @public
|
|
25
25
|
*/
|
|
26
26
|
export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
|
|
27
|
+
const {children} = props
|
|
27
28
|
const parentTheme = useContext(ThemeContext)
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
theme: rootTheme = parentTheme?.theme || null,
|
|
32
|
-
tone = parentTheme?.tone || 'default',
|
|
33
|
-
} = props
|
|
29
|
+
const scheme = props.scheme ?? (parentTheme?.scheme || 'light')
|
|
30
|
+
const rootTheme = props.theme ?? (parentTheme?.theme || null)
|
|
31
|
+
const tone = props.tone ?? (parentTheme?.tone || 'default')
|
|
34
32
|
|
|
35
33
|
const themeContext: ThemeContextValue | null = useMemo(() => {
|
|
36
34
|
if (!rootTheme) return null
|
|
@@ -21,15 +21,16 @@ export const ElementQuery = forwardRef(function ElementQuery(
|
|
|
21
21
|
forwardedRef: React.ForwardedRef<HTMLDivElement>,
|
|
22
22
|
) {
|
|
23
23
|
const theme = useTheme_v2()
|
|
24
|
-
const {children, media
|
|
24
|
+
const {children, media: _media, ...restProps} = props
|
|
25
|
+
const media = _media ?? theme.media
|
|
25
26
|
|
|
26
27
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
27
28
|
const [element, setElement] = useState<HTMLDivElement | null>(null)
|
|
28
29
|
const elementSize = useElementSize(element)
|
|
29
30
|
const width = useMemo(() => elementSize?.border.width ?? window.innerWidth, [elementSize])
|
|
30
31
|
|
|
31
|
-
const max =
|
|
32
|
-
const min =
|
|
32
|
+
const max = findMaxBreakpoints(media, width)
|
|
33
|
+
const min = findMinBreakpoints(media, width)
|
|
33
34
|
|
|
34
35
|
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
35
36
|
|
|
@@ -8,9 +8,6 @@ describe('getLayerContext', () => {
|
|
|
8
8
|
version: 0.0,
|
|
9
9
|
isTopLayer: true,
|
|
10
10
|
level: 0,
|
|
11
|
-
registerChild: () => () => {
|
|
12
|
-
//
|
|
13
|
-
},
|
|
14
11
|
size: 0,
|
|
15
12
|
zIndex: 0,
|
|
16
13
|
}
|
|
@@ -21,7 +18,6 @@ describe('getLayerContext', () => {
|
|
|
21
18
|
version: 0.0,
|
|
22
19
|
isTopLayer: true,
|
|
23
20
|
level: 0,
|
|
24
|
-
registerChild: expect.any(Function),
|
|
25
21
|
size: 0,
|
|
26
22
|
zIndex: 0,
|
|
27
23
|
})
|
|
@@ -24,7 +24,6 @@ describe('utils/layer', () => {
|
|
|
24
24
|
version: 0.0,
|
|
25
25
|
isTopLayer: true,
|
|
26
26
|
level: 0,
|
|
27
|
-
registerChild: () => () => undefined,
|
|
28
27
|
size: 0,
|
|
29
28
|
zIndex: 0,
|
|
30
29
|
}
|
|
@@ -40,7 +39,6 @@ describe('utils/layer', () => {
|
|
|
40
39
|
|
|
41
40
|
expect(log.mock.calls[0][0].version).toBe(0.0)
|
|
42
41
|
expect(log.mock.calls[0][0].isTopLayer).toBe(true)
|
|
43
|
-
expect(typeof log.mock.calls[0][0].registerChild).toBe('function')
|
|
44
42
|
expect(log.mock.calls[0][0].size).toBe(0)
|
|
45
43
|
expect(log.mock.calls[0][0].zIndex).toBe(0)
|
|
46
44
|
})
|