Dmk

Dmk

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

Showing Posts 1 to 3

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.

Dmk

Dmk OP

Awesome! Let me know what you think!

Dmk

Dmk OP

Released v.2.0 today.

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

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews