limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/States

    Alert

    A persistent inline notice in one of five tones, with an optional action and a dismiss button. It has no timer and takes no focus: it stays until the host stops rendering it.

    Native componentGuide source

    Preview

    CodeSource
    fn view(palette: ComponentPalette) -> Element {
        Alert::new("Saved", "Your changes were saved.", palette)
            .tone(AlertTone::Success)
            .render()
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Alerts2 / 5
    CodeSource
    alert(AlertTone::Info, "Information", "A new version is available.")
    Alerts3 / 5
    CodeSource
    alert(AlertTone::Success, "Done", "Changes were saved.")
    Alerts4 / 5
    CodeSource
    alert(AlertTone::Warning, "Warning", "There are unsaved changes.")
    Alerts5 / 5
    CodeSource
    alert(AlertTone::Error, "Payment declined", "The payment could not be processed. Check your payment method and try again.")
    Alerts with actions1 / 2
    CodeSource
    Element::panel(
        Alert::new("Dark mode is now available", "Enable it in your profile settings.", palette)
            .id("feedback-alert-dark-mode")
            .action(Button::new("feedback-alert-enable", "Enable", palette).variant(ButtonVariant::Outline).render())
            .render(),
    )
    .size(Some(width), None)
    Alerts with actions2 / 2
    CodeSource
    if cx.state.flag("feedback-alert-dismiss") {
        Element::row(vec![
            Button::new("feedback-alert-dismiss", "Show again", palette)
                .variant(ButtonVariant::Outline)
                .render(),
            Element::spacer().flex(1.0),
        ])
    } else {
        Element::panel(
            Alert::new("Your subscription expires in 3 days", "Renew it to keep access.", palette)
                .tone(AlertTone::Warning)
                .id("feedback-alert-subscription")
                .dismiss("feedback-alert-dismiss")
                .render(),
        )
        .size(Some(width), None)
    }

    Alert

    A persistent inline notice in one of five tones, with an optional action and a dismiss button. It has no timer and takes no focus: it stays until the host stops rendering it.

    Import

    use limn::{Alert, AlertTone, Component};

    Usage

    An alert needs a title, a description and the palette. It fills the width it is given.

    fn view(palette: ComponentPalette) -> Element {
        Alert::new("Saved", "Your changes were saved.", palette)
            .tone(AlertTone::Success)
            .render()
    }

    An empty description is left out. An empty title is replaced by the tone’s own label.

    Tones

    Neutral is the default; Info, Success, Warning and Error are the others. The tone chooses the icon and its color. The surface and the border stay neutral, and only Error also tints the title and the description.

    Alert::new("Payment declined", "Check the payment method and try again.", palette)
        .tone(AlertTone::Error)
        .render()

    colors takes a whole AlertColors in place of the tone’s defaults. AlertColors::for_tone(tone, palette) gives those defaults, whose accent is a status color a host can use elsewhere.

    Action

    Alert::new("Dark mode is available", "Turn it on in your profile settings.", palette)
        .action(Button::new("enable-dark", "Enable", palette).variant(ButtonVariant::Outline).render())
        .render()

    action takes a control or a group of controls of yours, which keep their own IDs. It sits beside the copy, at the top. compact(true) puts it below the message, for a narrow layout.

    Dismiss

    fn view(state: &State, palette: ComponentPalette) -> Element {
        if state.renewal_dismissed {
            return Element::spacer();
        }
        Alert::new("Your subscription ends in 3 days", "Renew it to keep access.", palette)
            .tone(AlertTone::Warning)
            .dismiss("dismiss-renewal")
            .render()
    }
    
    fn update(state: &mut State, action: &UiAction) {
        if let UiAction::Clicked { id } = action {
            if id == "dismiss-renewal" {
                state.renewal_dismissed = true;
            }
        }
    }

    dismiss adds a close button at the end. Dismissal is controlled: the alert reports the click and stays until the host hides it.

    Actions

    ActionWhen
    UiAction::Clicked { id }The close button is activated, with the ID given to dismiss.

    A control passed to action reports its own actions.

    Accessibility

    With an id the platform is told of an alert known by that ID, named by its title and described by its description. The close button is a button named by labels().dismiss_notice. Without an id only the alert’s controls are known.

    Alert::new("Offline", "Changes are kept on this device.", palette)
        .id("offline")
        .render()

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/feedback.rs.