From 45cc7c39d21b2209ea215566c0f5ee043fef8ed8 Mon Sep 17 00:00:00 2001 From: Vardhan Patil Date: Mon, 17 Jun 2024 05:23:32 +0530 Subject: [PATCH] Add a new success flash type, and make the info flash look display info instead --- .../templates/phx_web/components/core_components.ex | 10 ++++++---- priv/templates/phx.gen.live/core_components.ex | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/installer/templates/phx_web/components/core_components.ex b/installer/templates/phx_web/components/core_components.ex index 586ca1b303..c49a724572 100644 --- a/installer/templates/phx_web/components/core_components.ex +++ b/installer/templates/phx_web/components/core_components.ex @@ -100,7 +100,7 @@ defmodule <%= @web_namespace %>.CoreComponents do 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 :kind, :atom, values: [:success, :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" @@ -116,13 +116,14 @@ defmodule <%= @web_namespace %>.CoreComponents do role="alert" class={[ "fixed top-2 right-2 mr-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1", - @kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900", + @kind == :success && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900", + @kind == :info && "bg-blue-50 text-blue-700 ring-blue-500 fill-blue-900", @kind == :error && "bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900" ]} {@rest} >

- <.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" /> + <.icon :if={@kind == :info || @kind == :success} name="hero-information-circle-mini" class="h-4 w-4" /> <.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" /> <%%= @title %>

@@ -147,7 +148,8 @@ defmodule <%= @web_namespace %>.CoreComponents do def flash_group(assigns) do ~H"""
- <.flash kind={:info} title=<%= maybe_heex_attr_gettext.("Success!", @gettext) %> flash={@flash} /> + <.flash kind={:info} title=<%= maybe_heex_attr_gettext.("Info", @gettext) %> flash={@flash} /> + <.flash kind={:success} title=<%= maybe_heex_attr_gettext.("Success!", @gettext) %> flash={@flash} /> <.flash kind={:error} title=<%= maybe_heex_attr_gettext.("Error!", @gettext) %> flash={@flash} /> <.flash id="client-error" diff --git a/priv/templates/phx.gen.live/core_components.ex b/priv/templates/phx.gen.live/core_components.ex index 586ca1b303..9c431e69a8 100644 --- a/priv/templates/phx.gen.live/core_components.ex +++ b/priv/templates/phx.gen.live/core_components.ex @@ -89,6 +89,7 @@ defmodule <%= @web_namespace %>.CoreComponents do """ end + @doc """ Renders flash notices. @@ -100,7 +101,7 @@ defmodule <%= @web_namespace %>.CoreComponents do 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 :kind, :atom, values: [:success, :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" @@ -116,13 +117,14 @@ defmodule <%= @web_namespace %>.CoreComponents do role="alert" class={[ "fixed top-2 right-2 mr-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1", - @kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900", + @kind == :success && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900", + @kind == :info && "bg-blue-50 text-blue-700 ring-blue-500 fill-blue-900", @kind == :error && "bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900" ]} {@rest} >

- <.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" /> + <.icon :if={@kind == :info || @kind == :success} name="hero-information-circle-mini" class="h-4 w-4" /> <.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" /> <%%= @title %>

@@ -147,7 +149,8 @@ defmodule <%= @web_namespace %>.CoreComponents do def flash_group(assigns) do ~H"""
- <.flash kind={:info} title=<%= maybe_heex_attr_gettext.("Success!", @gettext) %> flash={@flash} /> + <.flash kind={:info} title=<%= maybe_heex_attr_gettext.("Info", @gettext) %> flash={@flash} /> + <.flash kind={:success} title=<%= maybe_heex_attr_gettext.("Success!", @gettext) %> flash={@flash} /> <.flash kind={:error} title=<%= maybe_heex_attr_gettext.("Error!", @gettext) %> flash={@flash} /> <.flash id="client-error"