xPulse
πŸ‡¬πŸ‡§ EN

8. Live Token Editor

Live Token Editor

This demo sets :root variables directly in the browser and saves them locally. Perfect for testing colors, widths, and radius values live before writing them into your own theme.

:root {
  /* no live overrides */
}

The Live Token Editor is an interactive widget that lets you modify the active theme directly in the browser. It sets CSS custom properties on the :root element, persists overrides in localStorage, and shows the resulting CSS block ready to copy.

Usage

Include the widget via template method:

{% themeTokenEditor() %}

The method renders a complete <div data-xpulse-theme-editor> block. The JavaScript in theme.js detects the attribute automatically and hydrates the widget.

Editable Tokens

CSS Variable Label Format
--xpulse-bg Page Background Color
--xpulse-surface Surface Color
--xpulse-text Text Color
--xpulse-accent Accent Color
--xpulse-warning Warning Color
--xpulse-danger Danger Color
--xpulse-content-width Content Width Length (px, rem, …)
--xpulse-sidebar-width Sidebar Width Length
--xpulse-font-size-lead Lead Size Length
--xpulse-button-radius Button Radius Length

On load the widget reads the computed values of the active theme and pre-fills the inputs. Color tokens use <input type="color">, length tokens use <input type="text">.

Behaviour

Events

Event Payload When
xpulse:theme:tokens:changed { token, value } Token value changed
xpulse:theme:tokens:changed { reset: true } Reset triggered
document.addEventListener('xpulse:theme:tokens:changed', (e) => {
console.log(e.detail); // { token: '--xpulse-accent', value: '#ff0000' }
});

Programmatic Access

You can set a single token directly via the global xpulseTheme API:

xpulseTheme.applyToken('--xpulse-accent', '#e74c3c');

Workflow: Override β†’ Theme

Recommended workflow for building a new theme:

  1. Open the editor and adjust colors and lengths live.
  2. Copy the :root { … } block from the preview.
  3. Paste it into your own theme CSS (e.g. src/themes/my-theme.css).
  4. Click Reset β€” the widget now shows the defaults again.

CSS Classes

Class Element
.xpulse-theme-editor Outer container ([data-xpulse-theme-editor])
.xpulse-theme-editor__intro Title and description
.xpulse-theme-editor__grid Grid of input fields
.xpulse-theme-editor__field Individual <label> field
.xpulse-theme-editor__actions Reset button row
.xpulse-theme-editor__preview :root CSS preview
en/styleguide/08-token-editor.md 2026-04-17