YuhuanStudioYunUIDocs
Getting Started

Theming

Switch brand / accent / neutral palettes at runtime through data-* attributes — applyTheme, useYunUITheme, and twelve presets.

The design tokens are three layers — scheme (raw palettes) → function (which palette fills which role) → theme (the semantic --{role}-{family}-{intensity} variables light and dark mode resolve to).

Only the middle layer is switchable at runtime, and it switches through data-* attributes on an element. That is the whole API: no context provider, no CSS regeneration, no flash.

Import

tsx
1import {
2 applyTheme,
3 readTheme,
4 useYunUITheme,
5 YUNUI_PALETTES,
6 YUNUI_THEME_PRESETS,
7} from "@yuhuanowo/yunui";

applyTheme(theme, el?)

Writes the given roles onto <html> (or el). Pass null for a role to clear it and fall back to the stylesheet's default.

tsx
1applyTheme({ brand: "violet", accent: "pink", neutral: "slate" });
2applyTheme({ accent: null }); // back to the default accent
RoleWhat it colours
brandPrimary actions, links, the accent bar under an active nav item.
accentSecondary emphasis — badges, highlights, the eyebrow pill.
neutralGreys: surfaces, borders, body text.
solidcolor / contrast / inverse — how a solid fill picks its ink.
surfacefilled or translucent.
schemelight or dark.
accentSourcebrand (accent follows the brand hue) or mono.

useYunUITheme()

The same thing as React state — returns the current theme and a setter that writes the attributes for you.

tsx
1const [theme, setTheme] = useYunUITheme();
2<button onClick={() => setTheme({ brand: "cyan" })}>Cyan</button>

readTheme(el?)

Reads the attributes back. Useful for persisting a choice, or for an SSR-safe first paint where the server has already written the attributes.

Palettes and presets

YUNUI_PALETTES is the list of palette names — iterate it to build a picker. YUNUI_THEME_PRESETS is twelve curated brand/accent/neutral triples:

Presetbrand · accent · neutral
aurorablue · violet · slate
sunsetorange · pink · sand
forestgreen · lime · gray
oceancyan · teal · slate
grapeviolet · magenta · dusk
emberred · amber · sand
lagoonteal · emerald · mint
blossompink · fuchsia · rose
royalindigo · blue · slate
citruslime · yellow · sand
orchidplum · violet · dusk
monogray · gray · gray
tsx
1{Object.entries(YUNUI_THEME_PRESETS).map(([key, preset]) => (
2 <button key={key} onClick={() => applyTheme(preset)}>{preset.label}</button>
3))}

Note

This layer is additive. It does not touch the legacy flat variables, so a consumer that never calls applyTheme renders exactly as before. Migrate onto the semantic tokens component by component.

On this page