Skip to content

Dark Mode

ISS supports both global viewport dark mode and arbitrarily nested dark/light subtrees (such as a dark preview card inside a light window) with zero style recompilation.

Interactive Iced
Rust · WASM
Live interactive Rust Iced card toggling dark_scope and light_scope at runtime
Click Switch to Light / Switch to Dark to toggle live dark_scope resolution inside Rust Iced
use iced::widget::{container, text};
use iss::{tw, IssViewport, TwExt};
let vp = IssViewport::with_theme(1024.0, app.is_dark);
let card = container(
text("Settings").tw(vp.tw(tw!("text-base font-semibold text-zinc-900 dark:text-white"))),
)
.tw(vp.tw(tw!(
"p-5 rounded-xl bg-white dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-800"
)));
Mode Viewport Helper CSS Equivalent
IssThemeMode::System Default (IssViewport::with_theme) @media (prefers-color-scheme: dark)
IssThemeMode::Class vp.with_class_dark_mode() @custom-variant dark (&:where(.dark, .dark *));
IssThemeMode::DataAttribute vp.with_data_theme_dark_mode() @custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));

3. Scoped Subtrees: dark_scope & light_scope

Section titled “3. Scoped Subtrees: dark_scope & light_scope”

Wrap any subtree in dark_scope(...), light_scope(...), or theme_scope(is_dark, child). Descendants read the nearest enclosing scope during layout and draw without needing vp.tw(...) on every leaf.

use iced::widget::{container, text};
use iss::{col_tw, dark_scope, light_scope, tw, TwExt};
let page = col_tw(
[
container(text("Light Root").tw(tw!("text-zinc-900 dark:text-white")))
.tw(tw!("p-4 bg-white dark:bg-zinc-900 rounded-xl")),
dark_scope(col_tw(
[
text("Dark Panel").tw(tw!("text-zinc-900 dark:text-white font-semibold")),
light_scope(
container(text("Light Island").tw(tw!("text-zinc-900 dark:text-white")))
.tw(tw!("p-3 bg-white dark:bg-zinc-800 rounded-lg")),
),
],
tw!("p-4 gap-3 bg-white dark:bg-zinc-950 rounded-xl border border-zinc-800"),
)),
],
tw!("w-full p-5 gap-4 bg-zinc-100"),
);