Toast (Toast v0.0.1)

View Source

Server-rendered toast notifications for Phoenix LiveView.

This module provides the main API for sending toast notifications that are managed server-side using LiveView streams.

Summary

Functions

Clears all toasts.

Clears a specific toast by ID.

Sends a toast notification and updates the flash. Used for toasts that should persist across live navigation.

Sends a toast notification to the LiveComponent.

Updates an existing toast by ID.

Types

t()

@type t() :: %Toast{
  action: map() | nil,
  close_button: boolean(),
  description: String.t() | nil,
  duration: integer() | nil,
  icon: String.t() | nil,
  id: String.t(),
  important: boolean(),
  message: String.t(),
  position: atom() | nil,
  title: String.t() | nil,
  type: :info | :success | :error | :warning | :loading | :default
}

Functions

clear_all_toasts()

Clears all toasts.

clear_toast(id)

Clears a specific toast by ID.

put_toast(socket, type, message, opts \\ [])

Sends a toast notification and updates the flash. Used for toasts that should persist across live navigation.

send_toast(type, message, opts \\ [])

Sends a toast notification to the LiveComponent.

Examples

LiveToast.send_toast(:info, "Operation completed!")
LiveToast.send_toast(:error, "Something went wrong", title: "Error", duration: 10_000)

update_toast(toast_id, updates)

Updates an existing toast by ID.

Examples

Toast.update_toast("toast-123", message: "Updated message", type: :success)
Toast.update_toast("toast-123", title: "New Title", duration: 10_000)