PineUiPhoenix.Components.Toast (Pine UI v0.2.1)

Copy Markdown View Source

Transient notifications, stacked in a corner of the viewport.

A port of the Pines toast.

Place one <.toast_group> in your root layout, then push toasts to it from anywhere:

<.toast_group position="top-right" />

From a LiveView

push_event(socket, "pine:dispatch", %{
  event: "pine:toast",
  detail: %{title: "Saved", description: "Your changes are live.", type: "success"}
})

Or use the helper, which builds the same payload:

{:noreply, PineUiPhoenix.Components.Toast.push(socket, "Saved", type: "success")}

From the client

<.button x-on:click="$dispatch('pine:toast', {title: 'Copied'})">Copy</.button>

The group listens on window, deliberately: toasts are global to the page, and a trigger anywhere should reach the one group without knowing its id.

Summary

Feedback

Renders the toast container. Include this once, near the end of your root layout.

Renders a button that pushes a toast. Handy for demos and simple client-only cases.

Functions

Pushes a toast to the client from a LiveView.

Feedback

Functions

push(socket, title, opts \\ [])

Pushes a toast to the client from a LiveView.

{:noreply, Toast.push(socket, "Saved", description: "Your changes are live.", type: "success")}

Requires the PineBridge hook to be mounted (see the Installation guide).

Options

  • :description — secondary line
  • :type"default", "success", "error" or "warning"
  • :duration — lifetime in ms; 0 makes it sticky