Drawers
Displays an overlay panel that attaches to any side of the screen.
import { Drawer } from '@brainandbones/skeleton';
Examples
Usage
Create a Svelte writable store to manage the state of the drawer.
import { writable, type Writable } from 'svelte/store';
const storeDrawer: Writable<boolean> = writable(false);
Implement the Drawer component, passing the store reference. If you wish to make this accessible in global scope of your app, add this to your root layout.
<Drawer open={storeDrawer} position="left">
(contents)
</Drawer>
Set the store value to true | false
to open or close the Drawer.
const drawerOpen: any = () => { storeDrawer.set(true) };
const drawerClose: any = () => { storeDrawer.set(false) };
Implement the trigger methods on any interactive element.
<button class="btn btn-filled-primary" on:click={drawerOpen}>Open</button>
<button class="btn btn-filled-primary" on:click={drawerClose}>Close</button>
Closing the Drawer
Note that you can always close the Drawer by tapping the backdrop or pressing ESC on your keyboard.
Pairing with App Shell
Place the Drawer above and outside the App Shell in your root layout. This will prevent page content shifting as the Drawer changes state.
<Drawer></Drawer>
<AppShell></AppShell>
Properties
Prop | Type | Default | Values | Required | Description |
---|---|---|---|---|---|
open | Writable(boolean) | writable(false) | boolean | ✓ | Provide a store to manage visible state. |
position | string | left | left | right | top | bottom | - | Set the anchor position. |
duration | number | 150 | milliseconds | - | Define the Svelte transition animation duration. |
Backdrop
Prop | Type | Default | Description |
---|---|---|---|
bgBackdrop | string | bg-surface-400/70 dark:bg-surface-900/70 | Provide classes to set the backdrop background color |
blur | string | backdrop-blur-sm | Provide classes to set the blur style. |
Drawer
Prop | Type | Default | Description |
---|---|---|---|
bgDrawer | string | bg-surface-100 dark:bg-surface-800 | Provide classes to set the drawer background color. |
border | string | - | Provide classes to set border color. |
rounded | string | - | Provide classes to set border radius. |
width | string | (based on position) | Provide classes to override the width. |
height | string | (based on position) | Provide classes to override the height. |
margin | string | - | Provide classes to set margins. |
Slots
Name | Description |
---|---|
default | Provide your Drawer content here. |
Accessibility
ARIA GuidelinesProp | Type | Default | Description |
---|---|---|---|
labelledby | string | - | Provide an ID of the element labeling the drawer. |
describedby | string | - | Provide an ID of the element describing the drawer. |
Keyboard Interactions
Keys | Description |
---|---|
Esc | Closes the drawer. |