Skip to content

Commit

Permalink
fix(Popover): updates Popover for radix v1
Browse files Browse the repository at this point in the history
Update Popover for addition of Portal component

see #286
  • Loading branch information
stuarthendren committed Aug 4, 2022
1 parent 00b700a commit 282cb31
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {
Arrow,
Close,
Content,
Portal,
Root,
Trigger,
} from '@radix-ui/react-popover'
import React, { ComponentProps, ElementRef, FC, forwardRef } from 'react'
import type { AsProps, CSSProps } from '../../stitches.config'
import { styled } from '../../stitches.config'
import { ConditionalWrapper } from '../../utils'
import { paperStyles } from '../Paper'

const StyledContent = styled(Content, paperStyles, {
Expand All @@ -30,16 +32,28 @@ const StyledArrow = styled(Arrow, {
fill: '$paper',
})

type PopoverContentProps = CSSProps & AsProps & ComponentProps<typeof Content>
type PopoverContentProps = CSSProps &
AsProps &
ComponentProps<typeof Content> & {
/** By default, portals your content parts into the body, set false to add at dom location. */
portalled?: boolean
/** Specify a container element to portal the content into. */
container?: ComponentProps<typeof Portal>['container']
}

export const PopoverContent = forwardRef<
ElementRef<typeof StyledContent>,
PopoverContentProps
>(({ children, ...props }, forwardedRef) => (
<StyledContent {...props} ref={forwardedRef}>
<StyledArrow offset={-1} />
{children}
</StyledContent>
>(({ portalled = true, container, children, ...props }, forwardedRef) => (
<ConditionalWrapper
condition={portalled}
wrapper={(child) => <Portal container={container}>{child}</Portal>}
>
<StyledContent {...props} ref={forwardedRef}>
<StyledArrow offset={-1} />
{children}
</StyledContent>
</ConditionalWrapper>
))
PopoverContent.toString = () => `.${StyledContent.className}`

Expand Down

0 comments on commit 282cb31

Please sign in to comment.