@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,12 +1,11 @@
|
|
|
1
1
|
import {ChevronRightIcon} from '@sanity/icons'
|
|
2
|
-
import {
|
|
3
|
-
import {FontTextSize, Space} from '@sanity/ui/theme'
|
|
2
|
+
import {RadiusStyleProps, ResponsiveProp} from '@sanity/ui/css'
|
|
3
|
+
import {FontTextSize, Space, ThemeColorStateToneKey} from '@sanity/ui/theme'
|
|
4
4
|
import {
|
|
5
5
|
ElementType,
|
|
6
6
|
isValidElement,
|
|
7
7
|
KeyboardEvent,
|
|
8
8
|
MouseEvent,
|
|
9
|
-
ReactElement,
|
|
10
9
|
ReactNode,
|
|
11
10
|
useCallback,
|
|
12
11
|
useEffect,
|
|
@@ -16,19 +15,21 @@ import {isValidElementType} from 'react-is'
|
|
|
16
15
|
|
|
17
16
|
import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
|
|
18
17
|
import {Selectable} from '../../primitives/_selectable'
|
|
19
|
-
import {
|
|
20
|
-
import {Menu, MenuProps} from './menu'
|
|
18
|
+
import {ComponentType, Props} from '../../types'
|
|
19
|
+
import {DEFAULT_MENU_ELEMENT, Menu, MenuProps} from './menu'
|
|
21
20
|
import {useMenu} from './useMenu'
|
|
22
21
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
/** @public */
|
|
23
|
+
export const DEFAULT_MENU_GROUP_ELEMENT = 'button'
|
|
24
|
+
|
|
25
|
+
/** @public */
|
|
26
|
+
export type MenuGroupOwnProps = RadiusStyleProps & {
|
|
27
27
|
disabled?: boolean
|
|
28
28
|
fontSize?: ResponsiveProp<FontTextSize>
|
|
29
|
+
gap?: ResponsiveProp<Space>
|
|
29
30
|
icon?: ElementType | ReactNode
|
|
30
31
|
menu?: Omit<
|
|
31
|
-
MenuProps
|
|
32
|
+
MenuProps<typeof DEFAULT_MENU_ELEMENT>,
|
|
32
33
|
| 'onClickOutside'
|
|
33
34
|
| 'onEscape'
|
|
34
35
|
| 'onItemClick'
|
|
@@ -40,24 +41,30 @@ export interface MenuGroupProps extends GapStyleProps {
|
|
|
40
41
|
>
|
|
41
42
|
padding?: ResponsiveProp<Space>
|
|
42
43
|
popover?: Omit<PopoverProps, 'content' | 'open'>
|
|
43
|
-
radius?: Radius | Radius[]
|
|
44
44
|
/** @deprecated Use `gap` instead. */
|
|
45
45
|
space?: ResponsiveProp<Space>
|
|
46
|
-
text
|
|
47
|
-
tone?:
|
|
46
|
+
text?: ReactNode
|
|
47
|
+
tone?: ThemeColorStateToneKey
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
/** @public */
|
|
51
|
+
export type MenuGroupElementType = 'button' | ComponentType
|
|
52
|
+
|
|
53
|
+
/** @public */
|
|
54
|
+
export type MenuGroupProps<E extends MenuGroupElementType = MenuGroupElementType> = Props<
|
|
55
|
+
MenuGroupOwnProps,
|
|
56
|
+
E
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
/** @public */
|
|
60
|
+
export function MenuGroup<E extends MenuGroupElementType = typeof DEFAULT_MENU_GROUP_ELEMENT>(
|
|
61
|
+
props: MenuGroupProps<E>,
|
|
62
|
+
) {
|
|
54
63
|
const {
|
|
55
|
-
as =
|
|
64
|
+
as = DEFAULT_MENU_GROUP_ELEMENT,
|
|
56
65
|
children,
|
|
57
66
|
fontSize = 1,
|
|
58
67
|
gap,
|
|
59
|
-
gapX,
|
|
60
|
-
gapY,
|
|
61
68
|
icon: IconComponent,
|
|
62
69
|
menu: menuProps,
|
|
63
70
|
onClick,
|
|
@@ -67,8 +74,9 @@ export function MenuGroup(props: Props<MenuGroupProps, 'div'>): ReactElement {
|
|
|
67
74
|
space = 3,
|
|
68
75
|
text,
|
|
69
76
|
tone = 'default',
|
|
70
|
-
...
|
|
71
|
-
} = props
|
|
77
|
+
...rest
|
|
78
|
+
} = props as MenuGroupProps<typeof DEFAULT_MENU_GROUP_ELEMENT>
|
|
79
|
+
|
|
72
80
|
const menu = useMenu()
|
|
73
81
|
|
|
74
82
|
const {
|
|
@@ -112,7 +120,7 @@ export function MenuGroup(props: Props<MenuGroupProps, 'div'>): ReactElement {
|
|
|
112
120
|
)
|
|
113
121
|
|
|
114
122
|
const handleClick = useCallback(
|
|
115
|
-
(event: MouseEvent<
|
|
123
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
116
124
|
onClick?.(event)
|
|
117
125
|
|
|
118
126
|
setShouldFocus('first')
|
|
@@ -166,7 +174,7 @@ export function MenuGroup(props: Props<MenuGroupProps, 'div'>): ReactElement {
|
|
|
166
174
|
</Menu>
|
|
167
175
|
)
|
|
168
176
|
|
|
169
|
-
const handleKeyDown = useCallback((event: KeyboardEvent<
|
|
177
|
+
const handleKeyDown = useCallback((event: KeyboardEvent<HTMLButtonElement>) => {
|
|
170
178
|
const target = event.currentTarget
|
|
171
179
|
|
|
172
180
|
if (document.activeElement !== target) {
|
|
@@ -188,7 +196,7 @@ export function MenuGroup(props: Props<MenuGroupProps, 'div'>): ReactElement {
|
|
|
188
196
|
// data-as={as}
|
|
189
197
|
data-ui="MenuGroup"
|
|
190
198
|
// forwardedAs={as}
|
|
191
|
-
{...
|
|
199
|
+
{...rest}
|
|
192
200
|
aria-pressed={as === 'button' ? withinMenu : undefined}
|
|
193
201
|
as={as}
|
|
194
202
|
data-pressed={as !== 'button' ? withinMenu : undefined}
|
|
@@ -202,7 +210,7 @@ export function MenuGroup(props: Props<MenuGroupProps, 'div'>): ReactElement {
|
|
|
202
210
|
tone={tone}
|
|
203
211
|
type={as === 'button' ? 'button' : undefined}
|
|
204
212
|
>
|
|
205
|
-
<Flex gap={gap ?? space}
|
|
213
|
+
<Flex gap={gap ?? space} padding={padding}>
|
|
206
214
|
{IconComponent && (
|
|
207
215
|
<Text size={fontSize}>
|
|
208
216
|
{isValidElement(IconComponent) && IconComponent}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {GapStyleProps, PaddingStyleProps, RadiusStyleProps, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
-
import {Space} from '@sanity/ui/theme'
|
|
2
|
+
import {Space, ThemeColorStateToneKey} from '@sanity/ui/theme'
|
|
3
3
|
import {
|
|
4
4
|
ElementType,
|
|
5
|
-
ForwardedRef,
|
|
6
|
-
forwardRef,
|
|
7
5
|
isValidElement,
|
|
8
|
-
MouseEvent,
|
|
9
|
-
ReactNode,
|
|
6
|
+
type MouseEvent,
|
|
7
|
+
type ReactNode,
|
|
10
8
|
useCallback,
|
|
11
9
|
useEffect,
|
|
12
10
|
useImperativeHandle,
|
|
@@ -18,36 +16,45 @@ import {isValidElementType} from 'react-is'
|
|
|
18
16
|
|
|
19
17
|
import {Box, Flex, Text} from '../../primitives'
|
|
20
18
|
import {Selectable} from '../../primitives/_selectable'
|
|
21
|
-
import {
|
|
19
|
+
import type {ComponentType, Props} from '../../types'
|
|
22
20
|
import {Hotkeys} from '../hotkeys'
|
|
23
21
|
import {useMenu} from './useMenu'
|
|
24
22
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
/** @public */
|
|
24
|
+
export const DEFAULT_MENU_ITEM_ELEMENT = 'button'
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
export type MenuItemOwnProps = GapStyleProps &
|
|
28
|
+
PaddingStyleProps &
|
|
29
|
+
RadiusStyleProps & {
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
fontSize?: number | number[]
|
|
32
|
+
hotkeys?: string[]
|
|
33
|
+
icon?: ElementType | ReactNode
|
|
34
|
+
iconRight?: ElementType | ReactNode
|
|
35
|
+
pressed?: boolean
|
|
36
|
+
selected?: boolean
|
|
37
|
+
/** @deprecated Use `gap` instead. */
|
|
38
|
+
space?: ResponsiveProp<Space>
|
|
39
|
+
text?: ReactNode
|
|
40
|
+
tone?: ThemeColorStateToneKey
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @public */
|
|
44
|
+
export type MenuItemElementType = 'button' | 'a' | ComponentType
|
|
45
|
+
|
|
46
|
+
/** @public */
|
|
47
|
+
export type MenuItemProps<E extends MenuItemElementType = MenuItemElementType> = Omit<
|
|
48
|
+
Props<MenuItemOwnProps, E>,
|
|
49
|
+
'role'
|
|
50
|
+
>
|
|
41
51
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export const MenuItem = forwardRef(function MenuItem(
|
|
46
|
-
props: Props<MenuItemProps, 'div'>,
|
|
47
|
-
forwardedRef: ForwardedRef<HTMLDivElement>,
|
|
52
|
+
/** @public */
|
|
53
|
+
export function MenuItem<E extends MenuItemElementType = typeof DEFAULT_MENU_ITEM_ELEMENT>(
|
|
54
|
+
props: MenuItemProps<E>,
|
|
48
55
|
) {
|
|
49
56
|
const {
|
|
50
|
-
as =
|
|
57
|
+
as = DEFAULT_MENU_ITEM_ELEMENT,
|
|
51
58
|
children,
|
|
52
59
|
disabled,
|
|
53
60
|
fontSize = 1,
|
|
@@ -67,12 +74,13 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
67
74
|
paddingLeft,
|
|
68
75
|
pressed,
|
|
69
76
|
radius = 2,
|
|
77
|
+
ref: forwardedRef,
|
|
70
78
|
selected: selectedProp,
|
|
71
79
|
space = 3,
|
|
72
80
|
text,
|
|
73
81
|
tone = 'default',
|
|
74
|
-
...
|
|
75
|
-
} = props
|
|
82
|
+
...rest
|
|
83
|
+
} = props as MenuItemProps<typeof DEFAULT_MENU_ITEM_ELEMENT>
|
|
76
84
|
|
|
77
85
|
const menu = useMenu()
|
|
78
86
|
const {
|
|
@@ -84,16 +92,19 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
84
92
|
} = menu
|
|
85
93
|
const onItemMouseEnter = _onItemMouseEnter ?? menu.onMouseEnter
|
|
86
94
|
const onItemMouseLeave = _onItemMouseLeave ?? menu.onMouseLeave
|
|
87
|
-
const [rootElement, setRootElement] = useState<
|
|
95
|
+
const [rootElement, setRootElement] = useState<HTMLButtonElement | null>(null)
|
|
88
96
|
const active = Boolean(activeElement) && activeElement === rootElement
|
|
89
|
-
const ref = useRef<
|
|
97
|
+
const ref = useRef<HTMLButtonElement | null>(null)
|
|
90
98
|
|
|
91
|
-
useImperativeHandle<
|
|
99
|
+
useImperativeHandle<HTMLButtonElement | null, HTMLButtonElement | null>(
|
|
100
|
+
forwardedRef,
|
|
101
|
+
() => ref.current,
|
|
102
|
+
)
|
|
92
103
|
|
|
93
104
|
useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp])
|
|
94
105
|
|
|
95
106
|
const handleClick = useCallback(
|
|
96
|
-
(event: MouseEvent<
|
|
107
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
97
108
|
if (disabled) return
|
|
98
109
|
if (onClick) onClick(event)
|
|
99
110
|
if (onItemClick) onItemClick()
|
|
@@ -114,7 +125,7 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
114
125
|
[padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft],
|
|
115
126
|
)
|
|
116
127
|
|
|
117
|
-
const setRef = useCallback((el:
|
|
128
|
+
const setRef = useCallback((el: HTMLButtonElement | null) => {
|
|
118
129
|
ref.current = el
|
|
119
130
|
setRootElement(el)
|
|
120
131
|
}, [])
|
|
@@ -122,8 +133,7 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
122
133
|
return (
|
|
123
134
|
<Selectable
|
|
124
135
|
data-ui="MenuItem"
|
|
125
|
-
|
|
126
|
-
{...restProps}
|
|
136
|
+
{...rest}
|
|
127
137
|
as={as}
|
|
128
138
|
data-pressed={pressed ? '' : undefined}
|
|
129
139
|
data-selected={active ? '' : undefined}
|
|
@@ -134,6 +144,7 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
134
144
|
onMouseEnter={onItemMouseEnter}
|
|
135
145
|
onMouseLeave={onItemMouseLeave}
|
|
136
146
|
ref={setRef}
|
|
147
|
+
role="menuitem"
|
|
137
148
|
tabIndex={-1}
|
|
138
149
|
tone={tone}
|
|
139
150
|
type={as === 'button' ? 'button' : undefined}
|
|
@@ -175,6 +186,6 @@ export const MenuItem = forwardRef(function MenuItem(
|
|
|
175
186
|
)}
|
|
176
187
|
</Selectable>
|
|
177
188
|
)
|
|
178
|
-
}
|
|
189
|
+
}
|
|
179
190
|
|
|
180
|
-
MenuItem.displayName = '
|
|
191
|
+
MenuItem.displayName = 'MenuItem'
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {codeSkeleton, composeClassNames, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
+
import {FontCodeSize} from '@sanity/ui/theme'
|
|
3
|
+
|
|
4
|
+
import {Props} from '../../types'
|
|
5
|
+
import {Skeleton, SkeletonElementType, SkeletonOwnProps} from './skeleton'
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
export const DEFAULT_CODE_SKELETON_ELEMENT = 'div'
|
|
9
|
+
|
|
10
|
+
/** @beta */
|
|
11
|
+
export type CodeSkeletonOwnProps = SkeletonOwnProps & {
|
|
12
|
+
size?: ResponsiveProp<FontCodeSize>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @public */
|
|
16
|
+
export type CodeSkeletonElementType = SkeletonElementType
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
20
|
+
* @beta
|
|
21
|
+
*/
|
|
22
|
+
export type CodeSkeletonProps<E extends CodeSkeletonElementType = CodeSkeletonElementType> = Props<
|
|
23
|
+
CodeSkeletonOwnProps,
|
|
24
|
+
E
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export function CodeSkeleton<
|
|
32
|
+
E extends CodeSkeletonElementType = typeof DEFAULT_CODE_SKELETON_ELEMENT,
|
|
33
|
+
>(props: CodeSkeletonProps<E>) {
|
|
34
|
+
const {
|
|
35
|
+
className,
|
|
36
|
+
size = 2,
|
|
37
|
+
...rest
|
|
38
|
+
} = props as CodeSkeletonProps<typeof DEFAULT_CODE_SKELETON_ELEMENT>
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Skeleton
|
|
42
|
+
{...rest}
|
|
43
|
+
className={composeClassNames(
|
|
44
|
+
className,
|
|
45
|
+
codeSkeleton({
|
|
46
|
+
size,
|
|
47
|
+
}),
|
|
48
|
+
)}
|
|
49
|
+
/>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
CodeSkeleton.displayName = 'CodeSkeleton'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {composeClassNames, headingSkeleton, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
+
import {FontHeadingSize} from '@sanity/ui/theme'
|
|
3
|
+
|
|
4
|
+
import {Props} from '../../types'
|
|
5
|
+
import {Skeleton, SkeletonElementType, SkeletonOwnProps} from './skeleton'
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
export const DEFAULT_HEADING_SKELETON_ELEMENT = 'div'
|
|
9
|
+
|
|
10
|
+
/** @beta */
|
|
11
|
+
export type HeadingSkeletonOwnProps = SkeletonOwnProps & {
|
|
12
|
+
size?: ResponsiveProp<FontHeadingSize>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @public */
|
|
16
|
+
export type HeadingSkeletonElementType = SkeletonElementType
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
20
|
+
* @beta
|
|
21
|
+
*/
|
|
22
|
+
export type HeadingSkeletonProps<
|
|
23
|
+
E extends HeadingSkeletonElementType = HeadingSkeletonElementType,
|
|
24
|
+
> = Props<HeadingSkeletonOwnProps, E>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
export function HeadingSkeleton<
|
|
31
|
+
E extends HeadingSkeletonElementType = typeof DEFAULT_HEADING_SKELETON_ELEMENT,
|
|
32
|
+
>(props: HeadingSkeletonProps<E>) {
|
|
33
|
+
const {
|
|
34
|
+
className,
|
|
35
|
+
size = 2,
|
|
36
|
+
...rest
|
|
37
|
+
} = props as HeadingSkeletonProps<typeof DEFAULT_HEADING_SKELETON_ELEMENT>
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Skeleton
|
|
41
|
+
{...rest}
|
|
42
|
+
className={composeClassNames(
|
|
43
|
+
className,
|
|
44
|
+
headingSkeleton({
|
|
45
|
+
size,
|
|
46
|
+
}),
|
|
47
|
+
)}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
HeadingSkeleton.displayName = 'HeadingSkeleton'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {composeClassNames, labelSkeleton, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
+
import {FontLabelSize} from '@sanity/ui/theme'
|
|
3
|
+
|
|
4
|
+
import {Props} from '../../types'
|
|
5
|
+
import {Skeleton, SkeletonElementType, SkeletonOwnProps} from './skeleton'
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
export const DEFAULT_LABEL_SKELETON_ELEMENT = 'div'
|
|
9
|
+
|
|
10
|
+
/** @beta */
|
|
11
|
+
export type LabelSkeletonOwnProps = SkeletonOwnProps & {
|
|
12
|
+
size?: ResponsiveProp<FontLabelSize>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @public */
|
|
16
|
+
export type LabelSkeletonElementType = SkeletonElementType
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
20
|
+
* @beta
|
|
21
|
+
*/
|
|
22
|
+
export type LabelSkeletonProps<E extends LabelSkeletonElementType = LabelSkeletonElementType> =
|
|
23
|
+
Props<LabelSkeletonOwnProps, E>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This API might change. DO NOT USE IN PRODUCTION.
|
|
27
|
+
* @beta
|
|
28
|
+
*/
|
|
29
|
+
export function LabelSkeleton<
|
|
30
|
+
E extends LabelSkeletonElementType = typeof DEFAULT_LABEL_SKELETON_ELEMENT,
|
|
31
|
+
>(props: LabelSkeletonProps<E>) {
|
|
32
|
+
const {
|
|
33
|
+
className,
|
|
34
|
+
size = 2,
|
|
35
|
+
...rest
|
|
36
|
+
} = props as LabelSkeletonProps<typeof DEFAULT_LABEL_SKELETON_ELEMENT>
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Skeleton
|
|
40
|
+
{...rest}
|
|
41
|
+
className={composeClassNames(
|
|
42
|
+
className,
|
|
43
|
+
labelSkeleton({
|
|
44
|
+
size,
|
|
45
|
+
}),
|
|
46
|
+
)}
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
LabelSkeleton.displayName = 'LabelSkeleton'
|
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
import {composeClassNames, skeleton, SkeletonStyleProps} from '@sanity/ui/css'
|
|
2
|
-
import {
|
|
2
|
+
import {useEffect, useState} from 'react'
|
|
3
3
|
|
|
4
|
-
import {Box,
|
|
5
|
-
import {Props} from '../../types'
|
|
4
|
+
import {Box, BoxOwnProps} from '../../primitives'
|
|
5
|
+
import {ComponentType, Props} from '../../types'
|
|
6
|
+
|
|
7
|
+
/** @beta */
|
|
8
|
+
export const DEFAULT_SKELETON_ELEMENT = 'div'
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* This API might change. DO NOT USE IN PRODUCTION.
|
|
9
12
|
* @beta
|
|
10
13
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
export type SkeletonOwnProps = BoxOwnProps &
|
|
15
|
+
SkeletonStyleProps & {
|
|
16
|
+
animated?: boolean
|
|
17
|
+
delay?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @beta */
|
|
21
|
+
export type SkeletonElementType = 'div' | 'span' | ComponentType
|
|
22
|
+
|
|
23
|
+
/** @beta */
|
|
24
|
+
export type SkeletonProps<E extends SkeletonElementType = SkeletonElementType> = Props<
|
|
25
|
+
SkeletonOwnProps,
|
|
26
|
+
E
|
|
27
|
+
>
|
|
15
28
|
|
|
16
29
|
/**
|
|
17
30
|
* This API might change. DO NOT USE IN PRODUCTION.
|
|
18
31
|
* @beta
|
|
19
32
|
*/
|
|
20
|
-
export
|
|
21
|
-
props:
|
|
22
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
33
|
+
export function Skeleton<E extends SkeletonElementType = typeof DEFAULT_SKELETON_ELEMENT>(
|
|
34
|
+
props: SkeletonProps<E>,
|
|
23
35
|
) {
|
|
24
|
-
const {
|
|
36
|
+
const {
|
|
37
|
+
animated = false,
|
|
38
|
+
className,
|
|
39
|
+
delay,
|
|
40
|
+
radius,
|
|
41
|
+
...rest
|
|
42
|
+
} = props as SkeletonProps<typeof DEFAULT_SKELETON_ELEMENT>
|
|
43
|
+
|
|
25
44
|
const [visible, setVisible] = useState<boolean>(delay ? false : true)
|
|
26
45
|
|
|
27
46
|
useEffect(() => {
|
|
@@ -41,13 +60,17 @@ export const Skeleton = forwardRef(function Skeleton(
|
|
|
41
60
|
return (
|
|
42
61
|
<Box
|
|
43
62
|
data-ui="Skeleton"
|
|
44
|
-
{...
|
|
45
|
-
className={composeClassNames(
|
|
63
|
+
{...rest}
|
|
64
|
+
className={composeClassNames(
|
|
65
|
+
className,
|
|
66
|
+
skeleton({
|
|
67
|
+
radius,
|
|
68
|
+
}),
|
|
69
|
+
)}
|
|
46
70
|
data-animated={animated ? '' : undefined}
|
|
47
71
|
data-visible={visible ? '' : undefined}
|
|
48
|
-
ref={ref}
|
|
49
72
|
/>
|
|
50
73
|
)
|
|
51
|
-
}
|
|
74
|
+
}
|
|
52
75
|
|
|
53
|
-
Skeleton.displayName = '
|
|
76
|
+
Skeleton.displayName = 'Skeleton'
|