Examples menu

Theme Builder

Click the swatches to repaint the preview card, then undo and redo your changes. The history is a #[Persist] array: server state per tab, with no signals.

#[Persist] history: the undo/redo stack is a plain instance array. Each tab gets its own instance, so no static maps keyed by context id are needed; the state is freed with the tab's context.
No signals, no onCleanup: the visual state is fully server-authoritative and bound to the instance lifetime, so there is nothing to clean up by hand.
Undo/redo without JavaScript: setColor pushes a new entry; undo decrements $this->historyIdx, redo increments it. History truncation on branch is a single array_slice.
Data closure + $ctx->sync(): each #[Action] mutates the history, then calls sync() to re-render. The view's data closure re-reads the live $this->history entry every render.
Input validation: only pre-approved swatch hex values are accepted. The server ignores any color not in its whitelist, making the action safe from injected values.
block: 'demo': on every undo/redo/setColor, only the demo block is re-rendered and morphed. The page header and anatomy panel stay static.
Background #ffffff
Primary #6366f1
Text #1e293b
Border #e2e8f0
Accent #f59e0b
My App Docs · Blog · Login

Welcome! This preview card reflects your current theme in real time, every color stored and rendered on the server.

Featured product of the week
Step 1 / 1

Signals

history array server only initial: [default theme]

#[Persist] undo/redo stack. Per-tab instance state, not a signal, never sent to the client.

historyIdx int server only initial: 0

#[Persist] index of the active history entry. Undo/redo move this pointer.

Actions

setColor

Reads ?slot= and ?color= params, validates against the swatch whitelist, pushes to history, calls $ctx->sync().

undo

Decrements $this->historyIdx and re-renders via $ctx->sync().

redo

Increments $this->historyIdx and re-renders via $ctx->sync().

reset

Resets history to the single default theme entry.

Views

theme_builder.html.twig

Preview uses inline CSS from the current history entry. The demo block re-renders on each action.