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:

Most Liked

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?

Popular in Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
arkgil
Hi all! I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement