Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(drawer): add fluid size #1839

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions packages/components/drawer/src/Drawer.doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ import { Drawer } from '@spark-ui/drawer'

<Canvas of={stories.Usage} />

### Sizes
### Side

Pick a side among `right`, `left`, `top` and `bottom`.

<Canvas of={stories.Side} />

Pick a size among `sm`, `md`, `lg`.
### Size

Pick a size among `sm`, `md`, `lg`, `fluid` and `fullscreen`.

<Canvas of={stories.Sizes} />

Expand All @@ -103,15 +109,13 @@ When set to `true`, this option will remove the internal padding of the `Drawer.

<Canvas of={stories.Inset} />

### Side
### Sandbox

Pick a side among `right`, `left`, `top` and `bottom`.

<Canvas of={stories.Side} />
<Canvas of={stories.Sandbox} />

## Accessibility

Adheres to the [Drawer WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/drawermodal).
Adheres to the [Dialog WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/).

### Guidelines

Expand Down
109 changes: 99 additions & 10 deletions packages/components/drawer/src/Drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const Sizes = () => {
<RadioGroup.Radio value="sm">Small</RadioGroup.Radio>
<RadioGroup.Radio value="md">Medium</RadioGroup.Radio>
<RadioGroup.Radio value="lg">Large</RadioGroup.Radio>
<RadioGroup.Radio value="fluid">Fluid</RadioGroup.Radio>
<RadioGroup.Radio value="fullscreen">Fullscreen</RadioGroup.Radio>
</RadioGroup>

Expand All @@ -98,16 +99,22 @@ export const Sizes = () => {
<Drawer.Body className="flex flex-col gap-lg">
<Drawer.Description>Please select a drawer size</Drawer.Description>

{Array.from({ length: 10 }, (_, index) => (
<p key={index}>
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.
</p>
))}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

{size !== 'fluid' && (
<>
{Array.from({ length: 5 }, (_, index) => (
<p key={index}>
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.
</p>
))}
</>
)}
</Drawer.Body>

<Drawer.Footer className="flex justify-end gap-md">
Expand Down Expand Up @@ -177,6 +184,7 @@ export const Side = () => {
<RadioGroup.Radio value="top">Top</RadioGroup.Radio>
<RadioGroup.Radio value="bottom">Bottom</RadioGroup.Radio>
</RadioGroup>

<Drawer open={open} onOpenChange={setOpen}>
<Drawer.Trigger asChild>
<Button>Open drawer</Button>
Expand Down Expand Up @@ -219,3 +227,84 @@ export const Side = () => {
</>
)
}

export const Sandbox = () => {
const [size, setSize] = useState<ExcludeNull<DrawerContentProps>['size']>('md')
const [side, setSide] = useState<ExcludeNull<DrawerContentProps>['side']>('right')
const [open, setOpen] = useState(false)

return (
<div>
<RadioGroup
className="mb-lg flex gap-md"
value={side}
orientation="horizontal"
onValueChange={value => setSide(value as ExcludeNull<DrawerContentProps>['side'])}
>
<RadioGroup.Radio value="right">Right</RadioGroup.Radio>
<RadioGroup.Radio value="left">Left</RadioGroup.Radio>
<RadioGroup.Radio value="top">Top</RadioGroup.Radio>
<RadioGroup.Radio value="bottom">Bottom</RadioGroup.Radio>
</RadioGroup>

<RadioGroup
className="mb-lg flex gap-md"
value={size}
orientation="horizontal"
onValueChange={value => setSize(value as ExcludeNull<DrawerContentProps>['size'])}
>
<RadioGroup.Radio value="sm">Small</RadioGroup.Radio>
<RadioGroup.Radio value="md">Medium</RadioGroup.Radio>
<RadioGroup.Radio value="lg">Large</RadioGroup.Radio>
<RadioGroup.Radio value="fluid">Fluid</RadioGroup.Radio>
<RadioGroup.Radio value="fullscreen">Fullscreen</RadioGroup.Radio>
</RadioGroup>

<Drawer open={open} onOpenChange={setOpen}>
<Drawer.Trigger asChild>
<Button>Open drawer</Button>
</Drawer.Trigger>

<Drawer.Portal>
<Drawer.Overlay />

<Drawer.Content size={size} side={side}>
<Drawer.Header>
<Drawer.Title>Edit size</Drawer.Title>
</Drawer.Header>

<Drawer.Body className="flex flex-col gap-lg">
<Drawer.Description>Please select a drawer size</Drawer.Description>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

{size !== 'fluid' && (
<>
{Array.from({ length: 5 }, (_, index) => (
<p key={index}>
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.
</p>
))}
</>
)}
</Drawer.Body>

<Drawer.Footer className="flex justify-end gap-md">
<Button intent="neutral" design="outlined" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button>Submit</Button>
</Drawer.Footer>

<Drawer.CloseButton aria-label="Close edit size" />
</Drawer.Content>
</Drawer.Portal>
</Drawer>
</div>
)
}
11 changes: 11 additions & 0 deletions packages/components/drawer/src/DrawerContent.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const drawerContentStyles = cva(
sm: '',
md: '',
lg: '',
fluid: '',
fullscreen: 'h-screen w-screen',
},
side: {
Expand Down Expand Up @@ -54,6 +55,11 @@ export const drawerContentStyles = cva(
size: 'lg',
class: ['w-sz-864', 'max-w-full'],
},
{
side: ['left', 'right'],
size: 'fluid',
class: ['w-auto', 'max-w-full'],
},
{
side: ['top', 'bottom'],
size: 'sm',
Expand All @@ -69,6 +75,11 @@ export const drawerContentStyles = cva(
size: 'lg',
class: ['h-sz-864', 'max-h-full'],
},
{
side: ['top', 'bottom'],
size: 'fluid',
class: ['h-auto', 'max-h-full'],
},
],
defaultVariants: {
side: 'right',
Expand Down
Loading