app: support button as link
This commit is contained in:
parent
9b0ddf107e
commit
3628754120
2 changed files with 23 additions and 15 deletions
|
@ -200,29 +200,39 @@ 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}
|
||||
>
|
||||
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 """
|
||||
Renders an input with label and error messages.
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue