From f5b7693b96441fb987f58df8c0165a91bf5c5c9f Mon Sep 17 00:00:00 2001 From: Jamey Greenwood Date: Sat, 17 Jan 2026 14:54:11 +0000 Subject: [PATCH] refactor: extract hero_section to shared ShopComponents module Create a centered hero section component with: - Title (h1) and description (p) - Optional CTA button with preview/live mode support - Configurable background (:base or :sunken) Used in: home page (with CTA), about page (without CTA) Co-Authored-By: Claude Opus 4.5 --- .../components/shop_components.ex | 75 +++++++++++++++++++ .../theme_live/preview_pages/about.html.heex | 13 ++-- .../theme_live/preview_pages/home.html.heex | 23 ++---- 3 files changed, 87 insertions(+), 24 deletions(-) diff --git a/lib/simpleshop_theme_web/components/shop_components.ex b/lib/simpleshop_theme_web/components/shop_components.ex index d1b5312..41529cf 100644 --- a/lib/simpleshop_theme_web/components/shop_components.ex +++ b/lib/simpleshop_theme_web/components/shop_components.ex @@ -859,4 +859,79 @@ defmodule SimpleshopThemeWeb.ShopComponents do |> Enum.reject(&(&1 == "")) |> Enum.join(" ") end + + @doc """ + Renders a centered hero section with title, description, and optional CTA. + + ## Attributes + + * `title` - Required. The main heading text. + * `description` - Required. The description paragraph text. + * `background` - Background style. Either `:base` (default) or `:sunken`. + * `cta_text` - Optional. Text for the CTA button. + * `cta_page` - Optional. Page to navigate to on click (for preview mode). + * `mode` - Either `:live` (default) or `:preview`. + + ## Examples + + <.hero_section + title="Original designs, printed on demand" + description="From art prints to apparel – unique products created by independent artists." + cta_text="Shop the collection" + cta_page="collection" + mode={:preview} + /> + + <.hero_section + title="About the studio" + description="Nature photography, printed with care" + background={:sunken} + /> + """ + attr :title, :string, required: true + attr :description, :string, required: true + attr :background, :atom, default: :base + attr :cta_text, :string, default: nil + attr :cta_page, :string, default: nil + attr :cta_href, :string, default: nil + attr :mode, :atom, default: :live + + def hero_section(assigns) do + ~H""" +
+

+ <%= @title %> +

+

+ <%= @description %> +

+ <%= if @cta_text do %> + <%= if @mode == :preview do %> + + <% else %> + + <%= @cta_text %> + + <% end %> + <% end %> +
+ """ + end end diff --git a/lib/simpleshop_theme_web/live/theme_live/preview_pages/about.html.heex b/lib/simpleshop_theme_web/live/theme_live/preview_pages/about.html.heex index 15d65e4..382a385 100644 --- a/lib/simpleshop_theme_web/live/theme_live/preview_pages/about.html.heex +++ b/lib/simpleshop_theme_web/live/theme_live/preview_pages/about.html.heex @@ -13,14 +13,11 @@
-
-

- About the studio -

-

- Nature photography, printed with care -

-
+ <.hero_section + title="About the studio" + description="Nature photography, printed with care" + background={:sunken} + />
diff --git a/lib/simpleshop_theme_web/live/theme_live/preview_pages/home.html.heex b/lib/simpleshop_theme_web/live/theme_live/preview_pages/home.html.heex index 4122d78..0107248 100644 --- a/lib/simpleshop_theme_web/live/theme_live/preview_pages/home.html.heex +++ b/lib/simpleshop_theme_web/live/theme_live/preview_pages/home.html.heex @@ -12,22 +12,13 @@
-
-

- Original designs, printed on demand -

-

- From art prints to apparel – unique products created by independent artists and delivered straight to your door. -

- -
+ <.hero_section + title="Original designs, printed on demand" + description="From art prints to apparel – unique products created by independent artists and delivered straight to your door." + cta_text="Shop the collection" + cta_page="collection" + mode={:preview} + />