diff --git a/bloom_site/lib/bloom_site_web/components/button.ex b/bloom_site/lib/bloom_site_web/components/button.ex new file mode 100644 index 0000000..d97912d --- /dev/null +++ b/bloom_site/lib/bloom_site_web/components/button.ex @@ -0,0 +1,49 @@ +defmodule BloomSiteWeb.Components.Button do + use Phoenix.Component + + @doc """ + An extension of the *core_components button*. + The `<.button>` has the ability to handle a variant attribute. + This makes it possible to have a `contained` or `outlined` look. + + ⚠️ Uninstall the core button component! + As you do not need two button components, the button component of the core phoenix_package can be deleted. + """ + + attr(:type, :string, default: nil) + attr(:class, :string, default: nil) + attr(:rest, :global, include: ~w(disabled form name value)) + attr(:variant, :string, default: "contained") + + slot(:inner_block, required: true) + + def button(assigns) do + ~H""" + + """ + end + + defp get_variant(variant) do + case variant do + "contained" -> + "border-2 border-zinc-900 hover:border-zinc-700 bg-zinc-900 hover:bg-zinc-700" + + "outlined" -> + "border-2 border-zinc-900 bg-transparent text-zinc-900 hover:bg-zinc-700 hover:border-zinc-700 hover:text-white active:bg-zinc-700" + + _ -> + "bg-zinc-900 hover:bg-zinc-700" + end + end +end diff --git a/bloom_site/mix.exs b/bloom_site/mix.exs index 3f36fdf..a1201f7 100644 --- a/bloom_site/mix.exs +++ b/bloom_site/mix.exs @@ -54,7 +54,7 @@ defmodule BloomSite.MixProject do {:gettext, "~> 0.20"}, {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, - {:bloom, "~> 0.0.7"}, + {:bloom, path: "../"}, # {:bloom, path: "..", override: true}, {:phoenix_storybook, "~> 0.6.0"} ] diff --git a/bloom_site/storybook/bloom_components/button.story.exs b/bloom_site/storybook/bloom_components/button.story.exs new file mode 100644 index 0000000..e9ef91e --- /dev/null +++ b/bloom_site/storybook/bloom_components/button.story.exs @@ -0,0 +1,25 @@ +defmodule BloomSite.Storybook.BloomComponents.Button do + use PhoenixStorybook.Story, :component + + def function, do: &BloomSiteWeb.Components.Button.button/1 + + def variations do + [ + %Variation{ + id: :default, + slots: [ + "Button" + ] + }, + %Variation{ + id: :outlined, + attributes: %{ + variant: "outlined" + }, + slots: [ + "Outlined button" + ] + }, + ] + end +end diff --git a/lib/bloom/components/button.ex b/lib/bloom/components/button.ex new file mode 100644 index 0000000..7d45df7 --- /dev/null +++ b/lib/bloom/components/button.ex @@ -0,0 +1,49 @@ +defmodule Bloom.Components.Button do + use Phoenix.Component + + @doc """ + An extension of the *core_components button*. + The `<.button>` has the ability to handle a variant attribute. + This makes it possible to have a `contained` or `outlined` look. + + ⚠️ Uninstall the core button component! + As you do not need two button components, the button component of the core phoenix_package can be deleted. + """ + + attr(:type, :string, default: nil) + attr(:class, :string, default: nil) + attr(:rest, :global, include: ~w(disabled form name value)) + attr(:variant, :string, default: "contained") + + slot(:inner_block, required: true) + + def button(assigns) do + ~H""" + + """ + end + + defp get_variant(variant) do + case variant do + "contained" -> + "border-2 border-zinc-900 hover:border-zinc-700 bg-zinc-900 hover:bg-zinc-700" + + "outlined" -> + "border-2 border-zinc-900 bg-transparent text-zinc-900 hover:bg-zinc-700 hover:border-zinc-700 hover:text-white active:bg-zinc-700" + + _ -> + "bg-zinc-900 hover:bg-zinc-700" + end + end +end diff --git a/priv/templates/button.ex b/priv/templates/button.ex new file mode 100644 index 0000000..341a972 --- /dev/null +++ b/priv/templates/button.ex @@ -0,0 +1,49 @@ +defmodule <%= @module_name %>Web.Components.Button do + use Phoenix.Component + + @doc """ + An extension of the *core_components button*. + The `<.button>` has the ability to handle a variant attribute. + This makes it possible to have a `contained` or `outlined` look. + + ⚠️ Uninstall the core button component! + As you do not need two button components, the button component of the core phoenix_package can be deleted. + """ + + attr(:type, :string, default: nil) + attr(:class, :string, default: nil) + attr(:rest, :global, include: ~w(disabled form name value)) + attr(:variant, :string, default: "contained") + + slot(:inner_block, required: true) + + def button(assigns) do + ~H""" + + """ + end + + defp get_variant(variant) do + case variant do + "contained" -> + "border-2 border-zinc-900 hover:border-zinc-700 bg-zinc-900 hover:bg-zinc-700" + + "outlined" -> + "border-2 border-zinc-900 bg-transparent text-zinc-900 hover:bg-zinc-700 hover:border-zinc-700 hover:text-white active:bg-zinc-700" + + _ -> + "bg-zinc-900 hover:bg-zinc-700" + end + end +end