import * as React from 'react'import { Drawer, useDrawer } from '@welcome-ui/drawer'import { Button } from '@welcome-ui/button'const Example = () => {const drawer = useDrawer()return (<><Drawer.Trigger as={Button} store={drawer}>Open Drawer</Drawer.Trigger><Drawer aria-label="Default drawer" store={drawer}>Praesent sit amet quam ac velit faucibus dapibus. Quisque sapien ligula, rutrum quis aliquamnec, convallis sit amet erat. Mauris auctor blandit porta.</Drawer></>)}export default Example
Installation
Run the following command:
yarn add @welcome-ui/drawer
Import component:
import { Drawer, useDrawer } from '@welcome-ui/drawer'
The most basic drawer needs useDrawer()
, <Drawer.Trigger />
and <Drawer />
. If you don't want a backdrop to be visible, please provide it a withBackdrop
prop set to false
. Backdrop allows us to have a smooth scroll across all browsers by wrapping the Drawer. This way, the Drawer can be absolutely positioned in the fixed Backdrop wrapper.
Backdrop
You have to add on <Drawer />
a prop withBackdrop
. This adds our backdrop <Drawer.Backdrop />
on the drawer. You can also add a custom wrapper with the property backdrop
.
Layout
We provide basic layout components for your drawer: <Drawer.Title />
, <Drawer.Content />
and <Drawer.Footer />
. They are all optional. By default, you have a close button <Drawer.Close />
that you can remove by setting the withCloseButton
property to false
. If you're using <Drawer.Close />
along with <Drawer.Title />
, please make sure to position <Drawer.Close />
first in your code for styling purposes.
Placement
By default the placement
of the drawer will be on the right
but you can set it to top
, bottom
, or left
.
Sizes
By default the size
of the drawer will be lg
which is set in the theme. We provide 3 different sizes that will adapt according to the position of the Drawer. You can also set a custom size if needed.
Styling
All the elements can be styled as you see fit, by extending drawer's theme or directly with styled props.
useDrawer
We use useDialogStore
from Ariakit Dialog for the state of the drawer with the animated
flag set to true
by default.
Pass options to useDrawer
:
- defaultOpen: e.g.
const drawer = useDrawer({ defaultOpen: true })
And the hook returns (among other things):
- useState('open'): whether the drawer is currently open
- hide: a function to hide the drawer