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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
//! Gallery section: form inputs and choices, one demo per component, wired to signals.

// cspell:words onreset

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

/// Every inputs component in its common states.
#[component]
pub fn InputsSection() -> Element {
    rsx! {
        section { style: "display: flex; flex-direction: column; gap: 16px;",
            h3 { class: "ui-label", "AmountField" }
            AmountFieldDemo {}
            h3 { class: "ui-label", "Autocomplete" }
            AutocompleteDemo {}
            h3 { class: "ui-label", "CharacterCount" }
            CharacterCountDemo {}
            h3 { class: "ui-label", "CheckboxCard" }
            CheckboxCardDemo {}
            h3 { class: "ui-label", "CheckboxGroup" }
            CheckboxGroupDemo {}
            h3 { class: "ui-label", "Combobox" }
            ComboboxDemo {}
            h3 { class: "ui-label", "ErrorSummary" }
            ErrorSummaryDemo {}
            h3 { class: "ui-label", "Form" }
            FormDemo {}
            h3 { class: "ui-label", "InlineEdit" }
            InlineEditDemo {}
            h3 { class: "ui-label", "InputGroup" }
            InputGroupDemo {}
            h3 { class: "ui-label", "InputOTP" }
            InputOTPDemo {}
            h3 { class: "ui-label", "ListBox" }
            ListBoxDemo {}
            h3 { class: "ui-label", "Mentions" }
            MentionsDemo {}
            h3 { class: "ui-label", "NativeSelect" }
            NativeSelectDemo {}
            h3 { class: "ui-label", "NumberField" }
            NumberFieldDemo {}
            h3 { class: "ui-label", "PasswordField" }
            PasswordFieldDemo {}
            h3 { class: "ui-label", "RadioCard" }
            RadioCardDemo {}
            h3 { class: "ui-label", "RadioGroup" }
            RadioGroupDemo {}
            h3 { class: "ui-label", "SearchField" }
            SearchFieldDemo {}
            h3 { class: "ui-label", "Segmented" }
            SegmentedDemo {}
            h3 { class: "ui-label", "Select" }
            SelectDemo {}
            h3 { class: "ui-label", "SettingsRow" }
            SettingsRowDemo {}
            h3 { class: "ui-label", "Slider" }
            SliderDemo {}
            h3 { class: "ui-label", "TagGroup" }
            TagGroupDemo {}
        }
    }
}

/// A single-choice list with a visible label and a grouped multiple-choice list.
#[component]
fn ListBoxDemo() -> Element {
    let mut reviewer = use_signal(|| vec!["bruno".to_string()]);
    let mut labels = use_signal(|| vec!["design".to_string()]);
    let reviewer_text = reviewer.read().join(", ");
    let label_text = labels.read().join(", ");

    rsx! {
        div { style: "display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));",
            div { style: "display: grid; gap: 8px;",
                ListBox {
                    label: "Reviewer",
                    name: "reviewer",
                    options: vec![
                        SelectOption::new("amina", "Amina"),
                        SelectOption::new("bruno", "Bruno"),
                        SelectOption::new("chen", "Chen").disabled(true),
                        SelectOption::new("dana", "Dana"),
                    ],
                    value: reviewer(),
                    on_value_change: move |values| reviewer.set(values),
                }
                p { class: "ui-label", "Reviewer: {reviewer_text}" }
            }
            div { style: "display: grid; gap: 8px;",
                ListBox {
                    aria_label: "Labels",
                    groups: vec![
                        ListBoxGroup::new(
                            "Area",
                            [SelectOption::new("design", "Design"), SelectOption::new("docs", "Docs")],
                        ),
                        ListBoxGroup::new(
                            "Priority",
                            [SelectOption::new("urgent", "Urgent"), SelectOption::new("later", "Later")],
                        ),
                    ],
                    multiple: true,
                    value: labels(),
                    on_value_change: move |values| labels.set(values),
                }
                p { class: "ui-label", "Labels: {label_text}" }
            }
            ListBox { aria_label: "Loading reviewers", loading: true }
        }
    }
}

/// The platform picker, controlled by a signal.
#[component]
fn NativeSelectDemo() -> Element {
    let mut status = use_signal(|| "draft".to_string());

    rsx! {
        div { style: "display: grid; gap: 8px; max-width: 320px;",
            NativeSelect {
                aria_label: "Status",
                options: vec![
                    SelectOption::new("draft", "Draft"),
                    SelectOption::new("review", "In review"),
                    SelectOption::new("published", "Published"),
                    SelectOption::new("archived", "Archived").disabled(true),
                ],
                value: status(),
                onchange: move |event: FormEvent| status.set(event.value()),
            }
            p { class: "ui-label", "Status: {status}" }
            NativeSelect {
                aria_label: "Region",
                options: vec!["Europe".into(), "Americas".into(), "Asia Pacific".into()],
                placeholder: "Choose a region",
                visual_size: ControlSize::Sm,
            }
        }
    }
}

/// Lumen's default option list: a labelled, controlled select and a compact one with a placeholder.
#[component]
fn SelectDemo() -> Element {
    let mut plan = use_signal(|| "pro".to_string());

    rsx! {
        div { style: "display: grid; gap: 8px; max-width: 320px;",
            Label { id: "gallery-select-plan-label", "Plan" }
            Select {
                aria_labelledby: "gallery-select-plan-label",
                name: "plan",
                options: vec![
                    SelectOption::new("free", "Free"),
                    SelectOption::new("pro", "Pro"),
                    SelectOption::new("team", "Team"),
                    SelectOption::new("enterprise", "Enterprise").disabled(true),
                ],
                value: plan(),
                on_value_change: move |value| plan.set(value),
            }
            p { class: "ui-label", "Selected plan: {plan}" }
            Select {
                aria_label: "Billing cycle",
                options: vec!["Monthly".into(), "Quarterly".into(), "Yearly".into()],
                placeholder: "Choose a billing cycle",
                visual_size: ControlSize::Sm,
            }
            Select { aria_label: "Seats", disabled: true, default_value: "10", options: vec!["10".into()] }
        }
    }
}

/// Muted helper text under each demo.
const NOTE_STYLE: &str = "margin: 0; color: hsl(var(--ink-soft)); font-size: 0.875rem;";

/// A city search whose suggestions come from a datalist (browsers and desktop webviews).
#[component]
fn AutocompleteDemo() -> Element {
    let mut city = use_signal(String::new);
    let summary = if city.read().trim().is_empty() {
        "Type a city name.".to_string()
    } else {
        format!("Searching for “{}”.", city.read().trim())
    };

    rsx! {
        div { style: "display: grid; gap: 8px; max-width: 34rem;",
            Autocomplete {
                aria_label: "City",
                list: "gallery-cities",
                oninput: move |event: FormEvent| city.set(event.value()),
                options: vec![
                    "Bogotá".into(),
                    "Buenos Aires".into(),
                    "Lima".into(),
                    "Madrid".into(),
                    "Mexico City".into(),
                ],
                placeholder: "Search cities",
                value: city(),
            }
            p { style: NOTE_STYLE, "{summary}" }
        }
    }
}

/// A searchable framework picker with a disabled choice and a live summary of the value.
#[component]
fn ComboboxDemo() -> Element {
    let mut framework = use_signal(String::new);
    let summary = if framework.read().is_empty() {
        "Nothing chosen yet.".to_string()
    } else {
        format!("Value: {}", framework.read())
    };

    rsx! {
        div { style: "display: grid; gap: 8px;",
            Combobox {
                label: "Framework",
                list: "gallery-frameworks",
                name: "framework",
                on_value_change: move |value: String| framework.set(value),
                options: vec![
                    "Astro".into(),
                    "Dioxus".into(),
                    "React".into(),
                    SelectOption::from("Svelte").disabled(true),
                    "Web Components".into(),
                ],
                placeholder: "Search frameworks",
                value: framework(),
            }
            p { style: NOTE_STYLE, "{summary}" }
        }
    }
}

/// A comment box that suggests teammates after `@`.
#[component]
fn MentionsDemo() -> Element {
    let mut comment = use_signal(|| "Thanks for the review, ".to_string());
    let mentions = comment
        .read()
        .split_whitespace()
        .filter(|word| word.len() > 1 && word.starts_with('@'))
        .count();

    rsx! {
        div { style: "display: grid; gap: 8px; max-width: 34rem;",
            Mentions {
                label: "Comment",
                name: "comment",
                on_value_change: move |value: String| comment.set(value),
                options: vec![
                    SelectOption::new("ana", "Ana Torres"),
                    SelectOption::new("bruno", "Bruno Costa"),
                    SelectOption::new("carla", "Carla Ruiz"),
                    SelectOption::new("diego", "Diego Rojas"),
                ],
                placeholder: "Type @ to mention a teammate",
                value: comment(),
            }
            p { style: NOTE_STYLE, "Mentions in this comment: {mentions}" }
        }
    }
}

#[component]
fn NumberFieldDemo() -> Element {
    let mut guests = use_signal(|| "2".to_string());

    rsx! {
        Field { control_id: "gallery-guests",
            Label { r#for: "gallery-guests", "Guests" }
            NumberField {
                default_value: "2",
                id: "gallery-guests",
                max: "12",
                min: "1",
                name: "guests",
                on_value_change: move |value: String| guests.set(value),
                step: "1",
            }
        }
        p { style: "margin: 0;", "Guests: {guests}" }
    }
}

#[component]
fn AmountFieldDemo() -> Element {
    let mut amount = use_signal(|| AmountFieldChange::new("1234.50"));
    let change = amount.read().clone();
    let submitted = change.value.unwrap_or_else(|| "incomplete".to_string());

    rsx! {
        Field { control_id: "gallery-amount",
            Label { r#for: "gallery-amount", "Monto (es-CO)" }
            AmountField {
                default_value: "1234.50",
                id: "gallery-amount",
                locale: "es-CO",
                max: "5000000",
                min: "1000",
                name: "amount",
                on_value_change: move |next: AmountFieldChange| amount.set(next),
                range_underflow_message: "Mínimo {{min}}.",
            }
        }
        p { style: "margin: 0;", "Draft {change.draft}, submitted {submitted}" }
    }
}

#[component]
fn SliderDemo() -> Element {
    let mut volume = use_signal(|| 40.0);

    rsx! {
        Label { r#for: "gallery-volume", "Volume" }
        Slider {
            id: "gallery-volume",
            max: 100.0,
            min: 0.0,
            name: "volume",
            on_value_change: move |next: f64| volume.set(next),
            step: 5.0,
            value: volume(),
        }
        p { style: "margin: 0;", "Volume: {volume}%" }
        Slider { aria_label: "Disabled slider", default_value: 0.3, disabled: true, max: 1.0, min: 0.0, step: 0.1 }
    }
}

#[component]
fn InputOTPDemo() -> Element {
    let mut code = use_signal(String::new);
    let complete = code.read().len() == 6;

    rsx! {
        Label { r#for: "gallery-otp", "Verification code" }
        InputOTP {
            id: "gallery-otp",
            name: "otp",
            on_value_change: move |next: String| code.set(next),
        }
        p { style: "margin: 0;",
            if complete {
                "Code {code} is ready to submit."
            } else {
                "Enter the 6-digit code; paste works too."
            }
        }
        InputOTP { aria_invalid: "true", aria_label: "Expired code", default_value: "4821", length: 4 }
    }
}

#[component]
fn CheckboxCardDemo() -> Element {
    let mut updates = use_signal(|| true);
    let mut resources = use_signal(|| false);
    let summary = match (updates(), resources()) {
        (true, true) => "Product updates and design resources",
        (true, false) => "Product updates only",
        (false, true) => "Design resources only",
        (false, false) => "No emails",
    };

    rsx! {
        CheckboxGroup { legend: "Stay informed",
            CheckboxCard {
                checked: updates(),
                description: "A monthly summary of new features and improvements.",
                label: "Product updates",
                name: "card-notifications",
                onchange: move |next| updates.set(next),
                value: "product",
                "Delivered monthly"
            }
            CheckboxCard {
                checked: resources(),
                description: "Tips for creating consistent interfaces with your team.",
                label: "Design resources",
                name: "card-notifications",
                onchange: move |next| resources.set(next),
                value: "resources",
                variant: CheckboxCardVariant::Soft,
            }
            CheckboxCard {
                description: "Your workspace administrator manages these notifications.",
                disabled: true,
                label: "Security notices",
                value: "security",
            }
        }
        p { class: "ui-label", "Emails: {summary}" }
    }
}

#[component]
fn RadioCardDemo() -> Element {
    let mut workspace = use_signal(|| "personal".to_string());

    rsx! {
        RadioGroup {
            name: "card-workspace",
            on_value_change: move |next| workspace.set(next),
            value: workspace(),
            legend { "Choose a workspace" }
            RadioCard {
                description: "A focused space for your own projects.",
                label: "Personal",
                value: "personal",
                "One member"
            }
            RadioCard {
                description: "Shared projects, resources, and team settings.",
                label: "Team",
                value: "team",
                variant: RadioCardVariant::Soft,
                "Up to ten members"
            }
            RadioCard {
                description: "Contact your administrator to enable organization workspaces.",
                disabled: true,
                label: "Organization",
                value: "organization",
            }
        }
        p { class: "ui-label", "Workspace: {workspace}" }
    }
}

#[component]
fn CheckboxGroupDemo() -> Element {
    let mut product = use_signal(|| true);
    let mut billing = use_signal(|| false);
    let all = product() && billing();
    let some = product() || billing();

    rsx! {
        CheckboxGroup { legend: "Notifications",
            CheckboxGroupItem {
                checked: all,
                indeterminate: some && !all,
                onchange: move |next| {
                    product.set(next);
                    billing.set(next);
                },
                "All alerts"
            }
            CheckboxGroupItem {
                checked: product(),
                name: "alerts",
                onchange: move |next| product.set(next),
                value: "product",
                "Product alerts"
            }
            CheckboxGroupItem {
                checked: billing(),
                name: "alerts",
                onchange: move |next| billing.set(next),
                value: "billing",
                "Billing updates"
            }
        }
        CheckboxGroup {
            invalid: !some,
            legend: "Delivery days",
            orientation: Orientation::Horizontal,
            CheckboxGroupItem { default_checked: true, value: "mon", "Mon" }
            CheckboxGroupItem { value: "wed", "Wed" }
            CheckboxGroupItem { disabled: true, value: "sun", "Sun" }
        }
    }
}

#[component]
fn RadioGroupDemo() -> Element {
    let mut theme = use_signal(|| "dark".to_string());

    rsx! {
        RadioGroup {
            default_value: "dark",
            name: "theme",
            on_value_change: move |next| theme.set(next),
            legend { "Theme" }
            RadioGroupItem { value: "light", "Light" }
            RadioGroupItem { value: "dark", "Dark" }
            RadioGroupItem { value: "system", "Match the system" }
            RadioGroupItem { disabled: true, value: "contrast", "High contrast (coming soon)" }
        }
        p { class: "ui-label", "Theme: {theme}" }
    }
}

#[component]
fn SegmentedDemo() -> Element {
    let mut range = use_signal(|| "week".to_string());
    let options: Vec<SelectOption> = vec![
        SelectOption::new("day", "Day"),
        SelectOption::new("week", "Week"),
        SelectOption::new("month", "Month"),
        SelectOption::new("year", "Year").disabled(true),
    ];

    rsx! {
        div { style: "display: flex; flex-wrap: wrap; gap: 12px; align-items: center;",
            Segmented {
                aria_label: "Date range",
                name: "range",
                on_value_change: move |next| range.set(next),
                options: options.clone(),
                value: range(),
            }
            Segmented {
                aria_label: "Density",
                default_value: "Compact",
                options: vec!["Compact".into(), "Comfortable".into()],
                visual_size: ControlSize::Sm,
            }
        }
        p { class: "ui-label", "Showing the last {range}" }
    }
}

#[component]
fn TagGroupDemo() -> Element {
    let mut tags = use_signal(|| {
        vec![
            "Astro".to_string(),
            "Accessible".to_string(),
            "Rust".to_string(),
        ]
    });
    let mut removed = use_signal(|| None::<String>);

    rsx! {
        TagGroup {
            aria_label: "Selected tags",
            on_remove: move |value: String| {
                tags.retain(|tag| *tag != value);
                removed.set(Some(value));
            },
            for tag in tags() {
                TagGroupItem {
                    key: "{tag}",
                    remove_label: format!("Remove {tag}"),
                    removable: true,
                    value: tag.clone(),
                    "{tag}"
                }
            }
            TagGroupItem { value: "pinned", "Pinned" }
        }
        if let Some(tag) = removed() {
            p { class: "ui-label", "Removed {tag}" }
        }
    }
}

#[component]
fn CharacterCountDemo() -> Element {
    let mut bio = use_signal(|| "Designer and front-end developer.".to_string());

    rsx! {
        Field { control_id: "demo-bio",
            Label { r#for: "demo-bio", "Bio" }
            Textarea {
                aria_describedby: "demo-bio-count",
                id: "demo-bio",
                oninput: move |event: FormEvent| bio.set(event.value()),
                rows: 3,
                value: "{bio}",
            }
            CharacterCount { max: 60, value: bio(), value_id: "demo-bio-count" }
        }
    }
}

/// The errors for the sign-up demo's current values.
fn sign_up_errors(email: &str, name: &str) -> FormErrors {
    let mut fields = Vec::new();

    if !email.contains('@') {
        fields.push(
            FormFieldError::new("email", "Enter an email address, like ana@example.com.")
                .control_id("demo-summary-email"),
        );
    }

    if name.trim().is_empty() {
        fields
            .push(FormFieldError::new("name", "Enter your name.").control_id("demo-summary-name"));
    }

    FormErrors::from(fields)
}

#[component]
fn ErrorSummaryDemo() -> Element {
    let mut email = use_signal(String::new);
    let mut name = use_signal(String::new);
    let mut errors = use_signal(FormErrors::default);
    let email_error = errors()
        .field("email")
        .first()
        .map(|error| error.message.clone());
    let name_error = errors()
        .field("name")
        .first()
        .map(|error| error.message.clone());

    rsx! {
        Form {
            novalidate: true,
            onsubmit: move |event: FormEvent| {
                event.prevent_default();
                errors.set(sign_up_errors(&email(), &name()));
            },
            status: if errors().is_empty() { FormStatus::Idle } else { FormStatus::Error },
            ErrorSummary { errors: errors(), id: "demo-sign-up-errors" }
            Field { control_id: "demo-summary-name", invalid: name_error.is_some(),
                Label { r#for: "demo-summary-name", "Name" }
                Input {
                    id: "demo-summary-name",
                    oninput: move |event: FormEvent| name.set(event.value()),
                    value: "{name}",
                }
                FieldError { message: name_error }
            }
            Field { control_id: "demo-summary-email", invalid: email_error.is_some(),
                Label { r#for: "demo-summary-email", "Email" }
                Input {
                    id: "demo-summary-email",
                    oninput: move |event: FormEvent| email.set(event.value()),
                    r#type: "email",
                    value: "{email}",
                }
                FieldError { message: email_error }
            }
            Button { r#type: "submit", "Create account" }
        }
    }
}

#[component]
fn FormDemo() -> Element {
    let mut status = use_signal(|| FormStatus::Idle);
    let message = match status() {
        FormStatus::Submitting => "Sending your message",
        FormStatus::Success => "Message sent.",
        _ => "We reply within two working days.",
    };

    rsx! {
        Form {
            onsubmit: move |event: FormEvent| {
                event.prevent_default();
                status.set(FormStatus::Submitting);
                spawn(async move {
                    lumen_dioxus::time::sleep(std::time::Duration::from_millis(900)).await;
                    status.set(FormStatus::Success);
                });
            },
            onreset: move |_| status.set(FormStatus::Idle),
            status: status(),
            Field { control_id: "demo-form-message",
                Label { r#for: "demo-form-message", "Message" }
                Textarea { id: "demo-form-message", name: "message", rows: 3 }
            }
            p { class: "ui-field__hint", "{message}" }
            div { style: "display: flex; gap: 8px;",
                Button { loading: status() == FormStatus::Submitting, r#type: "submit", "Send" }
                Button { r#type: "reset", variant: ButtonVariant::Outline, "Reset" }
            }
        }
    }
}

#[component]
fn InlineEditDemo() -> Element {
    let mut title = use_signal(|| "Atlas launch plan".to_string());
    let mut notes = use_signal(String::new);

    rsx! {
        div { style: "display: grid; gap: 12px;",
            InlineEdit {
                heading_level: 3,
                id: "demo-inline-title",
                label: "Project name",
                max_length: 80,
                name: "project_name",
                on_value_change: move |change: InlineEditChangeDetail| title.set(change.value),
                required: true,
                value: title(),
            }
            InlineEdit {
                id: "demo-inline-notes",
                label: "Notes",
                multiline: true,
                on_value_change: move |change: InlineEditChangeDetail| notes.set(change.value),
                placeholder: "Add a note for the team",
                value: notes(),
            }
        }
    }
}

#[component]
fn InputGroupDemo() -> Element {
    let mut amount = use_signal(|| "120".to_string());

    rsx! {
        div { style: "display: grid; gap: 12px;",
            InputGroup {
                span { "$" }
                Input {
                    aria_label: "Amount",
                    inputmode: "decimal",
                    oninput: move |event: FormEvent| amount.set(event.value()),
                    value: "{amount}",
                }
                span { "USD" }
            }
            InputGroup {
                Icon { name: "search" }
                SearchField { aria_label: "Search the docs", placeholder: "Search the docs" }
            }
        }
    }
}

#[component]
fn PasswordFieldDemo() -> Element {
    let mut password = use_signal(String::new);
    let length = password().chars().count();
    let error = (length > 0 && length < 12)
        .then(|| format!("Use at least 12 characters ({length} so far)."));

    rsx! {
        PasswordField {
            autocomplete: "new-password",
            error,
            hint: "Use 12 or more characters. A short phrase works well.",
            id: "demo-password",
            label: "New password",
            name: "password",
            oninput: move |event: FormEvent| password.set(event.value()),
            value: "{password}",
        }
    }
}

const SEARCH_DEMO_COMPONENTS: [&str; 7] = [
    "CharacterCount",
    "ErrorSummary",
    "Form",
    "InputGroup",
    "PasswordField",
    "SearchField",
    "SettingsRow",
];

#[component]
fn SearchFieldDemo() -> Element {
    let mut query = use_signal(String::new);
    let needle = query().trim().to_lowercase();
    let matches: Vec<&str> = SEARCH_DEMO_COMPONENTS
        .into_iter()
        .filter(|name| name.to_lowercase().contains(&needle))
        .collect();

    rsx! {
        div { role: "search", style: "display: grid; gap: 8px;",
            SearchField {
                aria_label: "Filter components",
                oninput: move |event: FormEvent| query.set(event.value()),
                onkeydown: move |event: KeyboardEvent| {
                    if event.key() == Key::Escape {
                        query.set(String::new());
                    }
                },
                placeholder: "Filter components",
                value: "{query}",
            }
            if matches.is_empty() {
                p { class: "ui-field__hint", "No components match." }
            } else {
                ul { style: "margin: 0;",
                    for name in matches {
                        li { key: "{name}", "{name}" }
                    }
                }
            }
        }
    }
}

#[component]
fn SettingsRowDemo() -> Element {
    let mut dark = use_signal(|| false);
    let mut digest = use_signal(|| true);

    rsx! {
        div {
            SettingsRow {
                control: move |control: SettingsRowControlProps| rsx! {
                    Switch {
                        aria_describedby: control.aria_describedby,
                        aria_labelledby: control.aria_labelledby,
                        checked: dark(),
                        id: control.id,
                        onchange: move |next: bool| dark.set(next),
                    }
                },
                description: "Use dark colors across the workspace.",
                label: "Dark mode",
                leading: rsx! { Icon { name: "moon" } },
            }
            SettingsRow {
                control: move |control: SettingsRowControlProps| rsx! {
                    Switch {
                        aria_describedby: control.aria_describedby,
                        aria_labelledby: control.aria_labelledby,
                        checked: digest(),
                        id: control.id,
                        onchange: move |next: bool| digest.set(next),
                    }
                },
                description: "A summary of activity every Monday.",
                label: "Weekly digest",
                leading: rsx! { Icon { name: "bell" } },
            }
            SettingsRow { description: "Signed in as ana@example.com.", label: "Account",
                Button { size: ButtonSize::Sm, variant: ButtonVariant::Outline, "Sign out" }
            }
        }
    }
}