Searching Puzzle Pieces

Type to search Puzzle Pieces.

Sheet

One component that is a snap-point bottom sheet on phones and morphs — live, in place, while open — into a side drawer or centered dialog past the breakpoint, with spring-physics snaps, drag and flick gestures, a dismiss policy, entrance and exit effects, and an optional container-transform flight out of the trigger that opened it.

This piece is a wrapper, not a port: it renders the real <dialog-panel> and <sheet-panel> custom elements from @magic-spells/sheet and binds attributes to them. The value here is motion — spring integration, the scroll-chain handoff that decides whether a finger belongs to the sheet or to a nested scroller, the profile morph across the breakpoint — and none of that is worth forking. The design-system bridge is four CSS custom properties.

The sheet closes itself on Escape, a backdrop tap, an allowed swipe, or any data-action-hide-dialog button, and reports through @hide. Your job is to flip open back to false there — see Usage.

Your cart

A plain centered dialog — same position at every width, no snap points, no morph. This is the zero-drama baseline; the examples below add the responsive profiles.

The X in the corner is yours, not the piece's: filling the header slot replaces the stock header, so this one re-supplies the heading and adds a close button. It carries data-action-hide-dialog and no click handler at all — the sheet closes itself and tells the page afterwards.

Cart line 1 — filler content so the sheet scrolls.

Cart line 2 — filler content so the sheet scrolls.

Cart line 3 — filler content so the sheet scrolls.

Cart line 4 — filler content so the sheet scrolls.

Cart line 5 — filler content so the sheet scrolls.

Cart line 6 — filler content so the sheet scrolls.

Cart line 7 — filler content so the sheet scrolls.

Cart line 8 — filler content so the sheet scrolls.

Installation

Copy the piece into your app — it compiles with your build and the code is yours:

puzzle add piece sheet

Like Scroll Stack, this piece has a runtime dependency: the web component it wraps. @magic-spells/dialog-panel is a peer that npm 7+ and pnpm install for you; Yarn 1 only warns, so install it explicitly there.

npm install @magic-spells/sheet
# Yarn 1 only — npm 7+ and pnpm install the peer for you
# yarn add @magic-spells/sheet @magic-spells/dialog-panel

Then merge both stylesheets into your app's style entry (app/styles/styles.css). dialog-panel owns the dialog and overlay transport; sheet.css layers the panel geometry, the handle and the scrim on top of it. Without them the sheet is an unstyled full-bleed native dialog:

/* app/styles/styles.css */
@import "tailwindcss";
@import "@magic-spells/dialog-panel/css" layer(components);
@import "@magic-spells/sheet/css" layer(components);

Order matters — dialog-panel first, because sheet.css deliberately overrides several of its rules. So does layer(components): both stylesheets use plain element selectors, and an unlayered import would outrank every Tailwind utility you put on the panel.

Requires the pieces.css tokens merged into your app styles (see Introduction).

Usage

import Sheet from '@/components/ui/Sheet.pzl';
<Sheet open={ cartOpen } title="Your cart" @hide={ closeCart }>
  <CartLines/>
  <Button slot="footer" @press={ checkout }>Checkout</Button>
</Sheet>

// open is EDGE-TRIGGERED: only a change to it acts. The sheet dismisses
// itself on Escape, a backdrop tap, an allowed swipe, or any
// [data-action-hide-dialog] descendant, then reports through @hide —
// where you flip open back to false so the next open is a fresh edge.

// parent script
events = {
  closeCart: () => this.setData('cartOpen', false),
};

Saying nothing about position gets the responsive default: a snapping bottom sheet on a phone, and past the breakpoint a centered dialog sized to its own content. Pass desktopPosition="bottom" to keep it welded to the bottom edge on desktop too.

open is edge-triggered: only a change to it acts. That is what makes a self-closing sheet safe — an unrelated re-render never re-opens a sheet the user just swiped away while your state still says it is open.

Controlled snaps — stock header

snap index: 1

Filters

Those three buttons write the snap prop, and the piece calls snapTo() for you — that is the whole controlled path. They live inside the sheet because showModal() makes everything outside it inert.

This one deliberately keeps the zero-config chrome: pass title and the stock header renders a heading, generates its id, and wires aria-labelledby for you. No slot, no close button, no ids to invent. The grabber pill above it comes from the component.

A slow release settles on the nearest snap; a flick steps exactly one snap in its direction, measured from wherever the panel actually is.

snap is optional-controlled: pass it with @snapChange to own the committed index, or omit it and the sheet tracks its snap on its own. The counter next to the trigger reflects each commit. initialSnap picks the opening rung — snap does not seed it.

Snap points are a mobile-bottom feature only. Widen the window past 768px and this becomes a centered dialog sized to its own content, with nothing to snap to.

Different mobile and desktop positions

Shipping address

Below 768px: a bottom sheet welded to the edge with three snap points, dragged and flicked with a thumb. At or above it: a centered dialog that hugs its own content height and is dismiss-only.

Snaps belong to bottom sheets only, so crossing the breakpoint does not merely reposition the panel — it changes what the gesture even means. Drag it to a mid snap, widen the window, and watch it morph into a centered box. The dialog never closes and no @hide fires.

The mobile side is spelled out too: snapPoints and the default position="bottom" are the phone profile, desktopPosition="center" is the wide one.

Browse

Below 768px: a floating bottom card, inset from all four edges with rounded corners, swiped down to dismiss. At or above it: a navigation drawer flush against the left edge, swiped left to dismiss.

Both halves are declared — position and mode name the phone profile, desktopPosition and desktopMode name the desktop one. The axis the swipe travels on changes with the position, so the same gesture code answers a different question on each side of the breakpoint.

Order placed

Below 768px: a bottom sheet flush to the edge that rises in behind a short blur, and slides straight back down the way it came. At or above it: a floating bottom card that slides in and then fades and shrinks away instead of travelling back across a screen it only partly covers.

Position stays bottom on both sides — only the mode and the motion change. Four separate questions, four separate props: effect, desktopEffect, exitEffect, desktopExitEffect.

Positions — same at every width

Navigation

position sets the mobile profile and desktopPosition falls back to it, so a lone position="left" is a left drawer at every width — phone and desktop alike. Nothing here morphs; that is the point of this example.

A left drawer slides in from its edge and is fixed width — snap points do not apply to the sides. Retune that width with the --sheet-active-size custom property.

Swipe it back toward its edge, tap the backdrop, press Escape, or use the X.

Cart

Same drawer, opposite edge, and again the same on a phone as on a desktop. A right drawer on a narrow screen is a real choice — it is what you want for a cart that slides over the page rather than up from the floor.

Want the phone to differ? Give it its own position and let desktopPosition take the wide profile — see the morphing examples above.

Heads up

A centered dialog hugs its content height, on a phone and on a desktop, and takes its width from --sheet-center-width.

Two short lines stay two short lines. It ignores snapPoints and mode at every width, and it is still swipe-dismissible downward.

Card mode vs edge

Card mode

Card mode floats the panel inside a small margin with rounded corners on every side — it reads as a floating surface rather than a slab welded to the edge.

mode="card" is the mobile profile and desktopMode already defaults to card, so this one is a floating card at every width. Both sheets here also pin desktopPosition="bottom": mode describes a panel with an edge to hug, and a bottom sheet otherwise centers on desktop where there is no edge to hug.

Edge mode

Edge mode sits flush against the screen edge. It is the mobile default, so saying nothing gets it on a phone; desktopMode defaults to card, so this sheet forces desktopMode="edge" to stay flush past the breakpoint too.

Leave desktopMode off and you get the third pairing for free: flush on mobile, floating card on desktop.

Both of these are also the place to see a desktop BOTTOM panel, since they pin desktopPosition="bottom". Past the breakpoint it sizes to its content rather than to a snap point — snapPoints never crosses the breakpoint — so it sits at the bottom edge only as tall as it needs to be.

Entrance and exit effects

Saved

fade-scale grows in from 95% behind a short blur, with no travel at all.

The blur is spent well before the panel settles, so the tail of the run is pure geometry. A desktop center profile picks this effect by default.

Details

Arriving and leaving are separate questions. On a phone this is a bottom sheet that slides up and slides back down. On a desktop it is a right-side card that slides in — but closing it fades and shrinks it away instead of sliding it back across the screen.

Say nothing and leaving mirrors arriving — the exit props only exist for when the mirror reads wrong.

Growing out of the thing you tapped

Aurora Pack

morphTrigger names the element the sheet grows out of. A stand-in flies from that card to the panel while the real dialog stays out of the top layer, and the dialog is promoted mid-flight — so there is no frame where a full-size panel repaints into view.

Closing it deliberately runs the flight in reverse, back into the card. Swiping it away does not: the trigger is handed back with a small pop at the end instead, because a dismissal is not a return trip.

It degrades rather than breaks. Scroll the card out of view and close the sheet, and it leaves by the ordinary spring — a morph into somewhere off screen is worse than no morph. Reduced motion drops it for the same reason.

Without morphTrigger there is no morph, but focus return still works: whatever was focused when you flipped open is passed to the component as the return target.

A sheet that may not be waved away

last result: —

Delete project?

This cannot be undone.

Swipe, backdrop tap, and Escape are all refused. The two buttons below are the only way out, which is why this one also keeps the stock header and offers no X in the corner: every exit is an explicit, labelled choice.

Each button carries data-action-hide-dialog and a data-result, so @hide receives which one closed it. The readout next to the trigger is that value. Escape and a backdrop tap would have reported null — that is how a dismissal is told apart from an answer.

Spring override

Floaty

spring="attraction friction" retunes how the sheet arrives — both dials exclusive of 0 and 1. This one is looser and floatier than the default entrance.

The override governs the entrance only; exits and snap settles keep their tuned presets, so leaving stays brisk whatever you set.

Custom header and a close button

Summer promo

New

Filling the header slot replaces the stock title entirely, so a custom header brings its own heading and points labelledby at it. There is no is-slot-filled probe — the piece cannot render the fallback alongside your markup.

The grabber is not part of that trade. It is a pseudo-element on the header, so it floats inside the padding rather than sitting in the flow: it survives any header content. Toggle showGrabber next to the trigger to see it and the room it reserves disappear together — the drag surfaces are unchanged either way. It is hidden automatically on a fine pointer and on the desktop profile, so a mouse never sees one.

The header is still an unconditional drag surface. A tap on the X never becomes a drag: pointer capture is deferred until the finger has moved 5px.

Reference

Props

openControlled, and EDGE-TRIGGERED: only a change acts. true opens, false closes. An unrelated re-render never re-opens a sheet the user already dismissed.
titleHeading text rendered by the stock header, which also generates its id and wires aria-labelledby. Ignored once the header slot is filled.
labelledbyId of the labelling heading when the header slot is filled.
positionMobile profile: bottom, left, right, or center. Default bottom.
modeMobile geometry: edge or card. Default edge. Ignored by a center position at every width.
breakpointPixel width where the desktop profile takes over. Default 768.
desktopPositionDesktop position. Falls back to position — except a bottom sheet, which defaults to center so a wide panel sizes to its content instead of standing 85vh tall. Pass "bottom" to keep it bottom.
desktopModeDesktop mode. Always card unless set — it does NOT inherit mode.
effectEntrance: slide, fade-scale, or slide-fade. Default slide.
exitEffectExit effect; falls back to effect.
desktopEffectDesktop entrance; falls back to effect, except a centered desktop profile, which defaults to fade-scale.
desktopExitEffectDesktop exit; falls back to exitEffect, then desktopEffect.
snapPointsSpace-separated CSS heights, or an array of them. A MOBILE BOTTOM prop only — every other profile sizes itself by measurement. Default "85vh".
initialSnapZero-based snap index the sheet opens at. Default: the largest.
snapOptional-controlled snap index. Only a change calls snapTo(), and a change that writes back a rung the sheet itself announced through @snapChange is absorbed — a late render can never drag the sheet back to a rung the user already left. Pair with @snapChange. It does not seed the opening index — use initialSnap.
dismissWhich of swipe, backdrop, escape may dismiss. Absent or "all" opens all three; "none" refuses all three. A refused sheet still tracks your finger and springs back.
maxDisplayWidthLargest viewport width where opening is allowed. Above it show() refuses silently, so open={true} there leaves the page out of sync until you flip it back.
spring"attraction friction" entrance override, both dials in (0, 1).
morphTriggerCSS selector or Element the panel grows out of and shrinks back into, and the focus-return target. Without it the sheet still returns focus — document.activeElement at open time is used — it simply does not morph.
showGrabberDefault true. false zeroes the handle pill and the room reserved for it. CSS only; the drag surfaces are unaffected. The component already hides it on a fine pointer and on the desktop profile.
classMerged onto the sheet-panel element.
backdropClassMerged onto the dialog-backdrop element.
styleMerged onto sheet-panel after the piece's own classes. It must not CHANGE between renders — the component writes --sheet-active-size into that same attribute every frame.

Callbacks

@hide(detail)The exit finished. detail is { result, triggerElement }: result is the data-result of the [data-action-hide-dialog] button that closed it, and null for Escape, a backdrop tap or a swipe. Flip open back to false here.
@show()The entrance settled and the native dialog is in the top layer.
@snapChange(index)A release committed a different snap; fires on commit, never mid-drag.

Slots

headerFills sheet-header, replacing the title heading entirely; a filled header brings its own heading and points labelledby at it. The grabber is a pseudo-element and survives it. Always a drag surface.
footerFills sheet-footer, pinned below the content and hidden while empty. Takes one direct child, so wrap multiple buttons in a div that carries the slot attribute.
defaultUntagged children become sheet-content, the scrollable region.

CSS custom properties

Everything the ported piece exposed as numeric props — exit runway, morph duration and easing, the trigger-return pop, the blob's stacking level — is a custom property on the component, tunable from your own CSS with no prop at all. The piece bridges four of them onto the design tokens (--sheet-panel-background, --sheet-handle-color, and the two overlay tokens) and leaves the rest at the component's defaults:

--sheet-active-sizeFixed width of a left or right sheet (default min(26rem, 90vw)), and the active snap height of a mobile bottom sheet.
--sheet-center-widthWidth of a center dialog; its height always follows its content.
--sheet-panel-border-radiusExposed corner radius in edge mode (25px). --sheet-card-border-radius (20px) and --sheet-card-margin (12px) do the same for card mode.
--sheet-content-paddingContent inset (20px). --sheet-footer-padding follows it, plus the safe area.
--sheet-morph-durationProfile-morph duration (600ms) AND the trigger-morph gate: 0 disables the morph entirely, which is what prefers-reduced-motion sets.
--sheet-exit-cushionHow far past its edge a dismissal carries the panel (28px). Raise it to about your shadow blur if the panel leaves a halo.
--sheet-trigger-return-durationThe pop a trigger plays when a close did not morph back into it (280ms).
--sheet-panel-z-indexStacking of the dialog (1001), one above dialog-panel's scrim; --sheet-blob-z-index (1002) is the morph blob. Raise the trio together.

The full list lives in the component's README — these are the ones a piece consumer reaches for most.