Drawers

Displays an overlay panel that attaches to any side of the screen.

javascript
import { Drawer } from '@brainandbones/skeleton';

Examples

Usage

Create a Svelte writable store to manage the state of the drawer.

typescript
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.

html
<Drawer open={storeDrawer} position="left">
	(contents)
</Drawer>

Set the store value to true | false to open or close the Drawer.

typescript
const drawerOpen: any = () => { storeDrawer.set(true) };
typescript
const drawerClose: any = () => { storeDrawer.set(false) };

Implement the trigger methods on any interactive element.

html
<button class="btn btn-filled-primary" on:click={drawerOpen}>Open</button>
html
<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.

html
<Drawer></Drawer>

<AppShell></AppShell>

Properties

Prop Type Default Values Required Description
openWritable(boolean)writable(false)booleanProvide a store to manage visible state.
positionstringleftleft | right | top | bottom-Set the anchor position.
durationnumber150milliseconds-Define the Svelte transition animation duration.

Backdrop

Prop Type Default Description
bgBackdropstringbg-surface-400/70 dark:bg-surface-900/70Provide classes to set the backdrop background color
blurstringbackdrop-blur-smProvide classes to set the blur style.

Drawer

Prop Type Default Description
bgDrawerstringbg-surface-100 dark:bg-surface-800Provide classes to set the drawer background color.
borderstring-Provide classes to set border color.
roundedstring-Provide classes to set border radius.
widthstring(based on position)Provide classes to override the width.
heightstring(based on position)Provide classes to override the height.
marginstring-Provide classes to set margins.

Slots

Name Description
defaultProvide your Drawer content here.

Accessibility

ARIA Guidelines
Prop Type Default Description
labelledbystring-Provide an ID of the element labeling the drawer.
describedbystring-Provide an ID of the element describing the drawer.

Keyboard Interactions

Keys Description
Esc Closes the drawer.