### Install Vaul-Svelte Source: https://github.com/huntabyte/vaul-svelte/blob/main/README.md Install the Vaul-Svelte library into your project using npm. This is the first step to using the drawer component in your Svelte application. ```bash npm install vaul-svelte ``` -------------------------------- ### Basic Svelte Drawer Implementation Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This snippet demonstrates the fundamental setup for a Vaul-Svelte drawer, including a trigger button and content area. It requires importing the Drawer component from 'vaul-svelte'. ```svelte Open

Content

``` -------------------------------- ### Install vaul-svelte Package Source: https://context7.com/huntabyte/vaul-svelte/llms.txt Install the vaul-svelte package using your preferred package manager (npm, pnpm, or yarn). This is the first step to integrating drawer functionality into your Svelte application. ```bash # Install via npm npm install vaul-svelte # Or via pnpm pnpm add vaul-svelte # Or via yarn yarn add vaul-svelte ``` -------------------------------- ### Svelte Drawer with Snap Points Source: https://context7.com/huntabyte/vaul-svelte/llms.txt Implement a drawer in Svelte that can snap to predefined heights or positions using the 'snapPoints' prop and 'activeSnapPoint' binding. This example uses TypeScript and defines custom snap points for the drawer. ```svelte Open SnapPoints Drawer

The Hidden Details

The world of user interface design is an intricate landscape.

``` -------------------------------- ### Configure Directional Drawer (Top) with Vaul Svelte Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This example illustrates how to configure a drawer to open from the top of the screen instead of the default bottom. It uses the `direction="top"` prop on the `Drawer.Root` component. ```svelte Open from Top
Drawer from Top

Content slides down from the top of the screen.

``` -------------------------------- ### Create Non-Dismissible Drawer with Vaul Svelte Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This example demonstrates how to create a drawer that cannot be dismissed by swiping or clicking outside the drawer area. It utilizes the `dismissible={false}` prop on the `Drawer.Root` component. ```svelte Open Non-Dismissible

This drawer requires explicit closure.

Close Drawer
``` -------------------------------- ### Control Vaul Svelte Drawer Programmatically with Callbacks Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This example demonstrates how to control the drawer's open state programmatically and listen to various events like open changes, dragging, and release. It uses `bind:open`, `onOpenChange`, `onDrag`, `onRelease`, and `onActiveSnapPointChange` props. ```svelte Open Controlled Drawer

Current snap point: {activeSnapPoint}

Open state: {open}

``` -------------------------------- ### Implement Drawer with Background Scaling in Vaul Svelte Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This example shows how to make the background content scale down and dim when the drawer is open. It requires wrapping the drawer trigger and content in an element with the `data-vaul-drawer-wrapper` attribute and using `shouldScaleBackground` and `backgroundColor` props on `Drawer.Root`. ```svelte
Open with Scaling
Scaled Background The background behind this drawer is scaled down and darkened.
``` -------------------------------- ### Svelte Scrollable Drawer with Inputs Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This Svelte example shows a scrollable drawer component that accommodates input elements. It uses 'max-h-[96%]' to define the maximum height and 'overflow-auto' for scrollability within the drawer's content area. ```svelte Open Scrollable Drawer

But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system.

``` -------------------------------- ### Prevent Dragging on Specific Sections in Vaul Svelte Drawer Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This example shows how to prevent the drawer from being dragged when interacting with specific elements within the drawer's content. This is achieved by adding the `data-vaul-no-drag` attribute to the target HTML element. ```svelte Open

You can drag here to close the drawer

Try dragging me - this section won't drag the drawer

``` -------------------------------- ### Set Custom Close Threshold for Vaul Svelte Drawer Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This example shows how to customize the threshold required for the drawer to close when swiping down. The `closeThreshold` prop accepts a number between 0 and 1, representing the percentage of the drawer's height that needs to be swiped before it closes. Here, it's set to 0.3 (30%). ```svelte Open (30% threshold)

This drawer closes when swiped down by 30% of its height.

``` -------------------------------- ### Basic Vaul-Svelte Drawer Usage Source: https://github.com/huntabyte/vaul-svelte/blob/main/README.md Demonstrates the fundamental implementation of a drawer component in Svelte using Vaul-Svelte. It includes importing the Drawer, creating a root element, a trigger to open it, and the content that appears within the drawer. ```svelte Open

Content

``` -------------------------------- ### Vaul-Svelte Drawer API Source: https://github.com/huntabyte/vaul-svelte/blob/main/README.md This section details the API reference for the Vaul-Svelte drawer component, including its root, trigger, content, overlay, and other sub-components. ```APIDOC ## Root Component ### Description Contains all parts of a dialog. Use `shouldScaleBackground` to enable background scaling, it requires an element with `[data-vaul-drawer-wrapper]` data attribute to scale its background. Can be controlled by binding to the `open` prop, or using the `onOpenChange` prop. ### Props - **closeThreshold** (Number) - A number between 0 and 1 that determines when the drawer should be closed. Example: threshold of 0.5 would close the drawer if the user swiped for 50% of the height of the drawer or more. - **scrollLockTimeout** (Number) - Duration for which the drawer is not draggable after scrolling content inside of the drawer. Defaults to 500ms. - **snapPoints** (Array) - Array of numbers from 0 to 100 (percentage of screen height) or pixel values that corresponds to the drawer's snap points. Should go from least visible. Example `[0.2, 0.5, 0.8]`. - **fadeFromIndex** (Number) - Index of a `snapPoint` from which the overlay fade should be applied. Defaults to the last snap point. - **direction** (String) - Direction of the drawer. Can be `top`, `bottom`, `left`, or `right`. Defaults to `bottom`. - **backgroundColor** (String) - Background color of the body when the drawer is open and `shouldScaleBackground` is true. Defaults to black. - **[data-vaul-no-drag]** (Attribute) - When interacting with an element with this data attribute, the drawer won't be dragged. - **open** (Boolean) - Controls the open state of the drawer. Can be controlled via two-way binding. - **onOpenChange** (Function) - Callback function that is called when the open state changes. ### Usage Example ```svelte Open Drawer

Drawer Title

Drawer content goes here.

Close
``` ## Trigger Component ### Description The button that opens the dialog. ### Props Refer to [Bits UI Dialog Trigger Props](https://www.bits-ui.com/docs/components/dialog#trigger). ## Content Component ### Description Content that should be rendered in the drawer. ### Props Refer to [Bits UI Dialog Content Props](https://www.bits-ui.com/docs/components/dialog#content). ## Overlay Component ### Description A layer that covers the inert portion of the view when the dialog is open. ### Props Refer to [Bits UI Dialog Overlay Props](https://www.bits-ui.com/docs/components/dialog#overlay). ## Title Component ### Description An accessible title to be announced when the dialog is opened. ### Props Refer to [Bits UI Dialog Title Props](https://www.bits-ui.com/docs/components/dialog#title). ## Description Component ### Description An optional accessible description to be announced when the dialog is opened. ### Props Refer to [Bits UI Dialog Description Props](https://www.bits-ui.com/docs/components/dialog#description). ## Close Component ### Description The button that closes the dialog. ### Props Refer to [Bits UI Dialog Close Props](https://www.bits-ui.com/docs/components/dialog#close). ## Portal Component ### Description Portals your drawer into the body. ``` -------------------------------- ### Svelte Nested Drawers Implementation Source: https://context7.com/huntabyte/vaul-svelte/llms.txt This Svelte code demonstrates how to implement nested drawers using Drawer.NestedRoot. It ensures proper z-index management for multiple stacked drawers, with the outer drawer featuring a background scaling effect. ```svelte Open Nested Drawer
Drawer for Svelte. Open Second Drawer
This drawer is nested.

Place a Drawer.NestedRoot inside another drawer.

``` -------------------------------- ### TypeScript Configuration for vaul-svelte Source: https://context7.com/huntabyte/vaul-svelte/llms.txt Import the `Drawer` component and `DrawerDirection` type from `vaul-svelte` for TypeScript projects. The `DrawerDirection` type specifies the possible directions for the drawer, such as 'bottom', 'top', 'left', or 'right'. ```typescript // Import types for TypeScript projects import { Drawer, type DrawerDirection } from "vaul-svelte"; // Available direction types const direction: DrawerDirection = "bottom" | "top" | "left" | "right"; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.