Skip to content

Commit f4ee4a0

Browse files
authored
Make title optional in generated flash component (#6065)
* Remove title from generated flash component Use sky as color to be more info-like for type :info. Relates to: #5969 * move error title to text * semibold * re-add title, but make it optional
1 parent cc9c666 commit f4ee4a0

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

installer/templates/phx_web/components/core_components.ex

+15-12
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,23 @@ defmodule <%= @web_namespace %>.CoreComponents do
4646
role="alert"
4747
class={[
4848
"fixed top-2 right-2 mr-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1",
49-
@kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900",
49+
@kind == :info && "bg-sky-50 text-sky-800 shadow-md ring-sky-500 fill-sky-900",
5050
@kind == :error && "bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900"
5151
]}
5252
{@rest}
5353
>
54-
<p :if={@title} class="flex items-center gap-1.5 text-sm font-semibold leading-6">
55-
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" />
56-
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" />
57-
{@title}
58-
</p>
59-
<p class="mt-2 text-sm leading-5">{msg}</p>
60-
<button type="button" class="group absolute top-1 right-1 p-2" aria-label=<%= maybe_heex_attr_gettext.("close", @gettext) %>>
61-
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
62-
</button>
54+
<div class="flex gap-2">
55+
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-5 w-5 shrink-0" />
56+
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-5 w-5 shrink-0" />
57+
<div class="text-sm leading-5">
58+
<p :if={@title} class="font-semibold">{@title}</p>
59+
<p>{msg}</p>
60+
</div>
61+
<div class="flex-1" />
62+
<button type="button" class="group flex self-start" aria-label=<%= maybe_heex_attr_gettext.("close", @gettext) %>>
63+
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
64+
</button>
65+
</div>
6366
</div>
6467
"""
6568
end
@@ -77,8 +80,8 @@ defmodule <%= @web_namespace %>.CoreComponents do
7780
def flash_group(assigns) do
7881
~H"""
7982
<div id={@id} aria-live="polite">
80-
<.flash kind={:info} title=<%= maybe_heex_attr_gettext.("Success!", @gettext) %> flash={@flash} />
81-
<.flash kind={:error} title=<%= maybe_heex_attr_gettext.("Error!", @gettext) %> flash={@flash} />
83+
<.flash kind={:info} flash={@flash} />
84+
<.flash kind={:error} flash={@flash} />
8285
<.flash
8386
id="client-error"
8487
kind={:error}

installer/test/phx_new_test.exs

+3-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Mix.Tasks.Phx.NewTest do
111111
assert_file("phx_blog/lib/phx_blog_web/components/core_components.ex", fn file ->
112112
assert file =~ "defmodule PhxBlogWeb.CoreComponents"
113113
assert file =~ ~S|aria-label={gettext("close")}|
114-
assert file =~ ~S|<.flash kind={:info} title={gettext("Success!")} flash={@flash} />|
114+
assert file =~ ~S|gettext("Attempting to reconnect")|
115115
end)
116116

117117
assert_file("phx_blog/lib/phx_blog_web/components/layouts.ex", fn file ->
@@ -567,7 +567,8 @@ defmodule Mix.Tasks.Phx.NewTest do
567567

568568
assert_file("phx_blog/lib/phx_blog_web/components/core_components.ex", fn file ->
569569
assert file =~ ~S|aria-label="close"|
570-
assert file =~ ~S|<.flash kind={:info} title="Success!" flash={@flash} />|
570+
assert file =~ ~S|Attempting to reconnect|
571+
refute file =~ ~S|gettext("Attempting to reconnect")|
571572
end)
572573
end)
573574
end

priv/templates/phx.gen.live/core_components.ex

+15-12
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,23 @@ defmodule <%= @web_namespace %>.CoreComponents do
4646
role="alert"
4747
class={[
4848
"fixed top-2 right-2 mr-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1",
49-
@kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900",
49+
@kind == :info && "bg-sky-50 text-sky-800 shadow-md ring-sky-500 fill-sky-900",
5050
@kind == :error && "bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900"
5151
]}
5252
{@rest}
5353
>
54-
<p :if={@title} class="flex items-center gap-1.5 text-sm font-semibold leading-6">
55-
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" />
56-
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" />
57-
{@title}
58-
</p>
59-
<p class="mt-2 text-sm leading-5">{msg}</p>
60-
<button type="button" class="group absolute top-1 right-1 p-2" aria-label=<%= maybe_heex_attr_gettext.("close", @gettext) %>>
61-
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
62-
</button>
54+
<div class="flex gap-2">
55+
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-5 w-5 shrink-0" />
56+
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-5 w-5 shrink-0" />
57+
<div class="text-sm leading-5">
58+
<p :if={@title} class="font-semibold">{@title}</p>
59+
<p>{msg}</p>
60+
</div>
61+
<div class="flex-1" />
62+
<button type="button" class="group flex self-start" aria-label=<%= maybe_heex_attr_gettext.("close", @gettext) %>>
63+
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
64+
</button>
65+
</div>
6366
</div>
6467
"""
6568
end
@@ -77,8 +80,8 @@ defmodule <%= @web_namespace %>.CoreComponents do
7780
def flash_group(assigns) do
7881
~H"""
7982
<div id={@id} aria-live="polite">
80-
<.flash kind={:info} title=<%= maybe_heex_attr_gettext.("Success!", @gettext) %> flash={@flash} />
81-
<.flash kind={:error} title=<%= maybe_heex_attr_gettext.("Error!", @gettext) %> flash={@flash} />
83+
<.flash kind={:info} flash={@flash} />
84+
<.flash kind={:error} flash={@flash} />
8285
<.flash
8386
id="client-error"
8487
kind={:error}

0 commit comments

Comments
 (0)