@@ -3,12 +3,14 @@ import {
33 Arrow ,
44 Close ,
55 Content ,
6+ Portal ,
67 Root ,
78 Trigger ,
89} from '@radix-ui/react-popover'
910import React , { ComponentProps , ElementRef , FC , forwardRef } from 'react'
1011import type { AsProps , CSSProps } from '../../stitches.config'
1112import { styled } from '../../stitches.config'
13+ import { ConditionalWrapper } from '../../utils'
1214import { paperStyles } from '../Paper'
1315
1416const StyledContent = styled ( Content , paperStyles , {
@@ -30,16 +32,28 @@ const StyledArrow = styled(Arrow, {
3032 fill : '$paper' ,
3133} )
3234
33- type PopoverContentProps = CSSProps & AsProps & ComponentProps < typeof Content >
35+ type PopoverContentProps = CSSProps &
36+ AsProps &
37+ ComponentProps < typeof Content > & {
38+ /** By default, portals your content parts into the body, set false to add at dom location. */
39+ portalled ?: boolean
40+ /** Specify a container element to portal the content into. */
41+ container ?: ComponentProps < typeof Portal > [ 'container' ]
42+ }
3443
3544export const PopoverContent = forwardRef <
3645 ElementRef < typeof StyledContent > ,
3746 PopoverContentProps
38- > ( ( { children, ...props } , forwardedRef ) => (
39- < StyledContent { ...props } ref = { forwardedRef } >
40- < StyledArrow offset = { - 1 } />
41- { children }
42- </ StyledContent >
47+ > ( ( { portalled = true , container, children, ...props } , forwardedRef ) => (
48+ < ConditionalWrapper
49+ condition = { portalled }
50+ wrapper = { ( child ) => < Portal container = { container } > { child } </ Portal > }
51+ >
52+ < StyledContent { ...props } ref = { forwardedRef } >
53+ < StyledArrow offset = { - 1 } />
54+ { children }
55+ </ StyledContent >
56+ </ ConditionalWrapper >
4357) )
4458PopoverContent . toString = ( ) => `.${ StyledContent . className } `
4559
0 commit comments