Your framework. Your markup.
Build bottom sheets and side panels with a vanilla API. No framework adapter required.
Drawers that move with you. Bottom sheets, side panels and nested flows with a typed, framework-free API.
npm install @samline/drawerFour directionsDrag & snapTyped controllers
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.
YOUR BAG · 2 ITEMS
Natural canvas · Qty 1
Dotted pages · Qty 1
Delivery is chosen at checkout.
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.
THE EVERYDAY COLLECTION
A lightweight canvas bag for the daily essentials.
Recycled cotton · 38 × 42 cm · In stock
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.
WEEKEND IN MEXICO CITY
Start slowly with a neighborhood walk.
Art, a picnic and a little fresh air.
Leave the evening open for something new.
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.
CHECKOUT / DELIVERY
Two items · subtotal before delivery.
Choose a delivery option below.
No delivery selected
ONE SMALL SCRIPT. RIGHT AT HOME IN YOUR STACK.
Build bottom sheets and side panels with a vanilla API. No framework adapter required.
Modal drawers trap focus, isolate the background and restore focus on close. You supply meaningful labels and content.
Create one instance, keep its controller, and update or destroy it when your feature changes.
Top, bottom, left or right. Drawer owns direction-aware gestures and motion; your CSS defines the panel.
Link a child with parentId. The runtime coordinates parent transforms, dismissal and shared scroll locking.
Use ordered pixel or fractional snap points. Drag to settle or click the built-in handle to advance.
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
Named factories and registry helpers, with TypeScript declarations. CommonJS is also exported.
Optional module namespace
The optional Drawer namespace exposes the same functions as the root module. It does not install a global.
HTML / CDN
The standalone IIFE attaches one global. Load the package stylesheet separately and pin the version.
Styles
Import runtime motion and handle styles first. Add your own positioning, surface and theme CSS after it.
Install the package, add a trigger, then create your drawer. Copy a complete browser example for a setup without a bundler.
Read the installation guideInstall
npm
npm install @samline/drawerpnpm
pnpm add @samline/draweryarn
yarn add @samline/drawerbun
bun add @samline/drawerHTML / CDN
<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>Add a trigger
Use a native button. Copy the panel stylesheet below; the package owns motion and dismissal.
<button type="button" id="open-drawer" aria-haspopup="dialog">
Open drawer
</button>
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;
}
Create the drawer
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()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.
Read the effective defaults, renderable slots and lifecycle contract.
Explore the configuration referenceUse the controller from Get started to update content, drive the open state and clean up when your feature leaves.
Change the title or body without creating another instance. Omitted options keep their existing values.
Read about updatesdrawer.update({
title: 'Your order',
content: 'Your order is confirmed.',
})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 closedrawer.setOpen(true)
// Later, after the action completes:
drawer.setOpen(false)Subscriptions fire immediately and return an unsubscribe function. Destroy the drawer when your page or component leaves.
Read lifecycle and stateconst unsubscribe = drawer.subscribe(snapshot => {
console.log(snapshot.state.isOpen)
})
// During application teardown:
unsubscribe()
drawer.destroy()Try a working interaction or build your first drawer.
Installation, practical guides and the complete API for Drawer 5.1.2.
Read the documentation