@radix-ui/react-dialog 1.2.0-rc.1785253136758 → 1.2.0-rc.1785512840124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -4
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +2 -2
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -286,12 +286,12 @@ var DialogContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
286
286
|
onOpenAutoFocus,
|
|
287
287
|
onCloseAutoFocus,
|
|
288
288
|
"aria-describedby": ariaDescribedby,
|
|
289
|
+
children,
|
|
289
290
|
...contentProps
|
|
290
291
|
} = props;
|
|
291
|
-
const { children, ...layerProps } = contentProps;
|
|
292
292
|
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
293
293
|
(0, import_react_focus_guards.useFocusGuards)();
|
|
294
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
294
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_focus_scope.FocusScopeBranchProvider, { registry: context.branchRegistry, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
295
295
|
import_react_focus_scope.FocusScope,
|
|
296
296
|
{
|
|
297
297
|
asChild: true,
|
|
@@ -308,11 +308,11 @@ var DialogContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
308
308
|
"aria-labelledby": context.titlePresent ? context.titleId : void 0,
|
|
309
309
|
"aria-describedby": context.descriptionPresent ? concatAriaDescribedby(ariaDescribedby, context.descriptionId) : ariaDescribedby,
|
|
310
310
|
"data-state": getState(context.open),
|
|
311
|
-
...
|
|
311
|
+
...contentProps,
|
|
312
312
|
ref: forwardedRef,
|
|
313
313
|
deferPointerDownOutside: true,
|
|
314
314
|
onDismiss: () => context.onOpenChange(false),
|
|
315
|
-
children
|
|
315
|
+
children
|
|
316
316
|
}
|
|
317
317
|
)
|
|
318
318
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/dialog.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client';\nexport {\n createDialogScope,\n //\n Dialog,\n DialogTrigger,\n DialogPortal,\n DialogOverlay,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n //\n Root,\n Trigger,\n Portal,\n Overlay,\n Content,\n Title,\n Description,\n Close,\n /** @deprecated Noop component to avoid breaking changes. */\n WarningProvider,\n} from './dialog';\nexport type {\n DialogProps,\n DialogTriggerProps,\n DialogPortalProps,\n DialogOverlayProps,\n DialogContentProps,\n DialogTitleProps,\n DialogDescriptionProps,\n DialogCloseProps,\n} from './dialog';\n", "import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useId } from '@radix-ui/react-id';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { DismissableLayer, useDismissableLayerSurface } from '@radix-ui/react-dismissable-layer';\nimport {\n FocusScope,\n FocusScopeBranchProvider,\n useFocusScopeBranchRegistry,\n} from '@radix-ui/react-focus-scope';\nimport { Portal as PortalPrimitive } from '@radix-ui/react-portal';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useFocusGuards } from '@radix-ui/react-focus-guards';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { RemoveScroll } from 'react-remove-scroll';\nimport { hideOthers } from 'aria-hidden';\nimport { createSlot } from '@radix-ui/react-slot';\n\nimport type { Scope } from '@radix-ui/react-context';\nimport type { FocusScopeBranchRegistry } from '@radix-ui/react-focus-scope';\n\n/* -------------------------------------------------------------------------------------------------\n * Dialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst DIALOG_NAME = 'Dialog';\n\ntype ScopedProps<P> = P & { __scopeDialog?: Scope };\nconst [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);\n\ntype DialogContextValue = {\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n contentRef: React.RefObject<DialogContentElement | null>;\n contentId: string;\n titleId: string;\n descriptionId: string;\n titlePresent: boolean;\n descriptionPresent: boolean;\n setTitleCount: React.Dispatch<React.SetStateAction<number>>;\n setDescriptionCount: React.Dispatch<React.SetStateAction<number>>;\n open: boolean;\n onOpenChange(open: boolean): void;\n onOpenToggle(): void;\n modal: boolean;\n // Nodes of nested, portalled layers (eg. a non-modal `Popover`) that should\n // be treated as part of this Dialog for focus trapping and scroll locking.\n // See https://github.com/radix-ui/primitives/issues/3423\n branchNodes: HTMLElement[];\n branchRegistry: FocusScopeBranchRegistry;\n};\n\nconst [DialogProvider, useDialogContext] = createDialogContext<DialogContextValue>(DIALOG_NAME);\n\ninterface DialogProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?(open: boolean): void;\n modal?: boolean;\n}\n\nconst Dialog: React.FC<DialogProps> = (props: ScopedProps<DialogProps>) => {\n const {\n __scopeDialog,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n modal = true,\n } = props;\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const contentRef = React.useRef<DialogContentElement>(null);\n const { nodes: branchNodes, registry: branchRegistry } = useFocusScopeBranchRegistry();\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? false,\n onChange: onOpenChange,\n caller: DIALOG_NAME,\n });\n\n const [titleCount, setTitleCount] = React.useState(0);\n const [descriptionCount, setDescriptionCount] = React.useState(0);\n\n return (\n <DialogProvider\n scope={__scopeDialog}\n triggerRef={triggerRef}\n contentRef={contentRef}\n contentId={useId()}\n titleId={useId()}\n descriptionId={useId()}\n titlePresent={titleCount > 0}\n descriptionPresent={descriptionCount > 0}\n setTitleCount={setTitleCount}\n setDescriptionCount={setDescriptionCount}\n open={open}\n onOpenChange={setOpen}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n modal={modal}\n branchNodes={branchNodes}\n branchRegistry={branchRegistry}\n >\n {children}\n </DialogProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'DialogTrigger';\n\ntype DialogTriggerElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface DialogTriggerProps extends PrimitiveButtonProps {}\n\nconst DialogTrigger = /* @__PURE__ */ React.forwardRef<DialogTriggerElement, DialogTriggerProps>(\n function DialogTrigger(props: ScopedProps<DialogTriggerProps>, forwardedRef) {\n const { __scopeDialog, ...triggerProps } = props;\n const context = useDialogContext(TRIGGER_NAME, __scopeDialog);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);\n return (\n <Primitive.button\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n aria-controls={context.open ? context.contentId : undefined}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'DialogPortal';\n\ntype PortalContextValue = { forceMount?: true };\nconst [PortalProvider, usePortalContext] = createDialogContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n});\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface DialogPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps['container'];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogPortal: React.FC<DialogPortalProps> = (props: ScopedProps<DialogPortalProps>) => {\n const { __scopeDialog, forceMount, children, container } = props;\n const context = useDialogContext(PORTAL_NAME, __scopeDialog);\n return (\n <PortalProvider scope={__scopeDialog} forceMount={forceMount}>\n {React.Children.map(children, (child) => (\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {child}\n </PortalPrimitive>\n </Presence>\n ))}\n </PortalProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'DialogOverlay';\n\ntype DialogOverlayElement = DialogOverlayImplElement;\ninterface DialogOverlayProps extends DialogOverlayImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogOverlay = /* @__PURE__ */ React.forwardRef<DialogOverlayElement, DialogOverlayProps>(\n function DialogOverlay(props: ScopedProps<DialogOverlayProps>, forwardedRef) {\n const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);\n return context.modal ? (\n <Presence present={forceMount || context.open}>\n <DialogOverlayImpl {...overlayProps} ref={forwardedRef} />\n </Presence>\n ) : null;\n },\n);\n\ntype DialogOverlayImplElement = React.ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DialogOverlayImplProps extends PrimitiveDivProps {}\n\nconst Slot = createSlot('DialogOverlay.RemoveScroll');\n\nconst DialogOverlayImpl = /* @__PURE__ */ React.forwardRef<\n DialogOverlayImplElement,\n DialogOverlayImplProps\n>(\n // blank line to reduce diff noise\n function DialogOverlayImpl(props: ScopedProps<DialogOverlayImplProps>, forwardedRef) {\n const { __scopeDialog, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, __scopeDialog);\n\n // Register the overlay as a dismiss surface so a consumer calling\n // `stopPropagation` on it (eg. to avoid triggering parent handlers) does not\n // prevent the dialog from closing. See: https://github.com/radix-ui/primitives/issues/3346\n const registerDismissableSurface = useDismissableLayerSurface();\n const composedRefs = useComposedRefs(forwardedRef, registerDismissableSurface);\n\n return (\n // Make sure `Content` is scrollable even when it doesn't live inside\n // `RemoveScroll` (eg. when `Overlay` and `Content` are siblings). Nested\n // layers are registered as branches and added as shards so they remain\n // scrollable too. See https://github.com/radix-ui/primitives/issues/3423\n <RemoveScroll\n as={Slot}\n allowPinchZoom\n shards={React.useMemo(\n () => [context.contentRef, ...context.branchNodes.map((node) => ({ current: node }))],\n [context.contentRef, context.branchNodes],\n )}\n >\n <Primitive.div\n data-state={getState(context.open)}\n {...overlayProps}\n ref={composedRefs}\n // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.\n style={{ pointerEvents: 'auto', ...overlayProps.style }}\n />\n </RemoveScroll>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'DialogContent';\n\ntype DialogContentElement = DialogContentTypeElement;\ninterface DialogContentProps extends DialogContentTypeProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogContent = /* @__PURE__ */ React.forwardRef<DialogContentElement, DialogContentProps>(\n function DialogContent(props: ScopedProps<DialogContentProps>, forwardedRef) {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...contentProps } = props;\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n return (\n <Presence present={forceMount || context.open}>\n {context.modal ? (\n <DialogContentModal {...contentProps} ref={forwardedRef} />\n ) : (\n <DialogContentNonModal {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentTypeElement = DialogContentImplElement;\ninterface DialogContentTypeProps extends Omit<\n DialogContentImplProps,\n 'trapFocus' | 'disableOutsidePointerEvents'\n> {}\n\nconst DialogContentModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const contentRef = React.useRef<HTMLDivElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n const content = contentRef.current;\n if (content) return hideOthers(content);\n }, []);\n\n return (\n <DialogContentImpl\n {...props}\n ref={composedRefs}\n // we make sure focus isn't trapped once `DialogContent` has been closed\n // (closed !== unmounted when animating out)\n trapFocus={context.open}\n disableOutsidePointerEvents={context.open}\n onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {\n event.preventDefault();\n context.triggerRef.current?.focus();\n })}\n onPointerDownOutside={composeEventHandlers(props.onPointerDownOutside, (event) => {\n const originalEvent = event.detail.originalEvent;\n const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick;\n\n // If the event is a right-click, we shouldn't close because\n // it is effectively as if we right-clicked the `Overlay`.\n if (isRightClick) event.preventDefault();\n })}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(props.onFocusOutside, (event) =>\n event.preventDefault(),\n )}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst DialogContentNonModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentNonModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const hasInteractedOutsideRef = React.useRef(false);\n const hasPointerDownOutsideRef = React.useRef(false);\n\n return (\n <DialogContentImpl\n {...props}\n ref={forwardedRef}\n trapFocus={false}\n disableOutsidePointerEvents={false}\n onCloseAutoFocus={(event) => {\n props.onCloseAutoFocus?.(event);\n\n if (!event.defaultPrevented) {\n if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();\n // Always prevent auto focus because we either focus manually or want user agent focus\n event.preventDefault();\n }\n\n hasInteractedOutsideRef.current = false;\n hasPointerDownOutsideRef.current = false;\n }}\n onInteractOutside={(event) => {\n props.onInteractOutside?.(event);\n\n if (!event.defaultPrevented) {\n hasInteractedOutsideRef.current = true;\n if (event.detail.originalEvent.type === 'pointerdown') {\n hasPointerDownOutsideRef.current = true;\n }\n }\n\n // Prevent dismissing when clicking the trigger.\n // As the trigger is already setup to close, without doing so would\n // cause it to close and immediately open.\n const target = event.target as HTMLElement;\n const targetIsTrigger = context.triggerRef.current?.contains(target);\n if (targetIsTrigger) event.preventDefault();\n\n // On Safari if the trigger is inside a container with tabIndex={0}, when clicked\n // we will get the pointer down outside event on the trigger, but then a subsequent\n // focus outside event on the container, we ignore any focus outside event when we've\n // already had a pointer down outside event.\n if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) {\n event.preventDefault();\n }\n }}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentImplElement = React.ComponentRef<typeof DismissableLayer>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer>;\ntype FocusScopeProps = React.ComponentPropsWithoutRef<typeof FocusScope>;\ninterface DialogContentImplProps extends Omit<DismissableLayerProps, 'onDismiss'> {\n /**\n * When `true`, focus cannot escape the `Content` via keyboard,\n * pointer, or a programmatic focus.\n * @defaultValue false\n */\n trapFocus?: FocusScopeProps['trapped'];\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus'];\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus'];\n}\n\nconst DialogContentImpl = /* @__PURE__ */ React.forwardRef<\n DialogContentImplElement,\n DialogContentImplProps\n>(\n // blank line to reduce diff noise\n function DialogContentImpl(props: ScopedProps<DialogContentImplProps>, forwardedRef) {\n const {\n __scopeDialog,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n 'aria-describedby': ariaDescribedby,\n ...contentProps\n } = props;\n const { children, ...layerProps } = contentProps;\n const context = useDialogContext(CONTENT_NAME, __scopeDialog);\n\n // Make sure the whole tree has focus guards as our `Dialog` will be\n // the last element in the DOM (because of the `Portal`)\n useFocusGuards();\n\n return (\n <>\n <FocusScope\n asChild\n loop\n trapped={trapFocus}\n branches={context.branchNodes}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n <DismissableLayer\n role=\"dialog\"\n id={context.contentId}\n aria-labelledby={context.titlePresent ? context.titleId : undefined}\n aria-describedby={\n context.descriptionPresent\n ? concatAriaDescribedby(ariaDescribedby, context.descriptionId)\n : ariaDescribedby\n }\n data-state={getState(context.open)}\n {...layerProps}\n ref={forwardedRef}\n deferPointerDownOutside\n onDismiss={() => context.onOpenChange(false)}\n >\n {/* Lets nested, portalled layers register themselves as branches of this Dialog. */}\n <FocusScopeBranchProvider value={context.branchRegistry}>\n {children}\n </FocusScopeBranchProvider>\n </DismissableLayer>\n </FocusScope>\n </>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogTitleElement = React.ComponentRef<typeof Primitive.h2>;\ntype PrimitiveHeading2Props = React.ComponentPropsWithoutRef<typeof Primitive.h2>;\ninterface DialogTitleProps extends PrimitiveHeading2Props {}\n\nconst DialogTitle = /* @__PURE__ */ React.forwardRef<DialogTitleElement, DialogTitleProps>(\n function DialogTitle(props: ScopedProps<DialogTitleProps>, forwardedRef) {\n const { __scopeDialog, ...titleProps } = props;\n const context = useDialogContext('DialogTitle', __scopeDialog);\n const { setTitleCount } = context;\n useLayoutEffect(() => {\n setTitleCount((count) => count + 1);\n return () => setTitleCount((count) => count - 1);\n }, [setTitleCount]);\n return <Primitive.h2 id={context.titleId} {...titleProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogDescriptionElement = React.ComponentRef<typeof Primitive.p>;\ntype PrimitiveParagraphProps = React.ComponentPropsWithoutRef<typeof Primitive.p>;\ninterface DialogDescriptionProps extends PrimitiveParagraphProps {}\n\nconst DialogDescription = /* @__PURE__ */ React.forwardRef<\n DialogDescriptionElement,\n DialogDescriptionProps\n>(\n // blank line to reduce diff noise\n function DialogDescription(props: ScopedProps<DialogDescriptionProps>, forwardedRef) {\n const { __scopeDialog, ...descriptionProps } = props;\n const context = useDialogContext('DialogDescription', __scopeDialog);\n const { setDescriptionCount } = context;\n useLayoutEffect(() => {\n setDescriptionCount((count) => count + 1);\n return () => setDescriptionCount((count) => count - 1);\n }, [setDescriptionCount]);\n return <Primitive.p id={context.descriptionId} {...descriptionProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'DialogClose';\n\ntype DialogCloseElement = React.ComponentRef<typeof Primitive.button>;\ninterface DialogCloseProps extends PrimitiveButtonProps {}\n\nconst DialogClose = /* @__PURE__ */ React.forwardRef<DialogCloseElement, DialogCloseProps>(\n function DialogClose(props: ScopedProps<DialogCloseProps>, forwardedRef) {\n const { __scopeDialog, ...closeProps } = props;\n const context = useDialogContext(CLOSE_NAME, __scopeDialog);\n return (\n <Primitive.button\n type=\"button\"\n {...closeProps}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () => context.onOpenChange(false))}\n />\n );\n },\n);\n\n/** @deprecated Noop component to avoid breaking changes. */\nexport const WarningProvider: React.FC<\n ScopedProps<{\n children?: React.ReactNode;\n contentName: string;\n titleName: string;\n docsSlug: 'dialog';\n }>\n> = (props) => {\n return props.children;\n};\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// TODO: Move to primitive once that package exposed individual sub-modules\nfunction concatAriaDescribedby(...values: unknown[]): string | undefined {\n const ids = new Set<string>();\n for (const value of values) {\n if (typeof value !== 'string') continue;\n for (const id of String(value).trim().split(/\\s+/)) {\n if (id) ids.add(id);\n }\n }\n\n return ids.size > 0 ? Array.from(ids).join(' ') : undefined;\n}\n\nfunction getState(open: boolean) {\n return open ? 'open' : 'closed';\n}\n\nexport {\n createDialogScope,\n //\n Dialog,\n DialogTrigger,\n DialogPortal,\n DialogOverlay,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n //\n Dialog as Root,\n DialogTrigger as Trigger,\n DialogPortal as Portal,\n DialogOverlay as Overlay,\n DialogContent as Content,\n DialogTitle as Title,\n DialogDescription as Description,\n DialogClose as Close,\n};\nexport type {\n DialogProps,\n DialogTriggerProps,\n DialogPortalProps,\n DialogOverlayProps,\n DialogContentProps,\n DialogTitleProps,\n DialogDescriptionProps,\n DialogCloseProps,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAAqC;AACrC,gCAAgC;AAChC,2BAAmC;AACnC,sBAAsB;AACtB,0CAAqC;AACrC,qCAA6D;AAC7D,+BAIO;AACP,0BAA0C;AAC1C,4BAAyB;AACzB,6BAA0B;AAC1B,gCAA+B;AAC/B,qCAAgC;AAChC,iCAA6B;AAC7B,yBAA2B;AAC3B,wBAA2B;AAoEvB;AA3DJ,IAAM,cAAc;AAGpB,IAAM,CAAC,q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AAExE,kBAAM,eAAe;AAAA,UACvB;AAEA,kCAAwB,UAAU;AAClC,mCAAyB,UAAU;AAAA,QACrC;AAAA,QACA,mBAAmB,CAAC,UAAU;AAC5B,gBAAM,oBAAoB,KAAK;AAE/B,cAAI,CAAC,MAAM,kBAAkB;AAC3B,oCAAwB,UAAU;AAClC,gBAAI,MAAM,OAAO,cAAc,SAAS,eAAe;AACrD,uCAAyB,UAAU;AAAA,YACrC;AAAA,UACF;AAKA,gBAAM,SAAS,MAAM;AACrB,gBAAM,kBAAkB,QAAQ,WAAW,SAAS,SAAS,MAAM;AACnE,cAAI,gBAAiB,OAAM,eAAe;AAM1C,cAAI,MAAM,OAAO,cAAc,SAAS,aAAa,yBAAyB,SAAS;AACrF,kBAAM,eAAe;AAAA,UACvB;AAAA,QACF;AAAA;AAAA,IACF;AAAA,EAEJ,GAlDA;AAmDF;AA4BA,IAAM,oBAAoC,gBAAM;AAAA;AAAA,EAK9C,gCAASC,mBAAkB,OAA4C,cAAc;AACnF,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,oBAAoB;AAAA,MACpB,GAAG;AAAA,IACL,IAAI;AACJ,UAAM,
|
|
4
|
+
"sourcesContent": ["'use client';\nexport {\n createDialogScope,\n //\n Dialog,\n DialogTrigger,\n DialogPortal,\n DialogOverlay,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n //\n Root,\n Trigger,\n Portal,\n Overlay,\n Content,\n Title,\n Description,\n Close,\n /** @deprecated Noop component to avoid breaking changes. */\n WarningProvider,\n} from './dialog';\nexport type {\n DialogProps,\n DialogTriggerProps,\n DialogPortalProps,\n DialogOverlayProps,\n DialogContentProps,\n DialogTitleProps,\n DialogDescriptionProps,\n DialogCloseProps,\n} from './dialog';\n", "import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useId } from '@radix-ui/react-id';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { DismissableLayer, useDismissableLayerSurface } from '@radix-ui/react-dismissable-layer';\nimport {\n FocusScope,\n FocusScopeBranchProvider,\n useFocusScopeBranchRegistry,\n} from '@radix-ui/react-focus-scope';\nimport { Portal as PortalPrimitive } from '@radix-ui/react-portal';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useFocusGuards } from '@radix-ui/react-focus-guards';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { RemoveScroll } from 'react-remove-scroll';\nimport { hideOthers } from 'aria-hidden';\nimport { createSlot } from '@radix-ui/react-slot';\n\nimport type { Scope } from '@radix-ui/react-context';\nimport type { FocusScopeBranchRegistry } from '@radix-ui/react-focus-scope';\n\n/* -------------------------------------------------------------------------------------------------\n * Dialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst DIALOG_NAME = 'Dialog';\n\ntype ScopedProps<P> = P & { __scopeDialog?: Scope };\nconst [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);\n\ntype DialogContextValue = {\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n contentRef: React.RefObject<DialogContentElement | null>;\n contentId: string;\n titleId: string;\n descriptionId: string;\n titlePresent: boolean;\n descriptionPresent: boolean;\n setTitleCount: React.Dispatch<React.SetStateAction<number>>;\n setDescriptionCount: React.Dispatch<React.SetStateAction<number>>;\n open: boolean;\n onOpenChange(open: boolean): void;\n onOpenToggle(): void;\n modal: boolean;\n // Nodes of nested, portalled layers (eg. a non-modal `Popover`) that should\n // be treated as part of this Dialog for focus trapping and scroll locking.\n // See https://github.com/radix-ui/primitives/issues/3423\n branchNodes: HTMLElement[];\n branchRegistry: FocusScopeBranchRegistry;\n};\n\nconst [DialogProvider, useDialogContext] = createDialogContext<DialogContextValue>(DIALOG_NAME);\n\ninterface DialogProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?(open: boolean): void;\n modal?: boolean;\n}\n\nconst Dialog: React.FC<DialogProps> = (props: ScopedProps<DialogProps>) => {\n const {\n __scopeDialog,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n modal = true,\n } = props;\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const contentRef = React.useRef<DialogContentElement>(null);\n const { nodes: branchNodes, registry: branchRegistry } = useFocusScopeBranchRegistry();\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? false,\n onChange: onOpenChange,\n caller: DIALOG_NAME,\n });\n\n const [titleCount, setTitleCount] = React.useState(0);\n const [descriptionCount, setDescriptionCount] = React.useState(0);\n\n return (\n <DialogProvider\n scope={__scopeDialog}\n triggerRef={triggerRef}\n contentRef={contentRef}\n contentId={useId()}\n titleId={useId()}\n descriptionId={useId()}\n titlePresent={titleCount > 0}\n descriptionPresent={descriptionCount > 0}\n setTitleCount={setTitleCount}\n setDescriptionCount={setDescriptionCount}\n open={open}\n onOpenChange={setOpen}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n modal={modal}\n branchNodes={branchNodes}\n branchRegistry={branchRegistry}\n >\n {children}\n </DialogProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'DialogTrigger';\n\ntype DialogTriggerElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface DialogTriggerProps extends PrimitiveButtonProps {}\n\nconst DialogTrigger = /* @__PURE__ */ React.forwardRef<DialogTriggerElement, DialogTriggerProps>(\n function DialogTrigger(props: ScopedProps<DialogTriggerProps>, forwardedRef) {\n const { __scopeDialog, ...triggerProps } = props;\n const context = useDialogContext(TRIGGER_NAME, __scopeDialog);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);\n return (\n <Primitive.button\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n aria-controls={context.open ? context.contentId : undefined}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'DialogPortal';\n\ntype PortalContextValue = { forceMount?: true };\nconst [PortalProvider, usePortalContext] = createDialogContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n});\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface DialogPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps['container'];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogPortal: React.FC<DialogPortalProps> = (props: ScopedProps<DialogPortalProps>) => {\n const { __scopeDialog, forceMount, children, container } = props;\n const context = useDialogContext(PORTAL_NAME, __scopeDialog);\n return (\n <PortalProvider scope={__scopeDialog} forceMount={forceMount}>\n {React.Children.map(children, (child) => (\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {child}\n </PortalPrimitive>\n </Presence>\n ))}\n </PortalProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'DialogOverlay';\n\ntype DialogOverlayElement = DialogOverlayImplElement;\ninterface DialogOverlayProps extends DialogOverlayImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogOverlay = /* @__PURE__ */ React.forwardRef<DialogOverlayElement, DialogOverlayProps>(\n function DialogOverlay(props: ScopedProps<DialogOverlayProps>, forwardedRef) {\n const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);\n return context.modal ? (\n <Presence present={forceMount || context.open}>\n <DialogOverlayImpl {...overlayProps} ref={forwardedRef} />\n </Presence>\n ) : null;\n },\n);\n\ntype DialogOverlayImplElement = React.ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DialogOverlayImplProps extends PrimitiveDivProps {}\n\nconst Slot = createSlot('DialogOverlay.RemoveScroll');\n\nconst DialogOverlayImpl = /* @__PURE__ */ React.forwardRef<\n DialogOverlayImplElement,\n DialogOverlayImplProps\n>(\n // blank line to reduce diff noise\n function DialogOverlayImpl(props: ScopedProps<DialogOverlayImplProps>, forwardedRef) {\n const { __scopeDialog, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, __scopeDialog);\n\n // Register the overlay as a dismiss surface so a consumer calling\n // `stopPropagation` on it (eg. to avoid triggering parent handlers) does not\n // prevent the dialog from closing. See: https://github.com/radix-ui/primitives/issues/3346\n const registerDismissableSurface = useDismissableLayerSurface();\n const composedRefs = useComposedRefs(forwardedRef, registerDismissableSurface);\n\n return (\n // Make sure `Content` is scrollable even when it doesn't live inside\n // `RemoveScroll` (eg. when `Overlay` and `Content` are siblings). Nested\n // layers are registered as branches and added as shards so they remain\n // scrollable too. See https://github.com/radix-ui/primitives/issues/3423\n <RemoveScroll\n as={Slot}\n allowPinchZoom\n shards={React.useMemo(\n () => [context.contentRef, ...context.branchNodes.map((node) => ({ current: node }))],\n [context.contentRef, context.branchNodes],\n )}\n >\n <Primitive.div\n data-state={getState(context.open)}\n {...overlayProps}\n ref={composedRefs}\n // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.\n style={{ pointerEvents: 'auto', ...overlayProps.style }}\n />\n </RemoveScroll>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'DialogContent';\n\ntype DialogContentElement = DialogContentTypeElement;\ninterface DialogContentProps extends DialogContentTypeProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogContent = /* @__PURE__ */ React.forwardRef<DialogContentElement, DialogContentProps>(\n function DialogContent(props: ScopedProps<DialogContentProps>, forwardedRef) {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...contentProps } = props;\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n return (\n <Presence present={forceMount || context.open}>\n {context.modal ? (\n <DialogContentModal {...contentProps} ref={forwardedRef} />\n ) : (\n <DialogContentNonModal {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentTypeElement = DialogContentImplElement;\ninterface DialogContentTypeProps extends Omit<\n DialogContentImplProps,\n 'trapFocus' | 'disableOutsidePointerEvents'\n> {}\n\nconst DialogContentModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const contentRef = React.useRef<HTMLDivElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n const content = contentRef.current;\n if (content) return hideOthers(content);\n }, []);\n\n return (\n <DialogContentImpl\n {...props}\n ref={composedRefs}\n // we make sure focus isn't trapped once `DialogContent` has been closed\n // (closed !== unmounted when animating out)\n trapFocus={context.open}\n disableOutsidePointerEvents={context.open}\n onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {\n event.preventDefault();\n context.triggerRef.current?.focus();\n })}\n onPointerDownOutside={composeEventHandlers(props.onPointerDownOutside, (event) => {\n const originalEvent = event.detail.originalEvent;\n const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick;\n\n // If the event is a right-click, we shouldn't close because\n // it is effectively as if we right-clicked the `Overlay`.\n if (isRightClick) event.preventDefault();\n })}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(props.onFocusOutside, (event) =>\n event.preventDefault(),\n )}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst DialogContentNonModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentNonModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const hasInteractedOutsideRef = React.useRef(false);\n const hasPointerDownOutsideRef = React.useRef(false);\n\n return (\n <DialogContentImpl\n {...props}\n ref={forwardedRef}\n trapFocus={false}\n disableOutsidePointerEvents={false}\n onCloseAutoFocus={(event) => {\n props.onCloseAutoFocus?.(event);\n\n if (!event.defaultPrevented) {\n if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();\n // Always prevent auto focus because we either focus manually or want user agent focus\n event.preventDefault();\n }\n\n hasInteractedOutsideRef.current = false;\n hasPointerDownOutsideRef.current = false;\n }}\n onInteractOutside={(event) => {\n props.onInteractOutside?.(event);\n\n if (!event.defaultPrevented) {\n hasInteractedOutsideRef.current = true;\n if (event.detail.originalEvent.type === 'pointerdown') {\n hasPointerDownOutsideRef.current = true;\n }\n }\n\n // Prevent dismissing when clicking the trigger.\n // As the trigger is already setup to close, without doing so would\n // cause it to close and immediately open.\n const target = event.target as HTMLElement;\n const targetIsTrigger = context.triggerRef.current?.contains(target);\n if (targetIsTrigger) event.preventDefault();\n\n // On Safari if the trigger is inside a container with tabIndex={0}, when clicked\n // we will get the pointer down outside event on the trigger, but then a subsequent\n // focus outside event on the container, we ignore any focus outside event when we've\n // already had a pointer down outside event.\n if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) {\n event.preventDefault();\n }\n }}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentImplElement = React.ComponentRef<typeof DismissableLayer>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer>;\ntype FocusScopeProps = React.ComponentPropsWithoutRef<typeof FocusScope>;\ninterface DialogContentImplProps extends Omit<DismissableLayerProps, 'onDismiss'> {\n /**\n * When `true`, focus cannot escape the `Content` via keyboard,\n * pointer, or a programmatic focus.\n * @defaultValue false\n */\n trapFocus?: FocusScopeProps['trapped'];\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus'];\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus'];\n}\n\nconst DialogContentImpl = /* @__PURE__ */ React.forwardRef<\n DialogContentImplElement,\n DialogContentImplProps\n>(\n // blank line to reduce diff noise\n function DialogContentImpl(props: ScopedProps<DialogContentImplProps>, forwardedRef) {\n const {\n __scopeDialog,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n 'aria-describedby': ariaDescribedby,\n children,\n ...contentProps\n } = props;\n const context = useDialogContext(CONTENT_NAME, __scopeDialog);\n\n // Make sure the whole tree has focus guards as our `Dialog` will be\n // the last element in the DOM (because of the `Portal`)\n useFocusGuards();\n\n return (\n <FocusScopeBranchProvider registry={context.branchRegistry}>\n <FocusScope\n asChild\n loop\n trapped={trapFocus}\n branches={context.branchNodes}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n <DismissableLayer\n role=\"dialog\"\n id={context.contentId}\n aria-labelledby={context.titlePresent ? context.titleId : undefined}\n aria-describedby={\n context.descriptionPresent\n ? concatAriaDescribedby(ariaDescribedby, context.descriptionId)\n : ariaDescribedby\n }\n data-state={getState(context.open)}\n {...contentProps}\n ref={forwardedRef}\n deferPointerDownOutside\n onDismiss={() => context.onOpenChange(false)}\n >\n {children}\n </DismissableLayer>\n </FocusScope>\n </FocusScopeBranchProvider>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogTitleElement = React.ComponentRef<typeof Primitive.h2>;\ntype PrimitiveHeading2Props = React.ComponentPropsWithoutRef<typeof Primitive.h2>;\ninterface DialogTitleProps extends PrimitiveHeading2Props {}\n\nconst DialogTitle = /* @__PURE__ */ React.forwardRef<DialogTitleElement, DialogTitleProps>(\n function DialogTitle(props: ScopedProps<DialogTitleProps>, forwardedRef) {\n const { __scopeDialog, ...titleProps } = props;\n const context = useDialogContext('DialogTitle', __scopeDialog);\n const { setTitleCount } = context;\n useLayoutEffect(() => {\n setTitleCount((count) => count + 1);\n return () => setTitleCount((count) => count - 1);\n }, [setTitleCount]);\n return <Primitive.h2 id={context.titleId} {...titleProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogDescriptionElement = React.ComponentRef<typeof Primitive.p>;\ntype PrimitiveParagraphProps = React.ComponentPropsWithoutRef<typeof Primitive.p>;\ninterface DialogDescriptionProps extends PrimitiveParagraphProps {}\n\nconst DialogDescription = /* @__PURE__ */ React.forwardRef<\n DialogDescriptionElement,\n DialogDescriptionProps\n>(\n // blank line to reduce diff noise\n function DialogDescription(props: ScopedProps<DialogDescriptionProps>, forwardedRef) {\n const { __scopeDialog, ...descriptionProps } = props;\n const context = useDialogContext('DialogDescription', __scopeDialog);\n const { setDescriptionCount } = context;\n useLayoutEffect(() => {\n setDescriptionCount((count) => count + 1);\n return () => setDescriptionCount((count) => count - 1);\n }, [setDescriptionCount]);\n return <Primitive.p id={context.descriptionId} {...descriptionProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'DialogClose';\n\ntype DialogCloseElement = React.ComponentRef<typeof Primitive.button>;\ninterface DialogCloseProps extends PrimitiveButtonProps {}\n\nconst DialogClose = /* @__PURE__ */ React.forwardRef<DialogCloseElement, DialogCloseProps>(\n function DialogClose(props: ScopedProps<DialogCloseProps>, forwardedRef) {\n const { __scopeDialog, ...closeProps } = props;\n const context = useDialogContext(CLOSE_NAME, __scopeDialog);\n return (\n <Primitive.button\n type=\"button\"\n {...closeProps}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () => context.onOpenChange(false))}\n />\n );\n },\n);\n\n/** @deprecated Noop component to avoid breaking changes. */\nexport const WarningProvider: React.FC<\n ScopedProps<{\n children?: React.ReactNode;\n contentName: string;\n titleName: string;\n docsSlug: 'dialog';\n }>\n> = (props) => {\n return props.children;\n};\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// TODO: Move to primitive once that package exposed individual sub-modules\nfunction concatAriaDescribedby(...values: unknown[]): string | undefined {\n const ids = new Set<string>();\n for (const value of values) {\n if (typeof value !== 'string') continue;\n for (const id of String(value).trim().split(/\\s+/)) {\n if (id) ids.add(id);\n }\n }\n\n return ids.size > 0 ? Array.from(ids).join(' ') : undefined;\n}\n\nfunction getState(open: boolean) {\n return open ? 'open' : 'closed';\n}\n\nexport {\n createDialogScope,\n //\n Dialog,\n DialogTrigger,\n DialogPortal,\n DialogOverlay,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n //\n Dialog as Root,\n DialogTrigger as Trigger,\n DialogPortal as Portal,\n DialogOverlay as Overlay,\n DialogContent as Content,\n DialogTitle as Title,\n DialogDescription as Description,\n DialogClose as Close,\n};\nexport type {\n DialogProps,\n DialogTriggerProps,\n DialogPortalProps,\n DialogO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ayImpl", "DialogContent", "DialogContentModal", "DialogContentNonModal", "DialogContentImpl", "DialogTitle", "DialogDescription", "DialogClose"]
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
|
|
|
23
23
|
import { RemoveScroll } from "react-remove-scroll";
|
|
24
24
|
import { hideOthers } from "aria-hidden";
|
|
25
25
|
import { createSlot } from "@radix-ui/react-slot";
|
|
26
|
-
import {
|
|
26
|
+
import { jsx } from "react/jsx-runtime";
|
|
27
27
|
var DIALOG_NAME = "Dialog";
|
|
28
28
|
var [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);
|
|
29
29
|
var [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
|
|
@@ -239,12 +239,12 @@ var DialogContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
239
239
|
onOpenAutoFocus,
|
|
240
240
|
onCloseAutoFocus,
|
|
241
241
|
"aria-describedby": ariaDescribedby,
|
|
242
|
+
children,
|
|
242
243
|
...contentProps
|
|
243
244
|
} = props;
|
|
244
|
-
const { children, ...layerProps } = contentProps;
|
|
245
245
|
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
246
246
|
useFocusGuards();
|
|
247
|
-
return /* @__PURE__ */ jsx(
|
|
247
|
+
return /* @__PURE__ */ jsx(FocusScopeBranchProvider, { registry: context.branchRegistry, children: /* @__PURE__ */ jsx(
|
|
248
248
|
FocusScope,
|
|
249
249
|
{
|
|
250
250
|
asChild: true,
|
|
@@ -261,11 +261,11 @@ var DialogContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
261
261
|
"aria-labelledby": context.titlePresent ? context.titleId : void 0,
|
|
262
262
|
"aria-describedby": context.descriptionPresent ? concatAriaDescribedby(ariaDescribedby, context.descriptionId) : ariaDescribedby,
|
|
263
263
|
"data-state": getState(context.open),
|
|
264
|
-
...
|
|
264
|
+
...contentProps,
|
|
265
265
|
ref: forwardedRef,
|
|
266
266
|
deferPointerDownOutside: true,
|
|
267
267
|
onDismiss: () => context.onOpenChange(false),
|
|
268
|
-
children
|
|
268
|
+
children
|
|
269
269
|
}
|
|
270
270
|
)
|
|
271
271
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dialog.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useId } from '@radix-ui/react-id';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { DismissableLayer, useDismissableLayerSurface } from '@radix-ui/react-dismissable-layer';\nimport {\n FocusScope,\n FocusScopeBranchProvider,\n useFocusScopeBranchRegistry,\n} from '@radix-ui/react-focus-scope';\nimport { Portal as PortalPrimitive } from '@radix-ui/react-portal';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useFocusGuards } from '@radix-ui/react-focus-guards';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { RemoveScroll } from 'react-remove-scroll';\nimport { hideOthers } from 'aria-hidden';\nimport { createSlot } from '@radix-ui/react-slot';\n\nimport type { Scope } from '@radix-ui/react-context';\nimport type { FocusScopeBranchRegistry } from '@radix-ui/react-focus-scope';\n\n/* -------------------------------------------------------------------------------------------------\n * Dialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst DIALOG_NAME = 'Dialog';\n\ntype ScopedProps<P> = P & { __scopeDialog?: Scope };\nconst [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);\n\ntype DialogContextValue = {\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n contentRef: React.RefObject<DialogContentElement | null>;\n contentId: string;\n titleId: string;\n descriptionId: string;\n titlePresent: boolean;\n descriptionPresent: boolean;\n setTitleCount: React.Dispatch<React.SetStateAction<number>>;\n setDescriptionCount: React.Dispatch<React.SetStateAction<number>>;\n open: boolean;\n onOpenChange(open: boolean): void;\n onOpenToggle(): void;\n modal: boolean;\n // Nodes of nested, portalled layers (eg. a non-modal `Popover`) that should\n // be treated as part of this Dialog for focus trapping and scroll locking.\n // See https://github.com/radix-ui/primitives/issues/3423\n branchNodes: HTMLElement[];\n branchRegistry: FocusScopeBranchRegistry;\n};\n\nconst [DialogProvider, useDialogContext] = createDialogContext<DialogContextValue>(DIALOG_NAME);\n\ninterface DialogProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?(open: boolean): void;\n modal?: boolean;\n}\n\nconst Dialog: React.FC<DialogProps> = (props: ScopedProps<DialogProps>) => {\n const {\n __scopeDialog,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n modal = true,\n } = props;\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const contentRef = React.useRef<DialogContentElement>(null);\n const { nodes: branchNodes, registry: branchRegistry } = useFocusScopeBranchRegistry();\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? false,\n onChange: onOpenChange,\n caller: DIALOG_NAME,\n });\n\n const [titleCount, setTitleCount] = React.useState(0);\n const [descriptionCount, setDescriptionCount] = React.useState(0);\n\n return (\n <DialogProvider\n scope={__scopeDialog}\n triggerRef={triggerRef}\n contentRef={contentRef}\n contentId={useId()}\n titleId={useId()}\n descriptionId={useId()}\n titlePresent={titleCount > 0}\n descriptionPresent={descriptionCount > 0}\n setTitleCount={setTitleCount}\n setDescriptionCount={setDescriptionCount}\n open={open}\n onOpenChange={setOpen}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n modal={modal}\n branchNodes={branchNodes}\n branchRegistry={branchRegistry}\n >\n {children}\n </DialogProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'DialogTrigger';\n\ntype DialogTriggerElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface DialogTriggerProps extends PrimitiveButtonProps {}\n\nconst DialogTrigger = /* @__PURE__ */ React.forwardRef<DialogTriggerElement, DialogTriggerProps>(\n function DialogTrigger(props: ScopedProps<DialogTriggerProps>, forwardedRef) {\n const { __scopeDialog, ...triggerProps } = props;\n const context = useDialogContext(TRIGGER_NAME, __scopeDialog);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);\n return (\n <Primitive.button\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n aria-controls={context.open ? context.contentId : undefined}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'DialogPortal';\n\ntype PortalContextValue = { forceMount?: true };\nconst [PortalProvider, usePortalContext] = createDialogContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n});\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface DialogPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps['container'];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogPortal: React.FC<DialogPortalProps> = (props: ScopedProps<DialogPortalProps>) => {\n const { __scopeDialog, forceMount, children, container } = props;\n const context = useDialogContext(PORTAL_NAME, __scopeDialog);\n return (\n <PortalProvider scope={__scopeDialog} forceMount={forceMount}>\n {React.Children.map(children, (child) => (\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {child}\n </PortalPrimitive>\n </Presence>\n ))}\n </PortalProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'DialogOverlay';\n\ntype DialogOverlayElement = DialogOverlayImplElement;\ninterface DialogOverlayProps extends DialogOverlayImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogOverlay = /* @__PURE__ */ React.forwardRef<DialogOverlayElement, DialogOverlayProps>(\n function DialogOverlay(props: ScopedProps<DialogOverlayProps>, forwardedRef) {\n const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);\n return context.modal ? (\n <Presence present={forceMount || context.open}>\n <DialogOverlayImpl {...overlayProps} ref={forwardedRef} />\n </Presence>\n ) : null;\n },\n);\n\ntype DialogOverlayImplElement = React.ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DialogOverlayImplProps extends PrimitiveDivProps {}\n\nconst Slot = createSlot('DialogOverlay.RemoveScroll');\n\nconst DialogOverlayImpl = /* @__PURE__ */ React.forwardRef<\n DialogOverlayImplElement,\n DialogOverlayImplProps\n>(\n // blank line to reduce diff noise\n function DialogOverlayImpl(props: ScopedProps<DialogOverlayImplProps>, forwardedRef) {\n const { __scopeDialog, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, __scopeDialog);\n\n // Register the overlay as a dismiss surface so a consumer calling\n // `stopPropagation` on it (eg. to avoid triggering parent handlers) does not\n // prevent the dialog from closing. See: https://github.com/radix-ui/primitives/issues/3346\n const registerDismissableSurface = useDismissableLayerSurface();\n const composedRefs = useComposedRefs(forwardedRef, registerDismissableSurface);\n\n return (\n // Make sure `Content` is scrollable even when it doesn't live inside\n // `RemoveScroll` (eg. when `Overlay` and `Content` are siblings). Nested\n // layers are registered as branches and added as shards so they remain\n // scrollable too. See https://github.com/radix-ui/primitives/issues/3423\n <RemoveScroll\n as={Slot}\n allowPinchZoom\n shards={React.useMemo(\n () => [context.contentRef, ...context.branchNodes.map((node) => ({ current: node }))],\n [context.contentRef, context.branchNodes],\n )}\n >\n <Primitive.div\n data-state={getState(context.open)}\n {...overlayProps}\n ref={composedRefs}\n // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.\n style={{ pointerEvents: 'auto', ...overlayProps.style }}\n />\n </RemoveScroll>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'DialogContent';\n\ntype DialogContentElement = DialogContentTypeElement;\ninterface DialogContentProps extends DialogContentTypeProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogContent = /* @__PURE__ */ React.forwardRef<DialogContentElement, DialogContentProps>(\n function DialogContent(props: ScopedProps<DialogContentProps>, forwardedRef) {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...contentProps } = props;\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n return (\n <Presence present={forceMount || context.open}>\n {context.modal ? (\n <DialogContentModal {...contentProps} ref={forwardedRef} />\n ) : (\n <DialogContentNonModal {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentTypeElement = DialogContentImplElement;\ninterface DialogContentTypeProps extends Omit<\n DialogContentImplProps,\n 'trapFocus' | 'disableOutsidePointerEvents'\n> {}\n\nconst DialogContentModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const contentRef = React.useRef<HTMLDivElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n const content = contentRef.current;\n if (content) return hideOthers(content);\n }, []);\n\n return (\n <DialogContentImpl\n {...props}\n ref={composedRefs}\n // we make sure focus isn't trapped once `DialogContent` has been closed\n // (closed !== unmounted when animating out)\n trapFocus={context.open}\n disableOutsidePointerEvents={context.open}\n onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {\n event.preventDefault();\n context.triggerRef.current?.focus();\n })}\n onPointerDownOutside={composeEventHandlers(props.onPointerDownOutside, (event) => {\n const originalEvent = event.detail.originalEvent;\n const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick;\n\n // If the event is a right-click, we shouldn't close because\n // it is effectively as if we right-clicked the `Overlay`.\n if (isRightClick) event.preventDefault();\n })}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(props.onFocusOutside, (event) =>\n event.preventDefault(),\n )}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst DialogContentNonModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentNonModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const hasInteractedOutsideRef = React.useRef(false);\n const hasPointerDownOutsideRef = React.useRef(false);\n\n return (\n <DialogContentImpl\n {...props}\n ref={forwardedRef}\n trapFocus={false}\n disableOutsidePointerEvents={false}\n onCloseAutoFocus={(event) => {\n props.onCloseAutoFocus?.(event);\n\n if (!event.defaultPrevented) {\n if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();\n // Always prevent auto focus because we either focus manually or want user agent focus\n event.preventDefault();\n }\n\n hasInteractedOutsideRef.current = false;\n hasPointerDownOutsideRef.current = false;\n }}\n onInteractOutside={(event) => {\n props.onInteractOutside?.(event);\n\n if (!event.defaultPrevented) {\n hasInteractedOutsideRef.current = true;\n if (event.detail.originalEvent.type === 'pointerdown') {\n hasPointerDownOutsideRef.current = true;\n }\n }\n\n // Prevent dismissing when clicking the trigger.\n // As the trigger is already setup to close, without doing so would\n // cause it to close and immediately open.\n const target = event.target as HTMLElement;\n const targetIsTrigger = context.triggerRef.current?.contains(target);\n if (targetIsTrigger) event.preventDefault();\n\n // On Safari if the trigger is inside a container with tabIndex={0}, when clicked\n // we will get the pointer down outside event on the trigger, but then a subsequent\n // focus outside event on the container, we ignore any focus outside event when we've\n // already had a pointer down outside event.\n if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) {\n event.preventDefault();\n }\n }}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentImplElement = React.ComponentRef<typeof DismissableLayer>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer>;\ntype FocusScopeProps = React.ComponentPropsWithoutRef<typeof FocusScope>;\ninterface DialogContentImplProps extends Omit<DismissableLayerProps, 'onDismiss'> {\n /**\n * When `true`, focus cannot escape the `Content` via keyboard,\n * pointer, or a programmatic focus.\n * @defaultValue false\n */\n trapFocus?: FocusScopeProps['trapped'];\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus'];\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus'];\n}\n\nconst DialogContentImpl = /* @__PURE__ */ React.forwardRef<\n DialogContentImplElement,\n DialogContentImplProps\n>(\n // blank line to reduce diff noise\n function DialogContentImpl(props: ScopedProps<DialogContentImplProps>, forwardedRef) {\n const {\n __scopeDialog,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n 'aria-describedby': ariaDescribedby,\n ...contentProps\n } = props;\n const { children, ...layerProps } = contentProps;\n const context = useDialogContext(CONTENT_NAME, __scopeDialog);\n\n // Make sure the whole tree has focus guards as our `Dialog` will be\n // the last element in the DOM (because of the `Portal`)\n useFocusGuards();\n\n return (\n <>\n <FocusScope\n asChild\n loop\n trapped={trapFocus}\n branches={context.branchNodes}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n <DismissableLayer\n role=\"dialog\"\n id={context.contentId}\n aria-labelledby={context.titlePresent ? context.titleId : undefined}\n aria-describedby={\n context.descriptionPresent\n ? concatAriaDescribedby(ariaDescribedby, context.descriptionId)\n : ariaDescribedby\n }\n data-state={getState(context.open)}\n {...layerProps}\n ref={forwardedRef}\n deferPointerDownOutside\n onDismiss={() => context.onOpenChange(false)}\n >\n {/* Lets nested, portalled layers register themselves as branches of this Dialog. */}\n <FocusScopeBranchProvider value={context.branchRegistry}>\n {children}\n </FocusScopeBranchProvider>\n </DismissableLayer>\n </FocusScope>\n </>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogTitleElement = React.ComponentRef<typeof Primitive.h2>;\ntype PrimitiveHeading2Props = React.ComponentPropsWithoutRef<typeof Primitive.h2>;\ninterface DialogTitleProps extends PrimitiveHeading2Props {}\n\nconst DialogTitle = /* @__PURE__ */ React.forwardRef<DialogTitleElement, DialogTitleProps>(\n function DialogTitle(props: ScopedProps<DialogTitleProps>, forwardedRef) {\n const { __scopeDialog, ...titleProps } = props;\n const context = useDialogContext('DialogTitle', __scopeDialog);\n const { setTitleCount } = context;\n useLayoutEffect(() => {\n setTitleCount((count) => count + 1);\n return () => setTitleCount((count) => count - 1);\n }, [setTitleCount]);\n return <Primitive.h2 id={context.titleId} {...titleProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogDescriptionElement = React.ComponentRef<typeof Primitive.p>;\ntype PrimitiveParagraphProps = React.ComponentPropsWithoutRef<typeof Primitive.p>;\ninterface DialogDescriptionProps extends PrimitiveParagraphProps {}\n\nconst DialogDescription = /* @__PURE__ */ React.forwardRef<\n DialogDescriptionElement,\n DialogDescriptionProps\n>(\n // blank line to reduce diff noise\n function DialogDescription(props: ScopedProps<DialogDescriptionProps>, forwardedRef) {\n const { __scopeDialog, ...descriptionProps } = props;\n const context = useDialogContext('DialogDescription', __scopeDialog);\n const { setDescriptionCount } = context;\n useLayoutEffect(() => {\n setDescriptionCount((count) => count + 1);\n return () => setDescriptionCount((count) => count - 1);\n }, [setDescriptionCount]);\n return <Primitive.p id={context.descriptionId} {...descriptionProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'DialogClose';\n\ntype DialogCloseElement = React.ComponentRef<typeof Primitive.button>;\ninterface DialogCloseProps extends PrimitiveButtonProps {}\n\nconst DialogClose = /* @__PURE__ */ React.forwardRef<DialogCloseElement, DialogCloseProps>(\n function DialogClose(props: ScopedProps<DialogCloseProps>, forwardedRef) {\n const { __scopeDialog, ...closeProps } = props;\n const context = useDialogContext(CLOSE_NAME, __scopeDialog);\n return (\n <Primitive.button\n type=\"button\"\n {...closeProps}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () => context.onOpenChange(false))}\n />\n );\n },\n);\n\n/** @deprecated Noop component to avoid breaking changes. */\nexport const WarningProvider: React.FC<\n ScopedProps<{\n children?: React.ReactNode;\n contentName: string;\n titleName: string;\n docsSlug: 'dialog';\n }>\n> = (props) => {\n return props.children;\n};\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// TODO: Move to primitive once that package exposed individual sub-modules\nfunction concatAriaDescribedby(...values: unknown[]): string | undefined {\n const ids = new Set<string>();\n for (const value of values) {\n if (typeof value !== 'string') continue;\n for (const id of String(value).trim().split(/\\s+/)) {\n if (id) ids.add(id);\n }\n }\n\n return ids.size > 0 ? Array.from(ids).join(' ') : undefined;\n}\n\nfunction getState(open: boolean) {\n return open ? 'open' : 'closed';\n}\n\nexport {\n createDialogScope,\n //\n Dialog,\n DialogTrigger,\n DialogPortal,\n DialogOverlay,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n //\n Dialog as Root,\n DialogTrigger as Trigger,\n DialogPortal as Portal,\n DialogOverlay as Overlay,\n DialogContent as Content,\n DialogTitle as Title,\n DialogDescription as Description,\n DialogClose as Close,\n};\nexport type {\n DialogProps,\n DialogTriggerProps,\n DialogPortalProps,\n DialogOverlayProps,\n DialogContentProps,\n DialogTitleProps,\n DialogDescriptionProps,\n DialogCloseProps,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,kBAAkB,kCAAkC;AAC7D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,uBAAuB;AAC1C,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAoEvB
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useId } from '@radix-ui/react-id';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { DismissableLayer, useDismissableLayerSurface } from '@radix-ui/react-dismissable-layer';\nimport {\n FocusScope,\n FocusScopeBranchProvider,\n useFocusScopeBranchRegistry,\n} from '@radix-ui/react-focus-scope';\nimport { Portal as PortalPrimitive } from '@radix-ui/react-portal';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useFocusGuards } from '@radix-ui/react-focus-guards';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { RemoveScroll } from 'react-remove-scroll';\nimport { hideOthers } from 'aria-hidden';\nimport { createSlot } from '@radix-ui/react-slot';\n\nimport type { Scope } from '@radix-ui/react-context';\nimport type { FocusScopeBranchRegistry } from '@radix-ui/react-focus-scope';\n\n/* -------------------------------------------------------------------------------------------------\n * Dialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst DIALOG_NAME = 'Dialog';\n\ntype ScopedProps<P> = P & { __scopeDialog?: Scope };\nconst [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);\n\ntype DialogContextValue = {\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n contentRef: React.RefObject<DialogContentElement | null>;\n contentId: string;\n titleId: string;\n descriptionId: string;\n titlePresent: boolean;\n descriptionPresent: boolean;\n setTitleCount: React.Dispatch<React.SetStateAction<number>>;\n setDescriptionCount: React.Dispatch<React.SetStateAction<number>>;\n open: boolean;\n onOpenChange(open: boolean): void;\n onOpenToggle(): void;\n modal: boolean;\n // Nodes of nested, portalled layers (eg. a non-modal `Popover`) that should\n // be treated as part of this Dialog for focus trapping and scroll locking.\n // See https://github.com/radix-ui/primitives/issues/3423\n branchNodes: HTMLElement[];\n branchRegistry: FocusScopeBranchRegistry;\n};\n\nconst [DialogProvider, useDialogContext] = createDialogContext<DialogContextValue>(DIALOG_NAME);\n\ninterface DialogProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?(open: boolean): void;\n modal?: boolean;\n}\n\nconst Dialog: React.FC<DialogProps> = (props: ScopedProps<DialogProps>) => {\n const {\n __scopeDialog,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n modal = true,\n } = props;\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const contentRef = React.useRef<DialogContentElement>(null);\n const { nodes: branchNodes, registry: branchRegistry } = useFocusScopeBranchRegistry();\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? false,\n onChange: onOpenChange,\n caller: DIALOG_NAME,\n });\n\n const [titleCount, setTitleCount] = React.useState(0);\n const [descriptionCount, setDescriptionCount] = React.useState(0);\n\n return (\n <DialogProvider\n scope={__scopeDialog}\n triggerRef={triggerRef}\n contentRef={contentRef}\n contentId={useId()}\n titleId={useId()}\n descriptionId={useId()}\n titlePresent={titleCount > 0}\n descriptionPresent={descriptionCount > 0}\n setTitleCount={setTitleCount}\n setDescriptionCount={setDescriptionCount}\n open={open}\n onOpenChange={setOpen}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n modal={modal}\n branchNodes={branchNodes}\n branchRegistry={branchRegistry}\n >\n {children}\n </DialogProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'DialogTrigger';\n\ntype DialogTriggerElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface DialogTriggerProps extends PrimitiveButtonProps {}\n\nconst DialogTrigger = /* @__PURE__ */ React.forwardRef<DialogTriggerElement, DialogTriggerProps>(\n function DialogTrigger(props: ScopedProps<DialogTriggerProps>, forwardedRef) {\n const { __scopeDialog, ...triggerProps } = props;\n const context = useDialogContext(TRIGGER_NAME, __scopeDialog);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);\n return (\n <Primitive.button\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n aria-controls={context.open ? context.contentId : undefined}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'DialogPortal';\n\ntype PortalContextValue = { forceMount?: true };\nconst [PortalProvider, usePortalContext] = createDialogContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n});\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface DialogPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps['container'];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogPortal: React.FC<DialogPortalProps> = (props: ScopedProps<DialogPortalProps>) => {\n const { __scopeDialog, forceMount, children, container } = props;\n const context = useDialogContext(PORTAL_NAME, __scopeDialog);\n return (\n <PortalProvider scope={__scopeDialog} forceMount={forceMount}>\n {React.Children.map(children, (child) => (\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {child}\n </PortalPrimitive>\n </Presence>\n ))}\n </PortalProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * DialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'DialogOverlay';\n\ntype DialogOverlayElement = DialogOverlayImplElement;\ninterface DialogOverlayProps extends DialogOverlayImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogOverlay = /* @__PURE__ */ React.forwardRef<DialogOverlayElement, DialogOverlayProps>(\n function DialogOverlay(props: ScopedProps<DialogOverlayProps>, forwardedRef) {\n const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);\n return context.modal ? (\n <Presence present={forceMount || context.open}>\n <DialogOverlayImpl {...overlayProps} ref={forwardedRef} />\n </Presence>\n ) : null;\n },\n);\n\ntype DialogOverlayImplElement = React.ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DialogOverlayImplProps extends PrimitiveDivProps {}\n\nconst Slot = createSlot('DialogOverlay.RemoveScroll');\n\nconst DialogOverlayImpl = /* @__PURE__ */ React.forwardRef<\n DialogOverlayImplElement,\n DialogOverlayImplProps\n>(\n // blank line to reduce diff noise\n function DialogOverlayImpl(props: ScopedProps<DialogOverlayImplProps>, forwardedRef) {\n const { __scopeDialog, ...overlayProps } = props;\n const context = useDialogContext(OVERLAY_NAME, __scopeDialog);\n\n // Register the overlay as a dismiss surface so a consumer calling\n // `stopPropagation` on it (eg. to avoid triggering parent handlers) does not\n // prevent the dialog from closing. See: https://github.com/radix-ui/primitives/issues/3346\n const registerDismissableSurface = useDismissableLayerSurface();\n const composedRefs = useComposedRefs(forwardedRef, registerDismissableSurface);\n\n return (\n // Make sure `Content` is scrollable even when it doesn't live inside\n // `RemoveScroll` (eg. when `Overlay` and `Content` are siblings). Nested\n // layers are registered as branches and added as shards so they remain\n // scrollable too. See https://github.com/radix-ui/primitives/issues/3423\n <RemoveScroll\n as={Slot}\n allowPinchZoom\n shards={React.useMemo(\n () => [context.contentRef, ...context.branchNodes.map((node) => ({ current: node }))],\n [context.contentRef, context.branchNodes],\n )}\n >\n <Primitive.div\n data-state={getState(context.open)}\n {...overlayProps}\n ref={composedRefs}\n // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.\n style={{ pointerEvents: 'auto', ...overlayProps.style }}\n />\n </RemoveScroll>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'DialogContent';\n\ntype DialogContentElement = DialogContentTypeElement;\ninterface DialogContentProps extends DialogContentTypeProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst DialogContent = /* @__PURE__ */ React.forwardRef<DialogContentElement, DialogContentProps>(\n function DialogContent(props: ScopedProps<DialogContentProps>, forwardedRef) {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);\n const { forceMount = portalContext.forceMount, ...contentProps } = props;\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n return (\n <Presence present={forceMount || context.open}>\n {context.modal ? (\n <DialogContentModal {...contentProps} ref={forwardedRef} />\n ) : (\n <DialogContentNonModal {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentTypeElement = DialogContentImplElement;\ninterface DialogContentTypeProps extends Omit<\n DialogContentImplProps,\n 'trapFocus' | 'disableOutsidePointerEvents'\n> {}\n\nconst DialogContentModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const contentRef = React.useRef<HTMLDivElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n const content = contentRef.current;\n if (content) return hideOthers(content);\n }, []);\n\n return (\n <DialogContentImpl\n {...props}\n ref={composedRefs}\n // we make sure focus isn't trapped once `DialogContent` has been closed\n // (closed !== unmounted when animating out)\n trapFocus={context.open}\n disableOutsidePointerEvents={context.open}\n onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {\n event.preventDefault();\n context.triggerRef.current?.focus();\n })}\n onPointerDownOutside={composeEventHandlers(props.onPointerDownOutside, (event) => {\n const originalEvent = event.detail.originalEvent;\n const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick;\n\n // If the event is a right-click, we shouldn't close because\n // it is effectively as if we right-clicked the `Overlay`.\n if (isRightClick) event.preventDefault();\n })}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(props.onFocusOutside, (event) =>\n event.preventDefault(),\n )}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst DialogContentNonModal = /* @__PURE__ */ React.forwardRef<\n DialogContentTypeElement,\n DialogContentTypeProps\n>(\n // blank line to reduce diff noise\n function DialogContentNonModal(props: ScopedProps<DialogContentTypeProps>, forwardedRef) {\n const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);\n const hasInteractedOutsideRef = React.useRef(false);\n const hasPointerDownOutsideRef = React.useRef(false);\n\n return (\n <DialogContentImpl\n {...props}\n ref={forwardedRef}\n trapFocus={false}\n disableOutsidePointerEvents={false}\n onCloseAutoFocus={(event) => {\n props.onCloseAutoFocus?.(event);\n\n if (!event.defaultPrevented) {\n if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();\n // Always prevent auto focus because we either focus manually or want user agent focus\n event.preventDefault();\n }\n\n hasInteractedOutsideRef.current = false;\n hasPointerDownOutsideRef.current = false;\n }}\n onInteractOutside={(event) => {\n props.onInteractOutside?.(event);\n\n if (!event.defaultPrevented) {\n hasInteractedOutsideRef.current = true;\n if (event.detail.originalEvent.type === 'pointerdown') {\n hasPointerDownOutsideRef.current = true;\n }\n }\n\n // Prevent dismissing when clicking the trigger.\n // As the trigger is already setup to close, without doing so would\n // cause it to close and immediately open.\n const target = event.target as HTMLElement;\n const targetIsTrigger = context.triggerRef.current?.contains(target);\n if (targetIsTrigger) event.preventDefault();\n\n // On Safari if the trigger is inside a container with tabIndex={0}, when clicked\n // we will get the pointer down outside event on the trigger, but then a subsequent\n // focus outside event on the container, we ignore any focus outside event when we've\n // already had a pointer down outside event.\n if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) {\n event.preventDefault();\n }\n }}\n />\n );\n },\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype DialogContentImplElement = React.ComponentRef<typeof DismissableLayer>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer>;\ntype FocusScopeProps = React.ComponentPropsWithoutRef<typeof FocusScope>;\ninterface DialogContentImplProps extends Omit<DismissableLayerProps, 'onDismiss'> {\n /**\n * When `true`, focus cannot escape the `Content` via keyboard,\n * pointer, or a programmatic focus.\n * @defaultValue false\n */\n trapFocus?: FocusScopeProps['trapped'];\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus'];\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus'];\n}\n\nconst DialogContentImpl = /* @__PURE__ */ React.forwardRef<\n DialogContentImplElement,\n DialogContentImplProps\n>(\n // blank line to reduce diff noise\n function DialogContentImpl(props: ScopedProps<DialogContentImplProps>, forwardedRef) {\n const {\n __scopeDialog,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n 'aria-describedby': ariaDescribedby,\n children,\n ...contentProps\n } = props;\n const context = useDialogContext(CONTENT_NAME, __scopeDialog);\n\n // Make sure the whole tree has focus guards as our `Dialog` will be\n // the last element in the DOM (because of the `Portal`)\n useFocusGuards();\n\n return (\n <FocusScopeBranchProvider registry={context.branchRegistry}>\n <FocusScope\n asChild\n loop\n trapped={trapFocus}\n branches={context.branchNodes}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n <DismissableLayer\n role=\"dialog\"\n id={context.contentId}\n aria-labelledby={context.titlePresent ? context.titleId : undefined}\n aria-describedby={\n context.descriptionPresent\n ? concatAriaDescribedby(ariaDescribedby, context.descriptionId)\n : ariaDescribedby\n }\n data-state={getState(context.open)}\n {...contentProps}\n ref={forwardedRef}\n deferPointerDownOutside\n onDismiss={() => context.onOpenChange(false)}\n >\n {children}\n </DismissableLayer>\n </FocusScope>\n </FocusScopeBranchProvider>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogTitleElement = React.ComponentRef<typeof Primitive.h2>;\ntype PrimitiveHeading2Props = React.ComponentPropsWithoutRef<typeof Primitive.h2>;\ninterface DialogTitleProps extends PrimitiveHeading2Props {}\n\nconst DialogTitle = /* @__PURE__ */ React.forwardRef<DialogTitleElement, DialogTitleProps>(\n function DialogTitle(props: ScopedProps<DialogTitleProps>, forwardedRef) {\n const { __scopeDialog, ...titleProps } = props;\n const context = useDialogContext('DialogTitle', __scopeDialog);\n const { setTitleCount } = context;\n useLayoutEffect(() => {\n setTitleCount((count) => count + 1);\n return () => setTitleCount((count) => count - 1);\n }, [setTitleCount]);\n return <Primitive.h2 id={context.titleId} {...titleProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\ntype DialogDescriptionElement = React.ComponentRef<typeof Primitive.p>;\ntype PrimitiveParagraphProps = React.ComponentPropsWithoutRef<typeof Primitive.p>;\ninterface DialogDescriptionProps extends PrimitiveParagraphProps {}\n\nconst DialogDescription = /* @__PURE__ */ React.forwardRef<\n DialogDescriptionElement,\n DialogDescriptionProps\n>(\n // blank line to reduce diff noise\n function DialogDescription(props: ScopedProps<DialogDescriptionProps>, forwardedRef) {\n const { __scopeDialog, ...descriptionProps } = props;\n const context = useDialogContext('DialogDescription', __scopeDialog);\n const { setDescriptionCount } = context;\n useLayoutEffect(() => {\n setDescriptionCount((count) => count + 1);\n return () => setDescriptionCount((count) => count - 1);\n }, [setDescriptionCount]);\n return <Primitive.p id={context.descriptionId} {...descriptionProps} ref={forwardedRef} />;\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DialogClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'DialogClose';\n\ntype DialogCloseElement = React.ComponentRef<typeof Primitive.button>;\ninterface DialogCloseProps extends PrimitiveButtonProps {}\n\nconst DialogClose = /* @__PURE__ */ React.forwardRef<DialogCloseElement, DialogCloseProps>(\n function DialogClose(props: ScopedProps<DialogCloseProps>, forwardedRef) {\n const { __scopeDialog, ...closeProps } = props;\n const context = useDialogContext(CLOSE_NAME, __scopeDialog);\n return (\n <Primitive.button\n type=\"button\"\n {...closeProps}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () => context.onOpenChange(false))}\n />\n );\n },\n);\n\n/** @deprecated Noop component to avoid breaking changes. */\nexport const WarningProvider: React.FC<\n ScopedProps<{\n children?: React.ReactNode;\n contentName: string;\n titleName: string;\n docsSlug: 'dialog';\n }>\n> = (props) => {\n return props.children;\n};\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// TODO: Move to primitive once that package exposed individual sub-modules\nfunction concatAriaDescribedby(...values: unknown[]): string | undefined {\n const ids = new Set<string>();\n for (const value of values) {\n if (typeof value !== 'string') continue;\n for (const id of String(value).trim().split(/\\s+/)) {\n if (id) ids.add(id);\n }\n }\n\n return ids.size > 0 ? Array.from(ids).join(' ') : undefined;\n}\n\nfunction getState(open: boolean) {\n return open ? 'open' : 'closed';\n}\n\nexport {\n createDialogScope,\n //\n Dialog,\n DialogTrigger,\n DialogPortal,\n DialogOverlay,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n //\n Dialog as Root,\n DialogTrigger as Trigger,\n DialogPortal as Portal,\n DialogOverlay as Overlay,\n DialogContent as Content,\n DialogTitle as Title,\n DialogDescription as Description,\n DialogClose as Close,\n};\nexport type {\n DialogProps,\n DialogTriggerProps,\n DialogPortalProps,\n DialogOverlayProps,\n DialogContentProps,\n DialogTitleProps,\n DialogDescriptionProps,\n DialogCloseProps,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,4BAA4B;AACrC,S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AA,IACvD,GAAG,CAAC,mBAAmB,CAAC;AACxB,WAAO,oBAAC,UAAU,GAAV,EAAY,IAAI,QAAQ,eAAgB,GAAG,kBAAkB,KAAK,cAAc;AAAA,EAC1F,GATA;AAUF;AAMA,IAAM,aAAa;AAKnB,IAAM,cAA8B,gBAAM;AAAA,EACxC,gCAASC,aAAY,OAAsC,cAAc;AACvE,UAAM,EAAE,eAAe,GAAG,WAAW,IAAI;AACzC,UAAM,UAAU,iBAAiB,YAAY,aAAa;AAC1D,WACE;AAAA,MAAC,UAAU;AAAA,MAAV;AAAA,QACC,MAAK;AAAA,QACJ,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,SAAS,qBAAqB,MAAM,SAAS,MAAM,QAAQ,aAAa,KAAK,CAAC;AAAA;AAAA,IAChF;AAAA,EAEJ,GAXA;AAYF;AAGO,IAAM,kBAOT,wBAAC,UAAU;AACb,SAAO,MAAM;AACf,GAFI;AAOJ,SAAS,yBAAyB,QAAuC;AACvE,QAAM,MAAM,oBAAI,IAAY;AAC5B,aAAW,SAAS,QAAQ;AAC1B,QAAI,OAAO,UAAU,SAAU;AAC/B,eAAW,MAAM,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG;AAClD,UAAI,GAAI,KAAI,IAAI,EAAE;AAAA,IACpB;AAAA,EACF;AAEA,SAAO,IAAI,OAAO,IAAI,MAAM,KAAK,GAAG,EAAE,KAAK,GAAG,IAAI;AACpD;AAVS;AAYT,SAAS,SAAS,MAAe;AAC/B,SAAO,OAAO,SAAS;AACzB;AAFS;",
|
|
6
6
|
"names": ["DialogTrigger", "DialogOverlay", "DialogOverlayImpl", "DialogContent", "DialogContentModal", "DialogContentNonModal", "DialogContentImpl", "DialogTitle", "DialogDescription", "DialogClose"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-dialog",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.1785512840124",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,18 +14,18 @@
|
|
|
14
14
|
"aria-hidden": "^1.2.4",
|
|
15
15
|
"react-remove-scroll": "^2.7.2",
|
|
16
16
|
"@radix-ui/primitive": "1.1.7",
|
|
17
|
-
"@radix-ui/react-context": "1.2.2",
|
|
18
|
-
"@radix-ui/react-dismissable-layer": "1.1.20-rc.1785253136758",
|
|
19
|
-
"@radix-ui/react-focus-guards": "1.1.6",
|
|
20
17
|
"@radix-ui/react-compose-refs": "1.1.5",
|
|
21
|
-
"@radix-ui/react-
|
|
18
|
+
"@radix-ui/react-context": "1.2.2",
|
|
19
|
+
"@radix-ui/react-dismissable-layer": "1.1.20-rc.1785512840124",
|
|
22
20
|
"@radix-ui/react-id": "1.1.4",
|
|
23
|
-
"@radix-ui/react-
|
|
24
|
-
"@radix-ui/react-
|
|
25
|
-
"@radix-ui/react-
|
|
21
|
+
"@radix-ui/react-focus-guards": "1.1.6",
|
|
22
|
+
"@radix-ui/react-focus-scope": "1.2.0-rc.1785512840124",
|
|
23
|
+
"@radix-ui/react-slot": "1.4.0-rc.1785512840124",
|
|
24
|
+
"@radix-ui/react-primitive": "2.1.11-rc.1785512840124",
|
|
26
25
|
"@radix-ui/react-use-controllable-state": "1.2.6",
|
|
27
|
-
"@radix-ui/react-
|
|
28
|
-
"@radix-ui/react-use-layout-effect": "1.1.4"
|
|
26
|
+
"@radix-ui/react-portal": "1.1.18-rc.1785512840124",
|
|
27
|
+
"@radix-ui/react-use-layout-effect": "1.1.4",
|
|
28
|
+
"@radix-ui/react-presence": "1.1.11-rc.1785512840124"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/react": "^19.2.17",
|