Skip to content

Commit

Permalink
Update buttons using components
Browse files Browse the repository at this point in the history
  • Loading branch information
phonnz committed Dec 13, 2024
1 parent cdbf99a commit b10ab4f
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 8 deletions.
21 changes: 21 additions & 0 deletions fullstack/lib/fullstack_web/components/custom_components.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule FullstackWeb.CustomComponents do
use FullstackWeb, :html

attr :btn_type, :string, values: ["warning", "error"], default: "warning"
attr :rest, :global

def custom_button(assigns) do
~H"""
<button
class={[
"inline-flex items-center text-white justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 text-primary-foreground hover:bg-primary/90 h-10 mx-2 px-4 py-2 w-full sm:w-auto",
@btn_type == "warning" && "bg-orange-500",
@btn_type == "error" && "hover:ring-red-900 bg-red-700 hover:bg-red-600"
]}
{@rest}
>
<%= render_slot(@inner_block) %>
</button>
"""
end
end
1 change: 1 addition & 0 deletions fullstack/lib/fullstack_web/live/home_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule FullstackWeb.HomeLive.Index do
alias Fullstack.{Customers, Financial}
alias Fullstack.Services.Counters
alias Fullstack.Servers.Generators.Phrases
import FullstackWeb.CustomComponents

@impl true
def mount(_params, session, socket) do
Expand Down
17 changes: 9 additions & 8 deletions fullstack/lib/fullstack_web/live/home_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,19 @@
</div>
</div>
<div class="mt-10 sm:flex sm:justify-center lg:justify-start">
<button
<.custom_button
phx-click="crash"
class="inline-flex items-center text-white bg-orange-500 justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full sm:w-auto"
clas="inline-flex items-center text-white justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full sm:w-auto"
>
Crash the Browser!
</button>
<button
<.icon name="hero-exclamation-triangle" /> Crash the Browser!
</.custom_button>
<.custom_button
phx-click="destroy"
class="inline-flex text-white hover:ring-red-900 bg-red-700 hover:bg-red-600 items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 mt-3 w-full sm:mt-0 sm:ml-3 sm:w-auto"
btn_type="error"
clas="inline-flex text-white hover:ring-red-900 bg-red-700 hover:bg-red-600 items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 mt-3 w-full sm:mt-0 sm:ml-3 sm:w-auto"
>
Destroy Centralized!
</button>
<.icon name="hero-x-mark" /> Destroy Centralized!
</.custom_button>
</div>
<div class="mt-12 flex justify-center space-x-3">
<.ecosystem_logo :for={logo <- @logos} logo={logo} />
Expand Down
131 changes: 131 additions & 0 deletions fullstack/priv/static/img/livebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions fullstack/priv/static/img/phoenix.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b10ab4f

Please sign in to comment.