Compressed means brotli, measured with Bun after minification, with React excluded. Includes static imports; excludes CSS and feature chunks loaded on demand. Many libraries quote gzip, which runs larger for the same code.
Import scrollsheet/styles.css for sheets and scrollsheet/toast.css for toasts, or use scrollsheet/auto to embed the stylesheets.
Adapters support common APIs. Styling differs and some props are unsupported. Check the migration guides before switching.
React and React DOM are peer dependencies and are excluded from these size measurements.
Browser features
Sheets use native dialog and scroll-snap. JavaScript handles the gaps in browser support.
<dialog>, top layer
Stacks above page content
Every engine, Mar 2022
Chrome 37, Safari 15.4, Firefox 98
Without itFixed-position fallback, without dragging.
CSS scroll-snap
Touch dragging and snap stops
Every engine, Jul 2019
Chrome 69, Safari 11, Firefox 68
Without itDragging requires CSS scroll-snap.
linear() easing
Spring easing
Every engine, Dec 2023
Chrome 113, Safari 17.2, Firefox 112
Without itEase-out, same duration.
Scroll-driven animations
Backdrop opacity follows scroll
Chrome Jul 2023, Safari Sep 2025
Chrome 115+, Safari 26+; feature-detected
Without itJavaScript updates opacity each frame.
dialog.closedBy
Browser handles close requests
Chrome Mar 2025, Firefox Jul 2025
Chrome 134+, Firefox 141+; feature-detected
Without itJavaScript handles Escape and backdrop dismissal.
CloseWatcher
Android back button on non-modal sheets
Chrome Jun 2024, Firefox Mar 2026
Chrome 126+, Firefox 149+; feature-detected
Without itNon-modal sheets ignore the back gesture.
Examples
Try an example, then open Code to copy the source and styles. More examples are linked from the guides.
Live and non-modal
Map search
A non-modal sheet over a map. The search header grows when focused.
5th AveOcean BlvdElm St
maps.tsx
import * as React from "react";import { Sheet, type DetentSpec } from "scrollsheet";import { StarIcon } from "./icons";interface Cafe { name: string; rating: string; distance: string;}const CAFES: Cafe[] = [ { name: "Ember & Oak", rating: "4.7", distance: "0.3 mi" }, { name: "Third Wave Coffee Co.", rating: "4.5", distance: "0.4 mi" }, { name: "The Roasting Room", rating: "4.8", distance: "0.6 mi" }, { name: "Corner Pour", rating: "4.3", distance: "0.9 mi" }, { name: "Slate Cafe", rating: "4.6", distance: "1.1 mi" },];const PEEK: DetentSpec = "124px";const TALL: DetentSpec = 0.62;/** * The flex demo: non-modal so the map underneath stays pannable, a sticky * search header (plain position: sticky, no library API for it), and a * controlled activeDetent that grows on focus. Deliberately no blur-collapse: * iOS fires transient blurs while the keyboard settles, so collapsing on * blur bounces the sheet mid-keyboard — collapse stays a user gesture * (handle or drag). Results morph in via the sheet's own content-morph. */export default function MapsExample() { const [open, setOpen] = React.useState(false); const [active, setActive] = React.useState<DetentSpec>(PEEK); const [query, setQuery] = React.useState(""); const showResults = active === TALL; return ( <div className="ex-map-wrap"> <div className="ex-map" aria-hidden="true"> <span className="ex-map-street" style={{ top: "14%", left: "10%" }}> 5th Ave </span> <span className="ex-map-street" style={{ top: "58%", left: "62%" }}> Ocean Blvd </span> <span className="ex-map-street" style={{ top: "82%", left: "20%" }}> Elm St </span> <div className="ex-map-pin" /> </div> {!open && ( <button type="button" className="ex-trigger" style={{ position: "absolute", top: 14, left: 14 }} onClick={() => setOpen(true)} > Open map search </button> )} <Sheet.Root modal={false} open={open} onOpenChange={setOpen} detents={[PEEK, TALL]} activeDetent={active} onActiveDetentChange={setActive} themeColorDimming > <Sheet.Content className="ex-panel ex-map-panel" aria-label="Search this area"> <Sheet.Handle /> <div className="ex-panel-body"> <div className="ex-map-search"> <input type="search" className="ex-input" placeholder="Search coffee near you" aria-label="Search this area" value={query} onChange={(event) => setQuery(event.target.value)} onFocus={() => setActive(TALL)} /> </div> {showResults && ( <div className="ex-map-results ex-map-results-scroll"> {CAFES.map((cafe) => ( <div className="ex-map-result" key={cafe.name}> <div className="ex-map-result-name">{cafe.name}</div> <div className="ex-map-result-meta"> <StarIcon className="ex-map-star" /> {cafe.rating} · {cafe.distance} </div> </div> ))} </div> )} </div> </Sheet.Content> </Sheet.Root> </div> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}/* ── Triggers & generic buttons ─────────────────────────────────────────── */.ex-trigger { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 20px; font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: border-color 120ms ease, transform 120ms ease;}.ex-trigger:hover { border-color: var(--ex-accent);}.ex-trigger:active { transform: scale(0.97);}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-panel-body { padding: 4px 22px 28px;}.ex-panel-body h2,.ex-panel-pad h2 { font-size: 1.2rem; margin: 6px 0 8px;}.ex-panel-body p,.ex-panel-pad p { color: var(--ex-fg-muted); line-height: 1.55; margin: 0 0 16px;}.ex-input,.ex-textarea { display: block; width: 100%; appearance: none; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); padding: 12px 14px; font-size: 1rem; background: var(--ex-bg-elevated); color: var(--ex-fg); font-family: inherit;}.ex-input:focus-visible,.ex-textarea:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}/* ── Maps ────────────────────────────────────────────────────────────────── */.ex-map-wrap { position: relative; width: 100%; max-width: 380px; /* Same height as .ex-ride-map-card: the two live/non-modal previews sit next to each other and read as one pair only if their canvases match. */ height: 200px; border-radius: var(--ex-radius-md); overflow: hidden; box-shadow: var(--ex-shadow-sm);}.ex-map { position: absolute; inset: 0; background: linear-gradient(135deg, rgb(90 69 232 / 0.14), transparent 60%), repeating-linear-gradient(0deg, var(--ex-border) 0 1px, transparent 1px 64px), repeating-linear-gradient(90deg, var(--ex-border) 0 1px, transparent 1px 64px), var(--ex-bg-inset);}.ex-map-street { position: absolute; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em; color: var(--ex-fg-faint); text-transform: uppercase; pointer-events: none;}.ex-map-pin { position: absolute; top: 46%; left: 48%; width: 16px; height: 16px; border-radius: 50% 50% 50% 0; background: var(--ex-accent); transform: rotate(-45deg); box-shadow: 0 2px 6px rgb(0 0 0 / 0.3);}.ex-map-search { /* The search field never scrolls: the results list below owns its own overflow instead, which holds on every engine (sticky inside a toggling-overflow panel is flaky on iOS Safari). */ background: var(--ex-bg-elevated); /* Clear of the Handle's 44px hit box: with the input flush under the pill, iPhone touch adjustment snaps taps aimed at the field's top half onto the handle button — the sheet cycles detents and the keyboard never opens. 16px puts the whole field outside the snap contest. */ margin-top: 16px; padding-bottom: 12px; margin-bottom: 4px;}/* Flex column down the panel so the results list is sized by what's left after the search row — exactly the sheet's remaining height, keyboard or not — instead of a hardcoded vh guess that either clips short or leaves dead space when the keyboard caps the panel at the visual viewport. The chain passes through the library's [data-scrollsheet-body] wrapper (a documented hook); the library can't stretch it by default because the 'content' detent measures that wrapper's natural height. */.ex-map-panel { display: flex; flex-direction: column;}.ex-map-panel [data-scrollsheet-body] { display: flex; flex-direction: column; flex: 1; min-height: 0;}.ex-map-panel .ex-panel-body { display: flex; flex-direction: column; flex: 1; min-height: 0;}.ex-map-results-scroll { overflow-y: auto; overscroll-behavior: auto; flex: 1; min-height: 0;}.ex-map-results { padding-bottom: 8px;}.ex-map-result { padding: 12px 0; border-bottom: 1px solid var(--ex-border);}.ex-map-result:last-child { border-bottom: none;}.ex-map-result-name { font-weight: 600; font-size: 0.95rem;}.ex-map-result-meta { color: var(--ex-fg-muted); font-size: 0.82rem; margin-top: 2px;}@keyframes ex-spin { to { transform: rotate(360deg); }}/* ── rich: ride ─────────────────────────────────────────────────────── *//* Same grid-and-gradient backdrop as .ex-map (Map search): the two examples sit in the same gallery group, and matching the canvas is most of what makes this one read as a card instead of an illustration. */.ex-ride-map-card { position: relative; width: 100%; max-width: 380px; height: 200px; border-radius: var(--ex-radius-md); overflow: hidden; box-shadow: var(--ex-shadow-sm); margin-bottom: 4px; background: linear-gradient(135deg, rgb(90 69 232 / 0.14), transparent 60%), repeating-linear-gradient(0deg, var(--ex-border) 0 1px, transparent 1px 64px), repeating-linear-gradient(90deg, var(--ex-border) 0 1px, transparent 1px 64px), var(--ex-bg-inset);}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}
icons.tsx
/** * Inline lucide icons (ISC) used by the examples — kept dependency-free so * the examples stay copy-pasteable without an icon package install. * Generated file: edit the generator, not this by hand. */import * as React from "react";function Icon({ children, ...props }: React.ComponentProps<"svg">) { return ( <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" {...props} > {children} </svg> );}export function StarIcon(props: React.ComponentProps<"svg">) { return ( <Icon {...props}> <path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.12 2.12 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.12 2.12 0 0 0 1.597-1.16z" /> </Icon> );}
Menus and actions
Wallet menu
A floating menu that resizes as you switch views.
wallet.tsx
import * as React from "react";import { Sheet } from "scrollsheet";type View = "menu" | "key" | "remove";/** * Multi-view morph: switching views changes content height, and the sheet * springs to the new height automatically via the built-in ResizeObserver, * no JS animation code for that part. The incoming view's rows still need * their own reveal on mount (examples.css: .ex-wallet-view), since a plain * conditional render otherwise just pops the new content in with no motion. */export default function WalletExample() { const [view, setView] = React.useState<View>("menu"); const [open, setOpen] = React.useState(false); return ( <Sheet.Root open={open} onOpenChange={(next) => { setOpen(next); if (!next) setView("menu"); }} themeColorDimming > <Sheet.Trigger className="ex-trigger">Wallet options</Sheet.Trigger> <Sheet.Content className="ex-panel-inset" aria-label="Wallet options"> <div className="ex-panel-pad"> {view === "menu" && ( <div className="ex-wallet-view"> <Sheet.Title>Options</Sheet.Title> <button type="button" className="ex-menu-item" data-scrollsheet-no-drag onClick={() => setView("key")} > View private key </button> <button type="button" className="ex-menu-item" data-scrollsheet-no-drag onClick={() => setView("remove")} > Remove wallet </button> <Sheet.Close className="ex-menu-item ex-menu-cancel" data-scrollsheet-no-drag> Cancel </Sheet.Close> </div> )} {view === "key" && ( <div className="ex-wallet-view"> <Sheet.Title>Private key</Sheet.Title> <p className="ex-note" style={{ textAlign: "left", maxWidth: "none" }}> Your private key is what backs up this wallet. Keep it secret and secure at all times. </p> <ul className="ex-hint-list"> <li>Keep your private key safe</li> <li>Do not share it with anyone else</li> <li>Never enter it into a site you did not expect</li> </ul> <button type="button" className="ex-menu-item" data-scrollsheet-no-drag onClick={() => setView("menu")} > Back </button> </div> )} {view === "remove" && ( <div className="ex-wallet-view"> <Sheet.Title>Are you sure?</Sheet.Title> <p className="ex-note" style={{ textAlign: "left", maxWidth: "none" }}> You have not backed up this wallet yet. Removing it now means losing access for good. </p> <button type="button" className="ex-menu-item" data-scrollsheet-no-drag onClick={() => setView("menu")} > Back </button> <Sheet.Close className="ex-menu-item ex-menu-danger" data-scrollsheet-no-drag> Continue </Sheet.Close> </div> )} </div> </Sheet.Content> </Sheet.Root> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}/* ── Triggers & generic buttons ─────────────────────────────────────────── */.ex-trigger { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 20px; font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: border-color 120ms ease, transform 120ms ease;}.ex-trigger:hover { border-color: var(--ex-accent);}.ex-trigger:active { transform: scale(0.97);}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-panel-inset { --scrollsheet-inset-x: 12px; --scrollsheet-inset-bottom: 12px; border-radius: var(--ex-radius-xl); box-shadow: var(--ex-shadow-lg); background: var(--ex-bg-elevated); color: var(--ex-fg);}.ex-panel-pad { padding: 26px;}.ex-panel-body h2,.ex-panel-pad h2 { font-size: 1.2rem; margin: 6px 0 8px;}.ex-panel-pad h2 { font-size: 1.1rem; margin: 0 0 14px;}.ex-panel-body p,.ex-panel-pad p { color: var(--ex-fg-muted); line-height: 1.55; margin: 0 0 16px;}.ex-note { color: var(--ex-fg-faint); font-size: 0.82rem; margin-top: 10px; text-align: center; max-width: 34ch;}/* ── Menu list (wallet) ──────────────────────────────────────────────────── */.ex-menu-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; appearance: none; border: none; background: var(--ex-bg-inset); color: var(--ex-fg); border-radius: var(--ex-radius-md); padding: 14px 16px; font-size: 0.98rem; font-weight: 550; margin-bottom: 8px; cursor: pointer; font-family: inherit;}.ex-menu-item:hover { background: var(--ex-border);}.ex-menu-item:last-child { margin-bottom: 0;}.ex-menu-cancel { background: transparent; border: 1px solid var(--ex-border-strong);}.ex-menu-danger { background: var(--ex-danger-soft); color: var(--ex-danger);}.ex-hint-list { margin: 0 0 16px; padding-left: 18px; color: var(--ex-fg-muted); line-height: 1.7;}/* Each view's rows rise and fade in on mount, staggered by position, so switching views (menu -> key -> remove) reads as a step forward instead of the new content just popping in under the sheet's own height spring. transform/opacity only; timed off the library's own spring easing/duration (set on .scrollsheet-dialog, inherited here) so it matches the sheet's motion instead of inventing a second one. */.ex-wallet-view > * { animation: ex-wallet-in var(--scrollsheet-dur, 280ms) var(--scrollsheet-ease, ease) both;}.ex-wallet-view > *:nth-child(1) { animation-delay: 0ms;}.ex-wallet-view > *:nth-child(2) { animation-delay: 40ms;}.ex-wallet-view > *:nth-child(3) { animation-delay: 80ms;}.ex-wallet-view > *:nth-child(4) { animation-delay: 120ms;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}@media (prefers-reduced-motion: reduce) { .ex-wallet-view > * { animation: none; }}@keyframes ex-spin { to { transform: rotate(360deg); }}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}
Media
Lightbox
Open a photo and browse the gallery.
lightbox.tsx
import * as React from "react";import { flushSync } from "react-dom";import { Sheet, spring } from "scrollsheet";import { ChevronDownIcon, XIcon } from "./icons";/** * Lightbox: the PhotoSwipe/GLightbox pattern. A thumbnail grid opens a * full-bleed viewer that pages between shots without closing. * * Controlled `open` plus `detents={['full']}` and `disableDrag` — a lightbox * should never half-dismiss under a horizontal swipe, so the sheet holds * still. Paging is a horizontal scroll-snap track: the same native-scroll * thesis as the sheet itself, turned sideways. Swipes get browser momentum * and snap for free; buttons and arrow keys drive the same scroll position, * and the counter reads the active slide back from it. * * Zoom follows the same rule. Pinch and double-tap only set a zoom level * (a width/height on the slide's inner box); panning the zoomed shot is the * browser's own two-axis scroll, momentum included. While a shot is zoomed * the track stops paging, so horizontal pans stay inside the photo. * At 1x, a downward touch drag moves the photo. Short pulls return to * rest with the morph spring. Longer pulls use the same close path as Esc. * * Open and close morph the shot between its grid thumbnail and the viewer * via the View Transitions API where supported, with an opacity fallback. * The .ex-lb-topbar/.ex-lb-caption bars are * named view-transition targets (examples.css) * that fade and nudge in on their own schedule, later and quicker than the * photo's own morph, so the chrome reads as materializing around an * already-in-flight subject rather than cross-fading flat with the rest of * the page. Close reverses it fast, clearing before the photo has shrunk * back very far — chrome should get out of the way, not linger. * * Two things a placeholder SVG never exposed, both real photos do. First, * an <img> that hasn't decoded yet paints blank, and the transition's "new" * snapshot is captured whatever is on screen at that instant — decodeFullShot * warms the photo before the transition starts, or the morph cross-fades a * crisp thumbnail into nothing. Second, the sheet's own close settles in * zero time under --scrollsheet-travel: none (the morph is meant to carry * the exit, not a second animation racing it) — far faster than the photo's * own travel back to the grid. Closing the sheet the instant the content * unmounts would drop the backdrop out from under a photo still mid-flight, * so the sheet's surface (sheetOpen) stays up until the transition's * `finished` promise resolves, one beat after the content itself (index) * is gone. * * The fullscreen stage fits the photo at its intrinsic aspect ratio. */interface Shot { id: string; file: string; title: string; place: string; alt: string;}const SHOTS: Shot[] = [ { id: "bloom", file: "shot-01", title: "Frangipani", place: "Backlit branches", alt: "Pink frangipani blossoms on a branch against a blue sky", }, { id: "ridge", file: "shot-02", title: "Base camp trail", place: "Khumjung, Nepal", alt: "Snow-covered ridge along the Everest Base Camp trail", }, { id: "coast", file: "shot-03", title: "Sea cliff", place: "Coastal trail", alt: "Flowering shrubs on a coastal cliff above the sea", }, { id: "cafe", file: "shot-04", title: "Two espressos", place: "Kitsané Café, Montreal", alt: "Two espresso cups and a phone on a wooden café table", }, { id: "summit", file: "shot-05", title: "Summit day", place: "Crested Butte, Colorado", alt: "Hikers on a rocky summit under a cloud-filled sky", }, { id: "shed", file: "shot-06", title: "The green bike", place: "Backyard shed", alt: "A green bicycle leaned against a weathered wooden shed", },];interface ShotPhotoProps { shot: Shot; size: "thumb" | "full"; className?: string; style?: React.CSSProperties; loading?: "lazy" | "eager";}/** * Grid thumbnails serve the 420x280 pair; the viewer serves the 1000x667 * pair. Both ship AVIF with a WebP fallback (docs/public/img/CREDITS.md). */function ShotPhoto({ shot, size, className, style, loading }: ShotPhotoProps) { const suffix = size === "thumb" ? "-thumb" : ""; const width = size === "thumb" ? 420 : 1000; const height = size === "thumb" ? 280 : 667; return ( <picture> <source srcSet={`/img/${shot.file}${suffix}.avif`} type="image/avif" /> <img src={`/img/${shot.file}${suffix}.webp`} alt={shot.alt} width={width} height={height} loading={loading} className={className} style={style} /> </picture> );}const MORPH_NAME = "ex-lb-shot";const MAX_ZOOM = 3.5;const TAP_ZOOM = 2.4;const PULL_SLOP = 10;const PULL_DISMISS_DISTANCE = 112;// Longest the open waits on a slow connection before starting the morph// anyway. A cap, not a guarantee: past it the entrance can still flash an// undecoded frame, which beats leaving the tap unanswered. In practice this// rarely matters — the grid warms every full photo in the background on// mount (see the effect below), so by the time a tap lands, decodeFullShot// is usually a cache hit and resolves in a frame or two.const DECODE_BUDGET_MS = 500;// The native View Transition group animation is a plain CSS// animation-timing-function, not a WAAPI leg this file drives frame by// frame — spring() is what turns the same damped-spring math the sheet's// own travel uses into a linear() curve a CSS animation can run with zero// JS on the animation path. 380/38/1 mirrors the sheet's own default// spring (scrollsheet's internal SHEET_SPRING_CONFIG), so the photo settles// with the same character as the sheet it's attached to, easing in from// rest and back out to rest rather than snapping at either end. Computed// once at module scope, applied via a CSS custom property (a// ::view-transition-group() pseudo-element has no className/style to// target directly).const MORPH_SPRING = spring({ stiffness: 380, damping: 38, mass: 1 });const EXIT_DURATION_MS = 360;const FADE_DURATION_MS = 160;function ZoomIcon({ plus = false }: { plus?: boolean }) { return ( <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.8} strokeLinecap="round" aria-hidden="true" > <circle cx="10.5" cy="10.5" r="6.5" /> <path d="m16 16 4 4M8 10.5h5" /> {plus && <path d="M10.5 8v5" />} </svg> );}type DocumentWithVT = Document & { startViewTransition?: (update: () => void) => { finished: Promise<unknown> };};function reducedMotion(): boolean { return window.matchMedia("(prefers-reduced-motion: reduce)").matches;}function delay(ms: number): Promise<void> { return new Promise((resolve) => setTimeout(resolve, ms));}/** * Warms the full-size photo before the morph's "new" state is captured — * same path convention as ShotPhoto's `size="full"` (no suffix, AVIF with a * WebP fallback). Never rejects: a decode failure on both formats is a * broken image either way, and the open should proceed rather than hang. */async function decodeFullShot(shot: Shot): Promise<void> { const img = new Image(); img.src = `/img/${shot.file}.avif`; try { await img.decode(); return; } catch { // AVIF unsupported or failed; fall through to the WebP pair. } img.src = `/img/${shot.file}.webp`; try { await img.decode(); } catch { // Best effort only. }}interface ZoomShotProps { shot: Shot; active: boolean; onZoomChange: (zoomed: boolean) => void; onDismiss: () => void; canInteract: () => boolean; controlsRef?: React.Ref<ZoomControls>;}interface ZoomControls { zoom: (factor: number) => void; pan: (x: number, y: number) => void;}/** * Pinch and double-tap only decide the zoom level; the zoomed shot pans via * the browser's own two-axis scroll. Live pinch mutates styles directly * instead of going through state — per-frame setState would re-render the * whole gallery at gesture rate for nothing. */function ZoomShot({ shot, active, onZoomChange, onDismiss, canInteract, controlsRef }: ZoomShotProps) { const scrollerRef = React.useRef<HTMLDivElement | null>(null); const sizerRef = React.useRef<HTMLDivElement | null>(null); const mediaRef = React.useRef<HTMLDivElement | null>(null); const scaleRef = React.useRef(1); const pointers = React.useRef(new Map<number, { x: number; y: number; startX: number; startY: number; moved: boolean; }>()); const pinchStart = React.useRef<{ dist: number; scale: number } | null>(null); const lastTap = React.useRef<{ t: number; x: number; y: number } | null>(null); const pull = React.useRef<{ id: number; x: number; y: number; dragging: boolean } | null>(null); const wheelPull = React.useRef({ distance: 0, timer: 0 }); const [zoomed, setZoomed] = React.useState(false); const resetPull = () => { pull.current = null; const dialog = scrollerRef.current?.closest(".scrollsheet-dialog"); dialog?.removeAttribute("data-ex-lb-pulling"); dialog?.querySelector<HTMLElement>("[data-scrollsheet-backdrop]")?.style.removeProperty("opacity"); mediaRef.current?.style.removeProperty("transform"); }; const renderPull = (distance: number) => { const progress = Math.min(1, distance / PULL_DISMISS_DISTANCE); const dialog = scrollerRef.current?.closest(".scrollsheet-dialog"); const backdrop = dialog?.querySelector<HTMLElement>("[data-scrollsheet-backdrop]"); dialog?.setAttribute("data-ex-lb-pulling", ""); if (backdrop) backdrop.style.opacity = String(1 - progress * 0.6); if (mediaRef.current) { mediaRef.current.style.transform = `translateY(${distance}px) scale(${1 - progress * 0.14})`; } }; const applyScale = (next: number, focus?: { x: number; y: number }) => { const scroller = scrollerRef.current; const sizer = sizerRef.current; if (!scroller || !sizer) return; const prev = scaleRef.current; scaleRef.current = next; // Zooming in is instant so the focus-point scroll below lands on real // scroll range; only the release back to 1 animates (its scroll target // is 0, which clamping reaches on its own). sizer.style.transition = next < prev && !pinchStart.current ? "width 180ms cubic-bezier(0.16, 1, 0.3, 1), height 180ms cubic-bezier(0.16, 1, 0.3, 1)" : "none"; sizer.style.width = `${next * 100}%`; sizer.style.height = `${next * 100}%`; sizer.style.setProperty("--ex-lb-scale", String(next)); if (focus) { // Keep the focus point stationary: its content coordinate scales by // next/prev while its viewport position stays put. scroller.scrollLeft = ((scroller.scrollLeft + focus.x) * next) / prev - focus.x; scroller.scrollTop = ((scroller.scrollTop + focus.y) * next) / prev - focus.y; } const isZoomed = next > 1.001; setZoomed(isZoomed); if (active) onZoomChange(isZoomed || pinchStart.current !== null); }; // Swiping to another slide hands its zoom back. React.useEffect(() => { if (!active && scaleRef.current > 1) applyScale(1); }); const toggleZoom = (x: number, y: number) => { if (canInteract()) applyScale(scaleRef.current > 1.001 ? 1 : TAP_ZOOM, { x, y }); }; React.useImperativeHandle(controlsRef, () => ({ zoom(factor) { const scroller = scrollerRef.current; if (!scroller || !canInteract()) return; applyScale(Math.min(MAX_ZOOM, Math.max(1, scaleRef.current * factor)), { x: scroller.clientWidth / 2, y: scroller.clientHeight / 2, }); }, pan(x, y) { scrollerRef.current?.scrollBy({ left: x, top: y, behavior: "instant" }); }, })); // Trackpad pinch arrives as a cancelable ctrl+wheel. Listen on the stage // directly so the browser doesn't also zoom the page. React.useEffect(() => { const scroller = scrollerRef.current; if (!scroller || !active) return; const wheel = wheelPull.current; const onWheel = (event: WheelEvent) => { if (event.ctrlKey || event.metaKey) { event.preventDefault(); if (!canInteract() || pull.current?.dragging || wheel.distance > 0) return; const rect = scroller.getBoundingClientRect(); applyScale(Math.min(MAX_ZOOM, Math.max(1, scaleRef.current * Math.exp(-event.deltaY * 0.012))), { x: event.clientX - rect.left, y: event.clientY - rect.top, }); return; } if (scaleRef.current > 1 || pinchStart.current || pointers.current.size || !canInteract()) return; if (event.deltaMode !== WheelEvent.DOM_DELTA_PIXEL || Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return; if (event.deltaY < 0 && wheel.distance === 0) return; event.preventDefault(); wheel.distance = Math.max(0, wheel.distance + event.deltaY); renderPull(wheel.distance); window.clearTimeout(wheel.timer); wheel.timer = window.setTimeout(() => { const dismiss = wheel.distance >= PULL_DISMISS_DISTANCE; wheel.distance = 0; if (dismiss && canInteract()) onDismiss(); else resetPull(); }, 120); }; scroller.addEventListener("wheel", onWheel, { passive: false }); return () => scroller.removeEventListener("wheel", onWheel); }); React.useEffect(() => () => window.clearTimeout(wheelPull.current.timer), []); const onPointerDown = (event: React.PointerEvent<HTMLDivElement>) => { if (!active || event.pointerType !== "touch" || !canInteract()) return; const { clientX: x, clientY: y } = event; pointers.current.set(event.pointerId, { x, y, startX: x, startY: y, moved: false }); if (pointers.current.size === 1 && !zoomed && wheelPull.current.distance === 0) { pull.current = { id: event.pointerId, x: event.clientX, y: event.clientY, dragging: false }; } if (pointers.current.size === 2) { resetPull(); lastTap.current = null; const [a, b] = [...pointers.current.values()]; a.moved = b.moved = true; pinchStart.current = { dist: Math.hypot(a.x - b.x, a.y - b.y), scale: scaleRef.current, }; // Freeze track paging for the whole pinch, even before 1x is crossed. onZoomChange(true); } }; const onPointerMove = (event: React.PointerEvent<HTMLDivElement>) => { const entry = pointers.current.get(event.pointerId); if (!entry) return; entry.x = event.clientX; entry.y = event.clientY; entry.moved ||= Math.hypot(entry.x - entry.startX, entry.y - entry.startY) >= PULL_SLOP; const gesture = pull.current; if (gesture?.id === event.pointerId) { const dx = event.clientX - gesture.x; const dy = event.clientY - gesture.y; if (!gesture.dragging && Math.hypot(dx, dy) >= PULL_SLOP) { if (dy > Math.abs(dx)) gesture.dragging = true; else { pull.current = null; lastTap.current = null; } } if (gesture.dragging) { renderPull(Math.max(0, dy)); } } const start = pinchStart.current; const scroller = scrollerRef.current; if (!start || !scroller || pointers.current.size < 2) return; const [a, b] = [...pointers.current.values()]; const rect = scroller.getBoundingClientRect(); const mid = { x: (a.x + b.x) / 2 - rect.left, y: (a.y + b.y) / 2 - rect.top }; const dist = Math.hypot(a.x - b.x, a.y - b.y); // Under-zoom to 0.7 is allowed live so the release has something to // rubber-band back from. const next = Math.min(MAX_ZOOM, Math.max(0.7, (start.scale * dist) / Math.max(1, start.dist))); applyScale(next, mid); }; const endPointer = (event: React.PointerEvent<HTMLDivElement>) => { const wasPinch = pinchStart.current !== null; const pointer = pointers.current.get(event.pointerId); pointers.current.delete(event.pointerId); const gesture = pull.current; const pulled = gesture?.id === event.pointerId && gesture.dragging; if (gesture?.id === event.pointerId) { if (pulled && event.type === "pointerup" && event.clientY - gesture.y >= PULL_DISMISS_DISTANCE) { pull.current = null; lastTap.current = null; onDismiss(); return; } resetPull(); } if (wasPinch && pointers.current.size < 2) { pinchStart.current = null; if (scaleRef.current < 1.15) applyScale(1); else onZoomChange(scaleRef.current > 1.001); } // Double-tap (touch): two quick releases in nearly the same spot. // Mouse and trackpad go through onDoubleClick instead. if (pointer?.moved || event.type !== "pointerup") lastTap.current = null; if (pointer && !pointer.moved && !wasPinch && event.type === "pointerup" && event.pointerType === "touch") { const scroller = scrollerRef.current; if (!scroller) return; const rect = scroller.getBoundingClientRect(); const tap = { t: performance.now(), x: event.clientX - rect.left, y: event.clientY - rect.top, }; const last = lastTap.current; lastTap.current = tap; if (last && tap.t - last.t < 300 && Math.hypot(tap.x - last.x, tap.y - last.y) < 30) { lastTap.current = null; toggleZoom(tap.x, tap.y); } } }; return ( <div ref={scrollerRef} className="ex-lb-zoom" data-zoomed={zoomed || undefined} onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={endPointer} onPointerCancel={endPointer} onDoubleClick={(event) => { const rect = event.currentTarget.getBoundingClientRect(); toggleZoom(event.clientX - rect.left, event.clientY - rect.top); }} > <div ref={sizerRef} className="ex-lb-zoom-sizer"> <div ref={mediaRef} className="ex-lb-media"> <ShotPhoto shot={shot} size="full" className="ex-lb-full" style={active ? { viewTransitionName: MORPH_NAME } : undefined} loading={active ? undefined : "lazy"} /> </div> </div> </div> );}export default function LightboxExample() { const [index, setIndex] = React.useState<number | null>(null); // Sheet.Root's own open prop. Usually mirrors `index`, except for the one // beat during a morphing close where the content is already gone // (`index` null) but the sheet's surface must stay up until the photo // finishes traveling back to the grid — see closeViewer. const [sheetOpen, setSheetOpen] = React.useState(false); const [zoomed, setZoomed] = React.useState(false); // Keep the server render and initial hydration on the opacity fallback. const [morphs, setMorphs] = React.useState(false); React.useEffect(() => { setMorphs(Boolean((document as DocumentWithVT).startViewTransition)); }, []); // Warms every full photo once the grid is up, so a tap's own // decodeFullShot call (in openShot) is usually an instant cache hit // instead of a cold fetch — the grid's `client:visible` mount already // means the visitor can see the thumbnails before deciding which to open. React.useEffect(() => { for (const item of SHOTS) void decodeFullShot(item); }, []); const trackRef = React.useRef<HTMLDivElement | null>(null); const gridRef = React.useRef<HTMLDivElement | null>(null); const openedAt = React.useRef(0); const opening = React.useRef(false); const closing = React.useRef(false); const lastScroll = React.useRef(-Infinity); const zoomControls = React.useRef<ZoomControls>(null); const open = index !== null; const shot = index === null ? null : SHOTS[index]!; // Land the track on the tapped thumbnail. The <dialog> is display:none // until the library shows it in its own layout effect, so the track has // no width at mount — the first animation frame is the earliest moment // clientWidth is real, and it still runs before paint. React.useEffect(() => { if (!open) return; const track = trackRef.current; if (!track) return; const frame = requestAnimationFrame(() => { track.scrollLeft = track.clientWidth * openedAt.current; }); return () => cancelAnimationFrame(frame); }, [open]); const openShot = (i: number) => { if (opening.current || sheetOpen) return; opening.current = true; const thumb = gridRef.current?.children[i] as HTMLElement | undefined; thumb?.focus({ preventScroll: true }); const show = () => { openedAt.current = i; opening.current = false; lastScroll.current = -Infinity; setIndex(i); setSheetOpen(true); }; const doc = document as DocumentWithVT; if (!doc.startViewTransition || reducedMotion() || !thumb) { show(); return; } // Wait for the full photo to decode before the transition captures its // "new" state — see decodeFullShot's doc comment. Promise.race([decodeFullShot(SHOTS[i]!), delay(DECODE_BUDGET_MS)]).then(() => { // The thumbnail is the morph's old snapshot; its name must be gone // again by the time the new state is captured, or the viewer image // would be a duplicate of it. thumb.style.viewTransitionName = MORPH_NAME; doc.startViewTransition(() => { flushSync(show); thumb.style.viewTransitionName = ""; }); }); }; const closeViewer = () => { const i = index; if (i === null || closing.current) return; closing.current = true; const dialog = trackRef.current?.closest(".scrollsheet-dialog"); const panel = trackRef.current?.closest(".ex-lb-panel"); const backdrop = dialog?.querySelector<HTMLElement>("[data-scrollsheet-backdrop]"); const thumb = gridRef.current?.children[i] as HTMLElement | undefined; const hideContent = () => { // Dismiss lands the grid where the viewer left off. thumb?.scrollIntoView({ block: "nearest", behavior: "instant" }); dialog?.removeAttribute("data-ex-lb-pulling"); backdrop?.style.removeProperty("opacity"); setIndex(null); setZoomed(false); }; const finish = () => { if (thumb) thumb.style.viewTransitionName = ""; document.documentElement.removeAttribute("data-ex-lb-exiting"); closing.current = false; setSheetOpen(false); }; const doc = document as DocumentWithVT; const closeWithoutMorph = () => { hideContent(); finish(); }; if (reducedMotion()) { closeWithoutMorph(); return; } if (!doc.startViewTransition || !thumb) { const options = { duration: FADE_DURATION_MS, easing: "ease-out", fill: "forwards" } as const; const fade = panel?.animate({ opacity: [1, 0] }, options); if (backdrop) backdrop.animate({ opacity: [getComputedStyle(backdrop).opacity, 0] }, options); if (fade) void fade.finished.then(closeWithoutMorph, closeWithoutMorph); else closeWithoutMorph(); return; } doc.documentElement.setAttribute("data-ex-lb-exiting", ""); const transition = doc.startViewTransition(() => { flushSync(hideContent); thumb.style.viewTransitionName = MORPH_NAME; }); // The sheet's surface stays open through the whole morph — see the file // doc comment for why closing it the instant the content unmounts would // split one continuous return-to-grid into two separate motions. void transition.finished.then(finish, finish); }; // The scroll position is the source of truth for the active slide; // counter and caption follow a swipe mid-gesture. const onTrackScroll = (event: React.UIEvent<HTMLDivElement>) => { const track = event.currentTarget; if (track.clientWidth === 0) return; lastScroll.current = performance.now(); const nearest = Math.min(SHOTS.length - 1, Math.max(0, Math.round(track.scrollLeft / track.clientWidth))); setIndex((current) => (current === null || nearest === current ? current : nearest)); }; const canInteract = () => { const track = trackRef.current; return Boolean( track && index !== null && !closing.current && performance.now() - lastScroll.current > 80 && Math.abs(track.scrollLeft - track.clientWidth * index) < 2, ); }; const goTo = (next: number) => { const track = trackRef.current; if (!track || index === null || !canInteract() || track.closest("[data-ex-lb-pulling]")) return; track.scrollTo({ left: track.clientWidth * next, behavior: reducedMotion() ? "instant" : "smooth" }); }; const step = (delta: number) => goTo(Math.min(SHOTS.length - 1, Math.max(0, (index ?? 0) + delta))); // Arrow keys page the gallery. Bound on the panel rather than the document // so it only applies while the lightbox owns the screen. const onKeyDown = (event: React.KeyboardEvent) => { if (event.ctrlKey || event.metaKey || event.altKey || event.currentTarget.closest("[data-ex-lb-pulling]")) return; if (event.key === "+" || event.key === "=") zoomControls.current?.zoom(1.5); else if (event.key === "-") zoomControls.current?.zoom(1 / 1.5); else if (event.key === "0") zoomControls.current?.zoom(0); else if (zoomed && event.key === "ArrowRight") zoomControls.current?.pan(60, 0); else if (zoomed && event.key === "ArrowLeft") zoomControls.current?.pan(-60, 0); else if (zoomed && event.key === "ArrowDown") zoomControls.current?.pan(0, 60); else if (zoomed && event.key === "ArrowUp") zoomControls.current?.pan(0, -60); else if (event.key === "ArrowRight") step(1); else if (event.key === "ArrowLeft") step(-1); else if (event.key === "Home") goTo(0); else if (event.key === "End") goTo(SHOTS.length - 1); else return; event.preventDefault(); }; return ( <> {/* :root custom properties, not inline styles on an element — see MORPH_SPRING's doc comment. Deterministic pure computation, so this string is identical on the server render and the client's first render; no hydration mismatch. */} <style>{`:root{--ex-lb-morph-dur:${MORPH_SPRING.durationMs}ms;--ex-lb-morph-ease:${MORPH_SPRING.easing};--ex-lb-exit-dur:${EXIT_DURATION_MS}ms;--ex-lb-fade-dur:${FADE_DURATION_MS}ms}`}</style> <div className="ex-lb-grid" ref={gridRef}> {SHOTS.map((item, i) => ( <button type="button" key={item.id} className="ex-lb-thumb" aria-label={`Open ${item.title}`} aria-haspopup="dialog" onClick={() => openShot(i)} > <ShotPhoto shot={item} size="thumb" className="ex-lb-thumb-img" loading="lazy" /> </button> ))} </div> <Sheet.Root open={sheetOpen} onOpenChange={(next) => !next && closeViewer()} detents={["full"]} disableDrag backgroundEffect="none" > <Sheet.Content className={morphs ? "ex-panel ex-lb-panel ex-lb-morph" : "ex-panel ex-lb-panel"} aria-label="Photo viewer" onKeyDown={onKeyDown} > {shot && ( <> <div className="ex-lb-track" ref={trackRef} role="group" aria-label="Photos" aria-roledescription="carousel" data-zoomed={zoomed || undefined} onScroll={onTrackScroll} > {SHOTS.map((item) => ( <div key={item.id} className="ex-lb-slide" aria-hidden={item.id !== shot.id}> <ZoomShot shot={item} active={item.id === shot.id} onZoomChange={setZoomed} onDismiss={closeViewer} canInteract={canInteract} controlsRef={item.id === shot.id ? zoomControls : undefined} /> </div> ))} </div> <div className="ex-lb-topbar"> <div className="ex-lb-count" aria-live="polite"> {(index ?? 0) + 1} / {SHOTS.length} </div> <div className="ex-lb-tools"> <div className="ex-lb-zoom-tools" role="group" aria-label="Photo zoom"> <button type="button" className="ex-lb-tool" aria-label="Zoom out" disabled={!zoomed} onClick={() => zoomControls.current?.zoom(1 / 1.5)} > <ZoomIcon /> </button> <button type="button" className="ex-lb-tool" aria-label="Zoom in" onClick={() => zoomControls.current?.zoom(1.5)} > <ZoomIcon plus /> </button> </div> <Sheet.Close className="ex-lb-tool ex-lb-close" aria-label="Close viewer"> <XIcon /> </Sheet.Close> </div> </div> <button type="button" className="ex-lb-nav ex-lb-prev" aria-label="Previous photo" disabled={index === 0} onClick={() => step(-1)} > <ChevronDownIcon /> </button> <button type="button" className="ex-lb-nav ex-lb-next" aria-label="Next photo" disabled={index === SHOTS.length - 1} onClick={() => step(1)} > <ChevronDownIcon /> </button> <div className="ex-lb-caption"> <div className="ex-row-title">{shot.title}</div> <div className="ex-row-sub">{shot.place}</div> <div className="ex-lb-strip" role="group" aria-label="Choose a photo"> {SHOTS.map((item, i) => ( <button type="button" key={item.id} aria-label={item.title} aria-current={i === index} onClick={() => goTo(i)} > <ShotPhoto shot={item} size="thumb" loading="lazy" /> </button> ))} </div> </div> </> )} </Sheet.Content> </Sheet.Root> </> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-row-title { font-weight: 600;}.ex-row-sub { color: var(--ex-fg-muted); font-size: 0.85rem;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}@keyframes ex-spin { to { transform: rotate(360deg); }}/* ── Lightbox (thumbnail grid + paging viewer) ──────────────────────────── */.ex-lb-grid { display: grid; box-sizing: border-box; width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 12px;}.ex-lb-thumb { position: relative; aspect-ratio: 1; padding: 0; border: none; border-radius: 10px; overflow: hidden; cursor: pointer; background: none; transition: transform 120ms ease;}.ex-lb-thumb:hover { transform: scale(1.04);}.ex-lb-thumb-img { width: 100%; height: 100%; display: block; object-fit: cover;}.ex-lb-panel { --scrollsheet-travel: none; --scrollsheet-desktop-margin: 0px; --scrollsheet-max-inline: none; --scrollsheet-radius: 0px; --scrollsheet-shadow: none; --scrollsheet-safe-area: 0px; --scrollsheet-bg: transparent; display: flex; flex-direction: column; width: 100%; margin-inline: 0; padding: 0; background: transparent;}.scrollsheet-dialog:has(.ex-lb-panel) { --scrollsheet-backdrop: #000;}.scrollsheet-dialog[data-scrollsheet-state="open"]:has(.scrollsheet-panel.ex-lb-panel) .scrollsheet-backdrop { /* The gallery owns dimming at rest and during a pull. */ animation: none; opacity: 1; transition: opacity var(--ex-lb-morph-dur) var(--ex-lb-morph-ease);}.scrollsheet-dialog[data-scrollsheet-state="open"]:has(.ex-lb-panel):not(:has(.ex-lb-track)) .scrollsheet-backdrop { opacity: 0; transition: none;}@starting-style { .scrollsheet-dialog[data-scrollsheet-state="open"] .ex-lb-panel:not(.ex-lb-morph) { opacity: 0; }}@media (prefers-reduced-motion: no-preference) { .ex-lb-panel:not(.ex-lb-morph) { transition: opacity var(--ex-lb-fade-dur) ease-out; }}.ex-lb-panel [data-scrollsheet-body] { display: flex; flex-direction: column; flex: 1; min-height: 0;}/* Horizontal scroll-snap paging track: swipes get browser momentum and snap natively. Axis-orthogonal to the sheet's own vertical engine, so the browser arbitrates the two gestures with no JS. */.ex-lb-track { flex: 1; min-height: 0; display: flex; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; margin-block: calc(64px + env(safe-area-inset-top, 0px)) calc(80px + env(safe-area-inset-bottom, 0px));}@media (min-width: 768px) { .ex-lb-track { margin-bottom: calc(124px + env(safe-area-inset-bottom, 0px)); }}.ex-lb-track::-webkit-scrollbar { display: none;}.ex-lb-slide { flex: 0 0 100%; min-width: 100%; display: flex; scroll-snap-align: center; scroll-snap-stop: always;}/* While a shot is zoomed (or a pinch is in flight) the track stops paging, so horizontal pans stay inside the photo. */.ex-lb-track[data-zoomed] { overflow-x: hidden;}/* At 1x, horizontal swipes page natively and vertical pulls dismiss. Zoomed photos pan with the browser's own two-axis scroll. */.ex-lb-zoom { flex: 1; min-width: 0; min-height: 0; overflow: hidden; touch-action: pan-x; container-type: size; cursor: zoom-in; scrollbar-width: none;}.ex-lb-zoom::-webkit-scrollbar { display: none;}.ex-lb-zoom[data-zoomed] { overflow: auto; touch-action: pan-x pan-y; cursor: zoom-out;}.ex-lb-zoom-sizer { display: grid; place-items: center; width: 100%; height: 100%;}.ex-lb-media { width: calc(min(100cqw, 100cqh * 1000 / 667) * var(--ex-lb-scale, 1)); aspect-ratio: 1000 / 667; transition: transform var(--ex-lb-morph-dur) var(--ex-lb-morph-ease);}.ex-lb-full { width: 100%; height: 100%; display: block; border-radius: 8px; object-fit: cover; user-select: none; -webkit-user-drag: none;}.scrollsheet-dialog[data-ex-lb-pulling][data-scrollsheet-state="open"]:has(.ex-lb-panel) .scrollsheet-backdrop,[data-ex-lb-pulling] .ex-lb-media { transition: none;}@media (prefers-reduced-motion: reduce) { .scrollsheet-dialog[data-scrollsheet-state="open"]:has(.scrollsheet-panel.ex-lb-panel) .scrollsheet-backdrop, .ex-lb-media { transition: none; }}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Top/bottom chrome bars: named view-transition targets, scoped to .ex-lb-morph so non-supporting browsers fall back to a plain mount (no view-transition-name). Both bars only ever exist on one side of a transition — mounted with the viewer, gone with the grid — so unlike the photo's MORPH_NAME handoff there's no name collision to manage in JS; the CSS scoping is enough. `pointer-events: none` on the bar and `auto` on its children keeps the gradient strip from stealing taps meant for the photo underneath, the same footprint the two controls had before they shared a wrapper. */.ex-lb-morph .ex-lb-topbar { view-transition-name: ex-lb-topbar;}.ex-lb-morph .ex-lb-caption { view-transition-name: ex-lb-bottombar;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}.ex-lb-topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 0; pointer-events: none;}.ex-lb-topbar > * { pointer-events: auto;}.ex-lb-tools { display: flex; gap: 8px;}.ex-lb-zoom-tools { display: flex; border: 1px solid rgb(255 255 255 / 0.22); border-radius: 999px; background: #151515;}.ex-lb-tool,.ex-lb-nav { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid rgb(255 255 255 / 0.22); border-radius: 50%; color: #f5f5f5; background: #151515; cursor: pointer;}.ex-lb-tool svg,.ex-lb-nav svg { width: 18px; height: 18px;}.ex-lb-zoom-tools .ex-lb-tool { width: 43px; height: 42px; border: 0; border-radius: 0; background: transparent;}.ex-lb-zoom-tools .ex-lb-tool:first-child { border-radius: 999px 0 0 999px; border-right: 1px solid rgb(255 255 255 / 0.14);}.ex-lb-zoom-tools .ex-lb-tool:last-child { border-radius: 0 999px 999px 0;}@media (hover: hover) and (pointer: fine) { .ex-lb-panel :is(.ex-lb-tool, .ex-lb-nav):hover:not(:disabled) { background: #2c2c2c; }}.ex-lb-panel button:focus-visible { outline: 2px solid white; outline-offset: 3px;}.ex-lb-tool:disabled,.ex-lb-nav:disabled { color: #737373; cursor: default;}.ex-lb-count { padding: 5px 10px; border-radius: 999px; font-size: 12px; font-variant-numeric: tabular-nums; color: #ddd; background: #151515;}.ex-lb-nav { position: absolute; top: 50%; z-index: 1; translate: 0 -50%;}.ex-lb-prev { left: 12px;}.ex-lb-next { right: 12px;}.ex-lb-prev svg { rotate: 90deg;}.ex-lb-next svg { rotate: -90deg;}@media (max-width: 767px) { .ex-lb-nav { top: auto; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); width: 44px; height: 44px; translate: none; }}.ex-lb-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 20px calc(12px + env(safe-area-inset-bottom, 0px)); text-align: center; color: #fff;}.ex-lb-caption .ex-row-sub { color: #aaa;}.ex-lb-strip { display: none;}@media (min-width: 768px) { .ex-lb-strip { display: flex; justify-content: center; gap: 8px; margin-top: 8px; } .ex-lb-strip button { padding: 2px; border: 2px solid transparent; border-radius: 8px; background: none; cursor: pointer; } .ex-lb-strip button:not([aria-current="true"]) img { opacity: 0.65; } .ex-lb-strip button[aria-current="true"] { border-color: #fff; } .ex-lb-strip img { display: block; width: 56px; height: 44px; border-radius: 4px; object-fit: cover; }}[data-ex-lb-pulling] :is(.ex-lb-topbar, .ex-lb-nav, .ex-lb-caption) { opacity: 0; visibility: hidden;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}
icons.tsx
/** * Inline lucide icons (ISC) used by the examples — kept dependency-free so * the examples stay copy-pasteable without an icon package install. * Generated file: edit the generator, not this by hand. */import * as React from "react";function Icon({ children, ...props }: React.ComponentProps<"svg">) { return ( <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" {...props} > {children} </svg> );}export function ChevronDownIcon(props: React.ComponentProps<"svg">) { return ( <Icon {...props}> <path d="m6 9 6 6 6-6" /> </Icon> );}export function XIcon(props: React.ComponentProps<"svg">) { return ( <Icon {...props}> <path d="M18 6L6 18M6 6l12 12" /> </Icon> );}
Content and forms
Cart and checkout
Dismissal is disabled while checkout is processing.
Drag between 35%, 70%, and full height with native scroll-snap.
snap-heights.tsx
import * as React from "react";import { Sheet, type DetentSpec } from "scrollsheet";const SETTINGS = [ { label: "Notifications", hint: "Alerts, sounds, and badges" }, { label: "Appearance", hint: "Theme, accent color, text size" }, { label: "Privacy and security", hint: "Screen lock, data sharing" }, { label: "Storage and data", hint: "Downloads, cache, backups" }, { label: "Accessibility", hint: "Contrast, motion, captions" }, { label: "Language and region", hint: "App language, date format" }, { label: "Connected accounts", hint: "Linked services and apps" }, { label: "Help and support", hint: "Guides, contact, feedback" },];const DETENTS: DetentSpec[] = [0.35, 0.7, "full"];export default function SnapHeightsExample() { const [active, setActive] = React.useState<DetentSpec>(DETENTS[0]!); return ( <Sheet.Root detents={DETENTS} activeDetent={active} onActiveDetentChange={setActive} themeColorDimming > <Sheet.Trigger className="ex-trigger">Snap heights</Sheet.Trigger> <Sheet.Content className="ex-panel" aria-label="Settings"> <Sheet.Handle /> <div className="ex-panel-body"> <Sheet.Title>Settings</Sheet.Title> <Sheet.Description> Active detent: <code>{String(active)}</code>. Drag between 35%, 70%, and full, or click the handle or use arrow keys. </Sheet.Description> {SETTINGS.map((item) => ( <div className="ex-row" key={item.label}> <div className="ex-row-body"> <div className="ex-row-title">{item.label}</div> <div className="ex-row-sub">{item.hint}</div> </div> </div> ))} </div> </Sheet.Content> </Sheet.Root> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}/* ── Triggers & generic buttons ─────────────────────────────────────────── */.ex-trigger { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 20px; font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: border-color 120ms ease, transform 120ms ease;}.ex-trigger:hover { border-color: var(--ex-accent);}.ex-trigger:active { transform: scale(0.97);}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-panel-body { padding: 4px 22px 28px;}.ex-panel-body h2,.ex-panel-pad h2 { font-size: 1.2rem; margin: 6px 0 8px;}.ex-panel-body p,.ex-panel-pad p { color: var(--ex-fg-muted); line-height: 1.55; margin: 0 0 16px;}/* ── Generic rows ────────────────────────────────────────────────────────── */.ex-row { padding: 12px 0; border-bottom: 1px solid var(--ex-border); display: flex; align-items: center; gap: 12px; font-size: 0.95rem;}.ex-row:last-child { border-bottom: none;}.ex-row-body { flex: 1; min-width: 0;}.ex-row-title { font-weight: 600;}.ex-row-sub { color: var(--ex-fg-muted); font-size: 0.85rem;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}.ex-map-panel .ex-panel-body { display: flex; flex-direction: column; flex: 1; min-height: 0;}@keyframes ex-spin { to { transform: rotate(360deg); }}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}.ex-lb-caption .ex-row-sub { color: #aaa;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}
Content and forms
Profile form
handleOnly: drag the handle to move the sheet; scroll and select text in the form.
profile-form.tsx
import { Sheet } from "scrollsheet";/** * A text input inside a sheet, with enough fields below it to test on-device * keyboard avoidance: focusing a field should bring it above the software * keyboard rather than letting the keyboard cover it. */export default function ProfileFormExample() { return ( <Sheet.Root detents={[0.6, "full"]} handleOnly themeColorDimming> <Sheet.Trigger className="ex-trigger">Edit profile</Sheet.Trigger> <Sheet.Content className="ex-panel" aria-label="Edit profile"> <Sheet.Handle /> <div className="ex-panel-body"> <Sheet.Title>Edit profile</Sheet.Title> <Sheet.Description> Drag the handle up to see the full form. Tap a field to try the keyboard. </Sheet.Description> <div className="ex-field"> <label className="ex-label" htmlFor="ex-profile-name"> Name </label> <input id="ex-profile-name" className="ex-input" defaultValue="Priya Nair" /> </div> <div className="ex-field"> <label className="ex-label" htmlFor="ex-profile-email"> Email </label> <input id="ex-profile-email" type="email" className="ex-input" defaultValue="priya@example.com" /> </div> <div className="ex-field"> <label className="ex-label" htmlFor="ex-profile-location"> Location </label> <input id="ex-profile-location" className="ex-input" defaultValue="Bengaluru, India" /> </div> <div className="ex-field"> <label className="ex-label" htmlFor="ex-profile-bio"> Bio </label> <textarea id="ex-profile-bio" className="ex-textarea" rows={3} defaultValue="I design tools for developers." /> </div> <button type="button" className="ex-btn ex-btn-primary ex-btn-block" data-scrollsheet-no-drag > Save changes </button> </div> </Sheet.Content> </Sheet.Root> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}/* ── Triggers & generic buttons ─────────────────────────────────────────── */.ex-trigger { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 20px; font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: border-color 120ms ease, transform 120ms ease;}.ex-trigger:hover { border-color: var(--ex-accent);}.ex-trigger:active { transform: scale(0.97);}.ex-btn { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 16px; font-size: 0.92rem; font-weight: 600; cursor: pointer; font-family: inherit;}.ex-btn:hover { border-color: var(--ex-accent);}.ex-btn-primary { background: var(--ex-accent); border-color: var(--ex-accent); color: var(--ex-accent-fg);}.ex-btn-primary:hover { filter: brightness(1.06); border-color: var(--ex-accent);}.ex-btn-block { display: block; width: 100%; text-align: center;}.ex-btn:disabled { opacity: 0.55; cursor: not-allowed;}.ex-actions .ex-btn { flex: 1; justify-content: center;}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-panel-body { padding: 4px 22px 28px;}.ex-panel-body h2,.ex-panel-pad h2 { font-size: 1.2rem; margin: 6px 0 8px;}.ex-panel-body p,.ex-panel-pad p { color: var(--ex-fg-muted); line-height: 1.55; margin: 0 0 16px;}/* ── Form fields ─────────────────────────────────────────────────────────── */.ex-field { margin-bottom: 14px;}.ex-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--ex-fg-muted); margin-bottom: 6px;}.ex-input,.ex-textarea { display: block; width: 100%; appearance: none; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); padding: 12px 14px; font-size: 1rem; background: var(--ex-bg-elevated); color: var(--ex-fg); font-family: inherit;}.ex-textarea { resize: vertical;}.ex-input:focus-visible,.ex-textarea:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}.ex-map-panel .ex-panel-body { display: flex; flex-direction: column; flex: 1; min-height: 0;}@keyframes ex-spin { to { transform: rotate(360deg); }}.ex-ride-stops .ex-btn[aria-pressed="true"] { border-color: var(--ex-accent); color: var(--ex-accent);}.ex-page-actions .ex-btn[aria-pressed="true"] { border-color: var(--ex-accent); color: var(--ex-accent);}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}.ex-side-row .ex-btn { text-transform: capitalize;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}
Mechanics
Four sides
side: open the sheet from any of the four edges.
sides.tsx
import * as React from "react";import { Sheet } from "scrollsheet";const SIDES = ["top", "bottom", "left", "right"] as const;type Side = (typeof SIDES)[number];/** * One sheet, four edges: `side` is the only prop that changes. Top and * bottom sheets resolve detents as heights, left and right as widths — * everything else (drag, snap, dimming, dismissal) is identical. */export default function SidesExample() { // `side` outlives `open` on purpose: clearing it while the sheet is // closing would swap the panel to bottom-sheet geometry mid-animation. const [side, setSide] = React.useState<Side>("bottom"); const [open, setOpen] = React.useState(false); return ( <> <div className="ex-side-row"> {SIDES.map((s) => ( <button key={s} type="button" className="ex-btn" onClick={() => { setSide(s); setOpen(true); }} > {s} </button> ))} </div> <Sheet.Root side={side} detents={side === "left" || side === "right" ? ["280px"] : [0.4]} themeColorDimming open={open} onOpenChange={setOpen} > <Sheet.Content className="ex-panel" aria-label={`${side} sheet`}> {(side === "bottom" || side === "top") && <Sheet.Handle />} <div className="ex-panel-pad"> <Sheet.Title>side="{side}"</Sheet.Title> <Sheet.Description> This sheet opens from the {side} edge. Drag it toward that edge to close, or tap the backdrop. </Sheet.Description> </div> </Sheet.Content> </Sheet.Root> </> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}.ex-btn { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 16px; font-size: 0.92rem; font-weight: 600; cursor: pointer; font-family: inherit;}.ex-btn:hover { border-color: var(--ex-accent);}.ex-btn:disabled { opacity: 0.55; cursor: not-allowed;}.ex-actions .ex-btn { flex: 1; justify-content: center;}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-panel-pad { padding: 26px;}.ex-panel-body h2,.ex-panel-pad h2 { font-size: 1.2rem; margin: 6px 0 8px;}.ex-panel-pad h2 { font-size: 1.1rem; margin: 0 0 14px;}.ex-panel-body p,.ex-panel-pad p { color: var(--ex-fg-muted); line-height: 1.55; margin: 0 0 16px;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}@keyframes ex-spin { to { transform: rotate(360deg); }}.ex-ride-stops .ex-btn[aria-pressed="true"] { border-color: var(--ex-accent); color: var(--ex-accent);}.ex-page-actions .ex-btn[aria-pressed="true"] { border-color: var(--ex-accent); color: var(--ex-accent);}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}/* Four-sides example: the variant row. */.ex-side-row { display: flex; gap: 8px; flex-wrap: wrap;}.ex-side-row .ex-btn { text-transform: capitalize;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}
Menus and actions
Non-dismissible confirm
dismissible={false} and disableDrag: only the buttons close this sheet.
confirm.tsx
import * as React from "react";import { Sheet } from "scrollsheet";/** * dismissible={false}: swipe-down, backdrop tap, and Esc all stop closing * the sheet. Only the two buttons below can. */export default function ConfirmExample() { const [open, setOpen] = React.useState(false); return ( <Sheet.Root open={open} onOpenChange={setOpen} dismissible={false} disableDrag themeColorDimming > <Sheet.Trigger className="ex-trigger">Discard changes</Sheet.Trigger> <Sheet.Content className="ex-panel" aria-label="Discard unsaved changes"> <div className="ex-panel-pad"> <div className="ex-confirm-icon" aria-hidden="true"> ! </div> <Sheet.Title>Discard unsaved changes?</Sheet.Title> <Sheet.Description> Discarding will erase your unsaved edits. Use a button below to close this sheet. Swiping, tapping the backdrop, and Escape are disabled. </Sheet.Description> <div className="ex-actions"> <button type="button" className="ex-btn" data-scrollsheet-no-drag onClick={() => setOpen(false)} > Keep editing </button> <button type="button" className="ex-btn ex-btn-danger" data-scrollsheet-no-drag onClick={() => setOpen(false)} > Discard </button> </div> </div> </Sheet.Content> </Sheet.Root> );}
styles.css
Load these example styles along with scrollsheet's stylesheets. Copy icons.tsx when shown.
/* ───────────────────────────────────────────────────────────────────────── Shared example styling. Imported once by each app (playground/site) so every example in this directory looks the same everywhere it runs, without any example .tsx importing anything but "scrollsheet" and "react". Self-contained token set (--ex-*), namespaced so it never collides with a host app's own design tokens. scrollsheet itself ships a real default look for the panel (background/radius/shadow, see src/internal/styles.ts). Everything below styles the *content* inside it, plus a few panel variants (inset card, toast) that intentionally override that default. ───────────────────────────────────────────────────────────────────────── */:root { /* The edge-attached panel surface. Deliberately equal to the host page's own background so that a bottom sheet, the page behind it, and the page's <meta name="theme-color"> are all one color: theme-color is a single page-level value that browsers apply to every piece of chrome at once, so the only way the bottom bar can match the sheet AND the top bar match the page is for the sheet and the page to agree. Detached panels (.ex-panel-inset) keep --ex-bg-elevated: they float above the page and never touch the viewport edge, so they still need to read as raised. */ --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32); --ex-radius-sm: 8px; --ex-radius-md: 14px; --ex-radius-lg: 22px; --ex-radius-xl: 32px; --ex-radius-pill: 999px; --ex-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;}@media (prefers-color-scheme: dark) { :root { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6); }}/* An explicit theme choice must beat the media query in BOTH directions. A host that offers a theme toggle sets data-theme on the root element, and without these two blocks the examples keep following the OS instead: a dark-OS visitor who picks light gets a light page around sheets that stay dark. The tokens are restated rather than shared because a media query and a plain selector cannot be combined into one rule. */:root[data-theme="light"] { --ex-panel-bg: #ffffff; --ex-bg-elevated: #ffffff; --ex-bg-inset: #f5f5f4; --ex-fg: #1c1917; --ex-fg-muted: #57534e; --ex-fg-faint: #78716c; --ex-border: #e7e5e4; --ex-border-strong: #d6d3d1; --ex-accent: #5a45e8; --ex-accent-fg: #ffffff; --ex-accent-soft: #efecff; --ex-danger: #c4392f; --ex-danger-soft: #fbe9e6; --ex-success: #15803d; --ex-success-soft: #e8f5ec; --ex-shadow-sm: 0 1px 2px rgb(12 11 10 / 0.08); --ex-shadow-md: 0 8px 24px -8px rgb(12 11 10 / 0.2); --ex-shadow-lg: 0 24px 64px -20px rgb(12 11 10 / 0.32);}:root[data-theme="dark"] { --ex-panel-bg: #0a0a0b; --ex-bg-elevated: #1c1c1e; --ex-bg-inset: #222225; --ex-fg: #f4f4f5; --ex-fg-muted: #a1a1aa; --ex-fg-faint: #71717a; --ex-border: #303033; --ex-border-strong: #3f3f46; --ex-accent: #9385ff; --ex-accent-fg: #0a0a0b; --ex-accent-soft: #23204a; --ex-danger: #ff7a70; --ex-danger-soft: #2c1917; --ex-success: #4ade80; --ex-success-soft: #12271a; --ex-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4); --ex-shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5); --ex-shadow-lg: 0 24px 64px -20px rgb(0 0 0 / 0.6);}/* ── Triggers & generic buttons ─────────────────────────────────────────── */.ex-trigger { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 20px; font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: border-color 120ms ease, transform 120ms ease;}.ex-trigger:hover { border-color: var(--ex-accent);}.ex-trigger:active { transform: scale(0.97);}.ex-btn { appearance: none; border: 1px solid var(--ex-border-strong); background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-sm); padding: 11px 16px; font-size: 0.92rem; font-weight: 600; cursor: pointer; font-family: inherit;}.ex-btn:hover { border-color: var(--ex-accent);}.ex-btn-danger { background: var(--ex-danger); border-color: var(--ex-danger); color: #fff;}.ex-btn:disabled { opacity: 0.55; cursor: not-allowed;}.ex-actions { display: flex; gap: 10px; margin-top: 4px;}.ex-actions .ex-btn { flex: 1; justify-content: center;}/* ── Panel content wrappers ────────────────────────────────────────────── Sheet.Content carries .ex-panel (or .ex-panel-inset); a body wrapper inside supplies the padding, since the handle sits outside it. */.ex-panel { background: var(--ex-panel-bg); color: var(--ex-fg);}.ex-panel-pad { padding: 26px;}.ex-panel-body h2,.ex-panel-pad h2 { font-size: 1.2rem; margin: 6px 0 8px;}.ex-panel-pad h2 { font-size: 1.1rem; margin: 0 0 14px;}.ex-panel-body p,.ex-panel-pad p { color: var(--ex-fg-muted); line-height: 1.55; margin: 0 0 16px;}@keyframes ex-wallet-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; }}/* ── Confirm icon ────────────────────────────────────────────────────────── */.ex-confirm-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--ex-danger-soft); color: var(--ex-danger); display: flex; align-items: center; justify-content: center; margin-bottom: 14px;}@keyframes ex-spin { to { transform: rotate(360deg); }}.ex-ride-stops .ex-btn[aria-pressed="true"] { border-color: var(--ex-accent); color: var(--ex-accent);}.ex-page-actions .ex-btn[aria-pressed="true"] { border-color: var(--ex-accent); color: var(--ex-accent);}/* Thumbnail-to-viewer morph (View Transitions API, progressive). The custom properties come from lightbox.tsx's MORPH_SPRING — a linear() spring curve, the same shape the sheet's own open/close travel uses, instead of a hand-picked cubic-bezier that would only ease at one end. The fallback values are the pre-spring cubic-bezier, in case that <style> tag is ever missing (JS disabled, or this rule copied out on its own): a one-sided ease is still better than no easing at all. */::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-morph-dur, 280ms); animation-timing-function: var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1));}:root[data-ex-lb-exiting]::view-transition-group(ex-lb-shot) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.44, 0.58, 0, 1);}:root[data-ex-lb-exiting]::view-transition-old(root),:root[data-ex-lb-exiting]::view-transition-new(root) { animation-duration: var(--ex-lb-exit-dur); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);}:root[data-ex-lb-exiting]::view-transition-image-pair(ex-lb-shot) { overflow: clip; border-radius: 10px;}:root[data-ex-lb-exiting]::view-transition-old(ex-lb-shot) { animation: none; inline-size: 100%; block-size: 100%; object-fit: cover; mix-blend-mode: normal;}:root[data-ex-lb-exiting]::view-transition-new(ex-lb-shot) { display: none;}/* Entrance: starts a beat after the photo (30% of its duration) and finishes before it (60% long, ending at 90%) — chrome materializes around a subject already mid-flight instead of racing it. Exit: no delay, under half the duration — chrome should clear fast, not linger while the photo shrinks back to its thumbnail. Same spring curve as the photo morph on the way in. */@keyframes ex-lb-bar-in-top { from { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-out-top { to { opacity: 0; transform: translateY(-10px); }}@keyframes ex-lb-bar-in-bottom { from { opacity: 0; transform: translateY(10px); }}@keyframes ex-lb-bar-out-bottom { to { opacity: 0; transform: translateY(10px); }}::view-transition-new(ex-lb-topbar) { animation: ex-lb-bar-in-top calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-topbar) { animation: ex-lb-bar-out-top 120ms ease-out both;}::view-transition-new(ex-lb-bottombar) { animation: ex-lb-bar-in-bottom calc(var(--ex-lb-morph-dur, 280ms) * 0.6) var(--ex-lb-morph-ease, cubic-bezier(0.16, 1, 0.3, 1)) calc(var(--ex-lb-morph-dur, 280ms) * 0.3) both;}::view-transition-old(ex-lb-bottombar) { animation: ex-lb-bar-out-bottom 120ms ease-out both;}.ex-side-row .ex-btn { text-transform: capitalize;}/* Mobile: triggers and buttons drop to a tighter, native-feeling size. */@media (max-width: 719px) { .ex-trigger, .ex-btn { padding: 8px 14px; font-size: 0.88rem; }}[data-slot="mobile-select-trigger"] { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;}[data-slot="mobile-select-trigger"] > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="mobile-select-header"] { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 8px;}[data-slot="mobile-select-header"] h2 { margin: 0; font-size: 1.05rem;}[data-slot="mobile-select-search"] { padding: 0 20px 8px;}[data-slot="mobile-select-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; padding: 0 14px; border: 1px solid var(--ex-border-strong); border-radius: var(--ex-radius-sm); background: var(--ex-bg-elevated); color: var(--ex-fg); font: inherit; font-size: 16px;}[data-slot="mobile-select-search"] input:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: 1px;}[data-slot="mobile-select-list"] { padding: 0 12px;}[data-slot="mobile-select-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="mobile-select-option"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="mobile-select-option"] > span:first-child { display: flex; flex: 1; flex-direction: column; min-width: 0;}[data-slot="mobile-select-option"] > span:first-child > span:nth-child(2) { color: var(--ex-fg-muted); font-size: 0.78rem;}[data-slot="mobile-select-option"][data-active] { background: var(--ex-bg-inset);}[data-slot="mobile-select-option"][aria-selected="true"] { color: var(--ex-accent); font-weight: 600;}[data-slot="mobile-select-option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-content"] { overflow: hidden;}[data-slot="command-palette-search"] { padding: 8px 20px; border-bottom: 1px solid var(--ex-border);}[data-slot="command-palette-search"] input { width: 100%; box-sizing: border-box; min-height: 44px; border: 0; background: transparent; color: var(--ex-fg); font: inherit; font-size: 16px; outline: none;}[data-slot="command-palette-list"] { padding: 8px 12px;}[data-slot="command-palette-group"] { padding: 12px 8px 4px; color: var(--ex-fg-muted); font-size: 0.75rem; font-weight: 600;}[data-slot="command-palette-item"] { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 8px; border-radius: var(--ex-radius-sm); color: var(--ex-fg); font-size: 0.95rem; cursor: pointer;}[data-slot="command-palette-item"] > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}[data-slot="command-palette-item"][data-active] { background: var(--ex-bg-inset);}[data-slot="command-palette-item"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed;}[data-slot="command-palette-item"] kbd { color: var(--ex-fg-faint); font: inherit; font-size: 0.78rem;}[data-slot="picker-sheet-header"] { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 8px;}[data-slot="picker-sheet-header"] h2 { margin: 0; font-size: 1rem;}[data-slot="picker-sheet-header"] button { min-height: 44px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 0.95rem; cursor: pointer;}[data-slot="picker-sheet-header"] button:first-child { color: var(--ex-fg-muted);}[data-slot="picker-wheel"] { padding: 0 20px 24px; color: var(--ex-fg);}[data-slot="picker-wheel-band"] { margin-inline: 20px; border-radius: var(--ex-radius-sm); background: var(--ex-bg-inset);}[data-slot="picker-wheel-column"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px; border-radius: var(--ex-radius-sm);}[data-slot="picker-wheel-item"] { font-size: 1.15rem; font-variant-numeric: tabular-nums; transition: opacity 120ms;}@media (prefers-reduced-motion: reduce) { [data-slot="picker-wheel-item"] { transition: none; }}[data-slot="action-sheet-actions"],[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); color: var(--ex-fg); border-radius: var(--ex-radius-md);}[data-slot="action-sheet-actions"] { overflow: hidden;}[data-slot="action-sheet-content"] > div { display: flex; flex-direction: column; gap: 8px;}[data-slot="action-sheet-actions"] > div:first-child { padding: 12px 16px; border-bottom: 1px solid var(--ex-border); text-align: center; color: var(--ex-fg-muted); font-size: 0.8rem;}[data-slot="action-sheet-actions"] > div:first-child h2 { margin: 0; font-size: 0.8rem; font-weight: 600;}[data-slot="action-sheet-actions"] > div:first-child p { margin: 2px 0 0;}[data-slot="action-sheet-action"],[data-slot="action-sheet-cancel"] { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; border: 0; background: transparent; color: var(--ex-accent); font: inherit; font-size: 1.1rem; cursor: pointer;}[data-slot="action-sheet-cancel"] { background: var(--ex-bg-elevated); font-weight: 600;}[data-slot="action-sheet-action"] + [data-slot="action-sheet-action"] { border-top: 1px solid var(--ex-border);}[data-slot="action-sheet-action"][data-destructive] { color: var(--ex-danger);}[data-slot="action-sheet-action"]:disabled { opacity: 0.4; cursor: not-allowed;}[data-slot="action-sheet-action"]:focus-visible,[data-slot="action-sheet-cancel"]:focus-visible { outline: 2px solid var(--ex-accent); outline-offset: -2px;}