use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[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 {}
}
}
}
#[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 }
}
}
}
#[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,
}
}
}
}
#[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()] }
}
}
}
const NOTE_STYLE: &str = "margin: 0; color: hsl(var(--ink-soft)); font-size: 0.875rem;";
#[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}" }
}
}
}
#[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}" }
}
}
}
#[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" }
}
}
}
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" }
}
}
}
}