lumen-dioxus 6.0.0

Lumen UI components for Dioxus: web, desktop, mobile, and Dioxus Native (Blitz).
Documentation
//! Gallery section: data and records: stats, meters, ratings, timelines, timers, description
//! lists, tables, trees, long lists, dashboards, the theme builder, the world map, and the AI
//! surfaces.

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

const COLUMN: &str = "display: flex; flex-direction: column; gap: 16px;";
const ROW: &str = "display: flex; flex-wrap: wrap; gap: 12px; align-items: center;";

fn members() -> Vec<DataTableRow> {
    [
        ("ada", "Ada Lovelace", "Owner", 12),
        ("grace", "Grace Hopper", "Admin", 1200),
        ("linus", "Linus Torvalds", "Member", 3),
        ("margaret", "Margaret Hamilton", "Member", 48),
    ]
    .into_iter()
    .map(|(id, name, role, seats)| {
        let seats_text = if seats >= 1000 {
            format!("{},{:03}", seats / 1000, seats % 1000)
        } else {
            seats.to_string()
        };

        DataTableRow::new(id)
            .cell("name", name)
            .cell("role", role)
            .cell(
                "seats",
                DataTableCell::new(seats_text).with_sort_value(seats.to_string()),
            )
    })
    .collect()
}

fn files() -> Vec<TreeNode> {
    vec![
        TreeNode::new("src", "src").with_children(vec![
            TreeNode::new("components", "components").with_children(vec![
                TreeNode::new("button", "button.rs"),
                TreeNode::new("card", "card.rs"),
            ]),
            TreeNode::new("lib", "lib.rs"),
        ]),
        TreeNode::new("tests", "tests").with_children(vec![TreeNode::new("parity", "parity.rs")]),
        TreeNode::new("cargo", "Cargo.toml"),
    ]
}

/// Every data component in its common states.
#[component]
#[allow(clippy::too_many_lines)]
pub fn DataSection() -> Element {
    let mut rating = use_signal(|| 4.0);
    let mut seats = use_signal(|| 3.0);
    let mut sorting = use_signal(|| vec![DataTableSort::descending("seats")]);
    let mut selected = use_signal(Vec::<String>::new);
    let mut tree_selection = use_signal(|| "lib".to_string());
    let mut steps = use_signal(|| {
        vec![
            ReorderableListItem::new("draft", "Draft").with_description("Due today"),
            ReorderableListItem::new("review", "Review"),
            ReorderableListItem::new("ship", "Ship"),
        ]
    });
    let mut filters = use_signal(|| {
        vec![
            FilterBarFilter::new("status", "Status", "Open"),
            FilterBarFilter::new("owner", "Owner", "Ada"),
        ]
    });
    let mut approval = use_signal(ApprovalCardStatus::default);
    let mut pending = use_signal(|| false);
    let mut last_prompt = use_signal(String::new);
    let mut draft = use_signal(String::new);
    let mut feedback = use_signal(|| None::<MessageFeedback>);
    let mut country = use_signal(|| "CO".to_string());
    let log_lines: Vec<String> = (1..=200).map(|line| format!("Log line {line}")).collect();
    let columns = vec![
        DataTableColumn::new("name", "Name").sortable_text(),
        DataTableColumn::new("role", "Role"),
        DataTableColumn::new("seats", "Seats").sortable(DataTableSortType::Number),
    ];
    let primary = sorting.read().first().cloned();
    let approval_label = match approval() {
        ApprovalCardStatus::Pending => "Waiting for a decision",
        ApprovalCardStatus::Approved => "Approved",
        ApprovalCardStatus::Rejected => "Rejected",
        _ => "Updated",
    };

    rsx! {
        section { style: COLUMN,
            h2 { class: "ui-label", "Data" }

            StatGroup { aria_label: "Usage", dividers: true,
                Stat { tone: StatTone::Success,
                    StatIcon { Icon { icon: &icons::lucide::TRENDING_UP } }
                    StatLabel { "Revenue" }
                    StatValue { "$12,400" }
                    StatTrend { tone: StatTrendTone::Success, "+8%" }
                    StatDescription { "Since last month" }
                }
                Stat { label: "Active users", value: "1,204" }
                Stat { variant: StatVariant::Accent, label: "Seats", value: "{seats}" }
            }

            div { style: ROW,
                Meter { aria_label: "Seats used", max: 5.0, min: 0.0, segments: 5, value: seats() }
                Meter {
                    aria_label: "Storage",
                    max: 2000.0,
                    min: 0.0,
                    value: 1250.0,
                    value_label: "{{value}} MB of {{max}} MB",
                }
                Button {
                    size: ButtonSize::Sm,
                    variant: ButtonVariant::Outline,
                    onclick: move |_| seats.set((seats() + 1.0) % 6.0),
                    "Add seat"
                }
                Rating { value: rating(), on_value_change: move |next| rating.set(next) }
            }

            div { style: ROW,
                Timeline {
                    TimelineItem { dot: rsx! { "1" }, "Account created" }
                    TimelineItem { dot: rsx! { "2" }, "First deploy" }
                    TimelineItem { "Team invited" }
                }
                Timer { announce: TimerAnnounce::Complete, to: "2030-01-01T00:00:00Z" }
                Timer {
                    format: TimerFormat::Units,
                    from: "2026-01-01T00:00:00Z",
                    mode: TimerMode::Elapsed,
                }
            }

            Descriptions {
                columns: 2,
                items: vec![
                    DescriptionsItem::new("Plan", "Pro"),
                    DescriptionsItem::new("Region", "eu-west-1"),
                ],
                DescriptionItem {
                    DescriptionTerm { "Owner" }
                    DescriptionDetail { Badge { variant: BadgeVariant::Success, "Ada" } }
                }
            }

            Table { sticky_first_column: true,
                table {
                    thead {
                        tr {
                            th { scope: "col", "Plan" }
                            th { scope: "col", "Seats" }
                            th { scope: "col", "Price" }
                        }
                    }
                    tbody {
                        tr { td { "Starter" } td { "3" } td { "$0" } }
                        tr { td { "Pro" } td { "10" } td { "$24" } }
                    }
                }
            }

            DataTableSortControls {
                columns: columns.clone(),
                sort: primary,
                on_sort_change: move |next: Option<DataTableSort>| sorting.set(next.into_iter().collect()),
            }
            DataTable {
                aria_label: "Members",
                columns: columns.clone(),
                multi_sort: true,
                on_selected_row_ids_change: move |ids| selected.set(ids),
                on_sorting_change: move |next| sorting.set(next),
                render_details: move |row: DataTableRow| rsx! {
                    p { "{row.text(\"name\")} manages {row.text(\"seats\")} seats." }
                },
                rows: members(),
                selectable: true,
                selected_row_ids: selected(),
                sorting: sorting(),
            }
            p { "{selected.read().len()} selected" }

            DataTableView {
                columns: vec![
                    DataTableViewColumn::new("name", "Name").sortable().always_visible(),
                    DataTableViewColumn::new("role", "Role").with_filter_options(vec![
                        ("Owner".to_string(), "Owner".to_string()),
                        ("Admin".to_string(), "Admin".to_string()),
                        ("Member".to_string(), "Member".to_string()),
                    ]),
                ],
                label: "Member directory",
                render: move |view: DataTableViewResult| {
                    let toggle = view.toggle_sort;
                    let show_role = view.is_column_visible("role");

                    rsx! {
                        Table {
                            table {
                                thead {
                                    tr {
                                        th { scope: "col",
                                            button {
                                                class: "ui-data-table__sort",
                                                r#type: "button",
                                                onclick: move |_| toggle.call(("name".to_string(), false)),
                                                "Name"
                                            }
                                        }
                                        if show_role {
                                            th { scope: "col", "Role" }
                                        }
                                    }
                                }
                                tbody {
                                    for row in view.rows.iter() {
                                        tr { key: "{row.value(0)}",
                                            td { "{row.text(\"name\")}" }
                                            if show_role {
                                                td { "{row.text(\"role\")}" }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                rows: members(),
            }

            div { style: ROW,
                Tree {
                    aria_label: "Project files",
                    default_expanded: vec!["src".to_string()],
                    nodes: files(),
                    on_select: move |id| tree_selection.set(id),
                    selected: tree_selection(),
                }
                TreeGrid {
                    aria_label: "Package status",
                    columns: vec!["Package".to_string(), "Status".to_string()],
                    default_expanded: vec!["packages".to_string()],
                    rows: vec![
                        TreeGridRow::new("packages", ["packages", "—"]).with_children(vec![
                            TreeGridRow::new("astro", ["astro", "Ready"]),
                            TreeGridRow::new("dioxus", ["dioxus", "Beta"]),
                        ]),
                        TreeGridRow::new("docs", ["docs", "Draft"]),
                    ],
                }
            }

            // Dioxus Native reports no scroll events, so the gallery renders every row.
            VirtualList {
                aria_label: "Logs",
                item_count: log_lines.len(),
                item_size: 36.0,
                render_item: move |index: usize| rsx! { span { "{log_lines[index]}" } },
                style: "--ui-list-height: 12rem",
                windowing: false,
            }

            ReorderableList {
                items: steps(),
                label: "Release steps",
                move_buttons: true,
                on_reorder: move |detail: ReorderableListDetail| steps.set(detail.items),
            }

            ChangeSummary {
                items: vec![
                    ChangeSummaryItem::new("plan", "Plan", "Free", "Pro", true),
                    ChangeSummaryItem::new("billing", "Billing", "Monthly", "Monthly", false),
                ],
                summary: "1 of 2 fields changed",
            }

            FilterBar {
                filters: filters(),
                on_remove_filter: move |id: String| filters.write().retain(|filter| filter.id != id),
                on_reset: move |()| filters.write().clear(),
                result_label: "{filters.read().len()} filters active",
                Input { aria_label: "Search", placeholder: "Search", r#type: "search" }
            }

            ThemeBuilderEditor { title: "Brand theme",
                div { style: ROW,
                    Button { "Primary" }
                    Button { variant: ButtonVariant::Secondary, "Secondary" }
                    Badge { variant: BadgeVariant::Success, "Ready" }
                }
            }

            WorldMap {
                caption: "Selected: {country}",
                countries: world_map_countries().to_vec(),
                heading: "Offices",
                highlighted_countries: vec!["CO".to_string(), "BR".to_string(), "PT".to_string()],
                label: "Office locations",
                markers: vec![WorldMapMarker {
                    id: "bog".into(),
                    label: "Bogotá".into(),
                    latitude: 4.7,
                    longitude: -74.1,
                }],
                on_selected_country_change: move |id: String| country.set(id),
                selected_country: country(),
            }

            ApprovalCard {
                label: "Delete 3 generated files",
                on_response: move |detail: ApprovalCardResponseDetail| {
                    approval.set(match detail.response {
                        ApprovalCardResponse::Approve => ApprovalCardStatus::Approved,
                        ApprovalCardResponse::Reject => ApprovalCardStatus::Rejected,
                    });
                },
                request_id: "req-1",
                status: approval(),
                status_label: approval_label,
                p { "The agent wants to remove build output." }
            }

            Reasoning {
                label: if pending() { "Thinking…" } else { "Thought for a moment" },
                status: if pending() { StreamMessageStatus::Streaming } else { StreamMessageStatus::Complete },
                p { "Reading the question and checking the annual report." }
            }
            StreamMessage {
                actions: rsx! {
                    MessageActions {
                        copy_value: "You asked: {last_prompt}",
                        disabled: pending(),
                        feedback: Some(feedback()),
                        message_id: "reply-1",
                        on_feedback: move |detail: MessageFeedbackDetail| feedback.set(detail.value),
                        on_retry: move |_: MessageRetryDetail| pending.set(true),
                        retry: true,
                    }
                },
                sources: rsx! { SourceCitation { href: "https://example.com/report", label: "Annual report" } },
                status: if pending() { StreamMessageStatus::Streaming } else { StreamMessageStatus::Complete },
                status_label: if pending() { "Writing a reply" } else { "Done" },
                if last_prompt.read().is_empty() {
                    p { "Ask something to start." }
                } else {
                    p { "You asked: {last_prompt}" }
                }
            }
            ToolActivity {
                label: "Search the web",
                status: ToolActivityStatus::Success,
                status_label: "3 sources found",
                SourceCitation { href: "/docs/guide", label: "Guide" }
            }
            PromptSuggestions {
                disabled: pending(),
                on_suggestion_select: move |detail: PromptSuggestionDetail| draft.set(detail.value),
                suggestions: vec![
                    PromptSuggestion::new("Summarize").with_value("Summarize the annual report"),
                    PromptSuggestion::new("Draft a reply"),
                    PromptSuggestion::new("List open risks"),
                ],
            }
            PromptComposer {
                on_prompt_submit: move |detail: PromptComposerSubmitDetail| {
                    last_prompt.set(detail.text);
                    draft.set(String::new());
                    pending.set(true);
                },
                on_stop: move |()| pending.set(false),
                on_value_change: move |text: String| draft.set(text),
                pending: pending(),
                submit_on_enter: true,
                value: draft(),
            }
        }
    }
}