Skip to main content
xriptxr

Theme Swatch

Info:Content
5

A theme's palette as a row of chips, read straight off the derivation.

theme swatch palette chips colors tokens algorithm invocation

Live demo

live · @xtyle/astro

ThemeSwatch

The default palette read

Each row derives its algorithm and reads the palette straight off the result. Every chip is an <xtyle-swatch>, so the dot, label, and value readout come from that component rather than a hand-rolled one.

xtyle-default

xtyle-quiet

xtyle-loud

xtyle-hc

nxi-nite

Choosing the tokens

tokens takes any token names, so a row can narrow to one family. A token the algorithm never produced is skipped rather than drawn as a hole.

the accents

status hues

surfaces and text, large, with the colour-model readout on hover

chips alone, no labels

The picture and the parts list

A card shows a theme as a fake of an interface; a swatch row shows its literal values. Paired, they answer both "what does this feel like" and "what exactly did it produce".

Theme Swatch derives an invocation the way <xtyle-theme-scope> does and paints the palette instead of applying it, so the colors a theme produced can be read without the page having to wear it. It composes <xtyle-swatch> for every chip rather than reinventing one — the dot, the label, the value readout, and the colour-model details all come from that component, so a Swatch mod restyles these along with every other chip in the app.

tokens picks which of the derived tokens to show and takes any token name, so a row can be the default palette read, just the accents, or the four status hues; a token the algorithm never produced is skipped rather than drawn as a hole. Where <xtyle-theme-card> shows a theme as a fake of an interface, this shows it as its literal values — the two are the picture and the parts list, and a picker often wants both. The row itself renders through this component's own fill, so a mod can restructure it without touching the element.

When to use

How this component composes with the rest of the set.

Put one under a <xtyle-theme-card> so a theme reads as both a picture and its literal values.
Narrow tokens to a family (--success,--warn,--danger,--info) to show what a theme does to status color specifically.
Turn on details when someone needs the hex, rgb, hsl, and oklch of what the algorithm produced.
It composes <xtyle-swatch>, so a Swatch mod restyles these chips along with every other one.

Props

8 props, straight from the manifest.

PropTypeDefaultBindingsDescription
algorithm string xtyle-default
html svelte astro
The id of the algorithm to invoke.
tokens string[] --accent, --accent-2, --bg-0, --fg-0, --success, --warn, --danger, --info
html svelte astro
Which derived tokens to show, as a comma-separated list in HTML and an array in the framework bindings. A leading `--` is optional.
scheme "light" | "dark"
light dark
html svelte astro
Pins the scheme read, re-deriving inverted when the algorithm's native mode is the other one.
size SwatchSize
sm md lg
md
html svelte astro
The chip size, passed through to each composed `<xtyle-swatch>`.
labels boolean true
html svelte astro
Show each token's name beside its chip. Set false for a bare palette strip.
details boolean false
html svelte astro
Give every chip the Swatch colour-model readout on hover and focus.
knobs Knobs
html svelte astro
The algorithm's own dials, as an object in the framework bindings and JSON in the HTML attribute.
constraints Constraints
html svelte astro
Direct token overrides applied over the derivation.

Appearance

States

error

.xtyle-theme-swatch__error

The invocation could not be derived; the row says why instead of rendering empty.

Anatomy

The named parts that make up the component, with their selectors.

row

.xtyle-theme-swatch__row

The chip row. Wraps, so a long token list reflows rather than scrolling.

chip

.xtyle-theme-swatch__row > xtyle-swatch

One <xtyle-swatch> per shown token, carrying the derived color as both its swatch and its value.

Tokens & coverage

What the component consumes, checked live against what the algorithm produces.

Success:fully covered 5/5 consumed tokens produced default register: 310 tokens

Live coverage check against the xtyle-default register (derive(xtyleDefault, { anchors })coverComponent(manifest, register)). Every token this component consumes must be a key the algorithm produces.

--danger --font-sans --leading-tight --space-2 --text-xs

Accessibility

Each chip is an <xtyle-swatch>, so its label, value, and colour-model readout carry the meaning rather than the color alone.
The row is plain content and takes no focus unless details makes each chip focusable, which is the Swatch's own behavior.
A token the algorithm never produced is skipped, so the row never presents an unlabelled empty chip.

Code

The default read, an accent-only row, and a bare strip

A full palette read, a larger accents-only row with the colour-model readout, and a seeded light theme as chips alone.

<!-- The default palette read of an algorithm's theme -->
<xtyle-theme-swatch algorithm="xtyle-quiet"></xtyle-theme-swatch>

<!-- Just the accents, larger, with the colour-model readout on hover -->
<xtyle-theme-swatch tokens="--accent,--accent-2,--accent-3" size="lg" details></xtyle-theme-swatch>

<!-- A seeded invocation, pinned light, chips only -->
<xtyle-theme-swatch
	scheme="light"
	labels="false"
	constraints='{"--accent":"#7c5cff"}'
></xtyle-theme-swatch>