Skip to content

Commit dbce801

Browse files
authored
feat: button component (#38)
* feat: button component * fix:code quality * fix:tests * fix:tests * feat: add primary brand color to theme * fix: resolve conflicts
1 parent d6d7a11 commit dbce801

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

assets/css/app.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
The heroicons installation itself is managed by your mix.exs */
1111
@plugin "../vendor/heroicons";
1212

13+
14+
@theme {
15+
--color-primary: #ee7749;
16+
}
17+
18+
1319
/* Add variants based on LiveView classes */
1420
@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
1521
@custom-variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &);

lib/yearbook_web/components/core_components.ex

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,35 @@ defmodule YearbookWeb.CoreComponents do
8989
<.button phx-click="go" variant="primary">Send!</.button>
9090
<.button navigate={~p"/"}>Home</.button>
9191
"""
92-
attr :rest, :global, include: ~w(href navigate patch method download name value disabled)
93-
attr :class, :string
94-
attr :variant, :string, values: ~w(primary)
92+
attr :type, :string, default: "button"
93+
attr :class, :string, default: ""
94+
attr :variant, :string, default: "primary", values: ~w(primary secondary)
95+
attr :rest, :global, include: ~w(disabled form name value)
96+
9597
slot :inner_block, required: true
9698

97-
def button(%{rest: rest} = assigns) do
98-
variants = %{"primary" => "btn-primary", nil => "btn-primary btn-soft"}
99+
def button(assigns) do
100+
~H"""
101+
<button
102+
type={@type}
103+
class={[
104+
@class,
105+
variant_classes(@variant)
106+
]}
107+
{@rest}
108+
>
109+
{render_slot(@inner_block)}
110+
</button>
111+
"""
112+
end
99113

100-
assigns =
101-
assign_new(assigns, :class, fn ->
102-
["btn", Map.fetch!(variants, assigns[:variant])]
103-
end)
114+
# Variant classes
115+
defp variant_classes("primary") do
116+
"rounded-xl bg-primary p-4 font-semibold tracking-wider text-white cursor-pointer"
117+
end
104118

105-
if rest[:href] || rest[:navigate] || rest[:patch] do
106-
~H"""
107-
<.link class={@class} {@rest}>
108-
{render_slot(@inner_block)}
109-
</.link>
110-
"""
111-
else
112-
~H"""
113-
<button class={@class} {@rest}>
114-
{render_slot(@inner_block)}
115-
</button>
116-
"""
117-
end
119+
defp variant_classes("secondary") do
120+
"rounded-4xl bg-white p-4 font-semibold tracking-wider text-primary cursor-pointer"
118121
end
119122

120123
@doc """

lib/yearbook_web/live/page_live.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ defmodule YearbookWeb.PageLive do
99
@impl true
1010
def render(assigns) do
1111
~H"""
12-
<div class="">
13-
Hello World
14-
</div>
12+
Hello World
1513
"""
1614
end
1715
end

0 commit comments

Comments
 (0)