app: support button as link
This commit is contained in:
		
							parent
							
								
									9b0ddf107e
								
							
						
					
					
						commit
						3628754120
					
				
					 2 changed files with 23 additions and 15 deletions
				
			
		|  | @ -200,28 +200,38 @@ 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 | ||||||
|       <%= render_slot(@inner_block) %> |       "link" -> | ||||||
|     </button> |         ~H""" | ||||||
|     """ |         <.link class={@style} {@rest}> | ||||||
|  |           <%= render_slot(@inner_block) %> | ||||||
|  |         </.link> | ||||||
|  |         """ | ||||||
|  | 
 | ||||||
|  |       _ -> | ||||||
|  |         ~H""" | ||||||
|  |         <button type={@type} class={@style} {@rest}> | ||||||
|  |           <%= render_slot(@inner_block) %> | ||||||
|  |         </button> | ||||||
|  |         """ | ||||||
|  |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   @doc """ |   @doc """ | ||||||
|  |  | ||||||
|  | @ -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> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue