glaze_oat/toast
Oat documentation: https://oat.ink/components/toast/
Programmatic toast notifications.
Anatomy
Choose a Variant, configure Options, and call
toast to trigger a notification from application code.
Recipes
import glaze_oat/toast
let options =
toast.default_options(toast.Success)
|> toast.with_placement(toast.BottomRight)
|> toast.with_duration_ms(3000)
toast.toast("Saved", "Your changes were stored.", options)
import glaze_oat/toast
import lustre/attribute
import lustre/element/html
let options =
toast.default_options(toast.Info)
|> toast.with_duration_ms(2500)
html.button([
attribute.type_("button"),
attribute(
"onclick",
toast.toast_eval_string(
"Build complete",
"All checks passed.",
options,
),
),
], [html.text("Show toast")])
Notes
toastuses JavaScript FFI and is only available on the JS target.toast_eval_stringreturns a script string for integration contexts where inline evaluation is needed.
Types
Screen placement for a toast stack.
pub type Placement {
TopRight
TopLeft
TopCenter
BottomLeft
BottomRight
BottomCenter
}
Constructors
-
TopRight -
TopLeft -
TopCenter -
BottomLeft -
BottomRight -
BottomCenter
Values
pub fn default_options(variant: Variant) -> Options
Create default options for a given variant.
Defaults are top-right placement and 4000 milliseconds duration.
pub fn placement_to_string(placement: Placement) -> String
Convert a placement to the string expected by Oat runtime.
pub fn toast_eval_string(
title: String,
description: String,
options: Options,
) -> String
Trigger a toast notification.
Available on the JavaScript target.
Build a JavaScript expression string that triggers a toast.
Useful when integrating with APIs that expect script strings.
pub fn variant_to_string(variant: Variant) -> String
Convert a toast variant to the string expected by Oat runtime.
pub fn with_duration_ms(
options: Options,
duration_ms: Int,
) -> Options
Set toast duration in milliseconds.