Drawer
A programmatic sliding panel component that appears from the edge of the screen.
Props
Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | false | Controls the visibility of the drawer. Supports $bindable. |
componentId | string | undefined | The unique identifier for the component wrapper. |
position | 'left' | 'right' | 'top' | 'bottom' | 'left' | The side of the screen from which the drawer appears. |
closeOnBackdropClick | boolean | true | Whether clicking the backdrop should close the drawer. |
scrollLock | boolean | true | Whether to prevent body scrolling when the drawer is open. |
variant | string | '' | Custom variant class for theming. |
transitionFn | function | () => {} | Transition function for the drawer panel. |
transitionParams | object | {} | Parameters for the panel transition. |
backdropTransitionFn | function | () => {} | Transition function for the backdrop. |
backdropTransitionParams | object | undefined | Parameters for the backdrop transition. |
Samples
Basic Usage
A standard drawer anchored to the left.
0
<script>1
import { Drawer } from 'fluid-ui-svelte/components';2
import { Button, Text } from 'fluid-ui-svelte/base';3
4
let isBasicDrawerOpen = $state(false);5
</script>6
7
<Button onclick={async () => isBasicDrawerOpen = true}>Open Drawer</Button>8
9
<Drawer bind:isOpen={isBasicDrawerOpen} position="left">10
<div class="flex flex-col gap-4">11
<Text type="h2">Drawer Content</Text>12
<Text>This is some content inside the drawer.</Text>13
<Button onclick={async () => isBasicDrawerOpen = false}>Close</Button>14
</div>15
</Drawer>Anchoring Positions
Toggle drawers from all four directions.
0
<script>1
import { Drawer } from 'fluid-ui-svelte/components';2
let left = $state(false);3
let right = $state(false);4
let top = $state(false);5
let bottom = $state(false);6
</script>7
8
<Button onclick={async () => left = true}>Left</Button>9
<Button onclick={async () => right = true}>Right</Button>10
<Button onclick={async () => top = true}>Top</Button>11
<Button onclick={async () => bottom = true}>Bottom</Button>12
13
<Drawer bind:isOpen={left} position="left">Left Drawer</Drawer>14
<Drawer bind:isOpen={right} position="right">Right Drawer</Drawer>15
<Drawer bind:isOpen={top} position="top">Top Drawer</Drawer>16
<Drawer bind:isOpen={bottom} position="bottom">Bottom Drawer</Drawer>Custom Animations
Pass standard Svelte transitions or custom ones.
0
<script>1
import { Drawer } from 'fluid-ui-svelte/components';2
import { fly, fade } from 'svelte/transition';3
4
let isAnimatedDrawerOpen = $state(false);5
</script>6
7
<Button onclick={async () => isAnimatedDrawerOpen = true}>Open Animated</Button>8
9
<Drawer 10
bind:isOpen={isAnimatedDrawerOpen}11
position="right"12
transitionFn={fly} 13
transitionParams={{ x: 500, duration: 500 }}14
backdropTransitionFn={fade}15
>16
Animated Content17
</Drawer>Fly Transition
Using the fly transition for a sliding effect.
0
<script>1
import { Drawer } from 'fluid-ui-svelte/components';2
import { fly } from 'svelte/transition';3
4
let isFlyDrawerOpen = $state(false);5
</script>6
7
<Button onclick={async () => isFlyDrawerOpen = true}>Open Fly Drawer</Button>8
9
<Drawer 10
bind:isOpen={isFlyDrawerOpen}11
position="bottom"12
transitionFn={fly} 13
transitionParams={{ y: 200, duration: 800 }}14
>15
Fly Content16
</Drawer>