@sanity/ui 3.0.0-static.11 → 3.0.0-static.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 +1293 -1215
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-cjs/buildCommand.js +28 -10
- package/dist/_chunks-cjs/buildCommand.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +1284 -1202
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/_visual-editing.d.mts +528 -358
- package/dist/_visual-editing.d.ts +528 -358
- package/dist/cli.js +1 -1
- package/dist/css.d.mts +143 -73
- package/dist/css.d.ts +143 -73
- package/dist/css.js +329 -472
- package/dist/css.js.map +1 -1
- package/dist/css.mjs +330 -473
- package/dist/css.mjs.map +1 -1
- package/dist/index.d.mts +1362 -869
- package/dist/index.d.ts +1362 -869
- package/dist/index.js +383 -308
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +387 -312
- package/dist/index.mjs.map +1 -1
- package/dist/sanity-palette.css +105 -1
- package/dist/sanity-palette.min.css +1 -0
- package/dist/sanity-theme.css +4571 -1
- package/dist/sanity-theme.min.css +1 -0
- package/dist/system.css +22053 -21946
- package/dist/system.min.css +1 -0
- package/dist/theme.d.mts +51 -106
- package/dist/theme.d.ts +51 -106
- package/dist/theme.js +9 -9
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +9 -9
- package/dist/theme.mjs.map +1 -1
- package/package.json +10 -5
- package/src/cli/buildCommand.ts +46 -19
- package/src/css/_comp.ts +2 -2
- package/src/css/{compile/compileStyle.ts → _compileStyle.ts} +7 -7
- package/src/css/{system.style.ts → _system.style.ts} +3 -2
- package/src/css/aspects/display/display.ts +1 -0
- package/src/css/aspects/display/types.ts +2 -3
- package/src/css/aspects/flex/types.ts +4 -12
- package/src/css/aspects/flexItem/types.ts +1 -3
- package/src/css/aspects/font/types.ts +1 -3
- package/src/css/aspects/grid/grid.ts +1 -0
- package/src/css/aspects/grid/types.ts +5 -9
- package/src/css/aspects/gridItem/gridItem.ts +1 -1
- package/src/css/aspects/gridItem/types.ts +7 -18
- package/src/css/aspects/height/height.ts +3 -4
- package/src/css/aspects/inset/inset.ts +1 -0
- package/src/css/aspects/margin/margin.ts +1 -0
- package/src/css/aspects/margin/types.ts +1 -0
- package/src/css/aspects/maxWidth/maxWidth.ts +1 -0
- package/src/css/aspects/maxWidth/types.ts +1 -0
- package/src/css/aspects/minWidth/minWidth.ts +1 -0
- package/src/css/aspects/minWidth/types.ts +2 -0
- package/src/css/aspects/overflow/overflow.ts +1 -0
- package/src/css/aspects/padding/padding.ts +1 -0
- package/src/css/aspects/pointerEvents/pointerEvents.ts +1 -0
- package/src/css/aspects/position/position.ts +1 -0
- package/src/css/aspects/shadow/shadow.ts +1 -0
- package/src/css/aspects/textOverflow/textOverflow.ts +1 -0
- package/src/css/aspects/textOverflow/types.ts +1 -0
- package/src/css/aspects/width/types.ts +2 -0
- package/src/css/aspects/width/width.ts +1 -0
- package/src/css/{compile/compilePalette.ts → compilePalette.ts} +14 -10
- package/src/css/compileSystem.ts +7 -0
- package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
- package/src/css/{compile/compileTheme_v3.ts → compileTheme_v3.ts} +123 -104
- package/src/css/components/breadcrumbs/breadcrumbs.ts +1 -0
- package/src/css/components/dialog/dialog.ts +7 -0
- package/src/css/components/menu/menu.ts +2 -0
- package/src/css/components/skeleton/skeleton.ts +4 -0
- package/src/css/components/skeleton/types.ts +4 -0
- package/src/css/components/toast/toast.ts +5 -0
- package/src/css/components/tree/tree.ts +1 -0
- package/src/css/composeClassNames.ts +4 -2
- package/src/css/constants.ts +2 -0
- package/src/css/index.ts +3 -3
- package/src/css/primitives/_arrow/_arrow.ts +3 -0
- package/src/css/primitives/_input/input.ts +2 -0
- package/src/css/primitives/_selectable/_selectable.style.ts +1 -2
- package/src/css/primitives/_selectable/selectable.ts +1 -2
- package/src/css/primitives/avatar/avatar.style.ts +5 -8
- package/src/css/primitives/avatar/avatar.ts +6 -0
- package/src/css/primitives/avatar/types.ts +1 -0
- package/src/css/primitives/box/types.ts +1 -3
- package/src/css/primitives/button/button.ts +4 -21
- package/src/css/primitives/button/index.ts +1 -0
- package/src/css/primitives/button/types.ts +18 -0
- package/src/css/primitives/card/card.style.ts +3 -6
- package/src/css/primitives/card/card.ts +2 -2
- package/src/css/primitives/card/types.ts +2 -2
- package/src/css/primitives/checkbox/checkbox.ts +2 -0
- package/src/css/primitives/container/container.ts +1 -0
- package/src/css/primitives/container/types.ts +1 -0
- package/src/css/primitives/kbd/kbd.ts +1 -0
- package/src/css/primitives/label/types.ts +7 -2
- package/src/css/primitives/popover/popover.ts +2 -0
- package/src/css/primitives/radio/radio.ts +1 -0
- package/src/css/primitives/select/select.ts +2 -0
- package/src/css/primitives/spinner/spinner.ts +2 -0
- package/src/css/primitives/switch/switch.ts +5 -0
- package/src/css/primitives/text/types.ts +4 -0
- package/src/css/primitives/textArea/textArea.ts +1 -0
- package/src/css/primitives/textInput/textInput.ts +1 -0
- package/src/css/primitives/tooltip/tooltip.ts +2 -0
- package/src/css/scopeClassName.ts +1 -0
- package/src/css/types.ts +9 -12
- package/src/css/util.ts +5 -0
- package/src/css/utils/srOnly/srOnly.ts +3 -1
- package/src/css/varNames.ts +131 -141
- package/src/css/vars.ts +1 -6
- package/src/theme/palette/constants.ts +2 -0
- package/src/theme/palette/types.ts +3 -0
- package/src/theme/types.ts +2 -6
- package/src/theme/v0/focusRing.ts +1 -3
- package/src/theme/v0/font.ts +6 -18
- package/src/theme/v0/layer.ts +1 -3
- package/src/theme/v0/shadow.ts +2 -6
- package/src/theme/v2/avatar.ts +1 -3
- package/src/theme/v2/color/_system.ts +1 -3
- package/src/theme/v2/color/avatar.ts +2 -6
- package/src/theme/v2/color/badge.ts +2 -6
- package/src/theme/v2/color/button.ts +3 -9
- package/src/theme/v2/color/color.ts +3 -9
- package/src/theme/v2/color/input.ts +3 -9
- package/src/theme/v2/color/kbd.ts +1 -3
- package/src/theme/v2/color/selectable.ts +2 -6
- package/src/theme/v2/color/state.ts +1 -3
- package/src/theme/v2/color/syntax.ts +1 -3
- package/src/theme/v2/input.ts +1 -3
- package/src/theme/v2/theme.ts +2 -6
- package/src/theme/v3/buildTheme_v3.ts +1 -0
- package/src/theme/v3/color/color.ts +6 -4
- package/src/theme/v3/color/renderColor.ts +4 -1
- package/src/theme/v3/defaultTokens.ts +1 -0
- package/src/theme/v3/resolveTokens.ts +9 -9
- package/src/ui/RootClassNames.tsx +3 -0
- package/src/ui/StyleTags.tsx +3 -1
- package/src/ui/_compat/theme/themeColorProvider.tsx +2 -6
- package/src/ui/_compat/theme/themeProvider.tsx +2 -6
- package/src/ui/_compat/theme/types.ts +1 -3
- package/src/ui/_compat/theme/useRootTheme.ts +1 -3
- package/src/ui/_compat/theme/useTheme.ts +2 -6
- package/src/ui/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
- package/src/ui/components/autocomplete/autocomplete.tsx +86 -114
- package/src/ui/components/autocomplete/autocompleteOption.tsx +2 -0
- package/src/ui/components/autocomplete/types.ts +3 -8
- package/src/ui/components/breadcrumbs/breadcrumbs.tsx +27 -21
- package/src/ui/components/dialog/dialog.tsx +89 -291
- package/src/ui/components/dialog/dialogCard.tsx +183 -0
- package/src/ui/components/dialog/isTargetWithinScope.ts +14 -0
- package/src/ui/components/hotkeys/hotkeys.tsx +33 -15
- package/src/ui/components/menu/__workshop__/asComponent.tsx +6 -6
- package/src/ui/components/menu/menu.tsx +27 -33
- package/src/ui/components/menu/menuButton.tsx +10 -14
- package/src/ui/components/menu/menuDivider.tsx +25 -13
- package/src/ui/components/menu/menuGroup.tsx +34 -26
- package/src/ui/components/menu/menuItem.tsx +51 -40
- package/src/ui/components/skeleton/codeSkeleton.tsx +53 -0
- package/src/ui/components/skeleton/headingSkeleton.tsx +52 -0
- package/src/ui/components/skeleton/index.ts +3 -0
- package/src/ui/components/skeleton/labelSkeleton.tsx +51 -0
- package/src/ui/components/skeleton/skeleton.tsx +39 -16
- package/src/ui/components/skeleton/textSkeleton.tsx +31 -110
- package/src/ui/components/tab/tab.tsx +23 -19
- package/src/ui/components/tab/tabList.tsx +34 -33
- package/src/ui/components/tab/tabPanel.tsx +25 -19
- package/src/ui/components/toast/toast.tsx +21 -16
- package/src/ui/components/toast/toastLayer.tsx +28 -10
- package/src/ui/components/toast/toastProvider.tsx +2 -6
- package/src/ui/components/toast/types.ts +2 -6
- package/src/ui/components/toast/useToast.ts +1 -3
- package/src/ui/components/tree/tree.tsx +194 -187
- package/src/ui/components/tree/treeGroup.tsx +25 -5
- package/src/ui/components/tree/treeItem.tsx +35 -23
- package/src/ui/hooks/useClickOutside.ts +2 -6
- package/src/ui/hooks/useClickOutsideEvent.ts +3 -9
- package/src/ui/primitives/_selectable/selectable.tsx +33 -20
- package/src/ui/primitives/avatar/avatar.tsx +28 -31
- package/src/ui/primitives/avatar/avatarCounter.tsx +33 -25
- package/src/ui/primitives/avatar/avatarStack.tsx +31 -24
- package/src/ui/primitives/avatar/types.ts +2 -0
- package/src/ui/primitives/badge/__workshop__/props.tsx +1 -9
- package/src/ui/primitives/badge/__workshop__/tones.tsx +1 -6
- package/src/ui/primitives/badge/badge.tsx +33 -32
- package/src/ui/primitives/badge/types.ts +2 -1
- package/src/ui/primitives/box/box.tsx +59 -29
- package/src/ui/primitives/button/__workshop__/sanityUploadButton.tsx +3 -3
- package/src/ui/primitives/button/__workshop__/uploadButton.tsx +2 -1
- package/src/ui/primitives/button/button.test.tsx +1 -15
- package/src/ui/primitives/button/button.tsx +64 -70
- package/src/ui/primitives/card/__workshop__/asComponent.tsx +3 -3
- package/src/ui/primitives/card/card.tsx +22 -22
- package/src/ui/primitives/card/cardProvider.tsx +2 -0
- package/src/ui/primitives/checkbox/checkbox.tsx +26 -15
- package/src/ui/primitives/code/code.tsx +24 -22
- package/src/ui/primitives/container/container.tsx +26 -15
- package/src/ui/primitives/flex/flex.tsx +21 -19
- package/src/ui/primitives/grid/grid.tsx +21 -16
- package/src/ui/primitives/heading/heading.tsx +42 -19
- package/src/ui/primitives/inline/inline.tsx +26 -23
- package/src/ui/primitives/kbd/kbd.tsx +25 -23
- package/src/ui/primitives/label/label.tsx +41 -26
- package/src/ui/primitives/popover/popover.tsx +281 -277
- package/src/ui/primitives/popover/popoverCard.tsx +119 -118
- package/src/ui/primitives/radio/radio.tsx +30 -14
- package/src/ui/primitives/select/select.tsx +24 -16
- package/src/ui/primitives/spinner/animatedSpinnerIcon.tsx +4 -2
- package/src/ui/primitives/spinner/spinner.tsx +24 -12
- package/src/ui/primitives/stack/stack.tsx +27 -18
- package/src/ui/primitives/switch/switch.tsx +31 -14
- package/src/ui/primitives/text/text.tsx +42 -24
- package/src/ui/primitives/textArea/textArea.tsx +33 -18
- package/src/ui/primitives/textInput/textInput.tsx +28 -40
- package/src/ui/primitives/tooltip/constants.ts +1 -1
- package/src/ui/primitives/tooltip/tooltip.tsx +76 -59
- package/src/ui/primitives/tooltip/tooltipCard.tsx +89 -82
- package/src/ui/primitives/types.ts +1 -3
- package/src/ui/types/avatar.ts +3 -6
- package/src/ui/types/badge.ts +1 -3
- package/src/ui/types/button.ts +1 -3
- package/src/ui/types/card.ts +1 -3
- package/src/ui/types/dialog.ts +1 -3
- package/src/ui/types/props.ts +20 -10
- package/src/ui/utils/arrow/arrow.tsx +40 -14
- package/src/ui/utils/boundaryElement/boundaryElementProvider.tsx +2 -6
- package/src/ui/utils/boundaryElement/types.ts +1 -3
- package/src/ui/utils/boundaryElement/useBoundaryElement.ts +1 -3
- package/src/ui/utils/elementQuery/elementQuery.tsx +36 -14
- package/src/ui/utils/errorBoundary.tsx +2 -0
- package/src/ui/utils/index.ts +0 -1
- package/src/ui/utils/layer/layer.tsx +23 -93
- package/src/ui/utils/layer/layerCard.tsx +92 -0
- package/src/ui/utils/layer/layerProvider.tsx +2 -6
- package/src/ui/utils/layer/useLayer.ts +1 -3
- package/src/ui/utils/portal/portal.ts +2 -6
- package/src/ui/utils/portal/portalProvider.tsx +2 -6
- package/src/ui/utils/portal/types.ts +1 -3
- package/src/ui/utils/portal/usePortal.ts +1 -3
- package/src/ui/utils/srOnly/srOnly.tsx +25 -20
- package/src/ui/utils/virtualList/virtualList.tsx +36 -24
- package/src/css/compile/compileRule.ts +0 -97
- package/src/css/compile/compileRules.test.ts +0 -36
- package/src/css/compile/compileRules.ts +0 -43
- package/src/css/compile/compileSystem.ts +0 -7
- package/src/css/compile/types.ts +0 -6
- package/src/css/primitives/_selectable/_contants.ts +0 -11
- package/src/css/primitives/card/_constants.ts +0 -13
- package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
- package/src/ui/utils/conditionalWrapper/index.ts +0 -1
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {tooltipCard} from '@sanity/ui/css'
|
|
2
2
|
import {motion} from 'framer-motion'
|
|
3
|
-
import {CSSProperties, ForwardedRef,
|
|
3
|
+
import {type CSSProperties, ForwardedRef, useMemo} from 'react'
|
|
4
4
|
|
|
5
5
|
import {POPOVER_MOTION_PROPS} from '../../constants'
|
|
6
6
|
import {Placement, Props} from '../../types'
|
|
7
7
|
import {Arrow} from '../../utils'
|
|
8
|
-
import {Card,
|
|
8
|
+
import {Card, CardOwnProps} from '../card'
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_TOOLTIP_ARROW_HEIGHT,
|
|
11
11
|
DEFAULT_TOOLTIP_ARROW_RADIUS,
|
|
12
12
|
DEFAULT_TOOLTIP_ARROW_WIDTH,
|
|
13
13
|
} from './constants'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/* @internal */
|
|
16
|
+
export const DEFAULT_TOOLTIP_CARD_ELEMENT = 'div'
|
|
16
17
|
|
|
17
18
|
/* @internal */
|
|
18
|
-
export interface
|
|
19
|
+
export interface TooltipCardOwnProps extends CardOwnProps {
|
|
19
20
|
animate?: boolean
|
|
20
21
|
arrow: boolean
|
|
21
22
|
arrowRef: ForwardedRef<HTMLDivElement>
|
|
@@ -26,90 +27,96 @@ export interface TooltipCardProps extends CardProps {
|
|
|
26
27
|
placement?: Placement
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/** @internal */
|
|
31
|
+
export type TooltipCardElementType = 'div'
|
|
32
|
+
|
|
33
|
+
/** @internal */
|
|
34
|
+
export type TooltipCardProps<E extends TooltipCardElementType = TooltipCardElementType> = Props<
|
|
35
|
+
TooltipCardOwnProps,
|
|
36
|
+
E
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
const MotionCard = motion.create(Card)
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* @internal
|
|
31
43
|
*/
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
export function TooltipCard<E extends TooltipCardElementType = typeof DEFAULT_TOOLTIP_CARD_ELEMENT>(
|
|
45
|
+
props: TooltipCardProps<E>,
|
|
46
|
+
) {
|
|
47
|
+
const {
|
|
48
|
+
animate,
|
|
49
|
+
arrow,
|
|
50
|
+
arrowRef,
|
|
51
|
+
arrowX,
|
|
52
|
+
arrowY,
|
|
53
|
+
as = DEFAULT_TOOLTIP_CARD_ELEMENT,
|
|
54
|
+
children,
|
|
55
|
+
originX,
|
|
56
|
+
originY,
|
|
57
|
+
padding,
|
|
58
|
+
placement,
|
|
59
|
+
radius,
|
|
60
|
+
scheme,
|
|
61
|
+
shadow,
|
|
62
|
+
style,
|
|
63
|
+
tone = 'inherit',
|
|
64
|
+
...rest
|
|
65
|
+
} = props as TooltipCardProps<typeof DEFAULT_TOOLTIP_CARD_ELEMENT>
|
|
66
|
+
|
|
67
|
+
const rootStyle: CSSProperties = useMemo(
|
|
68
|
+
() => ({
|
|
47
69
|
originX,
|
|
48
70
|
originY,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
style,
|
|
55
|
-
tone = 'inherit',
|
|
56
|
-
...restProps
|
|
57
|
-
} = props
|
|
71
|
+
willChange: animate ? 'transform' : undefined,
|
|
72
|
+
...style,
|
|
73
|
+
}),
|
|
74
|
+
[animate, originX, originY, style],
|
|
75
|
+
)
|
|
58
76
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
const arrowStyle: CSSProperties = useMemo(
|
|
78
|
+
() => ({
|
|
79
|
+
left: arrowX !== null ? arrowX : undefined,
|
|
80
|
+
top: arrowY !== null ? arrowY : undefined,
|
|
81
|
+
right: undefined,
|
|
82
|
+
bottom: undefined,
|
|
83
|
+
}),
|
|
84
|
+
[arrowX, arrowY],
|
|
85
|
+
)
|
|
68
86
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
return (
|
|
88
|
+
<MotionCard
|
|
89
|
+
data-ui="Tooltip__card"
|
|
90
|
+
{...rest}
|
|
91
|
+
as={as}
|
|
92
|
+
className={tooltipCard()}
|
|
93
|
+
data-animate={animate ? '' : undefined}
|
|
94
|
+
data-placement={placement}
|
|
95
|
+
padding={padding}
|
|
96
|
+
radius={radius}
|
|
97
|
+
scheme={scheme}
|
|
98
|
+
shadow={shadow}
|
|
99
|
+
style={rootStyle}
|
|
100
|
+
variants={POPOVER_MOTION_PROPS.card}
|
|
101
|
+
transition={POPOVER_MOTION_PROPS.transition}
|
|
102
|
+
initial={animate ? ['hidden', 'initial'] : undefined}
|
|
103
|
+
animate={animate ? ['visible', 'scaleIn'] : undefined}
|
|
104
|
+
exit={animate ? ['hidden', 'scaleOut'] : undefined}
|
|
105
|
+
tone={tone}
|
|
106
|
+
>
|
|
107
|
+
{children}
|
|
78
108
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
style={rootStyle}
|
|
92
|
-
variants={POPOVER_MOTION_PROPS.card}
|
|
93
|
-
transition={POPOVER_MOTION_PROPS.transition}
|
|
94
|
-
initial={animate ? ['hidden', 'initial'] : undefined}
|
|
95
|
-
animate={animate ? ['visible', 'scaleIn'] : undefined}
|
|
96
|
-
exit={animate ? ['hidden', 'scaleOut'] : undefined}
|
|
97
|
-
tone={tone}
|
|
98
|
-
>
|
|
99
|
-
{children}
|
|
100
|
-
|
|
101
|
-
{arrow && (
|
|
102
|
-
<Arrow
|
|
103
|
-
ref={arrowRef}
|
|
104
|
-
style={arrowStyle}
|
|
105
|
-
width={DEFAULT_TOOLTIP_ARROW_WIDTH}
|
|
106
|
-
height={DEFAULT_TOOLTIP_ARROW_HEIGHT}
|
|
107
|
-
radius={DEFAULT_TOOLTIP_ARROW_RADIUS}
|
|
108
|
-
/>
|
|
109
|
-
)}
|
|
110
|
-
</MotionCard>
|
|
111
|
-
)
|
|
112
|
-
}),
|
|
113
|
-
)
|
|
109
|
+
{arrow && (
|
|
110
|
+
<Arrow
|
|
111
|
+
ref={arrowRef}
|
|
112
|
+
style={arrowStyle}
|
|
113
|
+
width={DEFAULT_TOOLTIP_ARROW_WIDTH}
|
|
114
|
+
height={DEFAULT_TOOLTIP_ARROW_HEIGHT}
|
|
115
|
+
radius={DEFAULT_TOOLTIP_ARROW_RADIUS}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
</MotionCard>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
114
121
|
|
|
115
|
-
TooltipCard.displayName = '
|
|
122
|
+
TooltipCard.displayName = 'TooltipCard'
|
package/src/ui/types/avatar.ts
CHANGED
|
@@ -3,17 +3,14 @@ export {
|
|
|
3
3
|
type AvatarSize,
|
|
4
4
|
} from '@sanity/ui/theme'
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
6
|
+
/** @public */
|
|
9
7
|
export type AvatarPosition = 'top' | 'bottom' | 'inside'
|
|
10
8
|
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
9
|
+
/** @public */
|
|
14
10
|
// export type AvatarSize = 0 | 1 | 2 | 3
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
13
|
* @public
|
|
14
|
+
* @deprecated Will be removed in next major version.
|
|
18
15
|
*/
|
|
19
16
|
export type AvatarStatus = 'online' | 'editing' | 'inactive'
|
package/src/ui/types/badge.ts
CHANGED
package/src/ui/types/button.ts
CHANGED
package/src/ui/types/card.ts
CHANGED
package/src/ui/types/dialog.ts
CHANGED
package/src/ui/types/props.ts
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type {ComponentClass, ComponentProps, ExoticComponent, FunctionComponent, JSX} from 'react'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Assign properties from `U` to `T`, excluding properties that already exist in `T`.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type Assign<T extends {}, U extends {}> = Omit<T, keyof U> & U
|
|
11
|
+
|
|
12
|
+
/** @public */
|
|
13
|
+
export type EmptyProps = {}
|
|
14
|
+
|
|
15
|
+
/** @public */
|
|
16
|
+
export type TagType = keyof JSX.IntrinsicElements
|
|
6
17
|
|
|
7
18
|
/** @public */
|
|
8
|
-
export type
|
|
19
|
+
export type ComponentType<P = any> = FunctionComponent<P> | ComponentClass<P> | ExoticComponent<P>
|
|
9
20
|
|
|
10
21
|
/** @public */
|
|
11
|
-
export type
|
|
22
|
+
export type ElementType<P> = TagType | ComponentType<P>
|
|
12
23
|
|
|
13
24
|
/** @public */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
P
|
|
25
|
+
export type Props<P extends EmptyProps, E extends ElementType<P>> = Assign<
|
|
26
|
+
E extends TagType ? JSX.IntrinsicElements[E] : ComponentProps<E>,
|
|
27
|
+
P & {as?: E}
|
|
18
28
|
>
|
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
import {_arrow, _arrowShape, _arrowStroke, _arrowStrokeMask} from '@sanity/ui/css'
|
|
2
|
-
import {CSSProperties,
|
|
2
|
+
import {CSSProperties, useMemo} from 'react'
|
|
3
3
|
|
|
4
|
-
import {Props} from '../../types'
|
|
4
|
+
import {ComponentType, Props} from '../../types'
|
|
5
5
|
import {compileCommands, getRoundedCommands, Point} from './cmds'
|
|
6
6
|
|
|
7
7
|
/** @internal */
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export const DEFAULT_ARROW_ELEMENT = 'div'
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
export type ArrowOwnProps = {
|
|
12
|
+
width: number
|
|
13
|
+
height: number
|
|
14
|
+
radius?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
export type ArrowElementType = 'div' | 'span' | ComponentType
|
|
19
|
+
|
|
20
|
+
/** @internal */
|
|
21
|
+
export type ArrowProps<E extends ArrowElementType = ArrowElementType> = Props<ArrowOwnProps, E>
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
export function Arrow<E extends ArrowElementType = typeof DEFAULT_ARROW_ELEMENT>(
|
|
25
|
+
props: ArrowProps<E>,
|
|
26
|
+
) {
|
|
27
|
+
const {
|
|
28
|
+
as: Element = DEFAULT_ARROW_ELEMENT,
|
|
29
|
+
width: w,
|
|
30
|
+
height: h,
|
|
31
|
+
radius = 0,
|
|
32
|
+
style,
|
|
33
|
+
...rest
|
|
34
|
+
} = props as ArrowProps<typeof DEFAULT_ARROW_ELEMENT>
|
|
13
35
|
|
|
14
36
|
const center = w / 2
|
|
15
37
|
|
|
@@ -31,11 +53,15 @@ export const Arrow = forwardRef(function Arrow(
|
|
|
31
53
|
const fillPath = `${path} M ${w} -1 M 0 -1 Z`
|
|
32
54
|
|
|
33
55
|
return (
|
|
34
|
-
<
|
|
35
|
-
{...
|
|
56
|
+
<Element
|
|
57
|
+
{...rest}
|
|
36
58
|
className={_arrow()}
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
style={
|
|
60
|
+
{
|
|
61
|
+
...style,
|
|
62
|
+
'--arrow-size': `${w}px`,
|
|
63
|
+
} as CSSProperties
|
|
64
|
+
}
|
|
39
65
|
>
|
|
40
66
|
<svg width={w} height={w} viewBox={`0 0 ${w} ${w}`}>
|
|
41
67
|
<mask id="stroke-mask">
|
|
@@ -44,8 +70,8 @@ export const Arrow = forwardRef(function Arrow(
|
|
|
44
70
|
<path className={_arrowStroke()} d={strokePath} mask="url(#stroke-mask)" />
|
|
45
71
|
<path className={_arrowShape()} d={fillPath} />
|
|
46
72
|
</svg>
|
|
47
|
-
</
|
|
73
|
+
</Element>
|
|
48
74
|
)
|
|
49
|
-
}
|
|
75
|
+
}
|
|
50
76
|
|
|
51
|
-
Arrow.displayName = '
|
|
77
|
+
Arrow.displayName = 'Arrow'
|
|
@@ -3,17 +3,13 @@ import {ReactElement, ReactNode, useMemo} from 'react'
|
|
|
3
3
|
import {BoundaryElementContext} from './boundaryElementContext'
|
|
4
4
|
import {BoundaryElementContextValue} from './types'
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
6
|
+
/** @public */
|
|
9
7
|
export interface BoundaryElementProviderProps {
|
|
10
8
|
children: ReactNode
|
|
11
9
|
element: HTMLElement | null
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
12
|
+
/** @public */
|
|
17
13
|
export function BoundaryElementProvider(props: BoundaryElementProviderProps): ReactElement {
|
|
18
14
|
const {children, element} = props
|
|
19
15
|
const value: BoundaryElementContextValue = useMemo(() => ({version: 0.0, element}), [element])
|
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
import {BREAKPOINTS} from '@sanity/ui/css'
|
|
2
|
-
import {
|
|
2
|
+
import {useImperativeHandle, useMemo, useState} from 'react'
|
|
3
3
|
|
|
4
4
|
import {useElementSize} from '../../hooks'
|
|
5
|
-
import {Props} from '../../types'
|
|
5
|
+
import {ComponentType, Props} from '../../types'
|
|
6
6
|
import {findMaxBreakpoints, findMinBreakpoints} from './helpers'
|
|
7
7
|
|
|
8
|
+
/** @beta */
|
|
9
|
+
export const DEFAULT_ELEMENT_QUERY_ELEMENT = 'div'
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* DO NOT USE IN PRODUCTION.
|
|
10
13
|
* @beta
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
15
|
+
export type ElementQueryOwnProps = {
|
|
13
16
|
media?: number[]
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
/** @beta */
|
|
20
|
+
export type ElementQueryElementType = 'div' | ComponentType
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* DO NOT USE IN PRODUCTION.
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
export type ElementQueryProps<E extends ElementQueryElementType = ElementQueryElementType> = Props<
|
|
27
|
+
ElementQueryOwnProps,
|
|
28
|
+
E
|
|
29
|
+
>
|
|
30
|
+
|
|
31
|
+
const DEFAULT_BREAKPOINTS = Object.values(BREAKPOINTS)
|
|
17
32
|
|
|
18
33
|
/**
|
|
19
34
|
* DO NOT USE IN PRODUCTION.
|
|
20
35
|
* @beta
|
|
21
36
|
*/
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
export function ElementQuery<
|
|
38
|
+
E extends ElementQueryElementType = typeof DEFAULT_ELEMENT_QUERY_ELEMENT,
|
|
39
|
+
>(props: ElementQueryProps<E>) {
|
|
40
|
+
const {
|
|
41
|
+
as: Element = DEFAULT_ELEMENT_QUERY_ELEMENT,
|
|
42
|
+
children,
|
|
43
|
+
media: mediaProp,
|
|
44
|
+
ref: forwardedRef,
|
|
45
|
+
...rest
|
|
46
|
+
} = props as ElementQueryProps<typeof DEFAULT_ELEMENT_QUERY_ELEMENT>
|
|
47
|
+
|
|
48
|
+
const breakpoints = mediaProp ?? DEFAULT_BREAKPOINTS
|
|
28
49
|
|
|
29
50
|
const [element, setElement] = useState<HTMLDivElement | null>(null)
|
|
30
51
|
const elementSize = useElementSize(element)
|
|
@@ -47,9 +68,10 @@ export const ElementQuery = forwardRef(function ElementQuery(
|
|
|
47
68
|
])
|
|
48
69
|
|
|
49
70
|
return (
|
|
50
|
-
<
|
|
71
|
+
<Element data-ui="ElementQuery" {...rest} data-eq-max={max} data-eq-min={min} ref={setElement}>
|
|
51
72
|
{children}
|
|
52
|
-
</
|
|
73
|
+
</Element>
|
|
53
74
|
)
|
|
54
|
-
}
|
|
55
|
-
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ElementQuery.displayName = 'ElementQuery'
|
|
@@ -25,6 +25,8 @@ export interface ErrorBoundaryState {
|
|
|
25
25
|
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
26
26
|
state: ErrorBoundaryState = {error: null}
|
|
27
27
|
|
|
28
|
+
static displayName = 'ErrorBoundary'
|
|
29
|
+
|
|
28
30
|
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
29
31
|
// Update state so the next render will show the fallback UI.
|
|
30
32
|
return {error}
|
package/src/ui/utils/index.ts
CHANGED
|
@@ -1,112 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FocusEvent,
|
|
3
|
-
ForwardedRef,
|
|
4
|
-
forwardRef,
|
|
5
|
-
useCallback,
|
|
6
|
-
useEffect,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
useRef,
|
|
9
|
-
} from 'react'
|
|
10
|
-
|
|
11
|
-
import {EMPTY_RECORD} from '../../constants'
|
|
12
|
-
import {containsOrEqualsElement, isHTMLElement} from '../../helpers'
|
|
13
|
-
import {Box, BoxProps} from '../../primitives'
|
|
1
|
+
import {CardElementType, CardOwnProps} from '../../primitives'
|
|
14
2
|
import {Props} from '../../types'
|
|
3
|
+
import {LayerCard} from './layerCard'
|
|
15
4
|
import {LayerProvider} from './layerProvider'
|
|
16
|
-
import {useLayer} from './useLayer'
|
|
17
5
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
/** @public */
|
|
7
|
+
export const DEFAULT_LAYER_ELEMENT = 'div'
|
|
8
|
+
|
|
9
|
+
/** @public */
|
|
10
|
+
export type LayerOwnProps = CardOwnProps & {
|
|
22
11
|
/** A callback that fires when the layer becomes the top layer when it was not the top layer before. */
|
|
23
12
|
onActivate?: (props: {activeElement: HTMLElement | null}) => void
|
|
24
13
|
zOffset?: number | number[]
|
|
25
14
|
}
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
16
|
+
/** @public */
|
|
17
|
+
export type LayerElementType = CardElementType
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
/** @public */
|
|
20
|
+
export type LayerProps<E extends LayerElementType = LayerElementType> = Props<LayerOwnProps, E>
|
|
21
|
+
|
|
22
|
+
/** @public */
|
|
23
|
+
export function Layer<E extends LayerElementType = typeof DEFAULT_LAYER_ELEMENT>(
|
|
24
|
+
props: LayerProps<E>,
|
|
34
25
|
) {
|
|
35
26
|
const {
|
|
27
|
+
as = DEFAULT_LAYER_ELEMENT,
|
|
36
28
|
children,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
style = EMPTY_RECORD,
|
|
41
|
-
...restProps
|
|
42
|
-
} = props
|
|
43
|
-
const {zIndex, isTopLayer} = useLayer()
|
|
44
|
-
const lastFocusedRef = useRef<HTMLElement | null>(null)
|
|
45
|
-
const ref = useRef<HTMLDivElement | null>(null)
|
|
46
|
-
const isTopLayerRef = useRef<boolean>(isTopLayer)
|
|
47
|
-
|
|
48
|
-
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
49
|
-
|
|
50
|
-
// When the layer very first mounts, it will be the top layer, but we don't want to fire
|
|
51
|
-
// the callback in that case. We use a ref to track the previous value of isTopLayer to
|
|
52
|
-
// determine if the layer has become the top layer since the last render.
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
const becameTopLayer = isTopLayerRef.current !== isTopLayer && isTopLayer
|
|
55
|
-
|
|
56
|
-
if (becameTopLayer) {
|
|
57
|
-
onActivate?.({activeElement: lastFocusedRef.current})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
isTopLayerRef.current = isTopLayer
|
|
61
|
-
}, [isTopLayer, onActivate])
|
|
62
|
-
|
|
63
|
-
const handleFocus = useCallback(
|
|
64
|
-
(event: FocusEvent<HTMLDivElement, Element>) => {
|
|
65
|
-
// Call the user-provided onFocus handler if any
|
|
66
|
-
onFocus?.(event)
|
|
67
|
-
|
|
68
|
-
const rootElement = ref.current
|
|
69
|
-
const target = document.activeElement
|
|
70
|
-
|
|
71
|
-
if (!isTopLayer || !rootElement || !target) return
|
|
72
|
-
|
|
73
|
-
if (isHTMLElement(target) && containsOrEqualsElement(rootElement, target)) {
|
|
74
|
-
lastFocusedRef.current = target
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
[isTopLayer, onFocus],
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<Box
|
|
82
|
-
data-ui="Layer"
|
|
83
|
-
{...restProps}
|
|
84
|
-
onFocus={handleFocus}
|
|
85
|
-
position={position}
|
|
86
|
-
ref={ref}
|
|
87
|
-
style={{...style, zIndex}}
|
|
88
|
-
>
|
|
89
|
-
{children}
|
|
90
|
-
</Box>
|
|
91
|
-
)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @public
|
|
96
|
-
*/
|
|
97
|
-
export const Layer = forwardRef(function Layer(
|
|
98
|
-
props: Props<LayerProps, 'div'>,
|
|
99
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
100
|
-
) {
|
|
101
|
-
const {children, zOffset = 1, ...restProps} = props
|
|
29
|
+
zOffset = 1,
|
|
30
|
+
...rest
|
|
31
|
+
} = props as LayerProps<typeof DEFAULT_LAYER_ELEMENT>
|
|
102
32
|
|
|
103
33
|
return (
|
|
104
34
|
<LayerProvider zOffset={zOffset}>
|
|
105
|
-
<
|
|
35
|
+
<LayerCard {...rest} as={as}>
|
|
106
36
|
{children}
|
|
107
|
-
</
|
|
37
|
+
</LayerCard>
|
|
108
38
|
</LayerProvider>
|
|
109
39
|
)
|
|
110
|
-
}
|
|
40
|
+
}
|
|
111
41
|
|
|
112
|
-
Layer.displayName = '
|
|
42
|
+
Layer.displayName = 'Layer'
|