Skip to content

Commit

Permalink
Refactor Popover using Radix UI (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigpalermo authored Jul 24, 2024
1 parent 662adab commit 136733b
Show file tree
Hide file tree
Showing 12 changed files with 784 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-design-system",
"comment": "Create new Popover using Radix UI",
"type": "minor"
}
],
"packageName": "pcln-design-system"
}
422 changes: 390 additions & 32 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/core/config/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"extends": "@priceline/heft-component-rig/profiles/react/config/jest.config.json",
"coverageThreshold": {
"global": {
"statements": 94,
"statements": 93,
"branches": 88,
"functions": 88,
"lines": 94
"functions": 87,
"lines": 93
}
}
}
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-visually-hidden": "^1.0.3",
"@radix-ui/react-popover": "^1.0.5",
"@styled-system/theme-get": "^5.1.2",
"@types/styled-system": "^5.1.22",
"deepmerge": "^4.3.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/CloseButton/CloseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type CloseButtonProps = IStyledSystemProps & {
size?: CloseButtonSize
title?: string
variant?: CloseButtonVariant
as?: unknown
}

/** @public */
Expand All @@ -42,6 +43,7 @@ export const CloseButton = ({
size = 'md',
title = 'close',
variant,
as,
...props
}: MotionButtonProps) => {
const [hover, setHover] = useState(false)
Expand Down
33 changes: 33 additions & 0 deletions packages/core/src/Popover/Overlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import styled from 'styled-components'
import { Box } from '../Box/Box'

const StyledOverlay = styled(Box)`
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: ${({ overlayOpacity }) => overlayOpacity};
cursor: pointer;
display: ${({ popoverOpen }) => (popoverOpen ? 'block' : 'none')};
`

export type OverlayProps = {
overlayOpacity?: number
zIndex?: number
}

const Overlay = ({ overlayOpacity, isOpen }) => {
return (
<StyledOverlay
aria-hidden='true'
tabIndex='-1'
popoverOpen={isOpen}
overlayOpacity={overlayOpacity}
color='background.darkest'
/>
)
}

export default Overlay
97 changes: 97 additions & 0 deletions packages/core/src/Popover/Popover.stories.args.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react'
import { action } from '@storybook/addon-actions'
import { Button, IconButton } from '..'
import { InformationOutline } from 'pcln-icons'

const Children = {
Button: <Button>Popover</Button>,
Icon: (
<IconButton
icon={<InformationOutline color='text.light' size={20} />}
title='More Information'
type='button'
/>
),
}

export const defaultArgs = {
borderRadius: 'lg',
children: 'Button',
openOnFocus: false,
placement: 'top',
onClose: action('Popover Close'),
onOpen: action('Popover Open'),
disableFloating: false,
}

export const argTypes = {
children: {
options: Object.keys(Children),
mapping: Children,
control: {
type: 'select',
},
},
color: {
type: 'string',
},
disableFloating: {
name: 'disableFloating',
description: 'Disable floating-ui',
table: {
defaultValue: { summary: 'Sets crossAxis and mainAxis in the floating-ui' },
},
type: { name: 'boolean', required: false },
control: { type: 'boolean' },
},
width: {
name: 'width',
type: { name: 'string', required: false },
description: 'Popover width',
},
onClose: { action: true },
onMinimize: { action: true },
placement: {
name: 'placement',
type: { name: 'string', required: true },
options: [
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end',
'right',
'right-start',
'right-end',
],
control: { type: 'select' },
},
overlayOpacity: {
name: 'overlayOpacity',
type: { name: 'number', required: false },
description: 'Overlay opacity',
control: { type: 'number' },
},
toggleIsOpenOnClick: {
name: 'toggleIsOpenOnClick',
type: { name: 'boolean', required: false },
description: 'Toggle isOpen on click',
control: { type: 'boolean' },
},
isOpen: {
name: 'isOpen',
type: { name: 'boolean', required: false },
description: 'Is the popover open?',
control: { type: 'boolean' },
},
openOnHover: {
name: 'openOnHover',
type: { name: 'boolean', required: false },
description: 'Open the popover when trigger is hovered',
control: { type: 'boolean' },
},
}
69 changes: 69 additions & 0 deletions packages/core/src/Popover/Popover.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Button, Flex, Text, ThemeProvider } from '..'
import React from 'react'
import { Popover } from './Popover'
import { argTypes, defaultArgs } from './Popover.stories.args'
import { action } from '@storybook/addon-actions'

export default {
title: 'Popover',
component: Popover,
args: defaultArgs,
argTypes: argTypes,
}

const TemplateContent = ({ ...args }) => (
<Flex justifyContent='center' alignItems='center' width={1} my={6}>
<Popover
idx='basic-popover'
onOpen={action('onOpen')}
onClose={action('onClose')}
renderContent={() => (
<Flex flexDirection='column' p={2} onClick={(e) => e.stopPropagation()}>
<Text fontSize={1} mb={1} mt={0} fontWeight='bold'>
Tip:
</Text>
<Text mt={0} mb={1} fontSize={0}>
Use arrow keys to navigate the calendar
</Text>
</Flex>
)}
overlayOpacity={0.3}
width={350}
p={2}
{...args}
>
<Button className='IconButton' aria-label='Sample popover'>
Open
</Button>
</Popover>
</Flex>
)

const BaseTemplate = ({ children, theme, ...args }) => {
return <TemplateContent {...args} />
}

export const _Popover = BaseTemplate.bind({})

export const OpenOnMount = BaseTemplate.bind({})
OpenOnMount.args = { openOnMount: true }

export const CustomPlacement = BaseTemplate.bind({})
CustomPlacement.args = { placement: 'bottom-end', openOnMount: true }

export const ForcedOpen = BaseTemplate.bind({})
ForcedOpen.args = { isOpen: true }

export const WithoutOverlay = BaseTemplate.bind({})
WithoutOverlay.args = { hideOverlay: true, openOnMount: true }

const CustomThemeTemplate = ({ children, theme, ...args }) => {
return (
<ThemeProvider theme={{ palette: { text: { base: 'red' } } }}>
<TemplateContent {...args} />
</ThemeProvider>
)
}

export const ContentUsesContextualTheme = CustomThemeTemplate.bind({})
ContentUsesContextualTheme.args = { openOnMount: true }
12 changes: 12 additions & 0 deletions packages/core/src/Popover/Popover.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import styled from 'styled-components'
import { getPaletteColor } from '../utils'

export const FixedCloseButton = styled.div`
position: fixed;
top: 4px;
right: 4px;
`

export const StyledArrow = styled.div`
fill: ${({ color }) => getPaletteColor(color)};
`
Loading

0 comments on commit 136733b

Please sign in to comment.