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,29 +200,39 @@ defmodule PrymnWeb.CoreComponents do
## Examples ## Examples
<.button>Send!</.button> <.button>Send!</.button>
<.button type="link" href="/foo/bar">Navigate</.button>
<.button phx-click="go" class="ml-2">Send!</.button> <.button phx-click="go" class="ml-2">Send!</.button>
""" """
attr :type, :string, default: nil attr :type, :string, default: nil
attr :class, :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 slot :inner_block, required: true
def button(assigns) do def button(assigns) do
~H""" assigns =
<button assign(assigns, :style, [
type={@type}
class={[
"phx-submit-loading:opacity-75 rounded-lg bg-zinc-900 hover:bg-zinc-700 py-2 px-3", "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", "text-sm font-semibold leading-6 text-white active:text-white/80",
@class assigns.class
]} ])
{@rest}
> 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) %> <%= render_slot(@inner_block) %>
</button> </button>
""" """
end end
end
@doc """ @doc """
Renders an input with label and error messages. Renders an input with label and error messages.

View file

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