Skip to content

Commit

Permalink
Merge pull request #4484 from alphagov/big-hero-children
Browse files Browse the repository at this point in the history
Big hero headings
  • Loading branch information
richardTowers authored Dec 3, 2024
2 parents ca0151d + d44c687 commit 469701a
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/views/_landing_page/hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $large-desktop-height: 400px;
}
}

.app-b-hero--mid-page {
.app-b-hero--middle_left {
overflow: hidden;

@include govuk-media-query($until: desktop) {
Expand Down
4 changes: 3 additions & 1 deletion app/models/landing_page/block/hero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module LandingPage::Block
HeroImage = Data.define(:alt, :sources)

class Hero < Base
attr_reader :image, :hero_content
attr_reader :image, :hero_content, :theme, :theme_colour

def initialize(block_hash, landing_page)
super
Expand All @@ -12,6 +12,8 @@ def initialize(block_hash, landing_page)
sources = HeroImageSources.new(**sources)
@image = HeroImage.new(alt:, sources:)
@hero_content = LandingPage::BlockFactory.build_all(data.dig("hero_content", "blocks"), landing_page)
@theme = data.fetch("theme", "default")
@theme_colour = data["theme_colour"]
end

def full_width?
Expand Down
6 changes: 1 addition & 5 deletions app/views/landing_page/blocks/_featured.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
<div class="featured">
<%= tag.div class: featured_child_content_classes do %>
<% block.featured_content.each do |subblock| %>
<%
options = {}
options[:position] = "top" if subblock.type == "heading"
%>
<%= render_block(subblock, options:) %>
<%= render_block(subblock) %>
<% end %>
<% end %>
<% if block.image %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_heading.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
heading_level = block.data["heading_level"] || 2
font_size = options[:position] == "top" ? "l" : "m"
font_size = options[:font_size]
text = block.data["content"]
path = block.data["path"] || nil
inverse = options[:inverse] || false
Expand Down
17 changes: 10 additions & 7 deletions app/views/landing_page/blocks/_hero.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<%
add_view_stylesheet("landing_page/hero")

hero_classes = %w[app-b-hero]
hero_classes << "app-b-hero--mid-page" if block.data["theme"] == "middle_left"
hero_classes = %W[app-b-hero app-b-hero--#{block.theme}]

grid_class = "govuk-grid-column-two-thirds-from-desktop"
grid_class = "govuk-grid-column-one-third-from-desktop" if block.data["theme"] == "middle_left"
grid_class = "govuk-grid-column-one-third-from-desktop" if block.theme == "middle_left"

hero_textbox_classes = %w[app-b-hero__textbox]
hero_textbox_classes << "border-top--#{style(block.data["theme_colour"])}" if block.data["theme_colour"]
hero_textbox_classes << "border-top--#{style(block.theme_colour)}" if block.theme_colour

image_alt_text = block.image.alt || ""
%>
Expand All @@ -27,9 +26,13 @@
<%= content_tag("div", class: grid_class) do %>
<%= content_tag("div", class: hero_textbox_classes) do %>
<% block.hero_content.each_with_index do |subblock, index| %>
<% options = {
position: block.data["position"],
margin_bottom: (0 if block.hero_content.length - 1 == index) } %>
<%
is_final_subblock = block.hero_content.length - 1 == index
options = {
margin_bottom: (0 if is_final_subblock),
font_size: ("l" if block.theme == "default" && subblock.type == "heading"),
}.compact
%>
<%= render_block(subblock, options:) %>
<% end %>
<% end %>
Expand Down
1 change: 0 additions & 1 deletion lib/data/landing_page_content_items/be_kinder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
alt: "Placeholder alt text"
sources:
Expand Down
1 change: 0 additions & 1 deletion lib/data/landing_page_content_items/be_thankful.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
alt: "Placeholder alt text"
sources:
Expand Down
1 change: 0 additions & 1 deletion lib/data/landing_page_content_items/donate_to_charity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
alt: "Placeholder alt text"
sources:
Expand Down
1 change: 0 additions & 1 deletion lib/data/landing_page_content_items/exercise_more.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
alt: "Placeholder alt text"
sources:
Expand Down
4 changes: 2 additions & 2 deletions lib/data/landing_page_content_items/goals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
sources:
desktop: "landing_page/placeholder/desktop.png"
Expand All @@ -60,7 +59,8 @@ blocks:
content: Government Goals
- type: govspeak
content: |
<p class="govuk-body govuk-!-font-size-27">Culpa atque nostrum numquam eveniet. Cum exercitationem perferendis accusamus minima possimus dolor enim eius. Et est impedit vel voluptate sunt.</p>
<p>Culpa atque nostrum numquam eveniet. Cum exercitationem perferendis accusamus minima possimus dolor enim eius. Et est impedit vel voluptate sunt.</p>
<p><a href="#">hello world</a></p>
- type: two_column_layout
theme: two_thirds_one_third
blocks:
Expand Down
1 change: 0 additions & 1 deletion lib/data/landing_page_content_items/homepage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
sources:
desktop: "landing_page/placeholder/missions_hero_desktop.jpg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
alt: "Placeholder alt text"
sources:
Expand Down
1 change: 0 additions & 1 deletion lib/data/landing_page_content_items/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ blocks:
- type: main_navigation
navigation_group_id: Top Menu
- type: hero
position: top
image:
sources:
desktop: "landing_page/placeholder/desktop.png"
Expand Down
22 changes: 22 additions & 0 deletions spec/models/landing_page/block/hero_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@
end
end

describe "#theme" do
it "defaults to default" do
expect(subject.theme).to eq("default")
end

it "returns the theme from config" do
blocks_hash["theme"] = "middle_left"
expect(subject.theme).to eq("middle_left")
end
end

describe "#theme_colour" do
it "defaults to nil" do
expect(subject.theme_colour).to eq(nil)
end

it "returns the theme_colour from config" do
blocks_hash["theme_colour"] = 2
expect(subject.theme_colour).to eq(2)
end
end

describe "#full_width?" do
it "is true" do
expect(subject.full_width?).to eq(true)
Expand Down

0 comments on commit 469701a

Please sign in to comment.