- Docs
- Getting started
Getting started
Install Drawer, supply your panel styles, and create your first working interaction.
Requirements
Use Node.js 20 or newer for package tooling and a modern browser with ES2020, Pointer Events and pointer capture. Modal isolation uses inert and aria-hidden; test any older browsers in your support matrix. HTML / CDN needs no Node.js or bundler at runtime. The website’s own build-tool requirements are separate from the published package.
Install
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>One instance, one controller
Start with createDrawer(), keep its controller and use setOpen(), update() and destroy(). You do not need registry helpers, a namespace module or headless state for this first integration. An id is optional; omitted ids are independent, and explicit ids must be unique.
Your first working drawer
Choose a loading mode, then save the HTML, CSS and JavaScript files together. Package / ESM works with an HTML-entry bundler such as Vite. HTML / CDN opens directly in a browser with an internet connection. Both use the same public API and panel styles.
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
Good things, ready to go.
Natural canvas · Qty 1
Dotted pages · Qty 1
Delivery is chosen at checkout.
Copy the files
HTML / CDN
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Drawer playground</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main>
<button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
Open drawer
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
<h3>Good things, ready to go.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>Natural canvas · Qty 1</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Studio notebook</strong>
<p>Dotted pages · Qty 1</p>
</div>
<span>$18</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Subtotal</strong>
<p>Delivery is chosen at checkout.</p>
</div>
<span>$50</span>
</div>
</div>
<button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
Review checkout
</button>
</div>
</template>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
<script src="./main.js" defer></script>
</body>
</html>
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;
}
JavaScript
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')
const drawer = window.Drawer.createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Your shopping bag',
description: 'Review the items, quantities and subtotal before continuing.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const choices = [...body.querySelectorAll('button[data-demo-choice]')]
choices.forEach(button =>
button.addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent =
'Selected:' + ' ' + button.dataset.demoChoice
drawer.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
Complete file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Drawer playground</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
/>
<style>
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;
}
</style>
</head>
<body>
<main>
<button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
Open drawer
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
<h3>Good things, ready to go.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>Natural canvas · Qty 1</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Studio notebook</strong>
<p>Dotted pages · Qty 1</p>
</div>
<span>$18</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Subtotal</strong>
<p>Delivery is chosen at checkout.</p>
</div>
<span>$50</span>
</div>
</div>
<button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
Review checkout
</button>
</div>
</template>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
<script>
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')
const drawer = window.Drawer.createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Your shopping bag',
description: 'Review the items, quantities and subtotal before continuing.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const choices = [...body.querySelectorAll('button[data-demo-choice]')]
choices.forEach(button =>
button.addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent =
'Selected:' + ' ' + button.dataset.demoChoice
drawer.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
Package / ESM
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Drawer playground</title>
</head>
<body>
<main>
<button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
Open drawer
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
<h3>Good things, ready to go.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>Natural canvas · Qty 1</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Studio notebook</strong>
<p>Dotted pages · Qty 1</p>
</div>
<span>$18</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Subtotal</strong>
<p>Delivery is chosen at checkout.</p>
</div>
<span>$50</span>
</div>
</div>
<button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
Review checkout
</button>
</div>
</template>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
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;
}
JavaScript
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')
const drawer = createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Your shopping bag',
description: 'Review the items, quantities and subtotal before continuing.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const choices = [...body.querySelectorAll('button[data-demo-choice]')]
choices.forEach(button =>
button.addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent =
'Selected:' + ' ' + button.dataset.demoChoice
drawer.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
Complete file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Drawer playground</title>
<style>
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;
}
</style>
</head>
<body>
<main>
<button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
Open drawer
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
<h3>Good things, ready to go.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>Natural canvas · Qty 1</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Studio notebook</strong>
<p>Dotted pages · Qty 1</p>
</div>
<span>$18</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Subtotal</strong>
<p>Delivery is chosen at checkout.</p>
</div>
<span>$50</span>
</div>
</div>
<button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
Review checkout
</button>
</div>
</template>
</main>
<script type="module">
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')
const drawer = createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Your shopping bag',
description: 'Review the items, quantities and subtotal before continuing.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const choices = [...body.querySelectorAll('button[data-demo-choice]')]
choices.forEach(button =>
button.addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent =
'Selected:' + ' ' + button.dataset.demoChoice
drawer.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
The package stylesheet supplies motion and the handle. The example stylesheet supplies panel position, dimensions, colors and focus styles. Keep that import order. Drawer owns dismissal, focus management and scroll locking; your application owns accessible content and instance cleanup.
Next steps
- Use React, Vue, Svelte or Astro with the same browser API.
- Explore working examples for all four edges, snap points and nested flows.
- Style your panel with the runtime’s documented data attributes.
- Understand the runtime contract for lifecycle side effects and callbacks.
- Review options when you need more control.
- Use Drawer with your agent through the versioned integration skill.
Looking for the former runtime sections?
These sections now live in the runtime contract. Existing installation fragments remain available here.