defmodule ComfycampWeb.Flash do @moduledoc """ Default flash component. """ use Phoenix.Component alias Phoenix.LiveView.JS import ComfycampWeb.Gettext import ComfycampWeb.CoreComponents import ComfycampWeb.Icons @doc """ Renders flash notices. ## Examples <.flash kind={:info} flash={@flash} /> <.flash kind={:info} phx-mounted={show("#flash")}>Welcome Back! """ attr :id, :string, doc: "the optional id of flash container" attr :flash, :map, default: %{}, doc: "the map of flash messages to display" attr :title, :string, default: nil attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup" attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container" slot :inner_block, doc: "the optional inner block that renders the flash message" def flash(assigns) do assigns = assign_new(assigns, :id, fn -> "flash-#{assigns.kind}" end) ~H"""
hide("##{@id}")} role="alert" class={[ "flash", @kind == :info && "flash-info", @kind == :error && "flash-error" ]} {@rest} >

<.exclamation_circle_icon :if={@kind == :error} /> <.information_circle_icon :if={@kind == :info} /> <%= @title %>

<%= msg %>

""" end @doc """ Shows the flash group with standard titles and content. ## Examples <.flash_group flash={@flash} /> """ attr :flash, :map, required: true, doc: "the map of flash messages" attr :id, :string, default: "flash-group", doc: "the optional id of flash container" def flash_group(assigns) do ~H"""
<.flash kind={:info} title={gettext("Success!")} flash={@flash} /> <.flash kind={:error} title={gettext("Error!")} flash={@flash} /> <.flash id="client-error" kind={:error} title={gettext("We can't find the internet")} phx-disconnected={show(".phx-client-error #client-error")} phx-connected={hide("#client-error")} hidden > <%= gettext("Attempting to reconnect") %> <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" /> <.flash id="server-error" kind={:error} title={gettext("Something went wrong!")} phx-disconnected={show(".phx-server-error #server-error")} phx-connected={hide("#server-error")} hidden > <%= gettext("Hang in there while we get back on track") %> <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" />
""" end end