Dmk

Dmk

Toast - Server-rendered toast notifications for Phoenix LiveView

Toast is a notification system for Phoenix LiveView that works as a drop-in replacement for your existing flash messages while providing rich, interactive toast notifications.

What is Toast?

Toast provides three ways to show notifications in your LiveView applications:

  • Toast messages - Call Toast.send_toast() from your LiveView to show rich, interactive notifications
  • Pipe operation - Use Toast.put_toast() to pipe toast messages in your socket chain
  • Flash messages - Your existing put_flash() calls continue to work, displayed in the same beautiful toast style

Key Features

:books: Stackable toasts - Unlike traditional flash messages, display multiple toasts simultaneously with smooth stacking animations

:counterclockwise_arrows_button: Drop-in replacement - Your existing put_flash() calls automatically render as beautiful toasts with zero code changes

:sparkles: Beautiful by default - Inspired by Sonner’s elegant design philosophy, looks great out of the box

:artist_palette: Framework agnostic styling - Ships with CSS that works with any CSS framework or custom styles, including full Tailwind v3 AND v4 compatibility

:gear: Highly customizable - Configure themes, positions, animations, icons, and action buttons

:rocket: Server-controlled - Leverages the full power of LiveView with no client-side state management

:package: Self-contained - CSS and JS included, no build step or npm dependencies required

:bullseye: Zero configuration - Works immediately with sensible defaults

Why Toast instead of live_toast?

While live_toast is an excellent library that served as inspiration alongside Sonner, Toast was created to address some specific needs:

  • Full Tailwind v3 AND v4 compatibility - Works seamlessly with both current and future Tailwind versions
  • Collapsed toast UI/UX - Provides better visual management when multiple toasts are active, with hover-to-expand functionality
  • Enhanced stacking behavior - Improved animations and visual hierarchy for multiple simultaneous notifications
  • Extended customization options - More granular control over styling, positioning, and behavior

Basic Usage

# In LiveView event handlers
def handle_event("save", _params, socket) do
  {:noreply,
   socket
   |> assign(:saved, true)
   |> Toast.put_toast(:success, "Changes saved!")}
end

# Send with custom options
Toast.send_toast(:success, "Upload complete!",
  title: "Success!",
  description: "Your file has been processed",
  duration: 10_000,
  action: %{
    label: "View File",
    event: "view_file",
    params: %{id: 123}
  }
)

# Your existing flash messages work unchanged
def handle_event("notify", _params, socket) do
  {:noreply, put_flash(socket, :info, "Notification sent!")}
end

Toast Types

Toast includes 6 built-in types with appropriate icons and colors:

  • :info - Blue informational messages
  • :success - Green success messages
  • :error - Red error messages
  • :warning - Yellow warning messages
  • :loading - Loading state with spinner
  • :default - Neutral style

Installation & Setup

Add to your mix.exs:

def deps do
  [{:toast, "~> 0.1.0"}]
end

Import the JavaScript hook in your app.js:

// Note: The import path may vary depending on your project structure
// For assets in the root directory:
import Toast from "../deps/toast/assets/js/toast.js";
// For assets in nested folders (e.g., assets/js/app.js):
import Toast from "../../deps/toast/assets/js/toast.js";

// Add to your LiveSocket hooks
let liveSocket = new LiveSocket("/live", Socket, {
  hooks: { Toast }
});

Import the CSS in your app.css:

/* Note: The import path may vary depending on your project structure */
/* For assets in the root directory: */
@import "../deps/toast/assets/css/toast.css";
/* For assets in nested folders (e.g., assets/css/app.css): */
@import "../../deps/toast/assets/css/toast.css";

Add the toast container to your root layout (root.html.heex):

<Toast.toast_group flash={@flash} />

Demo & Links

You can see Toast in action with interactive examples at the demo page, which showcases all the different toast types, stacking behavior, and customization options.

Hex Package: toast | Hex
Documentation: Toast — Toast v0.2.0
Demo: https://toast.dkenney.com/

Repository:

https://github.com/dmkenney/toast

Most Liked Switch mode

Dmk

Dmk

Released v.2.0 today.

Added support for HTML content and customizable animation duration of the toasts.

giusdp

giusdp

Great library! It looks really nice, I love the multiple types of toasts and the stacking behavior out of the box. I’ll give it a go for sure.

Where Next?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
385 14863 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
quatermain
Hello, I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself. I use Claude Code daily on a pr...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
yureehuh
Introduction Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New

We're in Beta

About us Mission Statement