For any future reference and readers, I followed @LostKobrakai’s advice and started extending the default <.button />
component.
It is pretty easy (and fun) to do. Take not it is still very much a WIP
attr :type, :string, default: nil
attr :variant, :atom, values: ~w(contained outlined text)a, default: :contained
attr :color, :atom, values: ~w(primary secondary error black inherit)a, default: :primary
attr :class, :string, default: nil
attr :rest, :global, include: ~w(disabled form name value)
slot :inner_block, required: true
def button(%{variant: :contained} = assigns) do
~H"""
<button
type={@type}
class={[
"phx-submit-loading:opacity-75 rounded-lg py-2 px-3",
"inline-flex items-center gap-2",
"text-sm font-semibold leading-6 text-white active:text-white/80",
"transition-all",
@color == :primary && "bg-indigo-600 hover:bg-indigo-500",
@color == :secondary && "bg-sky-600 hover:bg-sky-500",
@color == :error && "bg-red-600 hover:bg-red-500",
@color == :black && "bg-gray-800 hover:bg-gray-700",
@color == :inherit && "bg-inherit hover:bg-inherit",
@class
]}
{@rest}
>
<%= render_slot(@inner_block) %>
</button>
"""
end
def button(%{variant: :outlined} = assigns) do
~H"""
<button
type={@type}
class={[
"phx-submit-loading:opacity-75 rounded-lg py-2 px-3",
"inline-flex items-center gap-2",
"text-sm font-semibold leading-6 active:text-white/80 border",
"transition-all",
@color == :primary && "border-indigo-600 text-indigo-600 hover:bg-indigo-50",
@color == :secondary && "border-sky-600 text-sky-600 hover:bg-sky-50",
@color == :error && "border-red-600 text-red-600 hover:bg-red-50",
@color == :black && "border-gray-800 text-gray-800 hover:bg-gray-50",
@color == :inherit && "border-inherit text-inherit hover:bg-inherit",
@class
]}
{@rest}
>
<%= render_slot(@inner_block) %>
</button>
"""
end
def button(%{variant: :text} = assigns) do
~H"""
<button
type={@type}
class={[
"phx-submit-loading:opacity-75 rounded-lg py-2 px-3",
"inline-flex items-center gap-2",
"border-0",
"text-sm font-semibold leading-6 underline-offset-4 hover:underline",
"transition-all",
@color == :primary && "text-indigo-600 decoration-indigo-600",
@color == :secondary && "text-sky-600 decoration-sky-600",
@color == :error && "text-red-600 decoratin-red-600",
@color == :black && "text-gray-800 decoratin-gray-600",
@color == :inherit && "text-inherit decoratin-inherit",
@class
]}
{@rest}
>
<%= render_slot(@inner_block) %>
</button>
"""
end