-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
315 additions
and
13 deletions.
There are no files selected for viewing
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,127 @@ | ||
import { Meta, StoryFn } from '@storybook/react/*'; | ||
import { useState } from 'react'; | ||
|
||
import { Box } from '../Box'; | ||
import { Button } from '../Button'; | ||
import { Dialog, DialogContent, DialogOverlay, DialogPortal } from '../Dialog'; | ||
import { Text } from '../Text'; | ||
import { SidePanel } from './SidePanel'; | ||
|
||
const Component: Meta<typeof SidePanel> = { | ||
title: 'Components/SidePanel', | ||
component: SidePanel, | ||
argTypes: { | ||
side: { | ||
options: ['right', 'left', 'top', 'bottom'], | ||
control: { type: 'radio' }, | ||
}, | ||
}, | ||
}; | ||
|
||
const Content = ({ onClickBtn, ctaLabel }: { onClickBtn?: () => void; ctaLabel?: string }) => { | ||
const [count, setCount] = useState(1); | ||
|
||
return ( | ||
<> | ||
<Text size={2} as="h3" css={{ mb: '$3' }}> | ||
Hello, World! | ||
</Text> | ||
{[...Array(count)].map((_, i) => ( | ||
<Text key={i} css={{ mb: '$1' }}> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt | ||
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation | ||
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in | ||
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur | ||
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id | ||
est laborum. | ||
</Text> | ||
))} | ||
<Button | ||
css={{ mt: '$3' }} | ||
onClick={() => (onClickBtn ? onClickBtn() : setCount((c) => c + 1))} | ||
> | ||
{ctaLabel || 'Do some actions'} | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export const Basic: StoryFn<typeof SidePanel> = (args) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Box> | ||
<Button onClick={() => setOpen(true)}>Open side panel</Button> | ||
<Box css={{ mt: '$4' }}> | ||
{[...Array(10)].map((_, i) => ( | ||
<Text key={i} css={{ my: '$1' }}> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor | ||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud | ||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure | ||
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. | ||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt | ||
mollit anim id est laborum. | ||
</Text> | ||
))} | ||
</Box> | ||
</Box> | ||
|
||
<SidePanel {...args} open={open} onOpenChange={(isOpen) => setOpen(isOpen)}> | ||
<Content /> | ||
</SidePanel> | ||
</> | ||
); | ||
}; | ||
|
||
Basic.args = { | ||
noOverlay: false, | ||
side: 'right', | ||
noCloseIcon: false, | ||
}; | ||
|
||
export const CombinedWithModal: StoryFn<typeof SidePanel> = (args) => { | ||
const [open, setOpen] = useState(false); | ||
const [isModalOpen, setModalOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Dialog open={isModalOpen} onOpenChange={(isModalOpen) => setModalOpen(isModalOpen)}> | ||
<DialogPortal> | ||
<DialogOverlay /> | ||
<DialogContent> | ||
<Text css={{ m: '$2', mt: '$4' }}>This is a modal from the side panel</Text> | ||
</DialogContent> | ||
</DialogPortal> | ||
</Dialog> | ||
|
||
<SidePanel {...args} open={open} onOpenChange={(isOpen) => setOpen(isOpen)}> | ||
<Content ctaLabel="Open modal" onClickBtn={() => setModalOpen(true)} /> | ||
</SidePanel> | ||
|
||
<Box> | ||
<Button onClick={() => setOpen(true)}>Open side panel</Button> | ||
<Box css={{ mt: '$4' }}> | ||
{[...Array(10)].map((_, i) => ( | ||
<Text key={i} css={{ my: '$1' }}> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor | ||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud | ||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure | ||
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. | ||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt | ||
mollit anim id est laborum. | ||
</Text> | ||
))} | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
CombinedWithModal.args = { | ||
noOverlay: true, | ||
side: 'right', | ||
noCloseIcon: true, | ||
}; | ||
|
||
export default Component; |
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,19 @@ | ||
import { Property } from '@stitches/react/types/css'; | ||
|
||
import { ColorInfo } from '../../utils/getPrimaryColorInfo'; | ||
|
||
export namespace Theme { | ||
type Colors = { | ||
sidePanelBackground: Property.Color; | ||
}; | ||
|
||
type Factory = (primaryColor?: ColorInfo) => Colors; | ||
|
||
export const getLight: Factory = () => ({ | ||
sidePanelBackground: '$deepBlue2', | ||
}); | ||
|
||
export const getDark: Factory = () => ({ | ||
sidePanelBackground: '$deepBlue3', | ||
}); | ||
} |
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,152 @@ | ||
import * as DialogPrimitive from '@radix-ui/react-dialog'; | ||
import { Cross1Icon } from '@radix-ui/react-icons'; | ||
import React, { ComponentProps } from 'react'; | ||
|
||
import { CSS, keyframes, styled, VariantProps } from '../../stitches.config'; | ||
import { IconButton } from '../IconButton'; | ||
import { overlayStyles } from '../Overlay'; | ||
|
||
const fadeIn = keyframes({ | ||
from: { opacity: '0' }, | ||
to: { opacity: '1' }, | ||
}); | ||
|
||
const fadeOut = keyframes({ | ||
from: { opacity: '1' }, | ||
to: { opacity: '0' }, | ||
}); | ||
|
||
const SidePanelOverlay = styled(DialogPrimitive.Overlay, overlayStyles, { | ||
position: 'fixed', | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
|
||
'&[data-state="open"]': { | ||
animation: `${fadeIn} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
|
||
'&[data-state="closed"]': { | ||
animation: `${fadeOut} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
}); | ||
|
||
const slideIn = keyframes({ | ||
from: { transform: '$$transformValue' }, | ||
to: { transform: 'translate3d(0,0,0)' }, | ||
}); | ||
|
||
const slideOut = keyframes({ | ||
from: { transform: 'translate3d(0,0,0)' }, | ||
to: { transform: '$$transformValue' }, | ||
}); | ||
|
||
const StyledContent = styled(DialogPrimitive.Content, { | ||
backgroundColor: '$sidePanelBackground', | ||
boxShadow: 'inset 0 0 0 1px $colors$deepBlue4', | ||
position: 'fixed', | ||
top: 0, | ||
bottom: 0, | ||
width: 375, | ||
p: '$4', | ||
|
||
'&[data-state="open"]': { | ||
animation: `${slideIn} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
|
||
'&[data-state="closed"]': { | ||
animation: `${slideOut} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
|
||
variants: { | ||
side: { | ||
top: { | ||
$$transformValue: 'translate3d(0,-100%,0)', | ||
width: '100%', | ||
height: 250, | ||
bottom: 'auto', | ||
}, | ||
right: { | ||
$$transformValue: 'translate3d(100%,0,0)', | ||
right: 0, | ||
maxWidth: '50%', | ||
}, | ||
bottom: { | ||
$$transformValue: 'translate3d(0,100%,0)', | ||
width: '100%', | ||
height: 250, | ||
bottom: 0, | ||
top: 'auto', | ||
}, | ||
left: { | ||
$$transformValue: 'translate3d(-100%,0,0)', | ||
left: 0, | ||
maxWidth: '50%', | ||
}, | ||
}, | ||
}, | ||
|
||
defaultVariants: { | ||
side: 'right', | ||
}, | ||
}); | ||
|
||
const StyledCloseButton = styled(DialogPrimitive.Close, { | ||
position: 'absolute', | ||
top: '$2', | ||
right: '$2', | ||
cursor: 'pointer', | ||
}); | ||
|
||
interface SidePanelCloseButtonProps | ||
extends VariantProps<typeof IconButton>, | ||
ComponentProps<typeof IconButton> {} | ||
|
||
const SidePanelCloseIconButton = React.forwardRef< | ||
React.ElementRef<typeof IconButton>, | ||
SidePanelCloseButtonProps | ||
>((props, forwardedRef) => ( | ||
<StyledCloseButton asChild> | ||
<IconButton ref={forwardedRef} css={{ color: '$hiContrast' }} {...props}> | ||
<Cross1Icon /> | ||
</IconButton> | ||
</StyledCloseButton> | ||
)); | ||
|
||
type SidePanelContentVariants = VariantProps<typeof StyledContent>; | ||
type SidePanelContentPrimitiveProps = React.ComponentProps<typeof DialogPrimitive.Content>; | ||
type SidePanelProps = SidePanelContentPrimitiveProps & | ||
SidePanelContentVariants & { | ||
css?: CSS; | ||
noOverlay?: boolean; | ||
noCloseIcon?: boolean; | ||
open?: boolean; | ||
defaultOpen?: boolean; | ||
onOpenChange(open: boolean): void; | ||
}; | ||
|
||
export const SidePanel = React.forwardRef<React.ElementRef<typeof StyledContent>, SidePanelProps>( | ||
( | ||
{ | ||
noOverlay = false, | ||
noCloseIcon = false, | ||
children, | ||
onOpenChange, | ||
open = false, | ||
defaultOpen = false, | ||
...props | ||
}, | ||
forwardedRef, | ||
) => ( | ||
<DialogPrimitive.Root open={open} onOpenChange={onOpenChange} defaultOpen={defaultOpen}> | ||
<DialogPrimitive.Portal> | ||
{!noOverlay && <SidePanelOverlay />} | ||
<StyledContent {...props} ref={forwardedRef}> | ||
{children} | ||
{!noCloseIcon && <SidePanelCloseIconButton />} | ||
</StyledContent> | ||
</DialogPrimitive.Portal> | ||
</DialogPrimitive.Root> | ||
), | ||
); |
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 @@ | ||
export * from './SidePanel'; |
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