logo-icon
STWUI

Drawer

Drawer is a grid layout that can show/hide a sidebar on the left or right side of the page.

Default


svelte
<script lang="ts">
	import { Button, Portal } from 'stwui';

   let open = false;

   function openDrawer() {
		open = true;
	}

   function closeDrawer() {
		open = false;
	}
</script>

<Button type="primary" on:click={openDrawer}>Open</Button>

<Portal>
	{#if open}
		<Drawer handleClose={closeDrawer}>
			<Drawer.Header slot="header">Drawer Header</Drawer.Header>
			<Drawer.Content slot="content">Drawer Content</Drawer.Content>
			<Drawer.Footer slot="footer">Drawer Footer</Drawer.Footer>
		</Drawer>
	{/if}
</Portal>
With Placement






svelte
<script lang="ts">
	import { Button, Portal } from 'stwui';

   let drawerLeftOpen = false;
	let drawerTopOpen = false;
	let drawerBottomOpen = false;

   function openDrawerLeft() {
		drawerLeftOpen = true;
	}

	function closeDrawerLeft() {
		drawerLeftOpen = false;
	}

	function openDrawerTop() {
		drawerTopOpen = true;
	}

	function closeDrawerTop() {
		drawerTopOpen = false;
	}

	function openDrawerBottom() {
		drawerBottomOpen = true;
	}

	function closeDrawerBottom() {
		drawerBottomOpen = false;
	}
</script>

<Button type="primary" on:click={openDrawerLeft}>Open Left</Button>

<Button type="primary" on:click={openDrawerTop}>Open Top</Button>

<Button type="primary" on:click={openDrawerBottom}>Open Bottom</Button>

<Portal>
	{#if drawerLeftOpen}
		<Drawer handleClose={closeDrawerLeft} placement="left" />
	{/if}
</Portal>

<Portal>
	{#if drawerTopOpen}
		<Drawer handleClose={closeDrawerTop} placement="top" />
	{/if}
</Portal>

<Portal>
	{#if drawerBottomOpen}
		<Drawer handleClose={closeDrawerBottom} placement="bottom" />
	{/if}
</Portal>
Multiple Drawer Levels


svelte
<script lang="ts">
	import { Button, Portal } from 'stwui';

   let open = false;
	let drawerInsideOpen = false;

	function openDrawer() {
		drawerMultiOne = true;
	}

	function closeDrawer() {
		drawerMultiOne = false;
	}

	function openInsideDrawer() {
		drawerInsideOpen = true;
	}

	function closeInsideDrawer() {
		drawerInsideOpen = false;
	}
</script>

<Button type="primary" on:click={openDrawer}>Open</Button>

<Portal>
	{#if open}
		<Drawer handleClose={closeDrawer}>
			<Drawer.Header slot="header">Drawer Header</Drawer.Header>
			<Drawer.Content slot="content"
				>Drawer Content
				<Button type="primary" on:click={openInsideDrawer}>Open Drawer</Button>
			</Drawer.Content>
			<Drawer.Footer slot="footer">Drawer Footer</Drawer.Footer>

			<Portal>
				{#if drawerInsideOpen}
					<Drawer handleClose={closeInsideDrawer}>Content</Drawer>
				{/if}
			</Portal>
		</Drawer>
	{/if}
</Portal>

Drawer Props

handleClose (() => void) | undefined
placement 'left' | 'right' | 'top' | 'bottom' right
disableEscClose boolean false
disableOverlayClose boolean false

Drawer Slots

backdrop <Drawer.Backdrop slot="backdrop" />
header <Drawer.Header slot="header" />
content <Drawer.Content slot="content" />
default
footer <Drawer.Footer slot="footer" />

Drawer.Header Slots

default

Drawer.Content Slots

default

Drawer.Footer Slots

default