-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Popover using Radix UI (#1504)
- Loading branch information
1 parent
662adab
commit 136733b
Showing
12 changed files
with
784 additions
and
41 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/pcln-design-system/popover-refactor_2024-07-17-12-56.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}; | ||
` |
Oops, something went wrong.