@@ -4,13 +4,15 @@ import {
44 Content ,
55 Description ,
66 Overlay ,
7+ Portal ,
78 Root ,
89 Title ,
910 Trigger ,
1011} from '@radix-ui/react-alert-dialog'
1112import React , { ComponentProps , ElementRef , FC , forwardRef } from 'react'
1213import type { CSSProps } from '../../stitches.config'
1314import { CSS , styled } from '../../stitches.config'
15+ import { ConditionalWrapper } from '../../utils'
1416import { Button } from '../Button'
1517import { Heading } from '../Heading'
1618import { overlayAnimationStyles , overlayStyles } from '../Overlay'
@@ -56,11 +58,6 @@ export const StyledContent = styled(
5658 overlayAnimationStyles
5759)
5860
59- type ConfirmDialogProps = ComponentProps < typeof Root > & {
60- /** Modify the default styling of the overlay */
61- overlayCss ?: CSS
62- }
63-
6461/**
6562 * The `ConfirmDialog` component can be used get confirmation of an action from the user.
6663 * This is done by isolating the user from the main window by overlaying
@@ -80,39 +77,55 @@ type ConfirmDialogProps = ComponentProps<typeof Root> & {
8077 *
8178 * Based on [Radix Alert Dialog](https://radix-ui.com/primitives/docs/components/alert-dialog).
8279 */
83- export const ConfirmDialog : FC < ConfirmDialogProps > = ( {
84- children,
85- overlayCss,
86- ...props
87- } ) => {
88- return (
89- < Root { ...props } >
90- < StyledOverlay css = { overlayCss } />
91- { children }
92- </ Root >
93- )
94- }
80+ export const ConfirmDialog = Root
9581
9682type ConfirmDialogContentProps = ComponentProps < typeof StyledContent > &
9783 CSSProps & {
9884 /** Add a title to the content. */
9985 title ?: string
10086 /** Add a description to the content. */
10187 description ?: string
88+ /** Modify the default styling of the overlay */
89+ overlayCss ?: CSS
90+ /** By default, portals your overlay and content parts into the body, set false to add at dom location. */
91+ portalled ?: boolean
92+ /** Specify a container element to portal the content into. */
93+ container ?: ComponentProps < typeof Portal > [ 'container' ]
10294 }
10395
10496export const ConfirmDialogContent = forwardRef <
10597 ElementRef < typeof StyledContent > ,
10698 ConfirmDialogContentProps
107- > ( ( { title, description, children, ...props } , forwardedRef ) => (
108- < StyledContent { ...props } ref = { forwardedRef } >
109- { title && < ConfirmDialogTitle > { title } </ ConfirmDialogTitle > }
110- { description && (
111- < ConfirmDialogDescription > { description } </ ConfirmDialogDescription >
112- ) }
113- { children }
114- </ StyledContent >
115- ) )
99+ > (
100+ (
101+ {
102+ title,
103+ description,
104+ overlayCss,
105+ container,
106+ portalled = true ,
107+ children,
108+ ...props
109+ } ,
110+ forwardedRef
111+ ) => (
112+ < ConditionalWrapper
113+ condition = { portalled }
114+ wrapper = { ( child ) => < Portal container = { container } > { child } </ Portal > }
115+ >
116+ < >
117+ < StyledOverlay css = { overlayCss } />
118+ < StyledContent { ...props } ref = { forwardedRef } >
119+ { title && < ConfirmDialogTitle > { title } </ ConfirmDialogTitle > }
120+ { description && (
121+ < ConfirmDialogDescription > { description } </ ConfirmDialogDescription >
122+ ) }
123+ { children }
124+ </ StyledContent >
125+ </ >
126+ </ ConditionalWrapper >
127+ )
128+ )
116129ConfirmDialogContent . toString = ( ) => `.${ StyledContent . className } `
117130
118131export const ConfirmDialogTrigger = forwardRef <
0 commit comments