Tailwind.Notifier behaviour (Phoenix Tailwind Notifications v0.1.3) View Source

Helper to make useful notifications to be used in LiveView.

It implements the to_flash/2 function to put flashes on the socket.

Examples

defmodule MyWeb.Notifier do
  use Tailwind.Notifier, MyWeb.Gettext

  def action_to_icon(action) when is_atom(action) do
    case action do
      :deleted -> "fa fa-trash text-yellow-400"
      :created -> "fas fa-check text-green-400"
      :updated -> "fas fa-check text-green-400"
      :info -> "fa fa-info-circle text-green-400"
      :error -> "fa fa-exclamation-triangle text-red-400"
    end
  end

  defp model_id_name_link(%My.Accounts.User{id: id, name: name}), do: {gettext("User"), id, name, Routes...}
  defp model_id_name_link(%My.Customers.Customer{id: id, name: name}), do: {gettext("Customer"), id, name, Routes...}

  defp model_id_name_link(data), do: {:bad_model, data}
end

You can now use this Notfier in Tailwind.Phoenix.Show and Tailwind.Phoenix.Index.

Link to this section Summary

Functions

When used, implements Helpers for notifications.

Renders flash errors as drop in notifications.

Renders live flash errors as drop in notifications.

Link to this section Functions

Link to this macro

__using__(gettext)

View Source (macro)

When used, implements Helpers for notifications.

Renders flash errors as drop in notifications.

Link to this function

flash_live_errors(flashes)

View Source

Renders live flash errors as drop in notifications.

Link to this section Callbacks

Specs

action_to_icon(any()) :: String.t()