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
1. Global Dark Mode via IssViewport
Section titled “1. Global Dark Mode via IssViewport”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")));use iced::widget::{container, text};use iss::typed::*;
let vp = IssViewport::with_theme(1024.0, app.is_dark);
let card_style = IssStyle::new() .p(5) .rounded_xl() .bg(palette::WHITE) .border() .border_color(palette::ZINC_200) .dark(|s| s.bg(palette::ZINC_900).border_color(palette::ZINC_800));
let label_style = IssStyle::new() .text_base() .font_semibold() .text_color(palette::ZINC_900) .dark(|s| s.text_color(palette::WHITE));
let card = container(text("Settings").tw(vp.tw(label_style))).tw(vp.tw(card_style));2. Strategy Selection (IssThemeMode)
Section titled “2. Strategy Selection (IssThemeMode)”| 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"),);