lumen-dioxus 6.0.0

Lumen UI components for Dioxus: web, desktop, mobile, and Dioxus Native (Blitz).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
//! Gallery section: content and media display: `Agenda`, `Attachment`, `AttachmentList`,
//! `AttachmentPreview`, `Bubble`, `Code`, `CodeTabs`, `Eyebrow`, `FloatingBadge`, `FormattedDate`,
//! `FormattedNumber`, `Image`, `DeviceFrame`, `ImageComparison`, `MediaViewport`, `MediaThumbnail`,
//! `MediaFilmstrip`, `InstallCommand`, `Item`, `Kbd`, `Marker`, `Message`, `Pill`, `Schedule`,
//! `Terminal`, `Typography`, `Note`, `CoverImage`, `QRCode`, `Testimonial`, `TestimonialGroup`, and
//! `SecretValue`.

use std::time::Duration;

use dioxus::prelude::*;
use lumen_dioxus::prelude::*;

const ROW: &str = "display: flex; flex-wrap: wrap; gap: 12px; align-items: center;";
const COLUMN: &str = "display: flex; flex-direction: column; gap: 16px;";
const PLAIN_BUTTON: &str = "all: unset; cursor: pointer; border-radius: 999px;";

/// A flat SVG placeholder image with a label, so the gallery needs no network.
fn placeholder(color: &str, label: &str) -> String {
    let svg = format!(
        "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 180'><rect width='320' height='180' fill='{color}'/><text x='160' y='98' font-family='sans-serif' font-size='28' fill='white' text-anchor='middle'>{label}</text></svg>"
    );

    format!(
        "data:image/svg+xml;utf8,{}",
        svg.replace('%', "%25")
            .replace('#', "%23")
            .replace('<', "%3C")
            .replace('>', "%3E")
            .replace(' ', "%20")
    )
}

/// Every content component in its common states.
#[component]
pub fn ContentSection() -> Element {
    rsx! {
        section { style: COLUMN,
            h2 { class: "ui-label", "Content" }
            TextParts {}
            Conversation {}
            CodeSamples {}
            Formatting {}
            MediaParts {}
            Planning {}
            Social {}
            Secrets {}
        }
    }
}

/// Eyebrow, Typography, Kbd, Marker, Pill, `FloatingBadge`, Item, and Note.
#[component]
fn TextParts() -> Element {
    let mut filter = use_signal(|| "all");

    rsx! {
        div { style: COLUMN,
            Typography {
                Eyebrow { "Release notes" }
                h3 { "Lumen for Dioxus" }
                p {
                    "Press "
                    Kbd { "Ctrl" }
                    " + "
                    Kbd { "K" }
                    " to open the command palette."
                }
            }
            div { style: ROW,
                Marker { "1" }
                Marker { variant: MarkerVariant::Success, "Done" }
                Marker { variant: MarkerVariant::Warning, "Review" }
                Marker { variant: MarkerVariant::Danger, "Blocked" }
            }
            div { style: ROW,
                for (value , label , count) in [("all", "All", "24"), ("open", "Open", "7"), ("closed", "Closed", "17")] {
                    button {
                        key: "{value}",
                        aria_pressed: if filter() == value { "true" } else { "false" },
                        r#type: "button",
                        style: PLAIN_BUTTON,
                        onclick: move |_| filter.set(value),
                        Pill {
                            count,
                            variant: if filter() == value { PillVariant::Brand } else { PillVariant::Outline },
                            "{label}"
                        }
                    }
                }
                Pill { href: "#tags", "Linked tag" }
                span { style: "position: relative; display: inline-flex;",
                    Avatar { fallback: "SM" }
                    FloatingBadge { "3" }
                }
            }
            ul { style: "list-style: none; padding: 0; margin: 0; display: grid; gap: 8px;",
                Item { r#as: ItemElement::Li, "Design tokens" }
                Item { r#as: ItemElement::Li, glass: true, "Glass item" }
            }
            Note { label: "Note", "Dioxus Native draws these components without a webview." }
            Note { border_position: NoteBorderPosition::Right, "A note with the border on the right." }
        }
    }
}

/// Message, Bubble, Attachment, `AttachmentList`, and `AttachmentPreview`.
#[component]
fn Conversation() -> Element {
    let mut preview_state = use_signal(|| None::<AttachmentPreviewState>);
    let mut retry = use_signal(|| 0_u32);
    let mut last_state = use_signal(|| "ready".to_string());

    rsx! {
        div { style: COLUMN,
            Message {
                Bubble { "How do I install Lumen for Dioxus?" }
            }
            Message { from: MessageFrom::User,
                Bubble { from: MessageFrom::User, "Add lumen-dioxus to Cargo.toml." }
            }
            AttachmentList { aria_label: "Files",
                li { Attachment { "design-review.pdf" } }
                li { Attachment { href: "#download", glass: true, "tokens.json" } }
                li {
                    AttachmentPreview {
                        alt: "Gradient preview",
                        src: placeholder("#6d28d9", "Preview"),
                        state: preview_state(),
                        retry_key: retry().to_string(),
                        caption: rsx! { "preview.svg ({last_state})" },
                        on_state_change: move |state: AttachmentPreviewState| last_state.set(state.as_str().to_string()),
                        actions: rsx! {
                            Button {
                                size: ButtonSize::Sm,
                                variant: ButtonVariant::Outline,
                                onclick: move |_| preview_state.set(Some(AttachmentPreviewState::Loading)),
                                "Show loading"
                            }
                            Button {
                                size: ButtonSize::Sm,
                                variant: ButtonVariant::Ghost,
                                onclick: move |_| {
                                    preview_state.set(None);
                                    retry += 1;
                                },
                                "Reset"
                            }
                        },
                    }
                }
                li {
                    AttachmentPreview { alt: "Contract", src: "#contract.pdf", content_type: "application/pdf" }
                }
            }
        }
    }
}

/// Code, `CodeTabs`, Terminal, and `InstallCommand`.
#[component]
fn CodeSamples() -> Element {
    let mut manager = use_signal(|| "cargo".to_string());
    let items = vec![
        CodeTabsItem::new("cargo", "cargo add lumen-dioxus").language("bash"),
        CodeTabsItem::new("toml", "lumen-dioxus = \"6.0\"").language("toml"),
    ];

    rsx! {
        div { style: COLUMN,
            p {
                "Render "
                lumen_dioxus::Code { "LumenStyles" }
                " once near the root of the app."
            }
            lumen_dioxus::Code {
                variant: CodeVariant::Block,
                language: "ts",
                label: "theme.ts",
                copy: true,
                recovery_label: "Copy it manually",
                code: "const theme = 'paper' // the default reading theme\nexport default theme",
            }
            CodeTabs {
                items: items.clone(),
                storage_key: "gallery-install",
                on_value_change: move |value| manager.set(value),
            }
            p { "Selected: {manager}. The tabs below follow it through the shared storage key." }
            CodeTabs { items, storage_key: "gallery-install", copy: false }
            Terminal {
                title: "Install",
                copy: true,
                lines: vec![
                    TerminalLine::command("cargo add lumen-dioxus"),
                    TerminalLine::output("Adding lumen-dioxus v0.1.0").tone(TerminalLineTone::Success),
                    TerminalLine::comment("# then run the gallery"),
                    TerminalLine::command("cargo run --example gallery --features native-example"),
                ],
            }
            InstallCommand { command: "cargo add lumen-dioxus", label: "cargo command" }
        }
    }
}

/// `FormattedNumber` and `FormattedDate`.
#[component]
fn Formatting() -> Element {
    let mut revenue = use_signal(|| 1234.5_f64);

    rsx! {
        div { style: ROW,
            FormattedNumber { value: revenue() }
            FormattedNumber {
                value: revenue(),
                format: FormattedNumberFormat::Currency,
                currency: "USD",
                notation: FormattedNumberNotation::Compact,
            }
            FormattedNumber { value: 0.256, format: FormattedNumberFormat::Percent, maximum_fraction_digits: 1.0 }
            FormattedNumber { value: 12, format: FormattedNumberFormat::Unit, unit: "kilobyte" }
            span {
                "Colombia (COP): "
                FormattedNumber {
                    value: revenue(),
                    locale: "es-CO",
                    lang: "es-CO",
                    format: FormattedNumberFormat::Currency,
                    currency: "COP",
                }
            }
            span {
                "Arabic digits: "
                FormattedNumber {
                    value: revenue(),
                    locale: "ar-EG-u-nu-arab",
                    lang: "ar-EG",
                    dir: "rtl",
                }
            }
            span {
                "French distance: "
                FormattedNumber {
                    value: 2,
                    locale: "fr-FR",
                    lang: "fr-FR",
                    format: FormattedNumberFormat::Unit,
                    unit: "meter",
                    unit_display: FormattedNumberUnitDisplay::Long,
                }
            }
            FormattedNumber { value: "not a number" }
            FormattedDate { date_time: "2026-12-01", date_style: FormattedDateStyle::Long }
            FormattedDate {
                date_time: "2026-12-01T15:04:00Z",
                date_style: FormattedDateStyle::Medium,
                time_style: FormattedDateTimeStyle::Short,
            }
            Button {
                size: ButtonSize::Sm,
                variant: ButtonVariant::Outline,
                onclick: move |_| revenue *= 10.0,
                "Multiply by 10"
            }
        }
    }
}

/// Image, `CoverImage`, `DeviceFrame`, `ImageComparison`, `MediaViewport`, `MediaThumbnail`, and
/// `MediaFilmstrip`.
#[component]
fn MediaParts() -> Element {
    let mut reveal = use_signal(|| 50.0);
    let mut mode = use_signal(ImageComparisonMode::default);
    let mut viewport = use_signal(MediaViewportValue::default);
    let mut selected = use_signal(|| vec![true, false, false]);
    let count = selected.read().iter().filter(|value| **value).count();

    rsx! {
        div { style: COLUMN,
            div { style: ROW,
                Image { alt: "Indigo placeholder", src: placeholder("#4338ca", "Image"), width: "160" }
                CoverImage { hover: true, show_bottom_gradient: true, style: "width: 220px; height: 124px;",
                    Image { alt: "Cover placeholder", src: placeholder("#0f766e", "Cover"), radius: ImageRadius::None }
                }
            }
            DeviceFrame { device: DeviceFrameDevice::Iphone, style: "max-width: 220px;",
                Image { alt: "Phone screen", src: placeholder("#be185d", "App"), radius: ImageRadius::None }
            }
            ImageComparison {
                label: "Reveal the edited photo",
                value: reveal(),
                on_value_change: move |value| reveal.set(value),
                mode: mode(),
                before: rsx! {
                    Image { alt: "Original", src: placeholder("#475569", "Before"), radius: ImageRadius::None }
                },
                after: rsx! {
                    Image { alt: "Edited", src: placeholder("#16a34a", "After"), radius: ImageRadius::None }
                },
                div { style: ROW,
                    for (value , label) in [
                        (ImageComparisonMode::Reveal, "Reveal"),
                        (ImageComparisonMode::SideBySide, "Side by side"),
                        (ImageComparisonMode::Before, "Before"),
                        (ImageComparisonMode::After, "After"),
                    ]
                    {
                        Button {
                            key: "{label}",
                            size: ButtonSize::Sm,
                            variant: if mode() == value { ButtonVariant::Secondary } else { ButtonVariant::Ghost },
                            onclick: move |_| mode.set(value),
                            "{label}"
                        }
                    }
                }
            }
            MediaViewport {
                label: "Product photo",
                value: viewport(),
                on_value_change: move |value| viewport.set(value),
                Image { alt: "Product", src: placeholder("#c2410c", "Zoom me"), radius: ImageRadius::None }
            }
            MediaFilmstrip { label: "Photos", selection_label: format!("{count} selected"),
                for index in 0..3_usize {
                    li { key: "{index}",
                        MediaThumbnail {
                            label: format!("Photo {}", index + 1),
                            order: u32::try_from(index + 1).unwrap_or(0),
                            selected: selected.read()[index],
                            state: if index == 2 { MediaThumbnailState::Loading } else { MediaThumbnailState::Ready },
                            onclick: move |_| {
                                let mut list = selected.write();
                                list[index] = !list[index];
                            },
                            Image {
                                alt: "",
                                src: placeholder(["#1d4ed8", "#9333ea", "#0891b2"][index], "Photo"),
                                radius: ImageRadius::None,
                            }
                        }
                    }
                }
            }
        }
    }
}

/// Agenda and Schedule with the schedule model.
#[component]
fn Planning() -> Element {
    let mut events = use_signal(|| {
        vec![
            ScheduleEvent {
                id: "standup".into(),
                title: "Standup".into(),
                start: "2026-12-01T09:00:00Z".into(),
                end: "2026-12-01T09:15:00Z".into(),
                resource_id: Some("room-a".into()),
            },
            ScheduleEvent {
                id: "review".into(),
                title: "Design review".into(),
                start: "2026-12-02T14:00:00Z".into(),
                end: "2026-12-02T15:00:00Z".into(),
                resource_id: Some("room-a".into()),
            },
        ]
    });
    let dates = vec!["2026-12-01".to_string(), "2026-12-02".to_string()];
    let slots = create_schedule_slots(&dates, &events.read(), &[]);
    let conflicts = schedule_conflicts(&events.read()).len();

    rsx! {
        div { style: COLUMN,
            Agenda { aria_label: "Today",
                header { "Tuesday" }
                ol {
                    li { "09:00 Standup" }
                    li { "14:00 Design review" }
                }
            }
            Schedule { aria_label: "This week",
                div { "data-ui-schedule-grid": "", style: "--ui-schedule-columns: 2;",
                    for slot in slots {
                        div { key: "{slot.date}", "data-ui-schedule-slot": "",
                            strong { "{slot.date}" }
                            for event in slot.events {
                                div { key: "{event.id}", "data-ui-schedule-event": "", "{event.title}" }
                            }
                        }
                    }
                }
            }
            div { style: ROW,
                Button {
                    size: ButtonSize::Sm,
                    variant: ButtonVariant::Outline,
                    onclick: move |_| {
                        let moved = move_schedule_event(
                            &events.read(),
                            "review",
                            "2026-12-01T09:00:00Z",
                            "2026-12-01T10:00:00Z",
                            None,
                        );
                        events.set(moved);
                    },
                    "Move the review to Tuesday 09:00"
                }
                span { "Conflicts: {conflicts}" }
            }
        }
    }
}

/// Testimonial, `TestimonialGroup`, and `QRCode`.
#[component]
fn Social() -> Element {
    rsx! {
        div { style: COLUMN,
            Testimonial {
                author: "Ada Lovelace",
                author_role: "Analyst",
                initials: "AL",
                context: "Engine notes",
                cite: "https://lumen.santi020k.com",
                p { "The components render the same markup on every renderer." }
            }
            TestimonialGroup {
                label: "What people say",
                items: vec![
                    TestimonialGroupItem::new("Grace Hopper", "Ship it."),
                    TestimonialGroupItem::new("Alan Turing", "Clear and consistent."),
                    TestimonialGroupItem::new("Katherine Johnson", "Numbers line up."),
                ],
            }
            QRCode { value: "https://lumen.santi020k.com", size: 140 }
        }
    }
}

/// `SecretValue` with a supplied value and with a loader.
#[component]
fn Secrets() -> Element {
    let mut state = use_signal(|| "hidden".to_string());

    rsx! {
        div { style: COLUMN,
            SecretValue {
                label: "API key",
                value: "sk_test_example_key_1234",
                auto_hide_after: 10_000.0,
                on_state_change: move |next: SecretValueState| state.set(next.as_str().to_string()),
            }
            SecretValue {
                label: "Webhook secret",
                cache_on_hide: true,
                load_value: move |()| -> SecretValueFuture {
                    Box::pin(async {
                        lumen_dioxus::time::sleep(Duration::from_millis(600)).await;
                        Ok("webhook_secret_5f0c1d".to_string())
                    })
                },
            }
            p { "API key state: {state}" }
        }
    }
}