A brief toast notification (pp_snackbar/1), in the spirit of MUI's
Snackbar.
<.pp_snackbar open={@flash_message != nil}>
{@flash_message}
<:action>
<.pp_button variant="text" phx-click="dismiss_flash">Dismiss</.pp_button>
</:action>
</.pp_snackbar>Deliberately presentation-only — positioning (anchor_origin), the dark
inverted-surface chip, a mount-in transition, and the optional :action
slot, nothing else. A few things MUI's Snackbar has that this doesn't,
and why:
No
autoHideDuration. Auto-dismiss-after-a-few-seconds is oneProcess.send_after/3in your LiveView clearing whatever assign controlsopen— the same mechanismmix phx.new's generated flash messages already use. A client-side JS timer here would just be a second, redundant way to do the same thing, and one that can drift out of sync with the server's own idea of whether the message is still live.No exit transition.
open={false}removes the element from the DOM immediately (:ifunder the hood) — animating that would need the same always-rendered-plus-Phoenix.LiveView.JSmachineryPhoenixPaper.Dialoguses, which is a much bigger component for a toast.transitiononly animates the entrance (a real CSS@keyframesanimation that plays once when the element mounts), which covers the common case — a snackbar popping in — without needing that machinery.No built-in queueing of consecutive snackbars (MUI shows them one at a time, queued). That needs a place to actually hold the queue — a LiveComponent or a list in your LiveView's own assigns — not something a stateless function component can own. Render one
pp_snackbarfor whatever message you're currently showing; queuing which message that is is your call, the same as it would be building this by hand.No dedicated "wrap an Alert" mode — MUI's
Snackbarskips its own background/padding when given a child instead ofmessage/action, so anAlertinside shows only the Alert's own colors. Here, passpaperize={false}(drops the inverted-surface chip and the positioning classes together, this library's usual all-or-nothing contract) and supply both back yourself viaclass:<.pp_snackbar paperize={false} class="fixed inset-x-4 bottom-4 z-50 mx-auto w-fit"> <.pp_alert severity="success">Changes saved.</.pp_alert> </.pp_snackbar>
Always uses bg-pp-on-surface/text-pp-surface regardless of the current
theme — an inverted surface (dark chip on a light theme, light chip on a
dark theme) is the Material spec for a snackbar, not a themed surface like
PhoenixPaper.Paper.
Summary
Functions
Renders a snackbar. See the module doc.
Functions
Renders a snackbar. See the module doc.
Attributes
paperize(:boolean) - Defaults totrue.open(:boolean) - Defaults totrue.anchor_origin(:string) - corner/edge of the viewport it's anchored to. Defaults to"bottom-left". Must be one of"bottom-left","bottom-center","bottom-right","top-left","top-center", or"top-right".transition(:string) - the mount-in animation — there's no exit transition, see the module doc. Defaults to"grow". Must be one of"grow","fade","slide", or"none".elevation(:integer) - Defaults to6.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
actioninner_block(required)