Drawer
A panel that slides in from the side for filters or settings, opened from a project list. On a narrow screen it becomes a sheet that rises from the bottom, with a handle to close it.
Projects
- Q4 launch planMaya OkaforActive
- Brand refreshJonas WeberActive
- Help centreMaya OkaforPaused
Options
Code
import { useEffect, useId, useRef, useState } from "react";
import "./drawer.css";
/* A panel that slides in from the right, and from the bottom on a narrow
screen. Give it open and onClose; children go in the scrolling middle.
<Drawer open={open} onClose={close} title="Filters" confirm="Show results" onConfirm={apply}>…</Drawer> */
export function Drawer({ open, onClose, title, reset = "Reset", confirm = "Show results", onConfirm, children }) {
const drawer = useRef(null);
const id = useId();
/* Opening is at once. Closing slides away first. */
useEffect(() => {
const element = drawer.current;
if (open) {
element.removeAttribute("data-closing");
if (!element.open) element.showModal();
/* Focus starts on the title, not on the first button. */
element.querySelector("h2").focus();
return;
}
if (!element.open) return;
element.setAttribute("data-closing", "");
const timer = setTimeout(() => {
element.removeAttribute("data-closing");
element.close();
}, 200);
return () => clearTimeout(timer);
}, [open]);
const submit = (event) => {
event.preventDefault();
if (onConfirm) onConfirm(new FormData(event.currentTarget));
onClose();
};
return (
<dialog
className="dh-drawer"
ref={drawer}
aria-labelledby={id}
onCancel={(event) => {
event.preventDefault();
onClose();
}}
onClick={(event) => {
if (event.target === drawer.current) onClose();
}}
>
<form method="dialog" onSubmit={submit}>
<button className="dh-drawer-grab" type="button" aria-label="Close" onClick={onClose} />
<header>
<h2 id={id} tabIndex={-1}>{title}</h2>
<button className="dh-drawer-x" type="button" aria-label="Close" onClick={onClose}>
<svg viewBox="0 0 12 12" aria-hidden="true">
<path d="M3 3l6 6M9 3l-6 6" />
</svg>
</button>
</header>
<div className="dh-drawer-body">{children}</div>
<footer>
<button className="dh-drawer-btn" type="reset">
{reset}
</button>
<button className="dh-drawer-btn" type="submit" data-tone="primary">
{confirm}
</button>
</footer>
</form>
</dialog>
);
}
const projects = [
{ name: "Q4 launch plan", owner: "Maya Okafor", status: "Active", kind: "good" },
{ name: "Brand refresh", owner: "Jonas Weber", status: "Active", kind: "good" },
{ name: "Help centre", owner: "Maya Okafor", status: "Paused", kind: "warn" },
];
export function Example() {
const [open, setOpen] = useState(false);
return (
<div className="dh-drawer-demo">
<div className="dh-drawer-card">
<header>
<h3>Projects</h3>
<button className="dh-drawer-btn" type="button" onClick={() => setOpen(true)}>
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M3 5.750A.75.750 0 0 1 3.750 5h12.500a.75.750 0 0 1 0 1.500H3.750A.75.750 0 0 1 3 5.750Zm2.500 4.250a.75.750 0 0 1 .75-.75h7.500a.75.750 0 0 1 0 1.500h-7.500A.75.750 0 0 1 5.500 10Zm2.500 4.250a.75.750 0 0 1 .75-.75h2.500a.75.750 0 0 1 0 1.500h-2.500a.75.750 0 0 1-.75-.75Z" />
</svg>
Filters
<em>2</em>
</button>
</header>
<ul>
{projects.map((project) => (
<li key={project.name}>
<b>{project.name}</b>
<span>{project.owner}</span>
<small data-kind={project.kind}>{project.status}</small>
</li>
))}
</ul>
</div>
<Drawer open={open} onClose={() => setOpen(false)} title="Filters">
<fieldset>
<legend>Status</legend>
<label>
<input type="checkbox" name="status" value="active" defaultChecked /> Active <small>24</small>
</label>
<label>
<input type="checkbox" name="status" value="paused" defaultChecked /> Paused <small>6</small>
</label>
<label>
<input type="checkbox" name="status" value="archived" /> Archived <small>112</small>
</label>
</fieldset>
<fieldset>
<legend>Owner</legend>
<label>
<input type="radio" name="owner" value="anyone" defaultChecked /> Anyone
</label>
<label>
<input type="radio" name="owner" value="maya" /> Maya Okafor
</label>
<label>
<input type="radio" name="owner" value="team" /> My team
</label>
</fieldset>
</Drawer>
</div>
);
}/* A drawer: a panel that slides in from the side for filters or settings,
built on the dialog element so focus stays inside and Escape closes it.
A project list opens it. On a narrow screen it becomes a sheet that rises
from the bottom, with a handle. Sizes are in em, 1em to the em at the
usual 1.2308em. */
.dh-drawer-demo {
--accent: var(--dh-accent, #2563ff);
--line: color-mix(in srgb, var(--dh-fg, #171717) 9%, transparent);
--ring: 0 0 0 1px var(--line), 0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent);
--gloss: inset 0 1px 0 rgb(255 255 255 / 0.3), 0 0 0 1px color-mix(in srgb, var(--accent) 78%, #000), 0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 22%, transparent);
width: 27.6923em;
max-width: 100%;
color: var(--dh-fg, #171717);
font-size: 0.8125em;
line-height: 1.5385em;
text-align: left;
}
.dh-drawer-card {
overflow: hidden;
border-radius: 0.9231em;
background: var(--dh-raised, #fff);
box-shadow: var(--ring);
}
.dh-drawer-card header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.7692em 0.7692em 0.7692em 1.2308em;
}
.dh-drawer-card h3,
.dh-drawer h2 {
margin: 0;
font-size: 1.0769em;
font-weight: 500;
line-height: 1.5385em;
letter-spacing: -0.015em;
}
.dh-drawer-card ul {
margin: 0;
padding: 0;
list-style: none;
}
.dh-drawer-card li {
display: flex;
align-items: center;
gap: 0.6154em;
height: 2.9231em;
padding: 0 1.2308em;
border-top: 1px solid var(--line);
}
.dh-drawer-card b {
flex: 1;
min-width: 0;
overflow: hidden;
font-weight: 500;
letter-spacing: -0.01em;
text-overflow: ellipsis;
white-space: nowrap;
}
.dh-drawer-card li span {
width: 7.3846em;
color: var(--dh-muted, #5c5c5c);
white-space: nowrap;
}
/* A status is a dot in its colour, then the word. */
.dh-drawer-card li small {
--hue: #1fa750;
display: flex;
align-items: center;
gap: 0.4615em;
width: 4.4615em;
color: var(--dh-muted, #5c5c5c);
font-size: 0.9231em;
}
.dh-drawer-card li small::before {
content: "";
width: 0.4615em;
height: 0.4615em;
border-radius: 50%;
background: var(--hue);
}
.dh-drawer-card li small[data-kind="warn"] {
--hue: #e39b0b;
}
.dh-drawer-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.4615em;
height: 2.4615em;
padding: 0 0.9231em;
border: 0;
border-radius: 0.6154em;
background: var(--dh-raised, #fff);
color: var(--dh-fg, #171717);
font: inherit;
font-weight: 500;
letter-spacing: -0.01em;
cursor: pointer;
box-shadow: var(--ring);
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer-card .dh-drawer-btn {
height: 2.1538em;
padding: 0 0.4615em 0 0.6154em;
border-radius: 0.5385em;
}
.dh-drawer-btn svg {
width: 1.0769em;
height: 1.0769em;
fill: var(--dh-faint, #8a8a8a);
}
.dh-drawer-btn em {
min-width: 1.2308em;
padding: 0 0.3077em;
border-radius: 0.3077em;
background: color-mix(in srgb, var(--accent) 12%, transparent);
color: color-mix(in srgb, var(--accent) 80%, var(--dh-fg, #171717));
font: 500 0.8462em/1.2308em ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.dh-drawer-btn[data-tone="primary"] {
flex: 1;
background: linear-gradient(color-mix(in srgb, var(--accent) 84%, #fff), var(--accent));
color: var(--dh-on-accent, #fff);
box-shadow: var(--gloss);
}
.dh-drawer-btn:active,
.dh-drawer-x:active {
transform: scale(0.97);
}
.dh-drawer-demo :is(button, input, h2):focus-visible {
outline: 2px solid var(--dh-faint, #8a8a8a);
outline-offset: 1px;
}
.dh-drawer-demo h2:focus-visible {
outline: none;
}
/* The panel floats a little off the edges of the window. */
.dh-drawer {
inset: 0.6154em 0.6154em 0.6154em auto;
overflow: hidden;
width: 23.0769em;
max-width: calc(100% - 1.2308em);
height: auto;
max-height: none;
margin: 0;
padding: 0;
border: 0;
border-radius: 1.0769em;
background: var(--dh-raised, #fff);
color: var(--dh-fg, #171717);
font-size: 1em;
line-height: 1.5385em;
text-align: left;
box-shadow: var(--ring), 0 14px 28px -14px rgb(0 0 0 / 0.35);
}
.dh-drawer[open] {
animation: dh-drawer-in 320ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-drawer[data-closing] {
animation: dh-drawer-out 200ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-drawer::backdrop {
background: rgb(0 0 0 / 0.3);
-webkit-backdrop-filter: blur(2px);
backdrop-filter: blur(2px);
animation: dh-drawer-fade 320ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-drawer[data-closing]::backdrop {
animation: dh-drawer-fade 200ms cubic-bezier(0.23, 1, 0.32, 1) reverse both;
}
.dh-drawer form {
display: flex;
flex-direction: column;
height: 100%;
}
.dh-drawer header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.0769em 0.9231em 0.9231em 1.2308em;
}
.dh-drawer-x {
display: grid;
place-items: center;
width: 1.8462em;
height: 1.8462em;
padding: 0;
border: 0;
border-radius: 0.5385em;
background: none;
color: var(--dh-faint, #8a8a8a);
cursor: pointer;
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1), background-color 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer-x svg {
width: 0.9231em;
height: 0.9231em;
fill: none;
stroke: currentColor;
stroke-width: 1.4;
stroke-linecap: round;
}
.dh-drawer-grab {
display: none;
}
.dh-drawer-body {
flex: 1;
overflow-y: auto;
border-top: 1px solid var(--line);
}
.dh-drawer fieldset {
display: grid;
gap: 0.1538em;
margin: 0;
padding: 0.9231em 0.6154em 0.6154em;
border: 0;
}
.dh-drawer fieldset + fieldset {
border-top: 1px solid var(--line);
}
.dh-drawer legend {
float: left;
width: 100%;
margin-bottom: 0.3077em;
padding: 0 0.6154em;
color: var(--dh-faint, #8a8a8a);
font-size: 0.8462em;
font-weight: 500;
line-height: 1.2308em;
}
.dh-drawer label {
display: flex;
align-items: center;
gap: 0.7692em;
min-height: 2.4615em;
padding: 0 0.6154em;
border-radius: 0.6154em;
cursor: pointer;
transition: background-color 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer label small {
margin-left: auto;
color: var(--dh-faint, #8a8a8a);
font: 0.8462em/1.2308em ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* The boxes are wells that fill with the accent when ticked. */
.dh-drawer input {
-webkit-appearance: none;
appearance: none;
display: grid;
flex: none;
place-items: center;
width: 1.2308em;
height: 1.2308em;
margin: 0;
border-radius: 0.3846em;
background: var(--dh-well, #ededeb);
box-shadow: inset 0 0 0 1px var(--line);
cursor: pointer;
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer input[type="radio"] {
border-radius: 50%;
}
.dh-drawer input::before {
content: "";
width: 0.7692em;
height: 0.7692em;
background: var(--dh-on-accent, #fff);
clip-path: polygon(14% 52%, 26% 40%, 42% 56%, 74% 22%, 86% 34%, 42% 80%);
transform: scale(0);
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer input[type="radio"]::before {
width: 0.4615em;
height: 0.4615em;
border-radius: 50%;
clip-path: none;
}
.dh-drawer input:checked {
background: linear-gradient(color-mix(in srgb, var(--accent) 84%, #fff), var(--accent));
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 78%, #000), inset 0 1px 0 1px rgb(255 255 255 / 0.25);
}
.dh-drawer input:checked::before {
transform: none;
}
.dh-drawer input:active {
transform: scale(0.92);
}
.dh-drawer footer {
display: flex;
gap: 0.6154em;
padding: 0.7692em 0.9231em;
border-top: 1px solid var(--line);
background: color-mix(in srgb, var(--dh-fg, #171717) 3%, var(--dh-raised, #fff));
}
@media (hover: hover) and (pointer: fine) {
.dh-drawer label:hover,
.dh-drawer-x:hover {
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
}
}
/* A sheet on a narrow screen. */
@media (max-width: 640px) {
.dh-drawer {
inset: auto 0 0;
width: 100%;
max-width: none;
max-height: 85%;
border-radius: 1.0769em 1.0769em 0 0;
}
.dh-drawer[open] {
animation-name: dh-drawer-up;
}
.dh-drawer[data-closing] {
animation-name: dh-drawer-down;
}
.dh-drawer-x {
display: none;
}
/* The handle is small, but the button around it is easy to hit. */
.dh-drawer-grab {
display: grid;
place-items: center;
align-self: center;
width: 4.9231em;
height: 1.8462em;
margin-bottom: -0.7692em;
padding: 0;
border: 0;
background: none;
cursor: pointer;
}
.dh-drawer-grab::before {
content: "";
width: 2.7692em;
height: 0.3846em;
border-radius: 0.2308em;
background: var(--dh-raised, #fff);
box-shadow: var(--ring);
}
.dh-drawer label {
min-height: 3.3846em;
}
.dh-drawer footer {
flex-direction: column-reverse;
padding: 0.9231em 1.2308em max(0.9231em, env(safe-area-inset-bottom));
}
.dh-drawer footer .dh-drawer-btn {
flex: none;
height: 3.3846em;
}
}
@keyframes dh-drawer-in {
from {
transform: translateX(calc(100% + 1.2308em));
}
}
@keyframes dh-drawer-out {
to {
transform: translateX(calc(100% + 1.2308em));
}
}
@keyframes dh-drawer-up {
from {
transform: translateY(100%);
}
}
@keyframes dh-drawer-down {
to {
transform: translateY(100%);
}
}
@keyframes dh-drawer-fade {
from {
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.dh-drawer[open] {
animation: dh-drawer-fade 200ms both;
}
.dh-drawer[data-closing] {
animation: dh-drawer-fade 150ms reverse both;
}
.dh-drawer-btn,
.dh-drawer-x,
.dh-drawer label,
.dh-drawer input,
.dh-drawer input::before {
transition: none;
}
}<div class="dh-drawer-demo">
<div class="dh-drawer-card">
<header>
<h3>Projects</h3>
<button class="dh-drawer-btn" type="button" data-opens="dh-drawer-filters">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3 5.750A.75.750 0 0 1 3.750 5h12.500a.75.750 0 0 1 0 1.500H3.750A.75.750 0 0 1 3 5.750Zm2.500 4.250a.75.750 0 0 1 .75-.75h7.500a.75.750 0 0 1 0 1.500h-7.500A.75.750 0 0 1 5.500 10Zm2.500 4.250a.75.750 0 0 1 .75-.75h2.500a.75.750 0 0 1 0 1.500h-2.500a.75.750 0 0 1-.75-.75Z" /></svg>
Filters
<em>2</em>
</button>
</header>
<ul>
<li><b>Q4 launch plan</b><span>Maya Okafor</span><small data-kind="good">Active</small></li>
<li><b>Brand refresh</b><span>Jonas Weber</span><small data-kind="good">Active</small></li>
<li><b>Help centre</b><span>Maya Okafor</span><small data-kind="warn">Paused</small></li>
</ul>
</div>
<dialog class="dh-drawer" id="dh-drawer-filters" aria-labelledby="dh-drawer-filters-title">
<form method="dialog">
<button class="dh-drawer-grab" type="button" data-close aria-label="Close"></button>
<header>
<h2 id="dh-drawer-filters-title" tabindex="-1" autofocus>Filters</h2>
<button class="dh-drawer-x" type="button" data-close aria-label="Close">
<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 3l6 6M9 3l-6 6" /></svg>
</button>
</header>
<div class="dh-drawer-body">
<fieldset>
<legend>Status</legend>
<label><input type="checkbox" checked /> Active <small>24</small></label>
<label><input type="checkbox" checked /> Paused <small>6</small></label>
<label><input type="checkbox" /> Archived <small>112</small></label>
</fieldset>
<fieldset>
<legend>Owner</legend>
<label><input type="radio" name="dh-drawer-owner" checked /> Anyone</label>
<label><input type="radio" name="dh-drawer-owner" /> Maya Okafor</label>
<label><input type="radio" name="dh-drawer-owner" /> My team</label>
</fieldset>
</div>
<footer>
<button class="dh-drawer-btn" type="reset">Reset</button>
<button class="dh-drawer-btn" type="submit" data-tone="primary">Show results</button>
</footer>
</form>
</dialog>
</div>/* A drawer: a panel that slides in from the side for filters or settings,
built on the dialog element so focus stays inside and Escape closes it.
A project list opens it. On a narrow screen it becomes a sheet that rises
from the bottom, with a handle. Sizes are in em, 1em to the em at the
usual 1.2308em. */
.dh-drawer-demo {
--accent: var(--dh-accent, #2563ff);
--line: color-mix(in srgb, var(--dh-fg, #171717) 9%, transparent);
--ring: 0 0 0 1px var(--line), 0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent);
--gloss: inset 0 1px 0 rgb(255 255 255 / 0.3), 0 0 0 1px color-mix(in srgb, var(--accent) 78%, #000), 0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 22%, transparent);
width: 27.6923em;
max-width: 100%;
color: var(--dh-fg, #171717);
font-size: 0.8125em;
line-height: 1.5385em;
text-align: left;
}
.dh-drawer-card {
overflow: hidden;
border-radius: 0.9231em;
background: var(--dh-raised, #fff);
box-shadow: var(--ring);
}
.dh-drawer-card header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.7692em 0.7692em 0.7692em 1.2308em;
}
.dh-drawer-card h3,
.dh-drawer h2 {
margin: 0;
font-size: 1.0769em;
font-weight: 500;
line-height: 1.5385em;
letter-spacing: -0.015em;
}
.dh-drawer-card ul {
margin: 0;
padding: 0;
list-style: none;
}
.dh-drawer-card li {
display: flex;
align-items: center;
gap: 0.6154em;
height: 2.9231em;
padding: 0 1.2308em;
border-top: 1px solid var(--line);
}
.dh-drawer-card b {
flex: 1;
min-width: 0;
overflow: hidden;
font-weight: 500;
letter-spacing: -0.01em;
text-overflow: ellipsis;
white-space: nowrap;
}
.dh-drawer-card li span {
width: 7.3846em;
color: var(--dh-muted, #5c5c5c);
white-space: nowrap;
}
/* A status is a dot in its colour, then the word. */
.dh-drawer-card li small {
--hue: #1fa750;
display: flex;
align-items: center;
gap: 0.4615em;
width: 4.4615em;
color: var(--dh-muted, #5c5c5c);
font-size: 0.9231em;
}
.dh-drawer-card li small::before {
content: "";
width: 0.4615em;
height: 0.4615em;
border-radius: 50%;
background: var(--hue);
}
.dh-drawer-card li small[data-kind="warn"] {
--hue: #e39b0b;
}
.dh-drawer-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.4615em;
height: 2.4615em;
padding: 0 0.9231em;
border: 0;
border-radius: 0.6154em;
background: var(--dh-raised, #fff);
color: var(--dh-fg, #171717);
font: inherit;
font-weight: 500;
letter-spacing: -0.01em;
cursor: pointer;
box-shadow: var(--ring);
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer-card .dh-drawer-btn {
height: 2.1538em;
padding: 0 0.4615em 0 0.6154em;
border-radius: 0.5385em;
}
.dh-drawer-btn svg {
width: 1.0769em;
height: 1.0769em;
fill: var(--dh-faint, #8a8a8a);
}
.dh-drawer-btn em {
min-width: 1.2308em;
padding: 0 0.3077em;
border-radius: 0.3077em;
background: color-mix(in srgb, var(--accent) 12%, transparent);
color: color-mix(in srgb, var(--accent) 80%, var(--dh-fg, #171717));
font: 500 0.8462em/1.2308em ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.dh-drawer-btn[data-tone="primary"] {
flex: 1;
background: linear-gradient(color-mix(in srgb, var(--accent) 84%, #fff), var(--accent));
color: var(--dh-on-accent, #fff);
box-shadow: var(--gloss);
}
.dh-drawer-btn:active,
.dh-drawer-x:active {
transform: scale(0.97);
}
.dh-drawer-demo :is(button, input, h2):focus-visible {
outline: 2px solid var(--dh-faint, #8a8a8a);
outline-offset: 1px;
}
.dh-drawer-demo h2:focus-visible {
outline: none;
}
/* The panel floats a little off the edges of the window. */
.dh-drawer {
inset: 0.6154em 0.6154em 0.6154em auto;
overflow: hidden;
width: 23.0769em;
max-width: calc(100% - 1.2308em);
height: auto;
max-height: none;
margin: 0;
padding: 0;
border: 0;
border-radius: 1.0769em;
background: var(--dh-raised, #fff);
color: var(--dh-fg, #171717);
font-size: 1em;
line-height: 1.5385em;
text-align: left;
box-shadow: var(--ring), 0 14px 28px -14px rgb(0 0 0 / 0.35);
}
.dh-drawer[open] {
animation: dh-drawer-in 320ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-drawer[data-closing] {
animation: dh-drawer-out 200ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-drawer::backdrop {
background: rgb(0 0 0 / 0.3);
-webkit-backdrop-filter: blur(2px);
backdrop-filter: blur(2px);
animation: dh-drawer-fade 320ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-drawer[data-closing]::backdrop {
animation: dh-drawer-fade 200ms cubic-bezier(0.23, 1, 0.32, 1) reverse both;
}
.dh-drawer form {
display: flex;
flex-direction: column;
height: 100%;
}
.dh-drawer header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.0769em 0.9231em 0.9231em 1.2308em;
}
.dh-drawer-x {
display: grid;
place-items: center;
width: 1.8462em;
height: 1.8462em;
padding: 0;
border: 0;
border-radius: 0.5385em;
background: none;
color: var(--dh-faint, #8a8a8a);
cursor: pointer;
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1), background-color 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer-x svg {
width: 0.9231em;
height: 0.9231em;
fill: none;
stroke: currentColor;
stroke-width: 1.4;
stroke-linecap: round;
}
.dh-drawer-grab {
display: none;
}
.dh-drawer-body {
flex: 1;
overflow-y: auto;
border-top: 1px solid var(--line);
}
.dh-drawer fieldset {
display: grid;
gap: 0.1538em;
margin: 0;
padding: 0.9231em 0.6154em 0.6154em;
border: 0;
}
.dh-drawer fieldset + fieldset {
border-top: 1px solid var(--line);
}
.dh-drawer legend {
float: left;
width: 100%;
margin-bottom: 0.3077em;
padding: 0 0.6154em;
color: var(--dh-faint, #8a8a8a);
font-size: 0.8462em;
font-weight: 500;
line-height: 1.2308em;
}
.dh-drawer label {
display: flex;
align-items: center;
gap: 0.7692em;
min-height: 2.4615em;
padding: 0 0.6154em;
border-radius: 0.6154em;
cursor: pointer;
transition: background-color 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer label small {
margin-left: auto;
color: var(--dh-faint, #8a8a8a);
font: 0.8462em/1.2308em ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* The boxes are wells that fill with the accent when ticked. */
.dh-drawer input {
-webkit-appearance: none;
appearance: none;
display: grid;
flex: none;
place-items: center;
width: 1.2308em;
height: 1.2308em;
margin: 0;
border-radius: 0.3846em;
background: var(--dh-well, #ededeb);
box-shadow: inset 0 0 0 1px var(--line);
cursor: pointer;
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer input[type="radio"] {
border-radius: 50%;
}
.dh-drawer input::before {
content: "";
width: 0.7692em;
height: 0.7692em;
background: var(--dh-on-accent, #fff);
clip-path: polygon(14% 52%, 26% 40%, 42% 56%, 74% 22%, 86% 34%, 42% 80%);
transform: scale(0);
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-drawer input[type="radio"]::before {
width: 0.4615em;
height: 0.4615em;
border-radius: 50%;
clip-path: none;
}
.dh-drawer input:checked {
background: linear-gradient(color-mix(in srgb, var(--accent) 84%, #fff), var(--accent));
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 78%, #000), inset 0 1px 0 1px rgb(255 255 255 / 0.25);
}
.dh-drawer input:checked::before {
transform: none;
}
.dh-drawer input:active {
transform: scale(0.92);
}
.dh-drawer footer {
display: flex;
gap: 0.6154em;
padding: 0.7692em 0.9231em;
border-top: 1px solid var(--line);
background: color-mix(in srgb, var(--dh-fg, #171717) 3%, var(--dh-raised, #fff));
}
@media (hover: hover) and (pointer: fine) {
.dh-drawer label:hover,
.dh-drawer-x:hover {
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
}
}
/* A sheet on a narrow screen. */
@media (max-width: 640px) {
.dh-drawer {
inset: auto 0 0;
width: 100%;
max-width: none;
max-height: 85%;
border-radius: 1.0769em 1.0769em 0 0;
}
.dh-drawer[open] {
animation-name: dh-drawer-up;
}
.dh-drawer[data-closing] {
animation-name: dh-drawer-down;
}
.dh-drawer-x {
display: none;
}
/* The handle is small, but the button around it is easy to hit. */
.dh-drawer-grab {
display: grid;
place-items: center;
align-self: center;
width: 4.9231em;
height: 1.8462em;
margin-bottom: -0.7692em;
padding: 0;
border: 0;
background: none;
cursor: pointer;
}
.dh-drawer-grab::before {
content: "";
width: 2.7692em;
height: 0.3846em;
border-radius: 0.2308em;
background: var(--dh-raised, #fff);
box-shadow: var(--ring);
}
.dh-drawer label {
min-height: 3.3846em;
}
.dh-drawer footer {
flex-direction: column-reverse;
padding: 0.9231em 1.2308em max(0.9231em, env(safe-area-inset-bottom));
}
.dh-drawer footer .dh-drawer-btn {
flex: none;
height: 3.3846em;
}
}
@keyframes dh-drawer-in {
from {
transform: translateX(calc(100% + 1.2308em));
}
}
@keyframes dh-drawer-out {
to {
transform: translateX(calc(100% + 1.2308em));
}
}
@keyframes dh-drawer-up {
from {
transform: translateY(100%);
}
}
@keyframes dh-drawer-down {
to {
transform: translateY(100%);
}
}
@keyframes dh-drawer-fade {
from {
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.dh-drawer[open] {
animation: dh-drawer-fade 200ms both;
}
.dh-drawer[data-closing] {
animation: dh-drawer-fade 150ms reverse both;
}
.dh-drawer-btn,
.dh-drawer-x,
.dh-drawer label,
.dh-drawer input,
.dh-drawer input::before {
transition: none;
}
}/* Opens the drawer from its button, and lets it slide away before it closes.
The browser handles the focus trap and gives focus back to the button. */
document.querySelectorAll(".dh-drawer-demo").forEach((demo) => {
const shut = (drawer) => {
if (drawer.hasAttribute("data-closing")) return;
drawer.setAttribute("data-closing", "");
setTimeout(() => {
drawer.removeAttribute("data-closing");
drawer.close();
}, 200);
};
demo.querySelectorAll("[data-opens]").forEach((button) => {
button.addEventListener("click", () => demo.querySelector("#" + button.dataset.opens).showModal());
});
demo.querySelectorAll(".dh-drawer").forEach((drawer) => {
/* Escape. */
drawer.addEventListener("cancel", (event) => {
event.preventDefault();
shut(drawer);
});
/* A click on the dimmed page behind it. */
drawer.addEventListener("click", (event) => {
if (event.target === drawer) shut(drawer);
});
drawer.querySelectorAll("[data-close]").forEach((button) => {
button.addEventListener("click", () => shut(drawer));
});
/* Show results: read the form here, then close. */
drawer.querySelector("form").addEventListener("submit", (event) => {
event.preventDefault();
shut(drawer);
});
});
});Drawer is not in the Figma file yet.
Use the React or HTML code for now.