@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.
Files changed (251) hide show
  1. package/dist/_chunks-cjs/_visual-editing.js +1293 -1215
  2. package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
  3. package/dist/_chunks-cjs/buildCommand.js +28 -10
  4. package/dist/_chunks-cjs/buildCommand.js.map +1 -1
  5. package/dist/_chunks-es/_visual-editing.mjs +1284 -1202
  6. package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
  7. package/dist/_visual-editing.d.mts +528 -358
  8. package/dist/_visual-editing.d.ts +528 -358
  9. package/dist/cli.js +1 -1
  10. package/dist/css.d.mts +143 -73
  11. package/dist/css.d.ts +143 -73
  12. package/dist/css.js +329 -472
  13. package/dist/css.js.map +1 -1
  14. package/dist/css.mjs +330 -473
  15. package/dist/css.mjs.map +1 -1
  16. package/dist/index.d.mts +1362 -869
  17. package/dist/index.d.ts +1362 -869
  18. package/dist/index.js +383 -308
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +387 -312
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/sanity-palette.css +105 -1
  23. package/dist/sanity-palette.min.css +1 -0
  24. package/dist/sanity-theme.css +4571 -1
  25. package/dist/sanity-theme.min.css +1 -0
  26. package/dist/system.css +22053 -21946
  27. package/dist/system.min.css +1 -0
  28. package/dist/theme.d.mts +51 -106
  29. package/dist/theme.d.ts +51 -106
  30. package/dist/theme.js +9 -9
  31. package/dist/theme.js.map +1 -1
  32. package/dist/theme.mjs +9 -9
  33. package/dist/theme.mjs.map +1 -1
  34. package/package.json +10 -5
  35. package/src/cli/buildCommand.ts +46 -19
  36. package/src/css/_comp.ts +2 -2
  37. package/src/css/{compile/compileStyle.ts → _compileStyle.ts} +7 -7
  38. package/src/css/{system.style.ts → _system.style.ts} +3 -2
  39. package/src/css/aspects/display/display.ts +1 -0
  40. package/src/css/aspects/display/types.ts +2 -3
  41. package/src/css/aspects/flex/types.ts +4 -12
  42. package/src/css/aspects/flexItem/types.ts +1 -3
  43. package/src/css/aspects/font/types.ts +1 -3
  44. package/src/css/aspects/grid/grid.ts +1 -0
  45. package/src/css/aspects/grid/types.ts +5 -9
  46. package/src/css/aspects/gridItem/gridItem.ts +1 -1
  47. package/src/css/aspects/gridItem/types.ts +7 -18
  48. package/src/css/aspects/height/height.ts +3 -4
  49. package/src/css/aspects/inset/inset.ts +1 -0
  50. package/src/css/aspects/margin/margin.ts +1 -0
  51. package/src/css/aspects/margin/types.ts +1 -0
  52. package/src/css/aspects/maxWidth/maxWidth.ts +1 -0
  53. package/src/css/aspects/maxWidth/types.ts +1 -0
  54. package/src/css/aspects/minWidth/minWidth.ts +1 -0
  55. package/src/css/aspects/minWidth/types.ts +2 -0
  56. package/src/css/aspects/overflow/overflow.ts +1 -0
  57. package/src/css/aspects/padding/padding.ts +1 -0
  58. package/src/css/aspects/pointerEvents/pointerEvents.ts +1 -0
  59. package/src/css/aspects/position/position.ts +1 -0
  60. package/src/css/aspects/shadow/shadow.ts +1 -0
  61. package/src/css/aspects/textOverflow/textOverflow.ts +1 -0
  62. package/src/css/aspects/textOverflow/types.ts +1 -0
  63. package/src/css/aspects/width/types.ts +2 -0
  64. package/src/css/aspects/width/width.ts +1 -0
  65. package/src/css/{compile/compilePalette.ts → compilePalette.ts} +14 -10
  66. package/src/css/compileSystem.ts +7 -0
  67. package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
  68. package/src/css/{compile/compileTheme_v3.ts → compileTheme_v3.ts} +123 -104
  69. package/src/css/components/breadcrumbs/breadcrumbs.ts +1 -0
  70. package/src/css/components/dialog/dialog.ts +7 -0
  71. package/src/css/components/menu/menu.ts +2 -0
  72. package/src/css/components/skeleton/skeleton.ts +4 -0
  73. package/src/css/components/skeleton/types.ts +4 -0
  74. package/src/css/components/toast/toast.ts +5 -0
  75. package/src/css/components/tree/tree.ts +1 -0
  76. package/src/css/composeClassNames.ts +4 -2
  77. package/src/css/constants.ts +2 -0
  78. package/src/css/index.ts +3 -3
  79. package/src/css/primitives/_arrow/_arrow.ts +3 -0
  80. package/src/css/primitives/_input/input.ts +2 -0
  81. package/src/css/primitives/_selectable/_selectable.style.ts +1 -2
  82. package/src/css/primitives/_selectable/selectable.ts +1 -2
  83. package/src/css/primitives/avatar/avatar.style.ts +5 -8
  84. package/src/css/primitives/avatar/avatar.ts +6 -0
  85. package/src/css/primitives/avatar/types.ts +1 -0
  86. package/src/css/primitives/box/types.ts +1 -3
  87. package/src/css/primitives/button/button.ts +4 -21
  88. package/src/css/primitives/button/index.ts +1 -0
  89. package/src/css/primitives/button/types.ts +18 -0
  90. package/src/css/primitives/card/card.style.ts +3 -6
  91. package/src/css/primitives/card/card.ts +2 -2
  92. package/src/css/primitives/card/types.ts +2 -2
  93. package/src/css/primitives/checkbox/checkbox.ts +2 -0
  94. package/src/css/primitives/container/container.ts +1 -0
  95. package/src/css/primitives/container/types.ts +1 -0
  96. package/src/css/primitives/kbd/kbd.ts +1 -0
  97. package/src/css/primitives/label/types.ts +7 -2
  98. package/src/css/primitives/popover/popover.ts +2 -0
  99. package/src/css/primitives/radio/radio.ts +1 -0
  100. package/src/css/primitives/select/select.ts +2 -0
  101. package/src/css/primitives/spinner/spinner.ts +2 -0
  102. package/src/css/primitives/switch/switch.ts +5 -0
  103. package/src/css/primitives/text/types.ts +4 -0
  104. package/src/css/primitives/textArea/textArea.ts +1 -0
  105. package/src/css/primitives/textInput/textInput.ts +1 -0
  106. package/src/css/primitives/tooltip/tooltip.ts +2 -0
  107. package/src/css/scopeClassName.ts +1 -0
  108. package/src/css/types.ts +9 -12
  109. package/src/css/util.ts +5 -0
  110. package/src/css/utils/srOnly/srOnly.ts +3 -1
  111. package/src/css/varNames.ts +131 -141
  112. package/src/css/vars.ts +1 -6
  113. package/src/theme/palette/constants.ts +2 -0
  114. package/src/theme/palette/types.ts +3 -0
  115. package/src/theme/types.ts +2 -6
  116. package/src/theme/v0/focusRing.ts +1 -3
  117. package/src/theme/v0/font.ts +6 -18
  118. package/src/theme/v0/layer.ts +1 -3
  119. package/src/theme/v0/shadow.ts +2 -6
  120. package/src/theme/v2/avatar.ts +1 -3
  121. package/src/theme/v2/color/_system.ts +1 -3
  122. package/src/theme/v2/color/avatar.ts +2 -6
  123. package/src/theme/v2/color/badge.ts +2 -6
  124. package/src/theme/v2/color/button.ts +3 -9
  125. package/src/theme/v2/color/color.ts +3 -9
  126. package/src/theme/v2/color/input.ts +3 -9
  127. package/src/theme/v2/color/kbd.ts +1 -3
  128. package/src/theme/v2/color/selectable.ts +2 -6
  129. package/src/theme/v2/color/state.ts +1 -3
  130. package/src/theme/v2/color/syntax.ts +1 -3
  131. package/src/theme/v2/input.ts +1 -3
  132. package/src/theme/v2/theme.ts +2 -6
  133. package/src/theme/v3/buildTheme_v3.ts +1 -0
  134. package/src/theme/v3/color/color.ts +6 -4
  135. package/src/theme/v3/color/renderColor.ts +4 -1
  136. package/src/theme/v3/defaultTokens.ts +1 -0
  137. package/src/theme/v3/resolveTokens.ts +9 -9
  138. package/src/ui/RootClassNames.tsx +3 -0
  139. package/src/ui/StyleTags.tsx +3 -1
  140. package/src/ui/_compat/theme/themeColorProvider.tsx +2 -6
  141. package/src/ui/_compat/theme/themeProvider.tsx +2 -6
  142. package/src/ui/_compat/theme/types.ts +1 -3
  143. package/src/ui/_compat/theme/useRootTheme.ts +1 -3
  144. package/src/ui/_compat/theme/useTheme.ts +2 -6
  145. package/src/ui/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
  146. package/src/ui/components/autocomplete/autocomplete.tsx +86 -114
  147. package/src/ui/components/autocomplete/autocompleteOption.tsx +2 -0
  148. package/src/ui/components/autocomplete/types.ts +3 -8
  149. package/src/ui/components/breadcrumbs/breadcrumbs.tsx +27 -21
  150. package/src/ui/components/dialog/dialog.tsx +89 -291
  151. package/src/ui/components/dialog/dialogCard.tsx +183 -0
  152. package/src/ui/components/dialog/isTargetWithinScope.ts +14 -0
  153. package/src/ui/components/hotkeys/hotkeys.tsx +33 -15
  154. package/src/ui/components/menu/__workshop__/asComponent.tsx +6 -6
  155. package/src/ui/components/menu/menu.tsx +27 -33
  156. package/src/ui/components/menu/menuButton.tsx +10 -14
  157. package/src/ui/components/menu/menuDivider.tsx +25 -13
  158. package/src/ui/components/menu/menuGroup.tsx +34 -26
  159. package/src/ui/components/menu/menuItem.tsx +51 -40
  160. package/src/ui/components/skeleton/codeSkeleton.tsx +53 -0
  161. package/src/ui/components/skeleton/headingSkeleton.tsx +52 -0
  162. package/src/ui/components/skeleton/index.ts +3 -0
  163. package/src/ui/components/skeleton/labelSkeleton.tsx +51 -0
  164. package/src/ui/components/skeleton/skeleton.tsx +39 -16
  165. package/src/ui/components/skeleton/textSkeleton.tsx +31 -110
  166. package/src/ui/components/tab/tab.tsx +23 -19
  167. package/src/ui/components/tab/tabList.tsx +34 -33
  168. package/src/ui/components/tab/tabPanel.tsx +25 -19
  169. package/src/ui/components/toast/toast.tsx +21 -16
  170. package/src/ui/components/toast/toastLayer.tsx +28 -10
  171. package/src/ui/components/toast/toastProvider.tsx +2 -6
  172. package/src/ui/components/toast/types.ts +2 -6
  173. package/src/ui/components/toast/useToast.ts +1 -3
  174. package/src/ui/components/tree/tree.tsx +194 -187
  175. package/src/ui/components/tree/treeGroup.tsx +25 -5
  176. package/src/ui/components/tree/treeItem.tsx +35 -23
  177. package/src/ui/hooks/useClickOutside.ts +2 -6
  178. package/src/ui/hooks/useClickOutsideEvent.ts +3 -9
  179. package/src/ui/primitives/_selectable/selectable.tsx +33 -20
  180. package/src/ui/primitives/avatar/avatar.tsx +28 -31
  181. package/src/ui/primitives/avatar/avatarCounter.tsx +33 -25
  182. package/src/ui/primitives/avatar/avatarStack.tsx +31 -24
  183. package/src/ui/primitives/avatar/types.ts +2 -0
  184. package/src/ui/primitives/badge/__workshop__/props.tsx +1 -9
  185. package/src/ui/primitives/badge/__workshop__/tones.tsx +1 -6
  186. package/src/ui/primitives/badge/badge.tsx +33 -32
  187. package/src/ui/primitives/badge/types.ts +2 -1
  188. package/src/ui/primitives/box/box.tsx +59 -29
  189. package/src/ui/primitives/button/__workshop__/sanityUploadButton.tsx +3 -3
  190. package/src/ui/primitives/button/__workshop__/uploadButton.tsx +2 -1
  191. package/src/ui/primitives/button/button.test.tsx +1 -15
  192. package/src/ui/primitives/button/button.tsx +64 -70
  193. package/src/ui/primitives/card/__workshop__/asComponent.tsx +3 -3
  194. package/src/ui/primitives/card/card.tsx +22 -22
  195. package/src/ui/primitives/card/cardProvider.tsx +2 -0
  196. package/src/ui/primitives/checkbox/checkbox.tsx +26 -15
  197. package/src/ui/primitives/code/code.tsx +24 -22
  198. package/src/ui/primitives/container/container.tsx +26 -15
  199. package/src/ui/primitives/flex/flex.tsx +21 -19
  200. package/src/ui/primitives/grid/grid.tsx +21 -16
  201. package/src/ui/primitives/heading/heading.tsx +42 -19
  202. package/src/ui/primitives/inline/inline.tsx +26 -23
  203. package/src/ui/primitives/kbd/kbd.tsx +25 -23
  204. package/src/ui/primitives/label/label.tsx +41 -26
  205. package/src/ui/primitives/popover/popover.tsx +281 -277
  206. package/src/ui/primitives/popover/popoverCard.tsx +119 -118
  207. package/src/ui/primitives/radio/radio.tsx +30 -14
  208. package/src/ui/primitives/select/select.tsx +24 -16
  209. package/src/ui/primitives/spinner/animatedSpinnerIcon.tsx +4 -2
  210. package/src/ui/primitives/spinner/spinner.tsx +24 -12
  211. package/src/ui/primitives/stack/stack.tsx +27 -18
  212. package/src/ui/primitives/switch/switch.tsx +31 -14
  213. package/src/ui/primitives/text/text.tsx +42 -24
  214. package/src/ui/primitives/textArea/textArea.tsx +33 -18
  215. package/src/ui/primitives/textInput/textInput.tsx +28 -40
  216. package/src/ui/primitives/tooltip/constants.ts +1 -1
  217. package/src/ui/primitives/tooltip/tooltip.tsx +76 -59
  218. package/src/ui/primitives/tooltip/tooltipCard.tsx +89 -82
  219. package/src/ui/primitives/types.ts +1 -3
  220. package/src/ui/types/avatar.ts +3 -6
  221. package/src/ui/types/badge.ts +1 -3
  222. package/src/ui/types/button.ts +1 -3
  223. package/src/ui/types/card.ts +1 -3
  224. package/src/ui/types/dialog.ts +1 -3
  225. package/src/ui/types/props.ts +20 -10
  226. package/src/ui/utils/arrow/arrow.tsx +40 -14
  227. package/src/ui/utils/boundaryElement/boundaryElementProvider.tsx +2 -6
  228. package/src/ui/utils/boundaryElement/types.ts +1 -3
  229. package/src/ui/utils/boundaryElement/useBoundaryElement.ts +1 -3
  230. package/src/ui/utils/elementQuery/elementQuery.tsx +36 -14
  231. package/src/ui/utils/errorBoundary.tsx +2 -0
  232. package/src/ui/utils/index.ts +0 -1
  233. package/src/ui/utils/layer/layer.tsx +23 -93
  234. package/src/ui/utils/layer/layerCard.tsx +92 -0
  235. package/src/ui/utils/layer/layerProvider.tsx +2 -6
  236. package/src/ui/utils/layer/useLayer.ts +1 -3
  237. package/src/ui/utils/portal/portal.ts +2 -6
  238. package/src/ui/utils/portal/portalProvider.tsx +2 -6
  239. package/src/ui/utils/portal/types.ts +1 -3
  240. package/src/ui/utils/portal/usePortal.ts +1 -3
  241. package/src/ui/utils/srOnly/srOnly.tsx +25 -20
  242. package/src/ui/utils/virtualList/virtualList.tsx +36 -24
  243. package/src/css/compile/compileRule.ts +0 -97
  244. package/src/css/compile/compileRules.test.ts +0 -36
  245. package/src/css/compile/compileRules.ts +0 -43
  246. package/src/css/compile/compileSystem.ts +0 -7
  247. package/src/css/compile/types.ts +0 -6
  248. package/src/css/primitives/_selectable/_contants.ts +0 -11
  249. package/src/css/primitives/card/_constants.ts +0 -13
  250. package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
  251. 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
- * @beta
22
- */
23
- export interface BreadcrumbsProps extends GapStyleProps {
24
- expandButton?: Omit<ButtonProps, 'onClick' | 'selected'>
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
- * @beta
33
- */
34
- export const Breadcrumbs = forwardRef(function Breadcrumbs(
35
- props: Props<BreadcrumbsProps, 'div'>,
36
- ref: ForwardedRef<HTMLDivElement>,
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
- ...restProps
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="nav"
112
+ as={as}
106
113
  data-ui="Breadcrumbs"
107
- {...restProps}
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 = 'ForwardRef(Breadcrumbs)'
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
- containsOrEqualsElement,
32
- focusFirstDescendant,
33
- focusLastDescendant,
34
- isHTMLElement,
35
- } from '../../helpers'
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
- * @public
49
- */
50
- export interface DialogProps extends ContainerStyleProps, PaddingStyleProps, ShadowStyleProps {
51
- /**
52
- * @beta
53
- */
54
- __unstable_autoFocus?: boolean
55
- /**
56
- * @beta
57
- */
58
- __unstable_hideCloseButton?: boolean
59
- /**
60
- * Whether the dialog should animate in on mount.
61
- *
62
- * @beta
63
- * @defaultValue false
64
- */
65
- animate?: boolean
66
- cardRadius?: ResponsiveProp<Radius>
67
- contentRef?: ForwardedRef<HTMLDivElement>
68
- footer?: ReactNode
69
- header?: ReactNode
70
- id: string
71
- /** A callback that fires when the dialog becomes the top layer when it was not the top layer before. */
72
- onActivate?: LayerProps['onActivate']
73
- onClickOutside?: () => void
74
- onClose?: () => void
75
- open?: boolean
76
- portal?: string
77
- position?: DialogPosition | DialogPosition[]
78
- scheme?: ThemeColorSchemeKey
79
- tone?: CardTone
80
- zOffset?: number | number[]
81
- }
82
-
83
- interface DialogCardProps extends ContainerStyleProps, RadiusStyleProps, ShadowStyleProps {
84
- /**
85
- * @beta
86
- */
87
- __unstable_autoFocus: boolean
88
- /**
89
- * @beta
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 const Dialog = forwardRef(function Dialog(
281
- props: Props<DialogProps, 'div'>,
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: widthProp = 0,
93
+ shadow: cardShadow = 4,
94
+ width = 0,
307
95
  zOffset: _zOffsetProp,
308
96
  tone,
309
- ...restProps
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
- {...restProps}
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
- <DialogCard
407
- __unstable_autoFocus={autoFocus}
408
- __unstable_hideCloseButton={hideCloseButton}
409
- contentRef={contentRef}
410
- footer={footer}
411
- header={header}
412
- id={id}
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
- {children}
424
- </DialogCard>
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 = 'ForwardRef(Dialog)'
230
+ Dialog.displayName = 'Dialog'