- Docs
- Working examples
Working examples
Eighteen runnable Drawer integrations, with complete and separately copyable HTML, CSS and JavaScript.
The previews use the package’s public API from this checkout. Choose Package / ESM for a bundler or HTML / CDN for the pinned 5.1.2 standalone bundle and stylesheet. Save the split files together, or open a complete HTML file. Your application owns the geometry and colors; Drawer owns gestures and modal behavior.
Bottom sheet
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.
Explore the code
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>
Side panel
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
Carry a little less.
A lightweight canvas bag for the daily essentials.
Recycled cotton · 38 × 42 cm · In stock
Explore the code
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">THE EVERYDAY COLLECTION</p>
<h3>Carry a little less.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>A lightweight canvas bag for the daily essentials.</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Materials and fit</strong>
<p>Recycled cotton · 38 × 42 cm · In stock</p>
</div>
<span>14 L</span>
</div>
</div>
<button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
Add to your shortlist
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'right',
title: 'Everyday tote',
description: 'Review materials, dimensions and price before shortlisting this item.',
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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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">THE EVERYDAY COLLECTION</p>
<h3>Carry a little less.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>A lightweight canvas bag for the daily essentials.</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Materials and fit</strong>
<p>Recycled cotton · 38 × 42 cm · In stock</p>
</div>
<span>14 L</span>
</div>
</div>
<button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
Add to your shortlist
</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: 'right',
title: 'Everyday tote',
description: 'Review materials, dimensions and price before shortlisting this item.',
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">THE EVERYDAY COLLECTION</p>
<h3>Carry a little less.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>A lightweight canvas bag for the daily essentials.</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Materials and fit</strong>
<p>Recycled cotton · 38 × 42 cm · In stock</p>
</div>
<span>14 L</span>
</div>
</div>
<button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
Add to your shortlist
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'right',
title: 'Everyday tote',
description: 'Review materials, dimensions and price before shortlisting this item.',
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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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">THE EVERYDAY COLLECTION</p>
<h3>Carry a little less.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote</strong>
<p>A lightweight canvas bag for the daily essentials.</p>
</div>
<span>$32</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Materials and fit</strong>
<p>Recycled cotton · 38 × 42 cm · In stock</p>
</div>
<span>14 L</span>
</div>
</div>
<button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
Add to your shortlist
</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: 'right',
title: 'Everyday tote',
description: 'Review materials, dimensions and price before shortlisting this item.',
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>
Change direction to top or left and supply matching positioning rules. See all four directions.
Top panel
QUICK COMMANDS
What would you like to do?
Keep quick actions within reach, then dismiss the panel to return to your page.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
QUICK COMMANDS
What would you like to do?
No commands match. Try another name.
Find a command by typing a project, document or teammate action.
Explore the code
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">QUICK COMMANDS</p>
<h3>What would you like to do?</h3>
<label
>Search commands<input
type="search"
data-demo-search
placeholder="Try project, document or teammate…"
data-drawer-no-drag
/></label>
<div
class="demo-menu"
role="group"
aria-label="What would you like to do?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Create a project">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 5v14M5 12h14" /></svg></span
><span class="demo-menu-copy"
><strong>Create a project</strong><span>Start with a clean canvas</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m20 20-4.2-4.2" /></svg></span
><span class="demo-menu-copy"
><strong>Find a document</strong><span>Search your workspace</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
><span class="demo-menu-copy"
><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p data-demo-empty hidden role="status">No commands match. Try another name.</p>
<p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
</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;
top: 0;
left: 0;
right: 0;
border-radius: 0 0 1.5rem 1.5rem;
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: 'top',
title: 'Quick actions',
description: 'Search for a workspace command and choose your next action.',
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 }
)
)
body.querySelector('[data-demo-search]').addEventListener(
'input',
event => {
const query = event.currentTarget.value.trim().toLocaleLowerCase()
choices.forEach(button => {
button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
})
body.querySelector('[data-demo-empty]').hidden = choices.some(button => !button.hidden)
},
{ 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;
top: 0;
left: 0;
right: 0;
border-radius: 0 0 1.5rem 1.5rem;
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">QUICK COMMANDS</p>
<h3>What would you like to do?</h3>
<label
>Search commands<input
type="search"
data-demo-search
placeholder="Try project, document or teammate…"
data-drawer-no-drag
/></label>
<div
class="demo-menu"
role="group"
aria-label="What would you like to do?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Create a project">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 5v14M5 12h14" /></svg></span
><span class="demo-menu-copy"
><strong>Create a project</strong><span>Start with a clean canvas</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m20 20-4.2-4.2" /></svg></span
><span class="demo-menu-copy"
><strong>Find a document</strong><span>Search your workspace</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
><span class="demo-menu-copy"
><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p data-demo-empty hidden role="status">No commands match. Try another name.</p>
<p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
</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: 'top',
title: 'Quick actions',
description: 'Search for a workspace command and choose your next action.',
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 }
)
)
body.querySelector('[data-demo-search]').addEventListener(
'input',
event => {
const query = event.currentTarget.value.trim().toLocaleLowerCase()
choices.forEach(button => {
button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
})
body.querySelector('[data-demo-empty]').hidden = choices.some(
button => !button.hidden
)
},
{ 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">QUICK COMMANDS</p>
<h3>What would you like to do?</h3>
<label
>Search commands<input
type="search"
data-demo-search
placeholder="Try project, document or teammate…"
data-drawer-no-drag
/></label>
<div
class="demo-menu"
role="group"
aria-label="What would you like to do?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Create a project">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 5v14M5 12h14" /></svg></span
><span class="demo-menu-copy"
><strong>Create a project</strong><span>Start with a clean canvas</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m20 20-4.2-4.2" /></svg></span
><span class="demo-menu-copy"
><strong>Find a document</strong><span>Search your workspace</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
><span class="demo-menu-copy"
><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p data-demo-empty hidden role="status">No commands match. Try another name.</p>
<p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
</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;
top: 0;
left: 0;
right: 0;
border-radius: 0 0 1.5rem 1.5rem;
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: 'top',
title: 'Quick actions',
description: 'Search for a workspace command and choose your next action.',
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 }
)
)
body.querySelector('[data-demo-search]').addEventListener(
'input',
event => {
const query = event.currentTarget.value.trim().toLocaleLowerCase()
choices.forEach(button => {
button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
})
body.querySelector('[data-demo-empty]').hidden = choices.some(button => !button.hidden)
},
{ 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;
top: 0;
left: 0;
right: 0;
border-radius: 0 0 1.5rem 1.5rem;
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">QUICK COMMANDS</p>
<h3>What would you like to do?</h3>
<label
>Search commands<input
type="search"
data-demo-search
placeholder="Try project, document or teammate…"
data-drawer-no-drag
/></label>
<div
class="demo-menu"
role="group"
aria-label="What would you like to do?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Create a project">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 5v14M5 12h14" /></svg></span
><span class="demo-menu-copy"
><strong>Create a project</strong><span>Start with a clean canvas</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m20 20-4.2-4.2" /></svg></span
><span class="demo-menu-copy"
><strong>Find a document</strong><span>Search your workspace</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
><span class="demo-menu-copy"
><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p data-demo-empty hidden role="status">No commands match. Try another name.</p>
<p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
</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: 'top',
title: 'Quick actions',
description: 'Search for a workspace command and choose your next action.',
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 }
)
)
body.querySelector('[data-demo-search]').addEventListener(
'input',
event => {
const query = event.currentTarget.value.trim().toLocaleLowerCase()
choices.forEach(button => {
button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
})
body.querySelector('[data-demo-empty]').hidden = choices.some(
button => !button.hidden
)
},
{ 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>
Left navigation
STUDIO / WORKSPACE
A place for your next idea.
Open navigation from the left edge without leaving the current page.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
STUDIO / WORKSPACE
A place for your next idea.
Browse projects, invite your team or change workspace settings.
Explore the code
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">STUDIO / WORKSPACE</p>
<h3>A place for your next idea.</h3>
<div
class="demo-menu"
role="group"
aria-label="A place for your next idea."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Overview">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg></span
><span class="demo-menu-copy"
><strong>Overview</strong><span>Your projects at a glance</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Projects">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
><span class="demo-menu-copy"
><strong>Projects</strong><span>12 active projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Team">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path
d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
/></svg></span
><span class="demo-menu-copy"
><strong>Team</strong><span>People and permissions</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Settings</strong><span>Make this space yours</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
</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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'left',
title: 'Studio workspace',
description: 'Choose a project, team or workspace settings destination.',
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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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">STUDIO / WORKSPACE</p>
<h3>A place for your next idea.</h3>
<div
class="demo-menu"
role="group"
aria-label="A place for your next idea."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Overview">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg></span
><span class="demo-menu-copy"
><strong>Overview</strong><span>Your projects at a glance</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Projects">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
><span class="demo-menu-copy"
><strong>Projects</strong><span>12 active projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Team">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path
d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
/></svg></span
><span class="demo-menu-copy"
><strong>Team</strong><span>People and permissions</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Settings</strong><span>Make this space yours</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
</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: 'left',
title: 'Studio workspace',
description: 'Choose a project, team or workspace settings destination.',
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">STUDIO / WORKSPACE</p>
<h3>A place for your next idea.</h3>
<div
class="demo-menu"
role="group"
aria-label="A place for your next idea."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Overview">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg></span
><span class="demo-menu-copy"
><strong>Overview</strong><span>Your projects at a glance</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Projects">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
><span class="demo-menu-copy"
><strong>Projects</strong><span>12 active projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Team">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path
d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
/></svg></span
><span class="demo-menu-copy"
><strong>Team</strong><span>People and permissions</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Settings</strong><span>Make this space yours</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
</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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'left',
title: 'Studio workspace',
description: 'Choose a project, team or workspace settings destination.',
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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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">STUDIO / WORKSPACE</p>
<h3>A place for your next idea.</h3>
<div
class="demo-menu"
role="group"
aria-label="A place for your next idea."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Overview">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg></span
><span class="demo-menu-copy"
><strong>Overview</strong><span>Your projects at a glance</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Projects">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
><span class="demo-menu-copy"
><strong>Projects</strong><span>12 active projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Team">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="8" r="4" />
<path
d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
/></svg></span
><span class="demo-menu-copy"
><strong>Team</strong><span>People and permissions</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Settings</strong><span>Make this space yours</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
</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: 'left',
title: 'Studio workspace',
description: 'Choose a project, team or workspace settings destination.',
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>
Snap points
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
A day with room to wander.
Start slowly with a neighborhood walk.
Art, a picnic and a little fresh air.
Leave the evening open for something new.
Explore the code
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">WEEKEND IN MEXICO CITY</p>
<h3>A day with room to wander.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Coffee in Roma Norte</strong>
<p>Start slowly with a neighborhood walk.</p>
</div>
<span>09:00</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Explore Chapultepec</strong>
<p>Art, a picnic and a little fresh air.</p>
</div>
<span>11:30</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Dinner with friends</strong>
<p>Leave the evening open for something new.</p>
</div>
<span>19:00</span>
</div>
</div>
</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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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 day in Mexico City',
description: 'Browse the stops and times in this sample day itinerary.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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">WEEKEND IN MEXICO CITY</p>
<h3>A day with room to wander.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Coffee in Roma Norte</strong>
<p>Start slowly with a neighborhood walk.</p>
</div>
<span>09:00</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Explore Chapultepec</strong>
<p>Art, a picnic and a little fresh air.</p>
</div>
<span>11:30</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Dinner with friends</strong>
<p>Leave the evening open for something new.</p>
</div>
<span>19:00</span>
</div>
</div>
</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 day in Mexico City',
description: 'Browse the stops and times in this sample day itinerary.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
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">WEEKEND IN MEXICO CITY</p>
<h3>A day with room to wander.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Coffee in Roma Norte</strong>
<p>Start slowly with a neighborhood walk.</p>
</div>
<span>09:00</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Explore Chapultepec</strong>
<p>Art, a picnic and a little fresh air.</p>
</div>
<span>11:30</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Dinner with friends</strong>
<p>Leave the evening open for something new.</p>
</div>
<span>19:00</span>
</div>
</div>
</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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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 day in Mexico City',
description: 'Browse the stops and times in this sample day itinerary.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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">WEEKEND IN MEXICO CITY</p>
<h3>A day with room to wander.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Coffee in Roma Norte</strong>
<p>Start slowly with a neighborhood walk.</p>
</div>
<span>09:00</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Explore Chapultepec</strong>
<p>Art, a picnic and a little fresh air.</p>
</div>
<span>11:30</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Dinner with friends</strong>
<p>Leave the evening open for something new.</p>
</div>
<span>19:00</span>
</div>
</div>
</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 day in Mexico City',
description: 'Browse the stops and times in this sample day itinerary.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
The points are ordered visible sizes. Numeric 1 means zero offset; fractional stops track the viewport. Pixel strings are also supported and use integer pixel counts. The handle cycles through the points. Learn about gestures and snap points.
Nested flow
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
Review your delivery.
Two items · subtotal before delivery.
Choose a delivery option below.
No delivery selected
Explore the code
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">CHECKOUT / DELIVERY</p>
<h3>Review your delivery.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote + Studio notebook</strong>
<p>Two items · subtotal before delivery.</p>
</div>
<span>$50</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Delivery options</strong>
<p>Choose a delivery option below.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" /></svg
></span>
</div>
</div>
<p data-delivery-summary role="status">No delivery selected</p>
<template data-delivery-content
><div class="demo-body">
<div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
<button
type="button"
class="demo-menu-item"
data-demo-delivery="Standard delivery · $0 · 3–5 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
<path d="m3 8 9 5 9-5M12 13v8" /></svg></span
><span class="demo-menu-copy"
><strong>Standard delivery</strong
><span>Free · Arrives in 3–5 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button
type="button"
class="demo-menu-item"
data-demo-delivery="Express delivery · $8 · 1–2 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
><span class="demo-menu-copy"
><strong>Express delivery</strong
><span>$8 · Arrives in 1–2 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div></div></template
><button type="button" data-child data-drawer-no-drag>Choose delivery</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')
let child
const drawer = window.Drawer.createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Order summary',
description: 'Choose delivery while keeping your two items and subtotal in view.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-child]').addEventListener(
'click',
() => {
const deliveryContent = () => {
const choices = body
.querySelector('[data-delivery-content]')
.content.firstElementChild.cloneNode(true)
choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
button.addEventListener(
'click',
() => {
body.querySelector('[data-delivery-summary]').textContent =
button.dataset.demoDelivery
child.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return choices
}
if (child) child.update({ content: deliveryContent })
child ??= window.Drawer.createDrawer({
id: 'example-child',
parentId: 'example',
title: 'Choose your delivery',
description: 'Compare the cost and arrival time. Your order stays open underneath.',
content: deliveryContent,
autoFocus: true,
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close child' },
})
child.setOpen(true)
},
{ 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">CHECKOUT / DELIVERY</p>
<h3>Review your delivery.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote + Studio notebook</strong>
<p>Two items · subtotal before delivery.</p>
</div>
<span>$50</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Delivery options</strong>
<p>Choose a delivery option below.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" /></svg
></span>
</div>
</div>
<p data-delivery-summary role="status">No delivery selected</p>
<template data-delivery-content
><div class="demo-body">
<div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
<button
type="button"
class="demo-menu-item"
data-demo-delivery="Standard delivery · $0 · 3–5 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
<path d="m3 8 9 5 9-5M12 13v8" /></svg></span
><span class="demo-menu-copy"
><strong>Standard delivery</strong
><span>Free · Arrives in 3–5 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button
type="button"
class="demo-menu-item"
data-demo-delivery="Express delivery · $8 · 1–2 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
><span class="demo-menu-copy"
><strong>Express delivery</strong
><span>$8 · Arrives in 1–2 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div></div></template
><button type="button" data-child data-drawer-no-drag>Choose delivery</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')
let child
const drawer = window.Drawer.createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Order summary',
description: 'Choose delivery while keeping your two items and subtotal in view.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-child]').addEventListener(
'click',
() => {
const deliveryContent = () => {
const choices = body
.querySelector('[data-delivery-content]')
.content.firstElementChild.cloneNode(true)
choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
button.addEventListener(
'click',
() => {
body.querySelector('[data-delivery-summary]').textContent =
button.dataset.demoDelivery
child.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return choices
}
if (child) child.update({ content: deliveryContent })
child ??= window.Drawer.createDrawer({
id: 'example-child',
parentId: 'example',
title: 'Choose your delivery',
description: 'Compare the cost and arrival time. Your order stays open underneath.',
content: deliveryContent,
autoFocus: true,
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close child' },
})
child.setOpen(true)
},
{ 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">CHECKOUT / DELIVERY</p>
<h3>Review your delivery.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote + Studio notebook</strong>
<p>Two items · subtotal before delivery.</p>
</div>
<span>$50</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Delivery options</strong>
<p>Choose a delivery option below.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" /></svg
></span>
</div>
</div>
<p data-delivery-summary role="status">No delivery selected</p>
<template data-delivery-content
><div class="demo-body">
<div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
<button
type="button"
class="demo-menu-item"
data-demo-delivery="Standard delivery · $0 · 3–5 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
<path d="m3 8 9 5 9-5M12 13v8" /></svg></span
><span class="demo-menu-copy"
><strong>Standard delivery</strong
><span>Free · Arrives in 3–5 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button
type="button"
class="demo-menu-item"
data-demo-delivery="Express delivery · $8 · 1–2 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
><span class="demo-menu-copy"
><strong>Express delivery</strong
><span>$8 · Arrives in 1–2 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div></div></template
><button type="button" data-child data-drawer-no-drag>Choose delivery</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')
let child
const drawer = createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Order summary',
description: 'Choose delivery while keeping your two items and subtotal in view.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-child]').addEventListener(
'click',
() => {
const deliveryContent = () => {
const choices = body
.querySelector('[data-delivery-content]')
.content.firstElementChild.cloneNode(true)
choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
button.addEventListener(
'click',
() => {
body.querySelector('[data-delivery-summary]').textContent =
button.dataset.demoDelivery
child.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return choices
}
if (child) child.update({ content: deliveryContent })
child ??= createDrawer({
id: 'example-child',
parentId: 'example',
title: 'Choose your delivery',
description: 'Compare the cost and arrival time. Your order stays open underneath.',
content: deliveryContent,
autoFocus: true,
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close child' },
})
child.setOpen(true)
},
{ 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">CHECKOUT / DELIVERY</p>
<h3>Review your delivery.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Everyday tote + Studio notebook</strong>
<p>Two items · subtotal before delivery.</p>
</div>
<span>$50</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Delivery options</strong>
<p>Choose a delivery option below.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" /></svg
></span>
</div>
</div>
<p data-delivery-summary role="status">No delivery selected</p>
<template data-delivery-content
><div class="demo-body">
<div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
<button
type="button"
class="demo-menu-item"
data-demo-delivery="Standard delivery · $0 · 3–5 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
<path d="m3 8 9 5 9-5M12 13v8" /></svg></span
><span class="demo-menu-copy"
><strong>Standard delivery</strong
><span>Free · Arrives in 3–5 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button
type="button"
class="demo-menu-item"
data-demo-delivery="Express delivery · $8 · 1–2 business days"
>
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
><span class="demo-menu-copy"
><strong>Express delivery</strong
><span>$8 · Arrives in 1–2 business days</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div></div></template
><button type="button" data-child data-drawer-no-drag>Choose delivery</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')
let child
const drawer = createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'bottom',
title: 'Order summary',
description: 'Choose delivery while keeping your two items and subtotal in view.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-child]').addEventListener(
'click',
() => {
const deliveryContent = () => {
const choices = body
.querySelector('[data-delivery-content]')
.content.firstElementChild.cloneNode(true)
choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
button.addEventListener(
'click',
() => {
body.querySelector('[data-delivery-summary]').textContent =
button.dataset.demoDelivery
child.setOpen(false)
},
{ signal: lifecycle.signal }
)
)
return choices
}
if (child) child.update({ content: deliveryContent })
child ??= createDrawer({
id: 'example-child',
parentId: 'example',
title: 'Choose your delivery',
description: 'Compare the cost and arrival time. Your order stays open underneath.',
content: deliveryContent,
autoFocus: true,
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close child' },
})
child.setOpen(true)
},
{ 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>
Choose Standard or Express delivery to update the order summary; only the child closes. The child is related with parentId. Closing it leaves its parent open; destroying the parent also destroys its child. Keep ids unique when using these examples together.
Apply filters
Your page, uninterrupted
Keep the context.
Choose a category and apply it. A labeled form owns the input; Drawer owns focus and dismissal.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
Explore the code
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">
<form data-demo-form data-drawer-no-drag>
<label for="category">Category</label
><select id="category" name="category">
<option>All products</option>
<option>Books</option>
<option>Tools</option></select
><label
>Sort by<select name="sort">
<option>Recommended</option>
<option>Newest first</option>
<option>Price: low to high</option>
</select></label
>
<p class="demo-hint">
Narrow the collection, then return to browsing. Your selection is reported below the
preview.
</p>
<button type="submit">Apply filters</button>
</form>
</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: 'Filter the collection',
description: 'Choose a category and sort order for the collection.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('form').addEventListener(
'submit',
event => {
event.preventDefault()
const values = new FormData(event.currentTarget)
const category = values.get('category')
const sort = values.get('sort')
document.getElementById('demo-result').textContent =
'Selected category:' + ' ' + category + ' · ' + sort
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">
<form data-demo-form data-drawer-no-drag>
<label for="category">Category</label
><select id="category" name="category">
<option>All products</option>
<option>Books</option>
<option>Tools</option></select
><label
>Sort by<select name="sort">
<option>Recommended</option>
<option>Newest first</option>
<option>Price: low to high</option>
</select></label
>
<p class="demo-hint">
Narrow the collection, then return to browsing. Your selection is reported below the
preview.
</p>
<button type="submit">Apply filters</button>
</form>
</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: 'Filter the collection',
description: 'Choose a category and sort order for the collection.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('form').addEventListener(
'submit',
event => {
event.preventDefault()
const values = new FormData(event.currentTarget)
const category = values.get('category')
const sort = values.get('sort')
document.getElementById('demo-result').textContent =
'Selected category:' + ' ' + category + ' · ' + sort
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">
<form data-demo-form data-drawer-no-drag>
<label for="category">Category</label
><select id="category" name="category">
<option>All products</option>
<option>Books</option>
<option>Tools</option></select
><label
>Sort by<select name="sort">
<option>Recommended</option>
<option>Newest first</option>
<option>Price: low to high</option>
</select></label
>
<p class="demo-hint">
Narrow the collection, then return to browsing. Your selection is reported below the
preview.
</p>
<button type="submit">Apply filters</button>
</form>
</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: 'Filter the collection',
description: 'Choose a category and sort order for the collection.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('form').addEventListener(
'submit',
event => {
event.preventDefault()
const values = new FormData(event.currentTarget)
const category = values.get('category')
const sort = values.get('sort')
document.getElementById('demo-result').textContent =
'Selected category:' + ' ' + category + ' · ' + sort
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">
<form data-demo-form data-drawer-no-drag>
<label for="category">Category</label
><select id="category" name="category">
<option>All products</option>
<option>Books</option>
<option>Tools</option></select
><label
>Sort by<select name="sort">
<option>Recommended</option>
<option>Newest first</option>
<option>Price: low to high</option>
</select></label
>
<p class="demo-hint">
Narrow the collection, then return to browsing. Your selection is reported below the
preview.
</p>
<button type="submit">Apply filters</button>
</form>
</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: 'Filter the collection',
description: 'Choose a category and sort order for the collection.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('form').addEventListener(
'submit',
event => {
event.preventDefault()
const values = new FormData(event.currentTarget)
const category = values.get('category')
const sort = values.get('sort')
document.getElementById('demo-result').textContent =
'Selected category:' + ' ' + category + ' · ' + sort
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>
A native labeled form reads its selected category with FormData, reports the result outside the drawer and calls setOpen(false). It does not submit a network request.
Scroll long content
Your page, uninterrupted
Keep the context.
Scroll a long panel independently of the page. Its close action stays within reach.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
Project overview
Start a hand-off with the purpose of the project, its intended audience and the decisions already agreed with the team. Link the source repository and identify which journeys must work before release.
Run the project
Record the supported runtime, the package-manager command, the development command and the production build command. List required environment variable names, with safe sample values rather than credentials. Ask a teammate to try these steps on a fresh checkout.
Design assets
Point to the approved fonts, color tokens, icons and image sources. Note license requirements and where editable assets live. Keep the component inventory close to the design files so changes can be made in the right shared owner.
Keyboard review
Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible focus, names on icon buttons, form labels and focus restoration after overlays close. Include narrow layouts and enlarged text in the review.
Forms and error states
Document required fields, validation messages, successful submissions and recovery from a failed request. Use representative empty and long values. Make the result visible and distinguish a local demonstration from a connected service.
Loading and content
Explain empty, loading, error and populated states. Reserve space for media, keep useful content readable without JavaScript where practical, and identify who can edit public copy. Remove placeholders before release.
Deployment checklist
Record the build artifact, public base path, redirect requirements and rollback procedure. Verify a production build, internal anchors and important external destinations. Confirm the deployed revision before calling a release complete.
Ownership and follow-up
Name the maintainer for code, content and releases. Capture known limits honestly, link the relevant checks, and agree how future package or design changes update examples and documentation. A useful hand-off lets the next person repeat the work.
Explore the code
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" tabindex="0" role="region" aria-label="Drawer reading area">
<section>
<h3>Project overview</h3>
<p>
Start a hand-off with the purpose of the project, its intended audience and the
decisions already agreed with the team. Link the source repository and identify which
journeys must work before release.
</p>
</section>
<section>
<h3>Run the project</h3>
<p>
Record the supported runtime, the package-manager command, the development command and
the production build command. List required environment variable names, with safe
sample values rather than credentials. Ask a teammate to try these steps on a fresh
checkout.
</p>
</section>
<section>
<h3>Design assets</h3>
<p>
Point to the approved fonts, color tokens, icons and image sources. Note license
requirements and where editable assets live. Keep the component inventory close to the
design files so changes can be made in the right shared owner.
</p>
</section>
<section>
<h3>Keyboard review</h3>
<p>
Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
focus, names on icon buttons, form labels and focus restoration after overlays close.
Include narrow layouts and enlarged text in the review.
</p>
</section>
<section>
<h3>Forms and error states</h3>
<p>
Document required fields, validation messages, successful submissions and recovery
from a failed request. Use representative empty and long values. Make the result
visible and distinguish a local demonstration from a connected service.
</p>
</section>
<section>
<h3>Loading and content</h3>
<p>
Explain empty, loading, error and populated states. Reserve space for media, keep
useful content readable without JavaScript where practical, and identify who can edit
public copy. Remove placeholders before release.
</p>
</section>
<section>
<h3>Deployment checklist</h3>
<p>
Record the build artifact, public base path, redirect requirements and rollback
procedure. Verify a production build, internal anchors and important external
destinations. Confirm the deployed revision before calling a release complete.
</p>
</section>
<section>
<h3>Ownership and follow-up</h3>
<p>
Name the maintainer for code, content and releases. Capture known limits honestly,
link the relevant checks, and agree how future package or design changes update
examples and documentation. A useful hand-off lets the next person repeat the work.
</p>
</section>
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'right',
title: 'Project hand-off guide',
description: 'Read the practical steps for handing a project to its next maintainer.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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" tabindex="0" role="region" aria-label="Drawer reading area">
<section>
<h3>Project overview</h3>
<p>
Start a hand-off with the purpose of the project, its intended audience and the
decisions already agreed with the team. Link the source repository and identify which
journeys must work before release.
</p>
</section>
<section>
<h3>Run the project</h3>
<p>
Record the supported runtime, the package-manager command, the development command and
the production build command. List required environment variable names, with safe
sample values rather than credentials. Ask a teammate to try these steps on a fresh
checkout.
</p>
</section>
<section>
<h3>Design assets</h3>
<p>
Point to the approved fonts, color tokens, icons and image sources. Note license
requirements and where editable assets live. Keep the component inventory close to the
design files so changes can be made in the right shared owner.
</p>
</section>
<section>
<h3>Keyboard review</h3>
<p>
Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
focus, names on icon buttons, form labels and focus restoration after overlays close.
Include narrow layouts and enlarged text in the review.
</p>
</section>
<section>
<h3>Forms and error states</h3>
<p>
Document required fields, validation messages, successful submissions and recovery
from a failed request. Use representative empty and long values. Make the result
visible and distinguish a local demonstration from a connected service.
</p>
</section>
<section>
<h3>Loading and content</h3>
<p>
Explain empty, loading, error and populated states. Reserve space for media, keep
useful content readable without JavaScript where practical, and identify who can edit
public copy. Remove placeholders before release.
</p>
</section>
<section>
<h3>Deployment checklist</h3>
<p>
Record the build artifact, public base path, redirect requirements and rollback
procedure. Verify a production build, internal anchors and important external
destinations. Confirm the deployed revision before calling a release complete.
</p>
</section>
<section>
<h3>Ownership and follow-up</h3>
<p>
Name the maintainer for code, content and releases. Capture known limits honestly,
link the relevant checks, and agree how future package or design changes update
examples and documentation. A useful hand-off lets the next person repeat the work.
</p>
</section>
</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: 'right',
title: 'Project hand-off guide',
description: 'Read the practical steps for handing a project to its next maintainer.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
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" tabindex="0" role="region" aria-label="Drawer reading area">
<section>
<h3>Project overview</h3>
<p>
Start a hand-off with the purpose of the project, its intended audience and the
decisions already agreed with the team. Link the source repository and identify which
journeys must work before release.
</p>
</section>
<section>
<h3>Run the project</h3>
<p>
Record the supported runtime, the package-manager command, the development command and
the production build command. List required environment variable names, with safe
sample values rather than credentials. Ask a teammate to try these steps on a fresh
checkout.
</p>
</section>
<section>
<h3>Design assets</h3>
<p>
Point to the approved fonts, color tokens, icons and image sources. Note license
requirements and where editable assets live. Keep the component inventory close to the
design files so changes can be made in the right shared owner.
</p>
</section>
<section>
<h3>Keyboard review</h3>
<p>
Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
focus, names on icon buttons, form labels and focus restoration after overlays close.
Include narrow layouts and enlarged text in the review.
</p>
</section>
<section>
<h3>Forms and error states</h3>
<p>
Document required fields, validation messages, successful submissions and recovery
from a failed request. Use representative empty and long values. Make the result
visible and distinguish a local demonstration from a connected service.
</p>
</section>
<section>
<h3>Loading and content</h3>
<p>
Explain empty, loading, error and populated states. Reserve space for media, keep
useful content readable without JavaScript where practical, and identify who can edit
public copy. Remove placeholders before release.
</p>
</section>
<section>
<h3>Deployment checklist</h3>
<p>
Record the build artifact, public base path, redirect requirements and rollback
procedure. Verify a production build, internal anchors and important external
destinations. Confirm the deployed revision before calling a release complete.
</p>
</section>
<section>
<h3>Ownership and follow-up</h3>
<p>
Name the maintainer for code, content and releases. Capture known limits honestly,
link the relevant checks, and agree how future package or design changes update
examples and documentation. A useful hand-off lets the next person repeat the work.
</p>
</section>
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'right',
title: 'Project hand-off guide',
description: 'Read the practical steps for handing a project to its next maintainer.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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" tabindex="0" role="region" aria-label="Drawer reading area">
<section>
<h3>Project overview</h3>
<p>
Start a hand-off with the purpose of the project, its intended audience and the
decisions already agreed with the team. Link the source repository and identify which
journeys must work before release.
</p>
</section>
<section>
<h3>Run the project</h3>
<p>
Record the supported runtime, the package-manager command, the development command and
the production build command. List required environment variable names, with safe
sample values rather than credentials. Ask a teammate to try these steps on a fresh
checkout.
</p>
</section>
<section>
<h3>Design assets</h3>
<p>
Point to the approved fonts, color tokens, icons and image sources. Note license
requirements and where editable assets live. Keep the component inventory close to the
design files so changes can be made in the right shared owner.
</p>
</section>
<section>
<h3>Keyboard review</h3>
<p>
Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
focus, names on icon buttons, form labels and focus restoration after overlays close.
Include narrow layouts and enlarged text in the review.
</p>
</section>
<section>
<h3>Forms and error states</h3>
<p>
Document required fields, validation messages, successful submissions and recovery
from a failed request. Use representative empty and long values. Make the result
visible and distinguish a local demonstration from a connected service.
</p>
</section>
<section>
<h3>Loading and content</h3>
<p>
Explain empty, loading, error and populated states. Reserve space for media, keep
useful content readable without JavaScript where practical, and identify who can edit
public copy. Remove placeholders before release.
</p>
</section>
<section>
<h3>Deployment checklist</h3>
<p>
Record the build artifact, public base path, redirect requirements and rollback
procedure. Verify a production build, internal anchors and important external
destinations. Confirm the deployed revision before calling a release complete.
</p>
</section>
<section>
<h3>Ownership and follow-up</h3>
<p>
Name the maintainer for code, content and releases. Capture known limits honestly,
link the relevant checks, and agree how future package or design changes update
examples and documentation. A useful hand-off lets the next person repeat the work.
</p>
</section>
</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: 'right',
title: 'Project hand-off guide',
description: 'Read the practical steps for handing a project to its next maintainer.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
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 panel has its own scroll container and a sticky close button. Test wheel, keyboard and touch scrolling without moving the underlying page.
Non-modal inspector
LAYOUT INSPECTOR
Work beside your canvas.
A non-modal inspector has no backdrop or focus trap. You can still use the page while it is open.
Toggle the canvas grid, then use the page action without closing the inspector. No backdrop, focus trap or page scroll lock.
LAYOUT INSPECTOR
Work beside your canvas.
Editing the hero of a product landing page.
Toggle the layout grid while the canvas stays interactive.
Explore the code
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>
<button type="button" id="page-action">Try a page action</button>
<div id="canvas" class="demo-canvas">
<h2>A canvas you can keep editing</h2>
<p>
Use the inspector to reveal its layout grid, or try the page action while the inspector
stays open.
</p>
</div>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">LAYOUT INSPECTOR</p>
<h3>Work beside your canvas.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Selected: Hero section</strong>
<p>Editing the hero of a product landing page.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Canvas layout</strong>
<p>Toggle the layout grid while the canvas stays interactive.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg
></span>
</div>
</div>
<label class="demo-field-inline" data-drawer-no-drag
><input type="checkbox" data-demo-grid />Show canvas grid</label
>
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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-body label.demo-field-inline {
display: flex;
align-items: center;
gap: 0.75rem;
}
.demo-body .demo-field-inline input {
width: 1.125rem;
height: 1.125rem;
padding: 0;
flex-shrink: 0;
}
.demo-canvas {
margin-top: 1.5rem;
padding: 2rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-canvas[data-grid] {
background-image:
linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
background-size: 1.5rem 1.5rem;
}
.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: 'right',
title: 'Canvas inspector',
description: 'Inspect the hero layout while the canvas remains interactive.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const canvas = document.getElementById('canvas')
const grid = body.querySelector('[data-demo-grid]')
grid.checked = canvas.hasAttribute('data-grid')
grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
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)),
modal: false,
overlay: false,
})
document.getElementById('page-action').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'The page is still interactive.'
},
{ signal: lifecycle.signal }
)
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
document.getElementById('canvas').removeAttribute('data-grid')
},
{ 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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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-body label.demo-field-inline {
display: flex;
align-items: center;
gap: 0.75rem;
}
.demo-body .demo-field-inline input {
width: 1.125rem;
height: 1.125rem;
padding: 0;
flex-shrink: 0;
}
.demo-canvas {
margin-top: 1.5rem;
padding: 2rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-canvas[data-grid] {
background-image:
linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
background-size: 1.5rem 1.5rem;
}
.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>
<button type="button" id="page-action">Try a page action</button>
<div id="canvas" class="demo-canvas">
<h2>A canvas you can keep editing</h2>
<p>
Use the inspector to reveal its layout grid, or try the page action while the inspector
stays open.
</p>
</div>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">LAYOUT INSPECTOR</p>
<h3>Work beside your canvas.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Selected: Hero section</strong>
<p>Editing the hero of a product landing page.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Canvas layout</strong>
<p>Toggle the layout grid while the canvas stays interactive.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg
></span>
</div>
</div>
<label class="demo-field-inline" data-drawer-no-drag
><input type="checkbox" data-demo-grid />Show canvas grid</label
>
</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: 'right',
title: 'Canvas inspector',
description: 'Inspect the hero layout while the canvas remains interactive.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const canvas = document.getElementById('canvas')
const grid = body.querySelector('[data-demo-grid]')
grid.checked = canvas.hasAttribute('data-grid')
grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
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)),
modal: false,
overlay: false,
})
document.getElementById('page-action').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'The page is still interactive.'
},
{ signal: lifecycle.signal }
)
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
document.getElementById('canvas').removeAttribute('data-grid')
},
{ 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>
<button type="button" id="page-action">Try a page action</button>
<div id="canvas" class="demo-canvas">
<h2>A canvas you can keep editing</h2>
<p>
Use the inspector to reveal its layout grid, or try the page action while the inspector
stays open.
</p>
</div>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">LAYOUT INSPECTOR</p>
<h3>Work beside your canvas.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Selected: Hero section</strong>
<p>Editing the hero of a product landing page.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Canvas layout</strong>
<p>Toggle the layout grid while the canvas stays interactive.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg
></span>
</div>
</div>
<label class="demo-field-inline" data-drawer-no-drag
><input type="checkbox" data-demo-grid />Show canvas grid</label
>
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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-body label.demo-field-inline {
display: flex;
align-items: center;
gap: 0.75rem;
}
.demo-body .demo-field-inline input {
width: 1.125rem;
height: 1.125rem;
padding: 0;
flex-shrink: 0;
}
.demo-canvas {
margin-top: 1.5rem;
padding: 2rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-canvas[data-grid] {
background-image:
linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
background-size: 1.5rem 1.5rem;
}
.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: 'right',
title: 'Canvas inspector',
description: 'Inspect the hero layout while the canvas remains interactive.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const canvas = document.getElementById('canvas')
const grid = body.querySelector('[data-demo-grid]')
grid.checked = canvas.hasAttribute('data-grid')
grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
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)),
modal: false,
overlay: false,
})
document.getElementById('page-action').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'The page is still interactive.'
},
{ signal: lifecycle.signal }
)
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
document.getElementById('canvas').removeAttribute('data-grid')
},
{ 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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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-body label.demo-field-inline {
display: flex;
align-items: center;
gap: 0.75rem;
}
.demo-body .demo-field-inline input {
width: 1.125rem;
height: 1.125rem;
padding: 0;
flex-shrink: 0;
}
.demo-canvas {
margin-top: 1.5rem;
padding: 2rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-canvas[data-grid] {
background-image:
linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
background-size: 1.5rem 1.5rem;
}
.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>
<button type="button" id="page-action">Try a page action</button>
<div id="canvas" class="demo-canvas">
<h2>A canvas you can keep editing</h2>
<p>
Use the inspector to reveal its layout grid, or try the page action while the inspector
stays open.
</p>
</div>
<template id="drawer-content">
<div class="demo-body">
<p class="demo-kicker">LAYOUT INSPECTOR</p>
<h3>Work beside your canvas.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Selected: Hero section</strong>
<p>Editing the hero of a product landing page.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Canvas layout</strong>
<p>Toggle the layout grid while the canvas stays interactive.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg
></span>
</div>
</div>
<label class="demo-field-inline" data-drawer-no-drag
><input type="checkbox" data-demo-grid />Show canvas grid</label
>
</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: 'right',
title: 'Canvas inspector',
description: 'Inspect the hero layout while the canvas remains interactive.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
const canvas = document.getElementById('canvas')
const grid = body.querySelector('[data-demo-grid]')
grid.checked = canvas.hasAttribute('data-grid')
grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
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)),
modal: false,
overlay: false,
})
document.getElementById('page-action').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'The page is still interactive.'
},
{ signal: lifecycle.signal }
)
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
document.getElementById('canvas').removeAttribute('data-grid')
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
Toggle Show canvas grid to change the preview behind the panel, then try the page action while it remains open. modal: false and overlay: false leave the background interactive. This intentionally does not trap focus or isolate the page; choose it for an inspector, not a blocking confirmation.
Handle-only dragging
IDEAS / QUICK NOTE
Catch an idea before it goes.
Select text and use inputs normally. Only a drag that starts on the handle moves this sheet.
Drag only the native handle. Content gestures and keyboard controls remain independent.
IDEAS / QUICK NOTE
Catch an idea before it goes.
Check keyboard navigation, narrow layouts and the installation snippet. Add your review notes below.
Explore the code
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">IDEAS / QUICK NOTE</p>
<h3>Catch an idea before it goes.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Launch review checklist</strong>
<p>
Check keyboard navigation, narrow layouts and the installation snippet. Add your
review notes below.
</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
></span>
</div>
</div>
<label data-drawer-no-drag
>Your notes<textarea placeholder="Select text or write a note…"></textarea>
</label>
</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: 'Review notes',
description: 'Write launch-review feedback while keeping your checklist close.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
handleOnly: true,
})
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">IDEAS / QUICK NOTE</p>
<h3>Catch an idea before it goes.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Launch review checklist</strong>
<p>
Check keyboard navigation, narrow layouts and the installation snippet. Add your
review notes below.
</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
></span>
</div>
</div>
<label data-drawer-no-drag
>Your notes<textarea placeholder="Select text or write a note…"></textarea>
</label>
</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: 'Review notes',
description: 'Write launch-review feedback while keeping your checklist close.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
handleOnly: true,
})
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">IDEAS / QUICK NOTE</p>
<h3>Catch an idea before it goes.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Launch review checklist</strong>
<p>
Check keyboard navigation, narrow layouts and the installation snippet. Add your
review notes below.
</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
></span>
</div>
</div>
<label data-drawer-no-drag
>Your notes<textarea placeholder="Select text or write a note…"></textarea>
</label>
</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: 'Review notes',
description: 'Write launch-review feedback while keeping your checklist close.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
handleOnly: true,
})
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">IDEAS / QUICK NOTE</p>
<h3>Catch an idea before it goes.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Launch review checklist</strong>
<p>
Check keyboard navigation, narrow layouts and the installation snippet. Add your
review notes below.
</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
></span>
</div>
</div>
<label data-drawer-no-drag
>Your notes<textarea placeholder="Select text or write a note…"></textarea>
</label>
</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: 'Review notes',
description: 'Write launch-review feedback while keeping your checklist close.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
return body
},
contentClassName: 'demo-drawer',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
handleOnly: true,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
handleOnly: true restricts dragging to the native handle. The textarea is also marked data-drawer-no-drag. This is useful for text selection, sliders and other content gestures.
Update the same instance
ORDER STUDIO-1042
Follow the next step.
Load another detail into the same instance with update(). No second drawer or global event handler.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
ORDER STUDIO-1042
Follow the next step.
Your tote and notebook are being prepared.
See when your items are packed and what happens next.
Explore the code
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">ORDER STUDIO-1042</p>
<h3>Follow the next step.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Order confirmed</strong>
<p>Your tote and notebook are being prepared.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Next: packed for delivery</strong>
<p>See when your items are packed and what happens next.</p>
</div>
<span>02</span>
</div>
</div>
<button type="button" data-demo-update data-drawer-no-drag>Show packing update</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: 'Order STUDIO-1042',
description: 'Review your order confirmation, then load its packing update.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-demo-update]').addEventListener(
'click',
() => {
drawer.update({
title: 'Packed and ready to go',
content:
'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
})
},
{ 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">ORDER STUDIO-1042</p>
<h3>Follow the next step.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Order confirmed</strong>
<p>Your tote and notebook are being prepared.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Next: packed for delivery</strong>
<p>See when your items are packed and what happens next.</p>
</div>
<span>02</span>
</div>
</div>
<button type="button" data-demo-update data-drawer-no-drag>Show packing update</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: 'Order STUDIO-1042',
description: 'Review your order confirmation, then load its packing update.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-demo-update]').addEventListener(
'click',
() => {
drawer.update({
title: 'Packed and ready to go',
content:
'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
})
},
{ 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">ORDER STUDIO-1042</p>
<h3>Follow the next step.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Order confirmed</strong>
<p>Your tote and notebook are being prepared.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Next: packed for delivery</strong>
<p>See when your items are packed and what happens next.</p>
</div>
<span>02</span>
</div>
</div>
<button type="button" data-demo-update data-drawer-no-drag>Show packing update</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: 'Order STUDIO-1042',
description: 'Review your order confirmation, then load its packing update.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-demo-update]').addEventListener(
'click',
() => {
drawer.update({
title: 'Packed and ready to go',
content:
'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
})
},
{ 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">ORDER STUDIO-1042</p>
<h3>Follow the next step.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Order confirmed</strong>
<p>Your tote and notebook are being prepared.</p>
</div>
<span
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg
></span>
</div>
<div class="demo-scene-row">
<div>
<strong>Next: packed for delivery</strong>
<p>See when your items are packed and what happens next.</p>
</div>
<span>02</span>
</div>
</div>
<button type="button" data-demo-update data-drawer-no-drag>Show packing update</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: 'Order STUDIO-1042',
description: 'Review your order confirmation, then load its packing update.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body.querySelector('[data-demo-update]').addEventListener(
'click',
() => {
drawer.update({
title: 'Packed and ready to go',
content:
'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
})
},
{ 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 packing action advances order STUDIO-1042 from confirmation to a packed status, with items, delivery timing and the next step. It replaces title and body through update(). Uncheck Reset between attempts to keep the updated content when reopening. The checked playground option restores the initial example for another try; it is deliberately absent from copied integration code. For a form or editor, keep application data outside disposable dialog DOM.
Controlled snap size
SAMPLE BOARDING PASS · ST204
Your flight, at a glance.
Compact and expanded actions call setActiveSnapPoint(). The native handle and gestures still work.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
SAMPLE BOARDING PASS · ST204
Your flight, at a glance.
Terminal 2 · Gate 12 · Economy
Have your travel document ready at the gate.
One cabin bag and one personal item.
Check the airport screens for gate changes. This is a fictional sample boarding pass.
Explore the code
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">
<div class="demo-actions" data-drawer-no-drag>
<button type="button" data-demo-compact>Compact</button
><button type="button" data-demo-expanded>Expanded</button>
</div>
<p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
<h3>Your flight, at a glance.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Mexico City → Oaxaca</strong>
<p>Terminal 2 · Gate 12 · Economy</p>
</div>
<span>08:15</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Boarding</strong>
<p>Have your travel document ready at the gate.</p>
</div>
<span>07:40</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Cabin baggage</strong>
<p>One cabin bag and one personal item.</p>
</div>
<span>2 items</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Before departure</strong>
<p>
Check the airport screens for gate changes. This is a fictional sample boarding
pass.
</p>
</div>
<span>ST204</span>
</div>
</div>
</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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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: 'Boarding pass',
description: 'View boarding time and baggage details for this fictional sample flight.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('[data-demo-compact]')
.addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
signal: lifecycle.signal,
})
body
.querySelector('[data-demo-expanded]')
.addEventListener('click', () => drawer.setActiveSnapPoint(1), { 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)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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">
<div class="demo-actions" data-drawer-no-drag>
<button type="button" data-demo-compact>Compact</button
><button type="button" data-demo-expanded>Expanded</button>
</div>
<p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
<h3>Your flight, at a glance.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Mexico City → Oaxaca</strong>
<p>Terminal 2 · Gate 12 · Economy</p>
</div>
<span>08:15</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Boarding</strong>
<p>Have your travel document ready at the gate.</p>
</div>
<span>07:40</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Cabin baggage</strong>
<p>One cabin bag and one personal item.</p>
</div>
<span>2 items</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Before departure</strong>
<p>
Check the airport screens for gate changes. This is a fictional sample boarding
pass.
</p>
</div>
<span>ST204</span>
</div>
</div>
</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: 'Boarding pass',
description: 'View boarding time and baggage details for this fictional sample flight.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('[data-demo-compact]')
.addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
signal: lifecycle.signal,
})
body
.querySelector('[data-demo-expanded]')
.addEventListener('click', () => drawer.setActiveSnapPoint(1), {
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)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
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">
<div class="demo-actions" data-drawer-no-drag>
<button type="button" data-demo-compact>Compact</button
><button type="button" data-demo-expanded>Expanded</button>
</div>
<p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
<h3>Your flight, at a glance.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Mexico City → Oaxaca</strong>
<p>Terminal 2 · Gate 12 · Economy</p>
</div>
<span>08:15</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Boarding</strong>
<p>Have your travel document ready at the gate.</p>
</div>
<span>07:40</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Cabin baggage</strong>
<p>One cabin bag and one personal item.</p>
</div>
<span>2 items</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Before departure</strong>
<p>
Check the airport screens for gate changes. This is a fictional sample boarding
pass.
</p>
</div>
<span>ST204</span>
</div>
</div>
</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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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: 'Boarding pass',
description: 'View boarding time and baggage details for this fictional sample flight.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('[data-demo-compact]')
.addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
signal: lifecycle.signal,
})
body
.querySelector('[data-demo-expanded]')
.addEventListener('click', () => drawer.setActiveSnapPoint(1), { 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)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
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 {
height: 100dvh;
max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.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">
<div class="demo-actions" data-drawer-no-drag>
<button type="button" data-demo-compact>Compact</button
><button type="button" data-demo-expanded>Expanded</button>
</div>
<p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
<h3>Your flight, at a glance.</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<div>
<strong>Mexico City → Oaxaca</strong>
<p>Terminal 2 · Gate 12 · Economy</p>
</div>
<span>08:15</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Boarding</strong>
<p>Have your travel document ready at the gate.</p>
</div>
<span>07:40</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Cabin baggage</strong>
<p>One cabin bag and one personal item.</p>
</div>
<span>2 items</span>
</div>
<div class="demo-scene-row">
<div>
<strong>Before departure</strong>
<p>
Check the airport screens for gate changes. This is a fictional sample boarding
pass.
</p>
</div>
<span>ST204</span>
</div>
</div>
</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: 'Boarding pass',
description: 'View boarding time and baggage details for this fictional sample flight.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('[data-demo-compact]')
.addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
signal: lifecycle.signal,
})
body
.querySelector('[data-demo-expanded]')
.addEventListener('click', () => drawer.setActiveSnapPoint(1), {
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)),
snapPoints: [0.45, 0.72, 1],
activeSnapPoint: 0.45,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
The sample boarding pass keeps flight and baggage details in one panel. Compact and Expanded call setActiveSnapPoint() with exact members of the configured array. Direct calls update the snapshot; they do not echo onActiveSnapPointChange.
Repeat a trial
Stateful previews offer Reset between attempts, enabled by default. Its explanation states what resets: a result message, inspector grid setting or updated content. Completed selections stay readable after closing and clear on the next opening; the non-modal result and canvas grid also clear when its inspector closes. Turn it off to inspect retained state. The inspector checkbox reflects its retained canvas state. Other form fields, command searches, notes and reading position recreate normally; this option does not add persistence to them. Reading, notes, nested navigation and both snap examples need no reset control. Drawer itself returns snaps to the first point after the close animation finishes. These helpers belong to the playground and are omitted from copied consumer code.
The sample data is fictional. Menu, checkout, shortlist, account, file and draft actions return local selections for your application to handle; they are not connected services. The delivery chooser and inspector grid demonstrate actual local interface changes.
Account menu
SIGNED IN AS ALEX
Your spaces. One account.
Switch workspaces or open account actions without losing the current page.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
SIGNED IN AS ALEX
Your spaces. One account.
Keep private projects separate from shared team work.
Explore the code
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">SIGNED IN AS ALEX</p>
<h3>Your spaces. One account.</h3>
<div
class="demo-menu"
role="group"
aria-label="Your spaces. One account."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
<span class="demo-menu-icon" aria-hidden="true">A</span
><span class="demo-menu-copy"
><strong>Personal workspace</strong><span>Your private projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
<span class="demo-menu-icon" aria-hidden="true">S</span
><span class="demo-menu-copy"
><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Account settings</strong><span>Profile and preferences</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Keep private projects separate from shared team work.</p>
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'right',
title: 'Your account',
description: 'Choose your personal or team workspace, or open account settings.',
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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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">SIGNED IN AS ALEX</p>
<h3>Your spaces. One account.</h3>
<div
class="demo-menu"
role="group"
aria-label="Your spaces. One account."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
<span class="demo-menu-icon" aria-hidden="true">A</span
><span class="demo-menu-copy"
><strong>Personal workspace</strong><span>Your private projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
<span class="demo-menu-icon" aria-hidden="true">S</span
><span class="demo-menu-copy"
><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Account settings</strong><span>Profile and preferences</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Keep private projects separate from shared team work.</p>
</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: 'right',
title: 'Your account',
description: 'Choose your personal or team workspace, or open account settings.',
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">SIGNED IN AS ALEX</p>
<h3>Your spaces. One account.</h3>
<div
class="demo-menu"
role="group"
aria-label="Your spaces. One account."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
<span class="demo-menu-icon" aria-hidden="true">A</span
><span class="demo-menu-copy"
><strong>Personal workspace</strong><span>Your private projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
<span class="demo-menu-icon" aria-hidden="true">S</span
><span class="demo-menu-copy"
><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Account settings</strong><span>Profile and preferences</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Keep private projects separate from shared team work.</p>
</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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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: 'right',
title: 'Your account',
description: 'Choose your personal or team workspace, or open account settings.',
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;
top: 0;
bottom: 0;
right: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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">SIGNED IN AS ALEX</p>
<h3>Your spaces. One account.</h3>
<div
class="demo-menu"
role="group"
aria-label="Your spaces. One account."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
<span class="demo-menu-icon" aria-hidden="true">A</span
><span class="demo-menu-copy"
><strong>Personal workspace</strong><span>Your private projects</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
<span class="demo-menu-icon" aria-hidden="true">S</span
><span class="demo-menu-copy"
><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
/></svg></span
><span class="demo-menu-copy"
><strong>Account settings</strong><span>Profile and preferences</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Keep private projects separate from shared team work.</p>
</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: 'right',
title: 'Your account',
description: 'Choose your personal or team workspace, or open account settings.',
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>
Keep workspace choices and profile actions together. The application reports the selected action and closes its owned controller; connect these actions to your own router or account state.
File actions
PROJECT BRIEF.PDF · 2.4 MB
Keep the file. Open the possibilities.
Group contextual actions in a comfortable sheet. Report the selection back to the page.
Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.
PROJECT BRIEF.PDF · 2.4 MB
Keep the file. Open the possibilities.
Choose what to do with Project brief.pdf.
Explore the code
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">PROJECT BRIEF.PDF · 2.4 MB</p>
<h3>Keep the file. Open the possibilities.</h3>
<div
class="demo-menu"
role="group"
aria-label="Keep the file. Open the possibilities."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Add to favorites</strong><span>Keep it close for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="8" y="8" width="13" height="13" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
><span class="demo-menu-copy"
><strong>Make a copy</strong><span>Start another version</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Move to a folder</strong><span>Put everything in its place</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Choose what to do with Project brief.pdf.</p>
</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: 'Project brief.pdf',
description: 'Choose a contextual action for this document.',
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">PROJECT BRIEF.PDF · 2.4 MB</p>
<h3>Keep the file. Open the possibilities.</h3>
<div
class="demo-menu"
role="group"
aria-label="Keep the file. Open the possibilities."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Add to favorites</strong><span>Keep it close for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="8" y="8" width="13" height="13" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
><span class="demo-menu-copy"
><strong>Make a copy</strong><span>Start another version</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Move to a folder</strong><span>Put everything in its place</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Choose what to do with Project brief.pdf.</p>
</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: 'Project brief.pdf',
description: 'Choose a contextual action for this document.',
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">PROJECT BRIEF.PDF · 2.4 MB</p>
<h3>Keep the file. Open the possibilities.</h3>
<div
class="demo-menu"
role="group"
aria-label="Keep the file. Open the possibilities."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Add to favorites</strong><span>Keep it close for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="8" y="8" width="13" height="13" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
><span class="demo-menu-copy"
><strong>Make a copy</strong><span>Start another version</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Move to a folder</strong><span>Put everything in its place</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Choose what to do with Project brief.pdf.</p>
</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: 'Project brief.pdf',
description: 'Choose a contextual action for this document.',
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">PROJECT BRIEF.PDF · 2.4 MB</p>
<h3>Keep the file. Open the possibilities.</h3>
<div
class="demo-menu"
role="group"
aria-label="Keep the file. Open the possibilities."
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Add to favorites</strong><span>Keep it close for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="8" y="8" width="13" height="13" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
><span class="demo-menu-copy"
><strong>Make a copy</strong><span>Start another version</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path
d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
/></svg></span
><span class="demo-menu-copy"
><strong>Move to a folder</strong><span>Put everything in its place</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">Choose what to do with Project brief.pdf.</p>
</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: 'Project brief.pdf',
description: 'Choose a contextual action for this document.',
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>
A touch-friendly contextual menu groups actions with descriptions. These are local demonstrations; no files are changed.
Explicit draft confirmation
UNSAVED DRAFT
Keep what you have started?
An unsaved draft needs a decision. Outside clicks and gestures cannot dismiss this confirmation.
Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
UNSAVED DRAFT
Keep what you have started?
Launch note: The new collection goes live on Friday. Add the product screenshots before the review.
Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
Explore the code
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">UNSAVED DRAFT</p>
<h3>Keep what you have started?</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<p>
Launch note: The new collection goes live on Friday. Add the product screenshots
before the review.
</p>
</div>
</div>
<div
class="demo-menu"
role="group"
aria-label="Keep what you have started?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Save draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg></span
><span class="demo-menu-copy"
><strong>Save draft</strong><span>Keep your work for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 6l12 12M18 6 6 18" /></svg></span
><span class="demo-menu-copy"
><strong>Discard draft</strong><span>Close without saving</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 14 4 9l5-5" />
<path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
><span class="demo-menu-copy"
><strong>Continue editing</strong><span>Return to your page</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">
Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
</p>
</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: 'Unsaved launch note',
description: 'Choose whether to keep your draft, discard it or continue editing.',
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)),
dismissible: false,
closeButton: false,
showHandle: false,
})
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">UNSAVED DRAFT</p>
<h3>Keep what you have started?</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<p>
Launch note: The new collection goes live on Friday. Add the product screenshots
before the review.
</p>
</div>
</div>
<div
class="demo-menu"
role="group"
aria-label="Keep what you have started?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Save draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg></span
><span class="demo-menu-copy"
><strong>Save draft</strong><span>Keep your work for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 6l12 12M18 6 6 18" /></svg></span
><span class="demo-menu-copy"
><strong>Discard draft</strong><span>Close without saving</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 14 4 9l5-5" />
<path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
><span class="demo-menu-copy"
><strong>Continue editing</strong><span>Return to your page</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">
Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
</p>
</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: 'Unsaved launch note',
description: 'Choose whether to keep your draft, discard it or continue editing.',
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)),
dismissible: false,
closeButton: false,
showHandle: false,
})
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">UNSAVED DRAFT</p>
<h3>Keep what you have started?</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<p>
Launch note: The new collection goes live on Friday. Add the product screenshots
before the review.
</p>
</div>
</div>
<div
class="demo-menu"
role="group"
aria-label="Keep what you have started?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Save draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg></span
><span class="demo-menu-copy"
><strong>Save draft</strong><span>Keep your work for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 6l12 12M18 6 6 18" /></svg></span
><span class="demo-menu-copy"
><strong>Discard draft</strong><span>Close without saving</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 14 4 9l5-5" />
<path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
><span class="demo-menu-copy"
><strong>Continue editing</strong><span>Return to your page</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">
Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
</p>
</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: 'Unsaved launch note',
description: 'Choose whether to keep your draft, discard it or continue editing.',
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)),
dismissible: false,
closeButton: false,
showHandle: false,
})
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">UNSAVED DRAFT</p>
<h3>Keep what you have started?</h3>
<div class="demo-scene">
<div class="demo-scene-row">
<p>
Launch note: The new collection goes live on Friday. Add the product screenshots
before the review.
</p>
</div>
</div>
<div
class="demo-menu"
role="group"
aria-label="Keep what you have started?"
data-drawer-no-drag
>
<button type="button" class="demo-menu-item" data-demo-choice="Save draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m5 12 5 5L20 7" /></svg></span
><span class="demo-menu-copy"
><strong>Save draft</strong><span>Keep your work for later</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 6l12 12M18 6 6 18" /></svg></span
><span class="demo-menu-copy"
><strong>Discard draft</strong><span>Close without saving</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg></button
><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
<span class="demo-menu-icon" aria-hidden="true"
><svg
aria-hidden="true"
focusable="false"
width="1.25rem"
height="1.25rem"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 14 4 9l5-5" />
<path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
><span class="demo-menu-copy"
><strong>Continue editing</strong><span>Return to your page</span></span
><svg
aria-hidden="true"
focusable="false"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M13 5l7 7-7 7" />
</svg>
</button>
</div>
<p class="demo-hint">
Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
</p>
</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: 'Unsaved launch note',
description: 'Choose whether to keep your draft, discard it or continue editing.',
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)),
dismissible: false,
closeButton: false,
showHandle: false,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
dismissible: false keeps the panel open when Escape, the backdrop or a drag would normally dismiss it. showHandle: false and closeButton: false remove competing dismissal affordances. Each explicit choice still calls setOpen(false); the application owns saving or discarding the draft.
Guided configuration
CUSTOM TOTE / 3 STEPS
Choose. Personalize. Review.
Keep selections while moving forward and back inside one owned drawer.
Back keeps your choices within this open panel. Confirmation reports a local sample selection; closing and reopening starts a fresh form.
Step 1 / 3
Choose the finish
Make it yours
Up to three characters, printed on the inside pocket.
Review your tote
Everyday tote · $32 · Your selection
Explore the code
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" data-flow-progress aria-live="polite">Step 1 / 3</p>
<section data-flow-step="0">
<h3 tabindex="-1">Choose the finish</h3>
<label for="canvas-finish">Canvas finish</label
><select id="canvas-finish" data-flow-finish>
<option>Natural canvas</option>
<option>Midnight canvas</option></select
><button type="button" data-flow-next>Continue</button>
</section>
<section data-flow-step="1" hidden>
<h3 tabindex="-1">Make it yours</h3>
<label
>Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
/></label>
<p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-next>Continue</button>
</div>
</section>
<section data-flow-step="2" hidden>
<h3 tabindex="-1">Review your tote</h3>
<p>Everyday tote · $32 · Your selection</p>
<p data-flow-summary></p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-confirm>Confirm sample selection</button>
</div>
</section>
</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 [data-flow-step][hidden] {
display: none;
}
.demo-drawer [data-flow-step]:not([hidden]) {
display: grid;
gap: 1rem;
margin-top: 0;
}
.demo-drawer [data-flow-step] > :is(h3, p) {
margin: 0;
}
.demo-drawer [data-flow-step] > button {
justify-self: start;
}
.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: 'Make it your everyday tote',
description: 'Choose a finish, review your selection and go back without losing it.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
let step = 0
const steps = [...body.querySelectorAll('[data-flow-step]')]
const finish = body.querySelector('[data-flow-finish]')
const initials = body.querySelector('[data-flow-initials]')
const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
const show = next => {
step = next
steps.forEach((section, index) => {
section.hidden = index !== step
})
body.querySelector('[data-flow-progress]').textContent = 'Step' + ' ' + (step + 1) + ' / 3'
body.querySelector('[data-flow-summary]').textContent = selection()
steps[step].querySelector('h3').focus()
}
body
.querySelectorAll('button[data-flow-next]')
.forEach(button =>
button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
)
body
.querySelectorAll('button[data-flow-back]')
.forEach(button =>
button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
)
body.querySelector('button[data-flow-confirm]').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
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 [data-flow-step][hidden] {
display: none;
}
.demo-drawer [data-flow-step]:not([hidden]) {
display: grid;
gap: 1rem;
margin-top: 0;
}
.demo-drawer [data-flow-step] > :is(h3, p) {
margin: 0;
}
.demo-drawer [data-flow-step] > button {
justify-self: start;
}
.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" data-flow-progress aria-live="polite">Step 1 / 3</p>
<section data-flow-step="0">
<h3 tabindex="-1">Choose the finish</h3>
<label for="canvas-finish">Canvas finish</label
><select id="canvas-finish" data-flow-finish>
<option>Natural canvas</option>
<option>Midnight canvas</option></select
><button type="button" data-flow-next>Continue</button>
</section>
<section data-flow-step="1" hidden>
<h3 tabindex="-1">Make it yours</h3>
<label
>Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
/></label>
<p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-next>Continue</button>
</div>
</section>
<section data-flow-step="2" hidden>
<h3 tabindex="-1">Review your tote</h3>
<p>Everyday tote · $32 · Your selection</p>
<p data-flow-summary></p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-confirm>Confirm sample selection</button>
</div>
</section>
</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: 'Make it your everyday tote',
description: 'Choose a finish, review your selection and go back without losing it.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
let step = 0
const steps = [...body.querySelectorAll('[data-flow-step]')]
const finish = body.querySelector('[data-flow-finish]')
const initials = body.querySelector('[data-flow-initials]')
const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
const show = next => {
step = next
steps.forEach((section, index) => {
section.hidden = index !== step
})
body.querySelector('[data-flow-progress]').textContent =
'Step' + ' ' + (step + 1) + ' / 3'
body.querySelector('[data-flow-summary]').textContent = selection()
steps[step].querySelector('h3').focus()
}
body
.querySelectorAll('button[data-flow-next]')
.forEach(button =>
button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
)
body
.querySelectorAll('button[data-flow-back]')
.forEach(button =>
button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
)
body.querySelector('button[data-flow-confirm]').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
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" data-flow-progress aria-live="polite">Step 1 / 3</p>
<section data-flow-step="0">
<h3 tabindex="-1">Choose the finish</h3>
<label for="canvas-finish">Canvas finish</label
><select id="canvas-finish" data-flow-finish>
<option>Natural canvas</option>
<option>Midnight canvas</option></select
><button type="button" data-flow-next>Continue</button>
</section>
<section data-flow-step="1" hidden>
<h3 tabindex="-1">Make it yours</h3>
<label
>Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
/></label>
<p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-next>Continue</button>
</div>
</section>
<section data-flow-step="2" hidden>
<h3 tabindex="-1">Review your tote</h3>
<p>Everyday tote · $32 · Your selection</p>
<p data-flow-summary></p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-confirm>Confirm sample selection</button>
</div>
</section>
</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 [data-flow-step][hidden] {
display: none;
}
.demo-drawer [data-flow-step]:not([hidden]) {
display: grid;
gap: 1rem;
margin-top: 0;
}
.demo-drawer [data-flow-step] > :is(h3, p) {
margin: 0;
}
.demo-drawer [data-flow-step] > button {
justify-self: start;
}
.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: 'Make it your everyday tote',
description: 'Choose a finish, review your selection and go back without losing it.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
let step = 0
const steps = [...body.querySelectorAll('[data-flow-step]')]
const finish = body.querySelector('[data-flow-finish]')
const initials = body.querySelector('[data-flow-initials]')
const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
const show = next => {
step = next
steps.forEach((section, index) => {
section.hidden = index !== step
})
body.querySelector('[data-flow-progress]').textContent = 'Step' + ' ' + (step + 1) + ' / 3'
body.querySelector('[data-flow-summary]').textContent = selection()
steps[step].querySelector('h3').focus()
}
body
.querySelectorAll('button[data-flow-next]')
.forEach(button =>
button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
)
body
.querySelectorAll('button[data-flow-back]')
.forEach(button =>
button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
)
body.querySelector('button[data-flow-confirm]').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
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 [data-flow-step][hidden] {
display: none;
}
.demo-drawer [data-flow-step]:not([hidden]) {
display: grid;
gap: 1rem;
margin-top: 0;
}
.demo-drawer [data-flow-step] > :is(h3, p) {
margin: 0;
}
.demo-drawer [data-flow-step] > button {
justify-self: start;
}
.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" data-flow-progress aria-live="polite">Step 1 / 3</p>
<section data-flow-step="0">
<h3 tabindex="-1">Choose the finish</h3>
<label for="canvas-finish">Canvas finish</label
><select id="canvas-finish" data-flow-finish>
<option>Natural canvas</option>
<option>Midnight canvas</option></select
><button type="button" data-flow-next>Continue</button>
</section>
<section data-flow-step="1" hidden>
<h3 tabindex="-1">Make it yours</h3>
<label
>Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
/></label>
<p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-next>Continue</button>
</div>
</section>
<section data-flow-step="2" hidden>
<h3 tabindex="-1">Review your tote</h3>
<p>Everyday tote · $32 · Your selection</p>
<p data-flow-summary></p>
<div class="demo-actions">
<button type="button" data-flow-back>Back</button
><button type="button" data-flow-confirm>Confirm sample selection</button>
</div>
</section>
</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: 'Make it your everyday tote',
description: 'Choose a finish, review your selection and go back without losing it.',
autoFocus: true,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
let step = 0
const steps = [...body.querySelectorAll('[data-flow-step]')]
const finish = body.querySelector('[data-flow-finish]')
const initials = body.querySelector('[data-flow-initials]')
const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
const show = next => {
step = next
steps.forEach((section, index) => {
section.hidden = index !== step
})
body.querySelector('[data-flow-progress]').textContent =
'Step' + ' ' + (step + 1) + ' / 3'
body.querySelector('[data-flow-summary]').textContent = selection()
steps[step].querySelector('h3').focus()
}
body
.querySelectorAll('button[data-flow-next]')
.forEach(button =>
button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
)
body
.querySelectorAll('button[data-flow-back]')
.forEach(button =>
button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
)
body.querySelector('button[data-flow-confirm]').addEventListener(
'click',
() => {
document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
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>
Choose a canvas finish and optional initials, then review the selection. Back and Continue keep the same input DOM and values; confirmation reports a local result. Closing and reopening starts a fresh configuration. The playground checkbox controls its external result message, not field persistence. This uses one controller and application state, not a second navigation API.
Independent drawers
PROJECT WORKSPACE
Notes here. Activity there.
Open notes and activity together. Neither is the parent; closing one leaves the other open.
These non-modal panels have separate controllers and close actions. On small screens they occupy separate upper and lower regions.
Write a review note, then open activity. You can close either panel separately.
Alex added the product shots
Today · 09:20
Maya updated the launch checklist
Today · 09:05
Explore the code
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>
<button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
Open activity
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p>Write a review note, then open activity. You can close either panel separately.</p>
<label data-drawer-no-drag
>Project review note<textarea
placeholder="What should the team review next?"
></textarea></label
><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
><template data-companion-content
><div class="demo-body">
<section>
<h3>Alex added the product shots</h3>
<p>Today · 09:20</p>
</section>
<section>
<h3>Maya updated the launch checklist</h3>
<p>Today · 09:05</p>
</section>
</div></template
>
</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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
--initial-transform: 100dvw;
width: min(27rem, 46vw);
max-height: calc(100dvh - 2rem);
top: 1rem;
bottom: 1rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-drawer.demo-independent-notes {
right: auto;
left: 1rem;
}
.demo-drawer.demo-independent-activity {
left: auto;
right: 1rem;
}
@media (width < 48rem) {
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
width: calc(100% - 2rem);
height: 44dvh;
max-height: 44dvh;
}
.demo-drawer.demo-independent-notes {
top: 1rem;
bottom: auto;
}
.demo-drawer.demo-independent-activity {
top: auto;
bottom: 1rem;
}
}
.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')
let companion
const activityTrigger = document.getElementById('open-activity')
const openActivity = () => {
companion ??= window.Drawer.createDrawer({
id: 'example-activity',
direction: 'right',
title: 'Project activity',
description:
'Recent updates from your product team. Keep this log open beside your review notes.',
modal: false,
overlay: false,
autoFocus: false,
content: () =>
template.content
.querySelector('[data-companion-content]')
.content.firstElementChild.cloneNode(true),
contentClassName: 'demo-drawer demo-floating demo-independent-activity',
showHandle: false,
closeButton: { ariaLabel: 'Close activity' },
onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
})
companion.setOpen(true)
}
activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
const drawer = window.Drawer.createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'left',
title: 'Project notes',
description: 'Keep your review notes open beside an independent activity panel.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('button[data-open-companion]')
.addEventListener('click', openActivity, { signal: lifecycle.signal })
return body
},
contentClassName: 'demo-drawer demo-floating demo-independent-notes',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
modal: false,
overlay: false,
showHandle: false,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
companion?.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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
--initial-transform: 100dvw;
width: min(27rem, 46vw);
max-height: calc(100dvh - 2rem);
top: 1rem;
bottom: 1rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-drawer.demo-independent-notes {
right: auto;
left: 1rem;
}
.demo-drawer.demo-independent-activity {
left: auto;
right: 1rem;
}
@media (width < 48rem) {
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
width: calc(100% - 2rem);
height: 44dvh;
max-height: 44dvh;
}
.demo-drawer.demo-independent-notes {
top: 1rem;
bottom: auto;
}
.demo-drawer.demo-independent-activity {
top: auto;
bottom: 1rem;
}
}
.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>
<button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
Open activity
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p>Write a review note, then open activity. You can close either panel separately.</p>
<label data-drawer-no-drag
>Project review note<textarea
placeholder="What should the team review next?"
></textarea></label
><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
><template data-companion-content
><div class="demo-body">
<section>
<h3>Alex added the product shots</h3>
<p>Today · 09:20</p>
</section>
<section>
<h3>Maya updated the launch checklist</h3>
<p>Today · 09:05</p>
</section>
</div></template
>
</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')
let companion
const activityTrigger = document.getElementById('open-activity')
const openActivity = () => {
companion ??= window.Drawer.createDrawer({
id: 'example-activity',
direction: 'right',
title: 'Project activity',
description:
'Recent updates from your product team. Keep this log open beside your review notes.',
modal: false,
overlay: false,
autoFocus: false,
content: () =>
template.content
.querySelector('[data-companion-content]')
.content.firstElementChild.cloneNode(true),
contentClassName: 'demo-drawer demo-floating demo-independent-activity',
showHandle: false,
closeButton: { ariaLabel: 'Close activity' },
onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
})
companion.setOpen(true)
}
activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
const drawer = window.Drawer.createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'left',
title: 'Project notes',
description: 'Keep your review notes open beside an independent activity panel.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('button[data-open-companion]')
.addEventListener('click', openActivity, { signal: lifecycle.signal })
return body
},
contentClassName: 'demo-drawer demo-floating demo-independent-notes',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
modal: false,
overlay: false,
showHandle: false,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
companion?.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>
<button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
Open activity
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p>Write a review note, then open activity. You can close either panel separately.</p>
<label data-drawer-no-drag
>Project review note<textarea
placeholder="What should the team review next?"
></textarea></label
><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
><template data-companion-content
><div class="demo-body">
<section>
<h3>Alex added the product shots</h3>
<p>Today · 09:20</p>
</section>
<section>
<h3>Maya updated the launch checklist</h3>
<p>Today · 09:05</p>
</section>
</div></template
>
</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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
--initial-transform: 100dvw;
width: min(27rem, 46vw);
max-height: calc(100dvh - 2rem);
top: 1rem;
bottom: 1rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-drawer.demo-independent-notes {
right: auto;
left: 1rem;
}
.demo-drawer.demo-independent-activity {
left: auto;
right: 1rem;
}
@media (width < 48rem) {
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
width: calc(100% - 2rem);
height: 44dvh;
max-height: 44dvh;
}
.demo-drawer.demo-independent-notes {
top: 1rem;
bottom: auto;
}
.demo-drawer.demo-independent-activity {
top: auto;
bottom: 1rem;
}
}
.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')
let companion
const activityTrigger = document.getElementById('open-activity')
const openActivity = () => {
companion ??= createDrawer({
id: 'example-activity',
direction: 'right',
title: 'Project activity',
description:
'Recent updates from your product team. Keep this log open beside your review notes.',
modal: false,
overlay: false,
autoFocus: false,
content: () =>
template.content
.querySelector('[data-companion-content]')
.content.firstElementChild.cloneNode(true),
contentClassName: 'demo-drawer demo-floating demo-independent-activity',
showHandle: false,
closeButton: { ariaLabel: 'Close activity' },
onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
})
companion.setOpen(true)
}
activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
const drawer = createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'left',
title: 'Project notes',
description: 'Keep your review notes open beside an independent activity panel.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('button[data-open-companion]')
.addEventListener('click', openActivity, { signal: lifecycle.signal })
return body
},
contentClassName: 'demo-drawer demo-floating demo-independent-notes',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
modal: false,
overlay: false,
showHandle: false,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
companion?.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;
top: 0;
bottom: 0;
left: 0;
width: min(28rem, 90vw);
max-height: 100dvh;
}
.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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
--initial-transform: 100dvw;
width: min(27rem, 46vw);
max-height: calc(100dvh - 2rem);
top: 1rem;
bottom: 1rem;
border: 0.0625rem solid #d9cbd5;
border-radius: 0.875rem;
}
.demo-drawer.demo-independent-notes {
right: auto;
left: 1rem;
}
.demo-drawer.demo-independent-activity {
left: auto;
right: 1rem;
}
@media (width < 48rem) {
.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
width: calc(100% - 2rem);
height: 44dvh;
max-height: 44dvh;
}
.demo-drawer.demo-independent-notes {
top: 1rem;
bottom: auto;
}
.demo-drawer.demo-independent-activity {
top: auto;
bottom: 1rem;
}
}
.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>
<button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
Open activity
</button>
<output id="demo-result" aria-live="polite"></output>
<template id="drawer-content">
<div class="demo-body">
<p>Write a review note, then open activity. You can close either panel separately.</p>
<label data-drawer-no-drag
>Project review note<textarea
placeholder="What should the team review next?"
></textarea></label
><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
><template data-companion-content
><div class="demo-body">
<section>
<h3>Alex added the product shots</h3>
<p>Today · 09:20</p>
</section>
<section>
<h3>Maya updated the launch checklist</h3>
<p>Today · 09:05</p>
</section>
</div></template
>
</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')
let companion
const activityTrigger = document.getElementById('open-activity')
const openActivity = () => {
companion ??= createDrawer({
id: 'example-activity',
direction: 'right',
title: 'Project activity',
description:
'Recent updates from your product team. Keep this log open beside your review notes.',
modal: false,
overlay: false,
autoFocus: false,
content: () =>
template.content
.querySelector('[data-companion-content]')
.content.firstElementChild.cloneNode(true),
contentClassName: 'demo-drawer demo-floating demo-independent-activity',
showHandle: false,
closeButton: { ariaLabel: 'Close activity' },
onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
})
companion.setOpen(true)
}
activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
const drawer = createDrawer({
id: 'example',
triggerElement: trigger,
direction: 'left',
title: 'Project notes',
description: 'Keep your review notes open beside an independent activity panel.',
autoFocus: false,
content: () => {
const body = template.content.firstElementChild.cloneNode(true)
body
.querySelector('button[data-open-companion]')
.addEventListener('click', openActivity, { signal: lifecycle.signal })
return body
},
contentClassName: 'demo-drawer demo-floating demo-independent-notes',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
modal: false,
overlay: false,
showHandle: false,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
companion?.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
Open notes and activity at the same time. Both use modal: false and overlay: false, separate ids and no parentId. Closing notes leaves activity open, and vice versa. The page has separate triggers to reopen either one. On narrow screens the two panels occupy separate upper and lower regions. Each controller must be destroyed by its owner during cleanup; unlike the nested example, destroying one does not destroy the other. Notes are a local scratchpad, not saved storage.
A custom visual design
STUDIO / AN INVITATION
Your design sets the shape.
A floating invitation card: custom width, all-around corners and a soft accent gradient. Your CSS sets the design.
This is a local sample invitation. The floating shape and gradient are application CSS, not a built-in Drawer theme.
STUDIO / AN INVITATION
Good work starts together.
Join the product team to share projects, review designs and keep decisions in one place.
Product team · 6 teammates · Member access
Sample invitation only. Accepting does not create or change a real account.
Explore the code
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">STUDIO / AN INVITATION</p>
<h3>Good work starts together.</h3>
<p>
Join the product team to share projects, review designs and keep decisions in one place.
</p>
<p class="demo-hint">Product team · 6 teammates · Member access</p>
<button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
Accept sample invitation
</button>
<p class="demo-hint">
Sample invitation only. Accepting does not create or change a real account.
</p>
</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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
/* No runtime changes: geometry, corners and gradient belong to your CSS. */
.demo-drawer.demo-invitation {
--initial-transform: 100dvh;
inset: 1rem;
margin: auto;
width: min(34rem, calc(100% - 2rem));
height: fit-content;
min-height: 0;
max-height: calc(100dvh - 2rem);
border: 0.0625rem solid #952779;
border-radius: 2rem 0.5rem 2rem 0.5rem;
}
.demo-drawer.demo-invitation::before {
background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
}
.demo-drawer.demo-invitation button[data-drawer-close] {
border-radius: 100rem;
}
.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: 'A place on the team',
description: 'Alex invited you to the Studio workspace.',
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 demo-floating demo-invitation',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
showHandle: false,
})
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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
/* No runtime changes: geometry, corners and gradient belong to your CSS. */
.demo-drawer.demo-invitation {
--initial-transform: 100dvh;
inset: 1rem;
margin: auto;
width: min(34rem, calc(100% - 2rem));
height: fit-content;
min-height: 0;
max-height: calc(100dvh - 2rem);
border: 0.0625rem solid #952779;
border-radius: 2rem 0.5rem 2rem 0.5rem;
}
.demo-drawer.demo-invitation::before {
background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
}
.demo-drawer.demo-invitation button[data-drawer-close] {
border-radius: 100rem;
}
.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">STUDIO / AN INVITATION</p>
<h3>Good work starts together.</h3>
<p>
Join the product team to share projects, review designs and keep decisions in one place.
</p>
<p class="demo-hint">Product team · 6 teammates · Member access</p>
<button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
Accept sample invitation
</button>
<p class="demo-hint">
Sample invitation only. Accepting does not create or change a real account.
</p>
</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: 'A place on the team',
description: 'Alex invited you to the Studio workspace.',
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 demo-floating demo-invitation',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
showHandle: false,
})
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">STUDIO / AN INVITATION</p>
<h3>Good work starts together.</h3>
<p>
Join the product team to share projects, review designs and keep decisions in one place.
</p>
<p class="demo-hint">Product team · 6 teammates · Member access</p>
<button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
Accept sample invitation
</button>
<p class="demo-hint">
Sample invitation only. Accepting does not create or change a real account.
</p>
</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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
/* No runtime changes: geometry, corners and gradient belong to your CSS. */
.demo-drawer.demo-invitation {
--initial-transform: 100dvh;
inset: 1rem;
margin: auto;
width: min(34rem, calc(100% - 2rem));
height: fit-content;
min-height: 0;
max-height: calc(100dvh - 2rem);
border: 0.0625rem solid #952779;
border-radius: 2rem 0.5rem 2rem 0.5rem;
}
.demo-drawer.demo-invitation::before {
background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
}
.demo-drawer.demo-invitation button[data-drawer-close] {
border-radius: 100rem;
}
.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: 'A place on the team',
description: 'Alex invited you to the Studio workspace.',
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 demo-floating demo-invitation',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
showHandle: false,
})
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.demo-floating {
isolation: isolate;
background: transparent;
}
.demo-drawer.demo-floating::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
background: #faf9fc;
z-index: -1;
pointer-events: none;
}
/* No runtime changes: geometry, corners and gradient belong to your CSS. */
.demo-drawer.demo-invitation {
--initial-transform: 100dvh;
inset: 1rem;
margin: auto;
width: min(34rem, calc(100% - 2rem));
height: fit-content;
min-height: 0;
max-height: calc(100dvh - 2rem);
border: 0.0625rem solid #952779;
border-radius: 2rem 0.5rem 2rem 0.5rem;
}
.demo-drawer.demo-invitation::before {
background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
}
.demo-drawer.demo-invitation button[data-drawer-close] {
border-radius: 100rem;
}
.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">STUDIO / AN INVITATION</p>
<h3>Good work starts together.</h3>
<p>
Join the product team to share projects, review designs and keep decisions in one place.
</p>
<p class="demo-hint">Product team · 6 teammates · Member access</p>
<button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
Accept sample invitation
</button>
<p class="demo-hint">
Sample invitation only. Accepting does not create or change a real account.
</p>
</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: 'A place on the team',
description: 'Alex invited you to the Studio workspace.',
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 demo-floating demo-invitation',
overlayClassName: 'demo-overlay',
showHandle: true,
closeButton: { ariaLabel: 'Close drawer' },
onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
showHandle: false,
})
window.addEventListener(
'pagehide',
event => {
if (event.persisted) return
lifecycle.abort()
drawer.destroy()
},
{ signal: lifecycle.signal }
)
</script>
</body>
</html>
The invitation uses a floating card, asymmetric corners, a constrained width and an accent gradient. contentClassName attaches application CSS; Drawer still owns focus, gestures and dismissal. Compare its CSS tab with the bottom-sheet example: this is the same package, not a separate dialog implementation or built-in theme. The sample action returns a local selection and does not join a real workspace.
Cleanup
Copied pages preserve listeners during a persisted pagehide and destroy on a real departure. In an SPA, call drawer.destroy() when the feature unmounts and unsubscribe any application listeners. Never call destroyDrawers() from one feature if unrelated features still own drawers.