app: support button as link

This commit is contained in:
Nikos Papadakis 2023-09-10 15:46:42 +03:00
parent 9b0ddf107e
commit 3628754120
Signed by untrusted user who does not match committer: nikos
GPG key ID: 78871F9905ADFF02
2 changed files with 23 additions and 15 deletions

View file

@ -200,28 +200,38 @@ defmodule PrymnWeb.CoreComponents do
## Examples
<.button>Send!</.button>
<.button type="link" href="/foo/bar">Navigate</.button>
<.button phx-click="go" class="ml-2">Send!</.button>
"""
attr :type, :string, default: nil
attr :class, :string, default: nil
attr :rest, :global, include: ~w(disabled form name value)
attr :rest, :global, include: ~w(disabled form name value patch navigate)
slot :inner_block, required: true
def button(assigns) do
~H"""
<button
type={@type}
class={[
assigns =
assign(assigns, :style, [
"phx-submit-loading:opacity-75 rounded-lg bg-zinc-900 hover:bg-zinc-700 py-2 px-3",
"text-sm font-semibold leading-6 text-white active:text-white/80",
@class
]}
{@rest}
>
<%= render_slot(@inner_block) %>
</button>
"""
assigns.class
])
case assigns.type do
"link" ->
~H"""
<.link class={@style} {@rest}>
<%= render_slot(@inner_block) %>
</.link>
"""
_ ->
~H"""
<button type={@type} class={@style} {@rest}>
<%= render_slot(@inner_block) %>
</button>
"""
end
end
@doc """

View file

@ -4,9 +4,7 @@
<%= "#{Enum.count(@servers)} servers" %>
</small>
<:actions>
<.link patch={~p"/servers/new"}>
<.button>Connect a Server</.button>
</.link>
<.button type="link" patch={~p"/servers/new"}>Connect a Server</.button>
</:actions>
</.header>