View Source LiveToast (Live Toast v0.4.2)
LiveComponent for displaying toast messages.
Summary
Functions
Merges a new toast message into the current toast list.
Implement your own function to override the class of the toasts.
toast_group/1 is just a small Phoenix.Component wrapper around the LiveComponent for toasts. You can use the LiveComponent directly if you prefer, this is just a convenience.
Types
@type t() :: %LiveToast{ action: (map() -> binary()) | nil, component: (map() -> binary()) | nil, container_id: binary() | nil, duration: non_neg_integer() | nil, icon: (map() -> binary()) | nil, kind: atom(), msg: binary(), title: binary() | nil, uuid: Ecto.UUID.t() | nil }
Instance of a toast message.
Functions
@spec send_toast(t()) :: Ecto.UUID.t()
Merges a new toast message into the current toast list.
Implement your own function to override the class of the toasts.
Example:
defmodule MyModule do
def toast_class_fn(assigns) do
[
"group/toast z-100 pointer-events-auto relative w-full items-center justify-between origin-center overflow-hidden rounded-lg p-4 shadow-lg border col-start-1 col-end-1 row-start-1 row-end-2",
if(assigns[:rest][:hidden] == true, do: "hidden", else: "flex"),
assigns[:kind] == :info && " bg-white text-black",
assigns[:kind] == :error && "!text-red-700 !bg-red-100 border-red-200"
]
end
end
# use it in your layout:
# <LiveToast.toast_group flash={@flash} connected={assigns[:socket] != nil} toast_class_fn={MyModule.toast_class_fn/1} />
toast_group/1 is just a small Phoenix.Component wrapper around the LiveComponent for toasts. You can use the LiveComponent directly if you prefer, this is just a convenience.
Attributes
flash
(:map
) (required) - the map of flash messages.id
(:string
) - the optional id of flash container. Defaults to"toast-group"
.connected
(:boolean
) - whether we're in a liveview or not. Defaults tofalse
.corner
(:atom
) - the corner to display the toasts. Defaults to:top_right
.toast_class_fn
(:any
) - function to override the look of the toasts. Defaults to&LiveToast.toast_class_fn/1
.