ThemeBuilder
Builds scoped token previews with hue, scheme, manual color, and export controls.
See it in context
Preview
Brand theme
Copy a working example
Usage
Astro examples assume UIPrimitives is mounted once in your root layout. Do not add the runtime next to each component instance.
---
import { Label, ThemeBuilder } from '@santi020k/lumen-astro'
---
<ThemeBuilder data-ui-theme-target="#ex-theme-preview">
<header><h3>Brand theme</h3></header>
<div style="display: grid; gap: 0.45rem;">
<Label for="ex-theme-hue">Brand hue</Label>
<input
id="ex-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<Label for="ex-theme-accent">Accent hue</Label>
<input
id="ex-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>---
import { Label, ThemeBuilder } from '@santi020k/lumen-astro'
---
<ThemeBuilder data-ui-theme-target="#ex-theme-preview">
<header><h3>Brand theme</h3></header>
<div style="display: grid; gap: 0.45rem;">
<Label for="ex-theme-hue">Brand hue</Label>
<input
id="ex-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<Label for="ex-theme-accent">Accent hue</Label>
<input
id="ex-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>import { Label, ThemeBuilder } from '@santi020k/lumen-react'
export const Example = () => (
<>
<ThemeBuilder data-ui-theme-target="#ex-theme-preview">
<header><h3>Brand theme</h3></header>
<div style={{ display: 'grid', gap: '0.45rem' }}>
<Label htmlFor="ex-theme-hue">Brand hue</Label>
<input
id="ex-theme-hue"
data-ui-theme-brand-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="264"
/>
<Label htmlFor="ex-theme-accent">Accent hue</Label>
<input
id="ex-theme-accent"
data-ui-theme-accent-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-theme-preview" style={{ display: 'flex', gap: '0.5rem', padding: '0.5rem' }}>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--brand))' }}></span>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--accent))' }}></span>
</div>
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
<button className="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button className="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button className="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea className="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>
</>
)import { Label, ThemeBuilder } from '@santi020k/lumen-react'
export const Example = () => (
<>
<ThemeBuilder data-ui-theme-target="#ex-theme-preview">
<header><h3>Brand theme</h3></header>
<div style={{ display: 'grid', gap: '0.45rem' }}>
<Label htmlFor="ex-theme-hue">Brand hue</Label>
<input
id="ex-theme-hue"
data-ui-theme-brand-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="264"
/>
<Label htmlFor="ex-theme-accent">Accent hue</Label>
<input
id="ex-theme-accent"
data-ui-theme-accent-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-theme-preview" style={{ display: 'flex', gap: '0.5rem', padding: '0.5rem' }}>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--brand))' }}></span>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--accent))' }}></span>
</div>
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
<button className="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button className="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button className="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea className="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>
</>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-theme-builder data-ui-theme-target="#ex-theme-preview">
<header><h3>Brand theme</h3></header>
<div style="display: grid; gap: 0.45rem;">
<lumen-label for="ex-theme-hue">Brand hue</lumen-label>
<input
id="ex-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<lumen-label for="ex-theme-accent">Accent hue</lumen-label>
<input
id="ex-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</lumen-theme-builder><script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-theme-builder data-ui-theme-target="#ex-theme-preview">
<header><h3>Brand theme</h3></header>
<div style="display: grid; gap: 0.45rem;">
<lumen-label for="ex-theme-hue">Brand hue</lumen-label>
<input
id="ex-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<lumen-label for="ex-theme-accent">Accent hue</lumen-label>
<input
id="ex-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</lumen-theme-builder>Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astropnpm add @santi020k/lumen-astrolumen add ThemeBuilderlumen add ThemeBuilderpnpm add @santi020k/lumen-reactpnpm add @santi020k/lumen-reactlumen add ThemeBuilder --target reactlumen add ThemeBuilder --target reactpnpm add @santi020k/lumen-elementspnpm add @santi020k/lumen-elementslumen add ThemeBuilder --target elementslumen add ThemeBuilder --target elementsGlass
Add the glass prop to apply the shared blur, saturation, border, and highlight tokens. Glass reads best over vivid content, so place the surface above imagery or color.
Brand theme
---
import { Label, ThemeBuilder } from '@santi020k/lumen-astro'
---
<div class="docs-glass-demo">
<ThemeBuilder data-ui-theme-target="#ex-glass-theme-preview" glass>
<header><h2>Brand theme</h2></header>
<div style="display: grid; gap: 0.45rem;">
<Label for="ex-glass-theme-hue">Brand hue</Label>
<input
id="ex-glass-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<Label for="ex-glass-theme-accent">Accent hue</Label>
<input
id="ex-glass-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-glass-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>
</div>---
import { Label, ThemeBuilder } from '@santi020k/lumen-astro'
---
<div class="docs-glass-demo">
<ThemeBuilder data-ui-theme-target="#ex-glass-theme-preview" glass>
<header><h2>Brand theme</h2></header>
<div style="display: grid; gap: 0.45rem;">
<Label for="ex-glass-theme-hue">Brand hue</Label>
<input
id="ex-glass-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<Label for="ex-glass-theme-accent">Accent hue</Label>
<input
id="ex-glass-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-glass-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>
</div>import { Label, ThemeBuilder } from '@santi020k/lumen-react'
export const Example = () => (
<>
<div className="docs-glass-demo">
<ThemeBuilder data-ui-theme-target="#ex-glass-theme-preview" glass>
<header><h2>Brand theme</h2></header>
<div style={{ display: 'grid', gap: '0.45rem' }}>
<Label htmlFor="ex-glass-theme-hue">Brand hue</Label>
<input
id="ex-glass-theme-hue"
data-ui-theme-brand-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="264"
/>
<Label htmlFor="ex-glass-theme-accent">Accent hue</Label>
<input
id="ex-glass-theme-accent"
data-ui-theme-accent-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-glass-theme-preview" style={{ display: 'flex', gap: '0.5rem', padding: '0.5rem' }}>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--brand))' }}></span>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--accent))' }}></span>
</div>
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
<button className="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button className="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button className="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea className="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>
</div>
</>
)import { Label, ThemeBuilder } from '@santi020k/lumen-react'
export const Example = () => (
<>
<div className="docs-glass-demo">
<ThemeBuilder data-ui-theme-target="#ex-glass-theme-preview" glass>
<header><h2>Brand theme</h2></header>
<div style={{ display: 'grid', gap: '0.45rem' }}>
<Label htmlFor="ex-glass-theme-hue">Brand hue</Label>
<input
id="ex-glass-theme-hue"
data-ui-theme-brand-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="264"
/>
<Label htmlFor="ex-glass-theme-accent">Accent hue</Label>
<input
id="ex-glass-theme-accent"
data-ui-theme-accent-hue
type="range"
className="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-glass-theme-preview" style={{ display: 'flex', gap: '0.5rem', padding: '0.5rem' }}>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--brand))' }}></span>
<span data-ui-swatch style={{ -UiSwatch: 'hsl(var(--accent))' }}></span>
</div>
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
<button className="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button className="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button className="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea className="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</ThemeBuilder>
</div>
</>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<div class="docs-glass-demo">
<lumen-theme-builder data-ui-theme-target="#ex-glass-theme-preview" glass>
<header><h2>Brand theme</h2></header>
<div style="display: grid; gap: 0.45rem;">
<lumen-label for="ex-glass-theme-hue">Brand hue</lumen-label>
<input
id="ex-glass-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<lumen-label for="ex-glass-theme-accent">Accent hue</lumen-label>
<input
id="ex-glass-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-glass-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</lumen-theme-builder>
</div><script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<div class="docs-glass-demo">
<lumen-theme-builder data-ui-theme-target="#ex-glass-theme-preview" glass>
<header><h2>Brand theme</h2></header>
<div style="display: grid; gap: 0.45rem;">
<lumen-label for="ex-glass-theme-hue">Brand hue</lumen-label>
<input
id="ex-glass-theme-hue"
data-ui-theme-brand-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="264"
/>
<lumen-label for="ex-glass-theme-accent">Accent hue</lumen-label>
<input
id="ex-glass-theme-accent"
data-ui-theme-accent-hue
type="range"
class="ui-slider"
min="0"
max="359"
value="54"
/>
</div>
<div id="ex-glass-theme-preview" style="display: flex; gap: 0.5rem; padding: 0.5rem;">
<span data-ui-swatch style="--ui-swatch:hsl(var(--brand))"></span>
<span data-ui-swatch style="--ui-swatch:hsl(var(--accent))"></span>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="ui-button" data-ui-theme-export type="button">Export CSS</button>
<button class="ui-button ui-button--outline" data-ui-theme-import type="button">Import CSS</button>
<button class="ui-button ui-button--secondary" data-ui-theme-check-contrast type="button">Fix Contrast</button>
</div>
<textarea class="ui-textarea" data-ui-theme-output aria-label="Theme CSS"></textarea>
</lumen-theme-builder>
</div>API reference
Lumen-specific props and runtime attributes for the Astro primitive. React props follow the same names; Elements use equivalent kebab-case attributes where custom elements expose them.
| Attribute | Values | Default | Description |
|---|---|---|---|
| glass | boolean | "subtle" | "strong" | false | Applies the tokenized liquid-glass surface treatment with backdrop-filter fallbacks; "subtle" and "strong" adjust the fill intensity. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:theme-change | ThemeBuilder root ([data-ui-theme-builder]) | { hue: number, accentHue: number, mode: 'generated' | 'manual', scheme: 'dark' | 'light', tokens: Record<string, string> } | Fires after ThemeBuilder hue, manual color, mode, or scheme controls update theme tokens on the target element. |
| ui:theme-export | ThemeBuilder root ([data-ui-theme-builder]) | { css?: string, format: 'css' | 'figma' | 'tokens', tokens: Record<string, string> | null, value: string } | Fires after a [data-ui-theme-export] control writes the selected CSS, Figma, or design-token export to the output and clipboard when available. |