glaze/basecoat/toast
Basecoat documentation: https://basecoatui.com/components/toast/
Programmatic toast notifications.
Note: This component requires JavaScript from Basecoat.
Anatomy
- Render a container once with
toaster - Trigger notifications either by rendering
toastmarkup, or by callingshowto build a JavaScript snippet
Recipes
import glaze/basecoat/toast
import lustre/element/html
fn success_toast_markup() {
toast.toast([toast.success()], [
toast.title([], [html.text("Success")]),
toast.description([], [html.text("Your changes have been saved.")]),
])
}
fn show_toast_script() {
toast.show(toast.Config(toast.Success, "Success", "Saved!", None, None))
}
References
- MDN ARIA
statusrole: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/status_role - MDN
CustomEvent: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
Types
Optional toast action button.
pub type Action {
Action(label: String, onclick: option.Option(String))
}
Constructors
-
Action(label: String, onclick: option.Option(String))
Optional toast cancel button.
pub type Cancel {
Cancel(
label: option.Option(String),
onclick: option.Option(String),
)
}
Constructors
-
Cancel( label: option.Option(String), onclick: option.Option(String), )
Toast category (visual style).
pub type Category {
Success
Info
Warning
Error
}
Constructors
-
Success -
Info -
Warning -
Error
Configuration used by show.
pub type Config {
Config(
category: Category,
title: String,
description: String,
action: option.Option(Action),
cancel: option.Option(Cancel),
)
}
Constructors
-
Config( category: Category, title: String, description: String, action: option.Option(Action), cancel: option.Option(Cancel), )
Values
pub fn action_button(
label: String,
attrs: List(attribute.Attribute(msg)),
) -> element.Element(msg)
pub fn cancel_button(
label: String,
attrs: List(attribute.Attribute(msg)),
) -> element.Element(msg)
pub fn content(
attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn description(
attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn duration(ms: Int) -> attribute.Attribute(msg)
pub fn error() -> attribute.Attribute(msg)
pub fn error_toast(title: String, description: String) -> String
pub fn footer(
attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn info() -> attribute.Attribute(msg)
pub fn show_simple(category: Category, title: String) -> String
pub fn success() -> attribute.Attribute(msg)
pub fn success_toast(
title: String,
description: String,
) -> String
pub fn title(
attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn toast(
attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn toaster(
attrs: List(attribute.Attribute(msg)),
) -> element.Element(msg)
pub fn toaster_aligned(
align: String,
attrs: List(attribute.Attribute(msg)),
) -> element.Element(msg)
pub fn warning() -> attribute.Attribute(msg)