A framework-free drawer runtime.

Drawer
Make room for what’s next.

Drawers that move with you. Bottom sheets, side panels and nested flows with a typed, framework-free API.

npm install @samline/drawer

Four directionsDrag & snapTyped controllers

Drawer playground
The everyday bottom sheetLive · @samline/drawer

YOUR BAG · 2 ITEMS

Good things, ready to go.

A little more room for the next step. Drag down, press Escape, or use the close button.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

A side panel for the detailsLive · @samline/drawer

THE EVERYDAY COLLECTION

Carry a little less.

Keep the page in view while you explore. The same API works from all four edges.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Three stops. One fluid sheet.Live · @samline/drawer

WEEKEND IN MEXICO CITY

A day with room to wander.

Drag the sheet or click its handle to move between ordered snap points.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Open a drawer inside anotherLive · @samline/drawer

CHECKOUT / DELIVERY

Review your delivery.

Open a child drawer. Drawer coordinates its parent, focus, and shared scroll lock.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

ONE SMALL SCRIPT. RIGHT AT HOME IN YOUR STACK.

JavaScript TypeScript React Vue Svelte Shopify WordPress
01 / More than an open state

A natural interaction.
A clear API.

Your framework. Your markup.

Build bottom sheets and side panels with a vanilla API. No framework adapter required.

Focus stays in the flow

Modal drawers trap focus, isolate the background and restore focus on close. You supply meaningful labels and content.

Open. Update. Clean up.

Create one instance, keep its controller, and update or destroy it when your feature changes.

From any edge

Top, bottom, left or right. Drawer owns direction-aware gestures and motion; your CSS defines the panel.

One step deeper

Link a child with parentId. The runtime coordinates parent transforms, dismissal and shared scroll locking.

Find the right stopping point

Use ordered pixel or fractional snap points. Drag to settle or click the built-in handle to advance.

02 / Fit it into your stack

Two ways in. One runtime.

Choose package imports or an HTML script tag. The optional /browser subpath is a namespace for module users; only the standalone script installs window.Drawer.

Package / ESM

@samline/drawer

Named factories and registry helpers, with TypeScript declarations. CommonJS is also exported.

Optional module namespace

@samline/drawer/browser

The optional Drawer namespace exposes the same functions as the root module. It does not install a global.

HTML / CDN

window.Drawer

The standalone IIFE attaches one global. Load the package stylesheet separately and pin the version.

Styles

@samline/drawer/style.css

Import runtime motion and handle styles first. Add your own positioning, surface and theme CSS after it.

03 / From install to interaction

A button. A drawer.

Install the package, add a trigger, then create your drawer. Copy a complete browser example for a setup without a bundler.

Read the installation guide
1

Install

npm

Terminal
npm install @samline/drawer

pnpm

Terminal
pnpm add @samline/drawer

yarn

Terminal
yarn add @samline/drawer

bun

Terminal
bun add @samline/drawer

HTML / CDN

Terminal
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css">
<script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js" defer></script>
2

Add a trigger

Use a native button. Copy the panel stylesheet below; the package owns motion and dismissal.

index.html
<button type="button" id="open-drawer" aria-haspopup="dialog">
  Open drawer
</button>
Add the panel stylesheet
style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}
3

Create the drawer

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const drawer = createDrawer({
  triggerElement: document.getElementById('open-drawer'),
  title: 'Make room for the details',
  content: 'Your next step, right here.',
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  closeButton: true,
})
// On application teardown:
// drawer.destroy()
main.js
const drawer = window.Drawer.createDrawer({
  triggerElement: document.getElementById('open-drawer'),
  title: 'Make room for the details',
  content: 'Your next step, right here.',
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  closeButton: true,
})
// On application teardown:
// drawer.destroy()

Load the CDN stylesheet and script from step 1, then load this file with defer after the runtime script.

Copy complete working files

Read the effective defaults, renderable slots and lifecycle contract.

Explore the configuration reference
04 / Build the flow

After the first open.
Keep the flow.

Use the controller from Get started to update content, drive the open state and clean up when your feature leaves.

Controller

Update the existing drawer

Change the title or body without creating another instance. Omitted options keep their existing values.

Read about updates
update.js
drawer.update({
  title: 'Your order',
  content: 'Your order is confirmed.',
})
Application flow

Drive the open state

Open the panel after an application action. Close it when the flow is complete; the instance stays available for the next interaction.

Understand open and close
state.js
drawer.setOpen(true)

// Later, after the action completes:
drawer.setOpen(false)
Lifecycle

Keep ownership explicit

Subscriptions fire immediately and return an unsubscribe function. Destroy the drawer when your page or component leaves.

Read lifecycle and state
main.js
const unsubscribe = drawer.subscribe(snapshot => {
  console.log(snapshot.state.isOpen)
})
// During application teardown:
unsubscribe()
drawer.destroy()
Explore working examples
05 / Before you build

A few details. Clearly answered.

Does Drawer style the entire panel?
The stylesheet provides motion, snap selectors, overlay transitions and the handle. Your application supplies panel positioning, dimensions, colors and content. The examples include that CSS.
Can I use it without a framework or bundler?
Yes. Link the stylesheet and load the pinned IIFE bundle, then call window.Drawer.createDrawer. ESM and CommonJS consumers use the package exports instead.
Can I use Drawer with my framework or CMS?
Yes. Use the same JavaScript API in React, Vue, Svelte or Astro, or add it to a Shopify theme or WordPress site. Create DOM drawers in the browser, after their content and triggers exist. The integration guide includes host-specific setup and cleanup.
Can I open more than one drawer?
Yes. Create independent controllers for unrelated panels, or give a child the parent drawer’s id through parentId for a nested flow. Keep explicit ids unique. Independent panels need their own cleanup; nested drawers let users complete a second step without losing the first.
Can a drawer start small and expand?
Yes. Snap points define the stops a drawer can move between. Use fractions of the available space for responsive sizes, then let users drag between stops or choose one with setActiveSnapPoint(). Your CSS still defines the panel’s overall geometry.
Can the page stay interactive while a drawer is open?
Yes. Set modal to false for an inspector, notes panel or other tool used alongside the page. This disables modal focus trapping, background isolation and page scroll locking. The backdrop is also omitted by default; overlay can be configured separately.
What about forms, long content and touch scrolling?
Put overflow on the content body and keep the close control reachable. Drawer coordinates dragging with scrollable content and responds to mobile viewport changes while an input is focused. Use handleOnly or data-drawer-no-drag for controls that need their own gestures, and test the finished layout on your target devices.
Can I change the content or keep form values between openings?
Call update() on the existing controller to change content or options. Keep values that must survive closing in application state and restore them when building the form. A content factory runs again when the dialog is rebuilt, so closing a drawer does not automatically save form data.
Can I prevent accidental dismissal during an important step?
Set dismissible to false to prevent Escape, backdrop and drag dismissal. A configured close button or a programmatic close can still dismiss it. For a confirmation or unfinished form, provide clear actions and choose deliberately which controls may close the panel.
Should I close the drawer or destroy it?
Close it with setOpen(false) when users may open the same drawer again. Its controller remains available while the visual content leaves after the exit transition. Call destroy() when the owning view or widget is removed; it releases the instance and its listeners, and that controller cannot be reused.
What does my application still need to provide?
Your application supplies the content, styling, meaningful dialog names, visible focus indicators and form validation or status messages. Drawer supplies dialog semantics, gestures and the configured focus and scroll behavior. Verify the complete experience with keyboard, touch and your own content.
Make space for your next idea

Keep the page. Open the possibilities.

Try a working interaction or build your first drawer.

Installation, practical guides and the complete API for Drawer 5.1.2.

Read the documentation