From 362875412080241acbf2d048097f02ac2a96ed95 Mon Sep 17 00:00:00 2001 From: Nikos Papadakis Date: Sun, 10 Sep 2023 15:46:42 +0300 Subject: [PATCH] app: support button as link --- .../prymn_web/components/core_components.ex | 34 ++++++++++++------- .../live/server_live/index.html.heex | 4 +-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/lib/prymn_web/components/core_components.ex b/app/lib/prymn_web/components/core_components.ex index 03f4fb1..e005c89 100644 --- a/app/lib/prymn_web/components/core_components.ex +++ b/app/lib/prymn_web/components/core_components.ex @@ -200,28 +200,38 @@ defmodule PrymnWeb.CoreComponents do ## Examples <.button>Send! + <.button type="link" href="/foo/bar">Navigate <.button phx-click="go" class="ml-2">Send! """ 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""" - - """ + assigns.class + ]) + + case assigns.type do + "link" -> + ~H""" + <.link class={@style} {@rest}> + <%= render_slot(@inner_block) %> + + """ + + _ -> + ~H""" + + """ + end end @doc """ diff --git a/app/lib/prymn_web/live/server_live/index.html.heex b/app/lib/prymn_web/live/server_live/index.html.heex index 14a9028..dcd7ec3 100644 --- a/app/lib/prymn_web/live/server_live/index.html.heex +++ b/app/lib/prymn_web/live/server_live/index.html.heex @@ -4,9 +4,7 @@ <%= "#{Enum.count(@servers)} servers" %> <:actions> - <.link patch={~p"/servers/new"}> - <.button>Connect a Server - + <.button type="link" patch={~p"/servers/new"}>Connect a Server