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

Types

Toast runtime options.

pub opaque type Options

Screen placement for a toast stack.

pub type Placement {
  TopRight
  TopLeft
  TopCenter
  BottomLeft
  BottomRight
  BottomCenter
}

Constructors

  • TopRight
  • TopLeft
  • TopCenter
  • BottomLeft
  • BottomRight
  • BottomCenter

Toast visual style.

pub type Variant {
  Info
  Success
  Danger
  Warning
}

Constructors

  • Info
  • Success
  • Danger
  • Warning

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.

pub fn with_placement(
  options: Options,
  placement: Placement,
) -> Options

Set toast placement.

Search Document