Theme Variables
Define live design tokens with IssTheme or Tailwind CSS v4 @theme syntax via theme!(), then swap themes at runtime with theme_provider without recompiling or re-parsing utilities.
Interactive Iced
Rust · WASM
Supported @theme Namespaces
Section titled “Supported @theme Namespaces”IssTheme supports every Tailwind CSS v4 token namespace: --color-*, --spacing, --spacing-*, --radius-*, --font-*, --text-*, --shadow-*, --ease-*, --breakpoint-*, --container-*, plus arbitrary custom properties (--*).
Defining a Theme & Applying Tokens
Section titled “Defining a Theme & Applying Tokens”use std::sync::Arc;use iced::widget::{button, text};use iss::{col_tw, theme, theme_provider, tw, TwExt};
let royal = Arc::new(theme!( r#"@theme { --color-surface: #1b1729; --color-brand: #7c3aed; --color-orchid: #f5d0fe; --radius-card: 16px; }"#));
let view = theme_provider( royal, col_tw( [ text("Themed Card").tw(tw!("text-sm font-bold text-(--color-orchid)")), button(text("Action").tw(tw!("text-xs font-semibold text-white"))) .on_press(Message::Action) .tw(tw!("px-3 py-1.5 rounded-lg bg-(--color-brand) hover:bg-(--color-brand)/85")), ], tw!("p-4 gap-3 rounded-(--radius-card) bg-(--color-surface)"), ),);use std::sync::Arc;use iced::widget::{button, text};use iss::typed::*;
let royal = Arc::new( IssTheme::new() .color("surface", IssColor::hex(0x1b1729)) .color("brand", palette::VIOLET_600) .color("orchid", palette::FUCHSIA_200) .radius("card", 16.0),);
let card_style = IssStyle::new() .p(4) .gap(3) .rounded_var("--radius-card") .bg_var("--color-surface");
let btn_style = IssStyle::new() .px(3) .py(1.5) .rounded_lg() .bg_var("--color-brand") .hover(|s| s.bg_var_alpha("--color-brand", 0.85));
let view = theme_provider( royal, col_tw( [ text("Themed Card").tw(IssStyle::new().text_sm().font_bold().text_color_var("--color-orchid")), button(text("Action").tw(IssStyle::new().text_xs().font_semibold().text_color(palette::WHITE))) .on_press(Message::Action) .tw(btn_style), ], card_style, ),);Live Token Syntax & Fallbacks
Section titled “Live Token Syntax & Fallbacks”| Syntax | Example | Behavior |
|---|---|---|
Shorthand (--var) |
bg-(--color-surface), p-(--spacing-card), rounded-(--radius-card) |
Resolves token live from nearest theme_provider |
Alpha modifier (--var)/alpha |
bg-(--color-brand)/20, hover:bg-(--color-brand)/85 |
Applies opacity dynamically to resolved token color |
Fallback [var(--a, fallback)] |
bg-[var(--color-accent,#7c3aed)], p-[var(--pad,12px)] |
Uses fallback value when the custom property is absent |
Nested var() fallbacks |
text-[var(--fg-brand,var(--fg-default,#f8fafc))] |
Walks balanced nested fallbacks deterministically |
| Typed builder methods | .bg_var("--color-surface"), .bg_var_alpha("--color-brand", 0.2) |
Live theme variable binding on IssStyle |