lumen-dioxus 6.0.0

Lumen UI components for Dioxus: web, desktop, mobile, and Dioxus Native (Blitz).
Documentation
//! Gallery section for the layout group: disclosures, headers, structure, panes, the carousel,
//! the kanban board, and the message scroller, wired to signals so the interactions show.

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

const KANBAN_COLUMNS: [(&str, &str); 3] = [
    ("planned", "Planned"),
    ("active", "In progress"),
    ("released", "Released"),
];

/// Every layout component in its common states.
#[component]
pub fn LayoutSection() -> Element {
    rsx! {
        section { style: "display: flex; flex-direction: column; gap: 24px;",
            h2 { class: "ui-label", "Layout" }
            HeadersDemo {}
            DisclosureDemo {}
            StructureDemo {}
            ResizableDemo {}
            CarouselDemo {}
            KanbanDemo {}
            MessagesDemo {}
        }
    }
}

#[component]
fn HeadersDemo() -> Element {
    let mut members = use_signal(|| 12_u32);

    rsx! {
        Hero {
            actions: rsx! {
                Button { "Get started" }
                Button { variant: ButtonVariant::Secondary, "Read the docs" }
            },
            description: rsx! { "Accessible primitives for web, desktop, and Dioxus Native." },
            eyebrow: rsx! { "Lumen for Dioxus" },
            footnote: rsx! {
                code { "cargo add lumen-dioxus" }
            },
            layout: HeroLayout::Centered,
            title: rsx! { "Build calm interfaces" },
        }
        GradientDivider {}
        PageHeader {
            actions: rsx! {
                Button { onclick: move |_| members += 1, "Invite" }
            },
            description: rsx! { "Manage who can see and edit this workspace." },
            eyebrow: rsx! { "Workspace" },
            leading: rsx! {
                Avatar { fallback: "LU" }
            },
            title: rsx! { "Team" },
        }
        SectionHeader {
            count: members().to_string(),
            description: rsx! { "Active members and pending invitations." },
            title: rsx! { "Members" },
        }
        FeatureGrid { variant: FeatureGridVariant::Card,
            FeatureGridItem {
                description: rsx! { "One token document drives every adapter." },
                index: rsx! { "01" },
                title: rsx! { "Shared tokens" },
            }
            FeatureGridItem {
                description: rsx! { "The same classes as the web packages." },
                index: rsx! { "02" },
                title: rsx! { "Markup parity" },
            }
            FeatureGridItem {
                description: rsx! { "Keyboard paths without JavaScript." },
                index: rsx! { "03" },
                title: rsx! { "Native ready" },
            }
        }
        Steps { layout: StepsLayout::Rail,
            StepsItem { title: rsx! { "Add the crate" }, "Depend on lumen-dioxus." }
            StepsItem { title: rsx! { "Render the styles" }, "Put LumenStyles near the root." }
            StepsItem { title: rsx! { "Compose" }, "Use the components from the prelude." }
        }
    }
}

#[component]
fn DisclosureDemo() -> Element {
    let mut open = use_signal(|| vec!["billing".to_string()]);
    let mut filters = use_signal(|| false);
    let open_label = open.read().join(", ");

    rsx! {
        Accordion {
            r#type: AccordionType::Single,
            value: open(),
            on_value_change: move |next| open.set(next),
            AccordionItem { value: "billing",
                AccordionTrigger { "Billing" }
                AccordionContent {
                    p { "Invoices, receipts, and payment methods." }
                }
            }
            AccordionItem { value: "team",
                AccordionTrigger { "Team" }
                AccordionContent {
                    p { "Members, roles, and pending invitations." }
                }
            }
        }
        p { class: "ui-label", "Open: {open_label}" }
        Accordion { icon: AccordionIcon::Plus, variant: AccordionVariant::Hairline,
            AccordionItem { value: "plans",
                AccordionTrigger { "Can I change my plan later?" }
                AccordionContent {
                    p { "Yes. Upgrades apply immediately." }
                }
            }
            AccordionItem { value: "refunds",
                AccordionTrigger { "Do you offer refunds?" }
                AccordionContent {
                    p { "Annual plans within 30 days." }
                }
            }
        }
        Collapsible {
            open: filters(),
            on_open_change: move |next| filters.set(next),
            CollapsibleTrigger { "Advanced filters" }
            CollapsibleContent {
                p { "Environment, region, and framework filters." }
            }
        }
    }
}

#[component]
fn StructureDemo() -> Element {
    let mut right_to_left = use_signal(|| false);
    let direction = if right_to_left() {
        DirectionValue::Rtl
    } else {
        DirectionValue::Ltr
    };

    rsx! {
        Container { size: ContainerSize::Md,
            Stack { gap: GridGap::Md,
                Toolbar { aria_label: "Formatting",
                    Button { size: ButtonSize::Sm, variant: ButtonVariant::Ghost, "Bold" }
                    Button { size: ButtonSize::Sm, variant: ButtonVariant::Ghost, "Italic" }
                    Button {
                        size: ButtonSize::Sm,
                        variant: ButtonVariant::Outline,
                        onclick: move |_| right_to_left.toggle(),
                        "Toggle direction"
                        VisuallyHidden { " (currently {direction.as_str()})" }
                    }
                }
                Direction { dir: direction,
                    Grid { columns: GridColumns::Three, gap: GridGap::Sm,
                        Card { "First" }
                        Card { "Second" }
                        Card { "Third" }
                    }
                }
                AspectRatio {
                    ratio: "21 / 9",
                    style: "background: hsl(var(--surface-muted)); border-radius: 12px;",
                    Stack {
                        align: StackAlign::Center,
                        justify: StackJustify::Center,
                        style: "height: 100%;",
                        "21:9 media"
                    }
                }
                Prose {
                    h3 { "Prose" }
                    p { "Rendered Markdown keeps Lumen's reading rhythm." }
                    ul {
                        li { "Headings" }
                        li { "Lists" }
                    }
                }
                ScrollArea { aria_label: "Release notes", style: "max-height: 8rem;",
                    for note in 1..=8 {
                        p { key: "{note}", "Release note {note}: adapters share one class contract." }
                    }
                }
                Watermark { content: "Draft",
                    div { style: "height: 120px; padding: 16px;", "Protected content" }
                }
                Affix { offset: 8.0,
                    Badge { "Sticky label" }
                }
            }
        }
    }
}

#[component]
fn ResizableDemo() -> Element {
    let mut sizes = use_signal(|| vec![28.0, 44.0, 28.0]);
    let label = sizes
        .read()
        .iter()
        .map(|size| format!("{size:.0}%"))
        .collect::<Vec<_>>()
        .join(" / ");

    rsx! {
        Resizable {
            aria_label: "Workspace panes",
            default_sizes: vec![28.0, 44.0, 28.0],
            min_size: vec![18.0, 24.0, 18.0],
            on_sizes_change: move |next| sizes.set(next),
            style: "height: 12rem;",
            ResizablePanel { r#as: ContainerElement::Aside,
                strong { "Navigation" }
            }
            ResizablePanel { r#as: ContainerElement::Section,
                strong { "Editor" }
            }
            ResizablePanel { r#as: ContainerElement::Section,
                strong { "Preview" }
            }
        }
        p { class: "ui-label", "Sizes: {label}" }
    }
}

#[component]
fn CarouselDemo() -> Element {
    rsx! {
        Carousel { aria_label: "Featured templates",
            CarouselViewport {
                for name in ["Dashboard", "Portfolio", "Storefront", "Editorial", "Analytics"] {
                    CarouselItem { key: "{name}", "{name}" }
                }
            }
            footer {
                CarouselPrevious {}
                CarouselNext {}
            }
        }
    }
}

#[component]
fn KanbanDemo() -> Element {
    let mut items = use_signal(|| {
        vec![
            (
                "notes".to_string(),
                "Release notes".to_string(),
                "planned".to_string(),
            ),
            (
                "audit".to_string(),
                "Accessibility audit".to_string(),
                "active".to_string(),
            ),
        ]
    });

    rsx! {
        KanbanBoard {
            aria_label: "Editorial workflow",
            style: "--ui-kanban-column-min-height: 10rem",
            on_move_request: move |detail: KanbanMoveDetail| {
                for item in items.write().iter_mut() {
                    if item.0 == detail.item_id {
                        item.2.clone_from(&detail.to_column);
                    }
                }
            },
            for (column, title) in KANBAN_COLUMNS {
                KanbanColumn { key: "{column}", value: column,
                    h3 { "{title}" }
                    for (id, name, _) in items.read().iter().filter(|item| item.2 == column).cloned() {
                        KanbanItem { key: "{id}", item_id: id.clone(),
                            Card { density: CardDensity::Compact,
                                strong { "{name}" }
                                KanbanHandle { aria_label: "Move {name}", "Move" }
                            }
                        }
                    }
                }
            }
        }
    }
}

#[component]
fn MessagesDemo() -> Element {
    let mut messages = use_signal(|| {
        vec![
            "Lumen components are installed.".to_string(),
            "Show me the Button docs.".to_string(),
        ]
    });
    let mut at_end = use_signal(|| true);

    rsx! {
        MessageScroller {
            aria_label: "Conversation",
            auto_scroll: true,
            on_at_end_change: move |next| at_end.set(next),
            style: "max-height: 10rem;",
            for (index, message) in messages.read().iter().enumerate() {
                p { key: "{index}", "{message}" }
            }
            MessageScrollerJump {}
        }
        Stack {
            align: StackAlign::Center,
            direction: Orientation::Horizontal,
            gap: GridGap::Sm,
            Button {
                onclick: move |_| {
                    let count = messages.read().len() + 1;
                    messages.write().push(format!("Message {count}"));
                },
                "Add message"
            }
            span { class: "ui-label",
                if at_end() {
                    "Following"
                } else {
                    "Paused"
                }
            }
        }
    }
}