Dialog
A centered modal on the native dialog element: the browser traps focus, inerts the page and owns the top layer, and the piece adds the panel chrome, the ARIA wiring and one dismiss policy.
This piece is a wrapper, not a port: it renders the real <dialog-panel> and <dialog-backdrop> custom elements from @magic-spells/dialog-panel and lets them run the open and close machine. Sheet and Bottom Sheet sit on the same component, so all three overlays share one loaded module and one close-and-notify contract. What is left here is exactly what a piece should own: a token-styled panel.
The dialog closes itself on Escape, a backdrop click, or any data-action-hide-dialog button, and reports through @hide. Your job is to flip open back to false there — see Usage.
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece dialog
Like Sheet, Bottom Sheet and Scroll Stack, this piece has a runtime dependency: the web component it wraps. It is the same package those two already pull in as a peer, so if you use any of them it is installed once and shared.
npm install @magic-spells/dialog-panel
Then merge the component's stylesheet into your app's style entry (app/styles/styles.css). It owns the dialog and overlay transport — the state-driven fade, the backdrop element, and the page scroll lock. Without it the dialog is an unstyled native dialog with no animation and no scrim:
/* app/styles/styles.css */ @import "tailwindcss"; @import "@magic-spells/dialog-panel/css" layer(components);
layer(components) is not optional cosmetics: the stylesheet uses plain element selectors, and an unlayered import would outrank every Tailwind utility on the panel — including the size cap and the surface color this piece sets.
Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import Dialog from '@/components/ui/Dialog.pzl';
<Dialog open={ open } title="Delete project?" description="This cannot be undone." @hide={ finish }>
<p>The project and all of its data are removed.</p>
<div slot="footer" class="flex gap-2">
<button type="button" data-action-hide-dialog data-result="cancel" class="…">Cancel</button>
<button type="button" data-action-hide-dialog data-result="delete" class="…">Delete</button>
</div>
</Dialog>
// open is EDGE-TRIGGERED: only a change to it acts. The dialog dismisses
// itself on Escape, a backdrop click, 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.open is edge-triggered: only a change to it acts. That is what makes a self-closing dialog safe — an unrelated re-render never re-opens a dialog the user just dismissed while your state still says it is open.
Coming from the ported piece: @close(reason) is gone. The dialog reports through @hide, whose detail carries result and triggerElement — result names the button that closed it and is null for every dismissal. The morph prop is gone too; see Morphing dialogs. dismissible, title, description, size and class all mean what they did.
A dialog that may not be waved away
Sizes
Close button and a scrolling body
Custom header
Morphing dialogs
The ported piece grew a container transform out of its trigger through @magic-spells/morph-engine, and the wrapper drops it. dialog-panel does accept a duck-typed engine, but no engine in this family implements that seam on its own — Sheet builds it inside its own component. A morphing centered dialog is therefore already a piece:
<button id="new-project-card" @click={ open }>…a card, a button, anything…</button>
<Sheet
open={ cardOpen }
position="center"
morphTrigger="#new-project-card"
title="Release v0.1 is ready"
@hide={ close }>
<p>The card you clicked grew into this panel, and it shrinks back on close.</p>
</Sheet>
// Sheet at position="center" IS a centered modal dialog — same
// dialog-panel underneath, same @show / @hide contract — and it is the
// piece that owns the container-transform flight.Same flight, same reduced-motion fallback, and the trigger doubles as the focus-return target. See Sheet for the live example. Without a morph, Dialog still returns focus on its own: whatever was focused when you flipped open is handed to the component as the return target.
Reference
Props
openControlled, and EDGE-TRIGGERED: only a change acts. true opens, false closes. An unrelated re-render never re-opens a dialog 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.descriptionSupporting paragraph in the stock header, with a generated id wired to aria-describedby. Ignored once the header slot is filled.labelledbyId of the labelling heading when the header slot is filled.describedbyId of the describing element when the header slot is filled.dismissibleDefault true. false refuses Escape and the backdrop by cancelling the component's beforeHide; buttons and the parent still close it, and a refused attempt fires no event at all.size"sm" | "md" (default) | "lg" — the panel's max-width: 24rem, 32rem, 42rem. Below the cap it is 90vw. There is no height prop; the panel caps at 85vh and scrolls.showCloseDefault false. true pins a close (X) button in the panel's top-right corner, outside the scroll region. It closes through the component and reports result null.closeLabelAccessible name for that button. Default "Close".classMerged onto the dialog element, after the piece's own panel classes.backdropClassMerged onto the dialog-backdrop element, after the piece's overlay classes.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 or a backdrop click. Flip open back to false here.@show()The entrance settled and the native dialog is in the top layer.Slots
headerReplaces the stock title and description block entirely; a filled header brings its own heading and points labelledby at it. Takes one direct child.footerA right-aligned row below the body, hidden while empty. Takes one direct child, so wrap multiple buttons in a div that carries the slot attribute.defaultUntagged children become the body, between the header and the footer, inside the scroll region.Styling the panel
dialog-panel publishes exactly one custom property, so unlike Sheet there is no variable bridge to build: the panel is plain token utilities, and class and backdropClass append to them. Four properties belong to the component's state machine and must not be set from a utility:
opacityThe component fades the panel and the backdrop between its four states. Setting it from a utility fights the animation and can strand the panel mid-transition.transformThe entrance and exit scale. Same rule: leave it to the state machine.transitionOwned per state, with a faster exit than entrance. Overriding it desynchronises the panel from the backdrop.displayThe backdrop only renders from the first opening frame, which is what keeps a closed panel free of a full-viewport blur layer. Never give the dialog a bare display utility either — it defeats the browser's own rule that a closed dialog is display: none. Use the open: variant.--dialog-backdrop-z-indexThe component's one custom property (default 1000). Raise it from your own CSS only as far as the page's stacking requires; very large values make the top-layer promotion flicker.Known gaps
The hidden detail carries no reason, so @hide cannot tell Escape from a backdrop click. Only a data-action-hide-dialog close is distinguishable, through result.
title and description have to be stable. They render in the header slot's fallback body, which the compiler paints once and never patches — so a heading bound to state keeps whatever text it had when the view mounted. Everything outside the slot (the size cap, class, aria-labelledby) updates normally. A heading that has to change belongs in a filled header slot, where ordinary call-site content patches as usual. Sheet and Bottom Sheet share the shape and the gap.
dialog-panel's drawer position attribute is deliberately not exposed. Its rules re-position the dialog and take over the transform, which collides with the size cap here — and an edge-anchored panel is what Sheet is for.