Skip to content

Commit

Permalink
button_classes/0
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Feb 18, 2025
1 parent 1079caf commit 8391081
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 80 deletions.
42 changes: 6 additions & 36 deletions installer/templates/phx_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,53 +163,23 @@ defmodule <%= @web_namespace %>.CoreComponents do

def button(assigns) do
~H"""
<button
type={@type}
class={[
"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}
>
<button type={@type} class={[button_classes(), @class]} {@rest}>
{render_slot(@inner_block)}
</button>
"""
end

@doc """
Renders a link styled as a button.
Returns the default button classes.
## Examples
<.link_button href={~p"/items/new"}>
<.link class={button_classes()} href={~p"/items/new"}>
New Item
</.link_button>
</.link>
"""
attr :class, :string, default: nil

attr :rest, :global,
include:
~w(patch navigate href replace method csrf_token download hreflang referrerpolicy rel target type),
doc: """
Additional HTML attributes added to the `a` tag.
"""

slot :inner_block, required: true

def link_button(assigns) do
~H"""
<.link
class={[
"inline-block 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}
>
{render_slot(@inner_block)}
</.link>
"""
def button_classes do
"inline-block 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"
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.html/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<.header>
Listing <%= schema.human_plural %>
<:actions>
<.link_button href={~p"<%= schema.route_prefix %>/new"}>
<.link class={button_classes()} href={~p"<%= schema.route_prefix %>/new"}>
New <%= schema.human_singular %>
</.link_button>
</.link>
</:actions>
</.header>

Expand Down
7 changes: 5 additions & 2 deletions priv/templates/phx.gen.html/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
<%= schema.human_singular %> {@<%= schema.singular %>.id}
<:subtitle>This is a <%= schema.singular %> record from your database.</:subtitle>
<:actions>
<.link_button href={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit"}>
<.link
class={button_classes()}
href={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit"}
>
Edit <%= schema.singular %>
</.link_button>
</.link>
</:actions>
</.header>

Expand Down
42 changes: 6 additions & 36 deletions priv/templates/phx.gen.live/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,53 +163,23 @@ defmodule <%= @web_namespace %>.CoreComponents do

def button(assigns) do
~H"""
<button
type={@type}
class={[
"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}
>
<button type={@type} class={[button_classes(), @class]} {@rest}>
{render_slot(@inner_block)}
</button>
"""
end

@doc """
Renders a link styled as a button.
Returns the default button classes.
## Examples
<.link_button href={~p"/items/new"}>
<.link class={button_classes()} href={~p"/items/new"}>
New Item
</.link_button>
</.link>
"""
attr :class, :string, default: nil

attr :rest, :global,
include:
~w(patch navigate href replace method csrf_token download hreflang referrerpolicy rel target type),
doc: """
Additional HTML attributes added to the `a` tag.
"""

slot :inner_block, required: true

def link_button(assigns) do
~H"""
<.link
class={[
"inline-block 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}
>
{render_slot(@inner_block)}
</.link>
"""
def button_classes do
"inline-block 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"
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
<.header>
Listing <%= schema.human_plural %>
<:actions>
<.link_button navigate={~p"<%= schema.route_prefix %>/new"}>
<.link class={button_classes()} navigate={~p"<%= schema.route_prefix %>/new"}>
New <%= schema.human_singular %>
</.link_button>
</.link>
</:actions>
</.header>
Expand Down
7 changes: 5 additions & 2 deletions priv/templates/phx.gen.live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
<%= schema.human_singular %> {@<%= schema.singular %>.<%= schema.opts[:primary_key] || :id %>}
<:subtitle>This is a <%= schema.singular %> record from your database.</:subtitle>
<:actions>
<.link_button navigate={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit?return_to=show"}>
<.link
class={button_classes()}
navigate={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit?return_to=show"}
>
Edit <%= schema.singular %>
</.link_button>
</.link>
</:actions>
</.header>
Expand Down

0 comments on commit 8391081

Please sign in to comment.