A simple svelte Drawer component build with vanilla Tailwind CSS.
Features
No package bullshit - just copy paste the ~50 lines from src/lib/ui/Drawer.svelte
code into your svelte project and you are good to go
Call it via
<script>
import Drawer from "$lib/ui/Drawer.svelte";
let isOpen = false;
const handleToggle = () => {
isOpen = !isOpen;
};
</script>
<Drawer {isOpen} on:clickAway={handleToggle}>
<button class="m-12 text-bold text-xl" on:click={handleToggle}>Close</button>
<!-- your stuff -->
</Drawer>
Open and Close state must be handled via the User. For easy usage propgate the state through your components via dispatcher. If the project gets more complicated I recommand handling the state via svelte stores.
svelte: 3.44.0
tailwindcss: 3.0.24
Parameter | Default | Description |
---|---|---|
isOpen | false | Two-way binding for open state of the component |
placement | right-0 | Side of screen to slide out from |
maxScreenSize | max-w-lg | Max Panel size (see tailwindcss.com/docs/max-width) |