@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
|
@@ -2,8 +2,6 @@ import {breadcrumbs, composeClassNames, GapStyleProps} from '@sanity/ui/css'
|
|
|
2
2
|
import {Space} from '@sanity/ui/theme'
|
|
3
3
|
import {
|
|
4
4
|
Children,
|
|
5
|
-
ForwardedRef,
|
|
6
|
-
forwardRef,
|
|
7
5
|
Fragment,
|
|
8
6
|
isValidElement,
|
|
9
7
|
ReactNode,
|
|
@@ -15,27 +13,35 @@ import {
|
|
|
15
13
|
|
|
16
14
|
import {useClickOutsideEvent} from '../../hooks'
|
|
17
15
|
import {Box, Button, ButtonProps, Flex, Popover, Stack, Text} from '../../primitives'
|
|
18
|
-
import {Props} from '../../types'
|
|
16
|
+
import {ComponentType, Props} from '../../types'
|
|
19
17
|
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
/** @beta */
|
|
19
|
+
export const DEFAULT_BREADCRUMBS_ELEMENT = 'nav'
|
|
20
|
+
|
|
21
|
+
/** @beta */
|
|
22
|
+
export type BreadcrumbsOwnProps = GapStyleProps & {
|
|
23
|
+
expandButton?: Omit<ButtonProps<'button'>, 'as' | 'onClick' | 'selected'>
|
|
25
24
|
maxLength?: number
|
|
26
25
|
separator?: ReactNode
|
|
27
26
|
/** @deprecated - Use `gap`, `gapX`, `gapY` instead */
|
|
28
27
|
space?: number | number[]
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
/** @beta */
|
|
31
|
+
export type BreadcrumbsElementType = 'div' | 'nav' | ComponentType
|
|
32
|
+
|
|
33
|
+
/** @beta */
|
|
34
|
+
export type BreadcrumbsProps<E extends BreadcrumbsElementType = BreadcrumbsElementType> = Props<
|
|
35
|
+
BreadcrumbsOwnProps,
|
|
36
|
+
E
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
/** @beta */
|
|
40
|
+
export function Breadcrumbs<E extends BreadcrumbsElementType = typeof DEFAULT_BREADCRUMBS_ELEMENT>(
|
|
41
|
+
props: BreadcrumbsProps<E>,
|
|
37
42
|
) {
|
|
38
43
|
const {
|
|
44
|
+
as = DEFAULT_BREADCRUMBS_ELEMENT,
|
|
39
45
|
children,
|
|
40
46
|
className,
|
|
41
47
|
expandButton: expandButtonProps,
|
|
@@ -47,8 +53,9 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
|
|
|
47
53
|
separator,
|
|
48
54
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
55
|
space: _spaceProp,
|
|
50
|
-
...
|
|
51
|
-
} = props
|
|
56
|
+
...rest
|
|
57
|
+
} = props as BreadcrumbsProps<typeof DEFAULT_BREADCRUMBS_ELEMENT>
|
|
58
|
+
|
|
52
59
|
const [open, setOpen] = useState(false)
|
|
53
60
|
const expandElementRef = useRef<HTMLButtonElement | null>(null)
|
|
54
61
|
const popoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -102,13 +109,12 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
|
|
|
102
109
|
|
|
103
110
|
return (
|
|
104
111
|
<Flex
|
|
105
|
-
as=
|
|
112
|
+
as={as}
|
|
106
113
|
data-ui="Breadcrumbs"
|
|
107
|
-
{...
|
|
114
|
+
{...rest}
|
|
108
115
|
className={composeClassNames(className, breadcrumbs())}
|
|
109
116
|
gapX={gapX}
|
|
110
117
|
gapY={gapY}
|
|
111
|
-
ref={ref}
|
|
112
118
|
>
|
|
113
119
|
{items.map((item, itemIndex) => (
|
|
114
120
|
<Fragment key={itemIndex}>
|
|
@@ -122,6 +128,6 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
|
|
|
122
128
|
))}
|
|
123
129
|
</Flex>
|
|
124
130
|
)
|
|
125
|
-
}
|
|
131
|
+
}
|
|
126
132
|
|
|
127
|
-
Breadcrumbs.displayName = '
|
|
133
|
+
Breadcrumbs.displayName = 'Breadcrumbs'
|
|
@@ -1,285 +1,74 @@
|
|
|
1
|
-
import {CloseIcon} from '@sanity/icons'
|
|
2
1
|
import {
|
|
3
2
|
composeClassNames,
|
|
4
3
|
ContainerStyleProps,
|
|
5
4
|
dialog,
|
|
6
|
-
dialogCardRoot,
|
|
7
5
|
dialogContainer,
|
|
8
|
-
dialogContent,
|
|
9
|
-
dialogFooter,
|
|
10
|
-
dialogHeader,
|
|
11
|
-
dialogLayout,
|
|
12
|
-
PaddingStyleProps,
|
|
13
|
-
RadiusStyleProps,
|
|
14
6
|
ResponsiveProp,
|
|
15
|
-
ShadowStyleProps,
|
|
16
7
|
} from '@sanity/ui/css'
|
|
17
8
|
import {ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
18
|
-
import {
|
|
19
|
-
FocusEvent,
|
|
20
|
-
ForwardedRef,
|
|
21
|
-
forwardRef,
|
|
22
|
-
ReactNode,
|
|
23
|
-
useCallback,
|
|
24
|
-
useEffect,
|
|
25
|
-
useImperativeHandle,
|
|
26
|
-
useRef,
|
|
27
|
-
} from 'react'
|
|
9
|
+
import {FocusEvent, ForwardedRef, ReactNode, useCallback, useRef} from 'react'
|
|
28
10
|
|
|
29
11
|
import {Z_OFFSETS} from '../../constants'
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from '
|
|
36
|
-
import {
|
|
37
|
-
useArrayProp,
|
|
38
|
-
useClickOutsideEvent,
|
|
39
|
-
useGlobalKeyDown,
|
|
40
|
-
usePrefersReducedMotion,
|
|
41
|
-
} from '../../hooks'
|
|
42
|
-
import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
|
|
43
|
-
import {CardTone, DialogPosition, Props, Radius} from '../../types'
|
|
44
|
-
import {Layer, LayerProps, Portal, useBoundaryElement, useLayer, usePortal} from '../../utils'
|
|
12
|
+
import {focusFirstDescendant, focusLastDescendant, isHTMLElement} from '../../helpers'
|
|
13
|
+
import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
|
|
14
|
+
import {Container} from '../../primitives'
|
|
15
|
+
import {CardTone, ComponentType, DialogPosition, Props, Radius} from '../../types'
|
|
16
|
+
import {Layer, LayerOwnProps, LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
|
|
17
|
+
import {DialogCard} from './dialogCard'
|
|
18
|
+
import {isTargetWithinScope} from './isTargetWithinScope'
|
|
45
19
|
import {useDialog} from './useDialog'
|
|
46
20
|
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*/
|
|
91
|
-
__unstable_hideCloseButton: boolean
|
|
92
|
-
children: ReactNode
|
|
93
|
-
contentRef?: ForwardedRef<HTMLDivElement>
|
|
94
|
-
footer: ReactNode
|
|
95
|
-
header: ReactNode
|
|
96
|
-
id: string
|
|
97
|
-
onClickOutside?: () => void
|
|
98
|
-
onClose?: () => void
|
|
99
|
-
portal?: string
|
|
100
|
-
// radius: Radius | Radius[]
|
|
101
|
-
scheme?: ThemeColorSchemeKey
|
|
102
|
-
// shadow: number | number[]
|
|
103
|
-
tone?: CardTone
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function isTargetWithinScope(
|
|
107
|
-
boundaryElement: HTMLElement | null,
|
|
108
|
-
portalElement: HTMLElement | null,
|
|
109
|
-
target: Node,
|
|
110
|
-
): boolean {
|
|
111
|
-
if (!boundaryElement || !portalElement) return true
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
containsOrEqualsElement(boundaryElement, target) ||
|
|
115
|
-
containsOrEqualsElement(portalElement, target)
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const DialogCard = forwardRef(function DialogCard(
|
|
120
|
-
props: DialogCardProps,
|
|
121
|
-
forwardedRef: ForwardedRef<HTMLDivElement>,
|
|
122
|
-
) {
|
|
123
|
-
const {
|
|
124
|
-
__unstable_autoFocus: autoFocus,
|
|
125
|
-
__unstable_hideCloseButton: hideCloseButton,
|
|
126
|
-
children,
|
|
127
|
-
contentRef: forwardedContentRef,
|
|
128
|
-
footer,
|
|
129
|
-
header,
|
|
130
|
-
id,
|
|
131
|
-
onClickOutside,
|
|
132
|
-
onClose,
|
|
133
|
-
portal: portalProp,
|
|
134
|
-
radius: radiusProp,
|
|
135
|
-
scheme,
|
|
136
|
-
shadow: shadowProp = 4,
|
|
137
|
-
tone,
|
|
138
|
-
width: widthProp,
|
|
139
|
-
} = props
|
|
140
|
-
const portal = usePortal()
|
|
141
|
-
const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
|
|
142
|
-
const boundaryElement = useBoundaryElement().element
|
|
143
|
-
const radius = useArrayProp(radiusProp)
|
|
144
|
-
const shadow = useArrayProp(shadowProp)
|
|
145
|
-
const width = useArrayProp(widthProp)
|
|
146
|
-
const ref = useRef<HTMLDivElement | null>(null)
|
|
147
|
-
const contentRef = useRef<HTMLDivElement | null>(null)
|
|
148
|
-
const layer = useLayer()
|
|
149
|
-
const {isTopLayer} = layer
|
|
150
|
-
const labelId = `${id}_label`
|
|
151
|
-
const showCloseButton = Boolean(onClose) && hideCloseButton === false
|
|
152
|
-
const showHeader = Boolean(header) || showCloseButton
|
|
153
|
-
|
|
154
|
-
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
155
|
-
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(
|
|
156
|
-
forwardedContentRef,
|
|
157
|
-
() => contentRef.current,
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
if (!autoFocus) return
|
|
162
|
-
|
|
163
|
-
// On mount: focus the first focusable element
|
|
164
|
-
if (ref.current) {
|
|
165
|
-
focusFirstDescendant(ref.current)
|
|
166
|
-
}
|
|
167
|
-
}, [autoFocus, ref])
|
|
168
|
-
|
|
169
|
-
useGlobalKeyDown(
|
|
170
|
-
useCallback(
|
|
171
|
-
(event: KeyboardEvent) => {
|
|
172
|
-
if (!isTopLayer || !onClose) return
|
|
173
|
-
|
|
174
|
-
const target = document.activeElement
|
|
175
|
-
|
|
176
|
-
if (target && !isTargetWithinScope(boundaryElement, portalElement, target)) {
|
|
177
|
-
// Ignore key presses when the focused element is outside of scope
|
|
178
|
-
return
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (event.key === 'Escape') {
|
|
182
|
-
event.preventDefault()
|
|
183
|
-
event.stopPropagation()
|
|
184
|
-
onClose()
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
[boundaryElement, isTopLayer, onClose, portalElement],
|
|
188
|
-
),
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
useClickOutsideEvent(
|
|
192
|
-
isTopLayer &&
|
|
193
|
-
onClickOutside &&
|
|
194
|
-
((event) => {
|
|
195
|
-
const target = event.target as Node | null
|
|
196
|
-
|
|
197
|
-
if (target && !isTargetWithinScope(boundaryElement, portalElement, target)) {
|
|
198
|
-
// Ignore clicks outside of the scope
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
onClickOutside()
|
|
203
|
-
}),
|
|
204
|
-
() => [ref.current],
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
return (
|
|
208
|
-
<Container
|
|
209
|
-
align="center"
|
|
210
|
-
className={dialogContainer()}
|
|
211
|
-
data-ui="DialogCard"
|
|
212
|
-
direction="column"
|
|
213
|
-
display="flex"
|
|
214
|
-
justify="center"
|
|
215
|
-
width={width}
|
|
216
|
-
>
|
|
217
|
-
<Card
|
|
218
|
-
className={dialogCardRoot()}
|
|
219
|
-
display="flex"
|
|
220
|
-
radius={radius}
|
|
221
|
-
ref={ref}
|
|
222
|
-
scheme={scheme}
|
|
223
|
-
shadow={shadow}
|
|
224
|
-
tone={tone}
|
|
225
|
-
>
|
|
226
|
-
<Flex className={dialogLayout()} direction="column" flex={1}>
|
|
227
|
-
{showHeader && (
|
|
228
|
-
<Box className={dialogHeader()} position="relative">
|
|
229
|
-
<Flex align="flex-start" padding={3}>
|
|
230
|
-
<Box flex={1} padding={2}>
|
|
231
|
-
{header && (
|
|
232
|
-
<Text id={labelId} size={1} weight="semibold">
|
|
233
|
-
{header}
|
|
234
|
-
</Text>
|
|
235
|
-
)}
|
|
236
|
-
</Box>
|
|
237
|
-
{showCloseButton && (
|
|
238
|
-
<Box flex="none">
|
|
239
|
-
<Button
|
|
240
|
-
aria-label="Close dialog"
|
|
241
|
-
disabled={!onClose}
|
|
242
|
-
icon={CloseIcon}
|
|
243
|
-
mode="bleed"
|
|
244
|
-
onClick={onClose}
|
|
245
|
-
padding={2}
|
|
246
|
-
/>
|
|
247
|
-
</Box>
|
|
248
|
-
)}
|
|
249
|
-
</Flex>
|
|
250
|
-
</Box>
|
|
251
|
-
)}
|
|
252
|
-
<Box
|
|
253
|
-
className={dialogContent()}
|
|
254
|
-
flex={1}
|
|
255
|
-
overflow="auto"
|
|
256
|
-
position="relative"
|
|
257
|
-
ref={contentRef}
|
|
258
|
-
tabIndex={-1}
|
|
259
|
-
>
|
|
260
|
-
{children}
|
|
261
|
-
</Box>
|
|
262
|
-
{footer && (
|
|
263
|
-
<Box className={dialogFooter()} position="relative">
|
|
264
|
-
{footer}
|
|
265
|
-
</Box>
|
|
266
|
-
)}
|
|
267
|
-
</Flex>
|
|
268
|
-
</Card>
|
|
269
|
-
</Container>
|
|
270
|
-
)
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
DialogCard.displayName = 'ForwardRef(DialogCard)'
|
|
21
|
+
/** @public */
|
|
22
|
+
export const DEFAULT_DIALOG_ELEMENT = 'div'
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export type DialogOwnProps = ContainerStyleProps &
|
|
26
|
+
Omit<LayerOwnProps, 'width'> & {
|
|
27
|
+
/**
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
__unstable_autoFocus?: boolean
|
|
31
|
+
/**
|
|
32
|
+
* @beta
|
|
33
|
+
*/
|
|
34
|
+
__unstable_hideCloseButton?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* Whether the dialog should animate in on mount.
|
|
37
|
+
*
|
|
38
|
+
* @beta
|
|
39
|
+
* @defaultValue false
|
|
40
|
+
*/
|
|
41
|
+
animate?: boolean
|
|
42
|
+
cardRadius?: ResponsiveProp<Radius>
|
|
43
|
+
contentRef?: ForwardedRef<HTMLDivElement>
|
|
44
|
+
footer?: ReactNode
|
|
45
|
+
header?: ReactNode
|
|
46
|
+
id: string
|
|
47
|
+
/** A callback that fires when the dialog becomes the top layer when it was not the top layer before. */
|
|
48
|
+
onActivate?: LayerProps['onActivate']
|
|
49
|
+
onClickOutside?: () => void
|
|
50
|
+
onClose?: () => void
|
|
51
|
+
open?: boolean
|
|
52
|
+
portal?: string
|
|
53
|
+
position?: DialogPosition | DialogPosition[]
|
|
54
|
+
scheme?: ThemeColorSchemeKey
|
|
55
|
+
tone?: CardTone
|
|
56
|
+
zOffset?: number | number[]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @public */
|
|
60
|
+
export type DialogElementType = 'div' | 'span' | ComponentType
|
|
61
|
+
|
|
62
|
+
/** @public */
|
|
63
|
+
export type DialogProps<E extends DialogElementType = DialogElementType> = Props<DialogOwnProps, E>
|
|
274
64
|
|
|
275
65
|
/**
|
|
276
66
|
* The Dialog component.
|
|
277
67
|
*
|
|
278
68
|
* @public
|
|
279
69
|
*/
|
|
280
|
-
export
|
|
281
|
-
props:
|
|
282
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
70
|
+
export function Dialog<E extends DialogElementType = typeof DEFAULT_DIALOG_ELEMENT>(
|
|
71
|
+
props: DialogProps<E>,
|
|
283
72
|
) {
|
|
284
73
|
const context = useDialog()
|
|
285
74
|
const {
|
|
@@ -287,7 +76,6 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
287
76
|
__unstable_hideCloseButton: hideCloseButton = false,
|
|
288
77
|
animate: _animate = false,
|
|
289
78
|
cardRadius: cardRadiusProp = 4,
|
|
290
|
-
// cardShadow = 3,
|
|
291
79
|
children,
|
|
292
80
|
className,
|
|
293
81
|
contentRef,
|
|
@@ -302,12 +90,13 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
302
90
|
portal: portalProp,
|
|
303
91
|
position: _positionProp,
|
|
304
92
|
scheme,
|
|
305
|
-
shadow: cardShadow,
|
|
306
|
-
width
|
|
93
|
+
shadow: cardShadow = 4,
|
|
94
|
+
width = 0,
|
|
307
95
|
zOffset: _zOffsetProp,
|
|
308
96
|
tone,
|
|
309
|
-
...
|
|
310
|
-
} = props
|
|
97
|
+
...rest
|
|
98
|
+
} = props as DialogProps<typeof DEFAULT_DIALOG_ELEMENT>
|
|
99
|
+
|
|
311
100
|
const positionProp = _positionProp ?? context.position ?? 'fixed'
|
|
312
101
|
const zOffsetProp = _zOffsetProp ?? context.zOffset ?? Z_OFFSETS.dialog
|
|
313
102
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
@@ -317,7 +106,7 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
317
106
|
const boundaryElement = useBoundaryElement().element
|
|
318
107
|
const cardRadius = useArrayProp(cardRadiusProp)
|
|
319
108
|
const position = useArrayProp(positionProp)
|
|
320
|
-
const width = useArrayProp(widthProp)
|
|
109
|
+
// const width = useArrayProp(widthProp)
|
|
321
110
|
const zOffset = useArrayProp(zOffsetProp)
|
|
322
111
|
const preDivRef = useRef<HTMLDivElement | null>(null)
|
|
323
112
|
const postDivRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -384,7 +173,7 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
384
173
|
return (
|
|
385
174
|
<Portal __unstable_name={portalProp}>
|
|
386
175
|
<Layer
|
|
387
|
-
{...
|
|
176
|
+
{...rest}
|
|
388
177
|
aria-labelledby={labelId}
|
|
389
178
|
aria-modal
|
|
390
179
|
className={composeClassNames(className, dialog())}
|
|
@@ -397,36 +186,45 @@ export const Dialog = forwardRef(function Dialog(
|
|
|
397
186
|
onFocus={handleFocus}
|
|
398
187
|
padding={padding}
|
|
399
188
|
position={position}
|
|
400
|
-
ref={ref}
|
|
401
189
|
role="dialog"
|
|
402
190
|
zOffset={zOffset}
|
|
403
191
|
>
|
|
404
192
|
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */}
|
|
405
193
|
<div ref={preDivRef} tabIndex={0} />
|
|
406
|
-
<
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
onClickOutside={onClickOutside}
|
|
414
|
-
onClose={onClose}
|
|
415
|
-
portal={portalProp}
|
|
416
|
-
radius={cardRadius}
|
|
417
|
-
ref={cardRef}
|
|
418
|
-
scheme={scheme}
|
|
419
|
-
shadow={cardShadow}
|
|
420
|
-
tone={tone}
|
|
194
|
+
<Container
|
|
195
|
+
align="center"
|
|
196
|
+
className={dialogContainer()}
|
|
197
|
+
data-ui="DialogCard"
|
|
198
|
+
direction="column"
|
|
199
|
+
display="flex"
|
|
200
|
+
justify="center"
|
|
421
201
|
width={width}
|
|
422
202
|
>
|
|
423
|
-
|
|
424
|
-
|
|
203
|
+
<DialogCard
|
|
204
|
+
__unstable_autoFocus={autoFocus}
|
|
205
|
+
__unstable_hideCloseButton={hideCloseButton}
|
|
206
|
+
contentRef={contentRef}
|
|
207
|
+
footer={footer}
|
|
208
|
+
header={header}
|
|
209
|
+
id={id}
|
|
210
|
+
onClickOutside={onClickOutside}
|
|
211
|
+
onClose={onClose}
|
|
212
|
+
portal={portalProp}
|
|
213
|
+
radius={cardRadius}
|
|
214
|
+
ref={cardRef}
|
|
215
|
+
scheme={scheme}
|
|
216
|
+
shadow={cardShadow}
|
|
217
|
+
tone={tone}
|
|
218
|
+
width={width}
|
|
219
|
+
>
|
|
220
|
+
{children}
|
|
221
|
+
</DialogCard>
|
|
222
|
+
</Container>
|
|
425
223
|
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */}
|
|
426
224
|
<div ref={postDivRef} tabIndex={0} />
|
|
427
225
|
</Layer>
|
|
428
226
|
</Portal>
|
|
429
227
|
)
|
|
430
|
-
}
|
|
228
|
+
}
|
|
431
229
|
|
|
432
|
-
Dialog.displayName = '
|
|
230
|
+
Dialog.displayName = 'Dialog'
|