Searching Puzzle Pieces

Type to search Puzzle Pieces.

Panel Stack

Nested-panel navigation — drill-down menus, settings flows, multi-step wizards. It is a compound family that wraps the @magic-spells/panel-stack web component, so the stack itself, the push and pop transitions, the inert handling, focus restoration, the declarative triggers and the Escape composition all come from the component rather than from a hand-rolled copy in this file.

Settings

Account

Your name, email and the address on file.

Notifications

What we email you about, and how often.

Privacy

Who can see your activity and what we keep.

Installation

Copy the family into your app:

puzzle add piece panel-stack

It has one runtime dependency — the web component it wraps:

npm install @magic-spells/panel-stack

Then merge its stylesheet into your app's style entry. It is required: the absolute panel positioning, the per-state transform and filter properties, the stack effect's inner shadow, the reduced-motion opt-out and the :not(:defined) anti-flash guard are all in it.

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

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

Usage

import PanelStack from '@/components/ui/PanelStack';
<PanelStack class="h-80" current={ panel } @change={ setPanel }>
  <PanelStack.Panel handle="root">
    <button data-action-stack-push target="shop">Shop</button>
  </PanelStack.Panel>
  <PanelStack.Panel handle="shop">
    <button data-action-stack-pop>Back</button>
  </PanelStack.Panel>
</PanelStack>

The stack fills its parent, so give it — or a wrapper — an explicit size. The first panel is the root of the stack; an authored current naming a different one seeds the stack as [root, current] silently, so Back and Escape still work.

Declarative triggers

The push and pop buttons are the component's own markup contract, handled by a delegated click listener. The piece adds nothing, and pop() restores focus to the trigger that opened the panel it is leaving.

<button data-action-stack-push target="shop">Open shop</button>
<button data-action-stack-pop>Back</button>

<!-- optional: send focus somewhere specific on entry -->
<input data-stack-focus type="search" placeholder="Search"/>

Controlled current

Root

Details

Deeper still

current = root · 0 changes

Stack effect

Library

Nightfall

The previous panel shrinks and darkens behind this one instead of sliding off.

Reference

PanelStack

currentControlled: the handle that should be showing. Resolved against the stack — root resets, an ancestor pops per level, anything else pushes.
defaultCurrentUncontrolled seed, frozen into the attribute once. Seeds the stack as [root, current] so Back still works.
effect'slide' (default) | 'stack'.
classMerged onto the panel-stack host. Give it a size — the stack fills its parent.
@change(handle)Value-first, once per settled transition (panel-stack:change). A nested stack is filtered out by target.
@push(detail)Raw { fromHandle, toHandle }. Cancelable — preventDefault() blocks the push and the component restores itself.
@pop(detail)Raw { fromHandle, toHandle }.
@reset(detail)Raw { rootHandle }, when the stack collapses back to the root.

PanelStack.Panel

handleRequired; the identifier this panel is pushed and popped by. The first Panel is the root.
classMerged onto stack-panel, after the background. Never write state, inert or aria-hidden — the component owns them.

Markup contract

data-action-stack-pushOn any element inside the stack, with target="<handle>". Pushes that panel and remembers the trigger.
data-action-stack-popPops one level and returns focus to the remembered trigger.
data-stack-focusMarks the element a panel should focus on entry; otherwise its first focusable child.
EscapePops one level at depth > 1. At the root it bubbles untouched so a wrapping Dialog closes normally.

Setting current is resolved against the stack: the same handle is a no-op, the root resets, a handle already in the ancestry pops one level at a time, and anything else pushes. An unknown handle is ignored. A cancelled push — preventDefault() on @push — is restored by the component; the piece never reverts anything itself. Panels are positioned with transforms, so neither the root nor a panel may be a morph root.