Drawers

Utility

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

Examples

Select a drawer position to preview.

Usage

Create a Store

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

typescript
import { writable, type Writable } from 'svelte/store';
typescript
const storeDrawer: Writable<boolean> = writable(false);

Implement Drawer

Pass the store to the Drawer component. For best results implement your Drawer component in your applications root scope.

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

Open and Close Triggers

Set the store value to true too open the drawer.

typescript
const drawerOpen: any = () => { storeDrawer.set(true) };
html
<button on:click={drawerOpen}>Open</button>

Set the store value to false too close the drawer. You can also tap the backdrop or hit ESC on your keyboard.

typescript
const drawerClose: any = () => { storeDrawer.set(false) };
html
<button on:click={drawerClose}>Close</button>

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>