grille_pain/lustre/toast

grille_pain/lustre/toast defines the different effects to use to display toasts with lustre.

Types

Options type allow to modify timeout or level at the notification level directly. This is used to create custom toasts and override defaults. If you don’t need custom toasts, you should head up to default functions (toast, info, success, error and warning).

It follows the Builder pattern.

import grille_pain/toast
import grille_pain/toast/level

fn custom_toast() {
  toast.options()
  |> toast.timeout(millisecond1s: 30_000)
  |> toast.level(level.Warning)
  |> toast.custom("Oops")
}
pub type Options(msg) {
  Options(
    timeout: option.Option(Int),
    level: option.Option(level.Level),
    sticky: Bool,
    msg: option.Option(fn(String) -> msg),
  )
}

Constructors

  • Options(
      timeout: option.Option(Int),
      level: option.Option(level.Level),
      sticky: Bool,
      msg: option.Option(fn(String) -> msg),
    )

Functions

pub fn custom(options: Options(a), content: String) -> Effect(a)
pub fn error(content: String) -> Effect(a)
pub fn hide(id: String) -> Effect(a)

Hide toast. Sticky toast can only be hidden using hide.

pub fn info(content: String) -> Effect(a)
pub fn level(options: Options(a), level: Level) -> Options(a)

Level of your toast.

pub fn notify(
  options: Options(a),
  msg: fn(String) -> b,
) -> Options(b)
pub fn options() -> Options(a)

Default, empty options. Use it to start Builder.

pub fn sticky(options: Options(a)) -> Options(a)

Activate stickiness for toast. A sticky toast will never go away while it’s not hidden manually.

pub fn success(content: String) -> Effect(a)
pub fn timeout(
  options: Options(a),
  milliseconds timeout: Int,
) -> Options(a)

Timeout to override defaults. Accepts a timeout in milliseconds.

pub fn toast(content: String) -> Effect(a)
pub fn warning(content: String) -> Effect(a)
Search Document