diff --git a/app/assets/images/landing_page/placeholder/chart.png b/app/assets/images/landing_page/placeholder/chart.png new file mode 100644 index 0000000000..e476466fb9 Binary files /dev/null and b/app/assets/images/landing_page/placeholder/chart.png differ diff --git a/app/assets/stylesheets/views/_landing_page/card.scss b/app/assets/stylesheets/views/_landing_page/card.scss new file mode 100644 index 0000000000..244e02c52d --- /dev/null +++ b/app/assets/stylesheets/views/_landing_page/card.scss @@ -0,0 +1,41 @@ +@import "govuk_publishing_components/individual_component_support"; + +.app-b-card { + display: flex; + flex-direction: column; + justify-content: space-between; + margin-bottom: govuk-spacing(6); + background-color: govuk-colour("dark-blue"); + color: govuk-colour("white"); +} + +.app-b-card__textbox { + padding: govuk-spacing(6) govuk-spacing(7); + background-color: govuk-colour("dark-blue"); + color: govuk-colour("white"); +} + +.app-b-card__figure { + border-style: solid; + border-width: 0 1px 1px; + border-color: govuk-colour("mid-grey"); + margin: auto 0 0; + background-color: govuk-colour("white"); +} + +.app-b-card__image { + display: block; + width: 100%; + margin: 0; +} + +@include govuk-media-query($media-type: print) { + .app-b-card { + background: none; + padding: 0; + + * { + color: $govuk-print-text-colour !important; // stylelint-disable-line declaration-no-important + } + } +} diff --git a/app/assets/stylesheets/views/_landing_page/grid.scss b/app/assets/stylesheets/views/_landing_page/grid.scss new file mode 100644 index 0000000000..9954c00957 --- /dev/null +++ b/app/assets/stylesheets/views/_landing_page/grid.scss @@ -0,0 +1,9 @@ +@import "govuk_publishing_components/individual_component_support"; + +@include govuk-media-query($from: desktop) { + .grid-container { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: govuk-spacing(6); + } +} \ No newline at end of file diff --git a/app/models/block/blocks_container.rb b/app/models/block/blocks_container.rb new file mode 100644 index 0000000000..0e17ca86c3 --- /dev/null +++ b/app/models/block/blocks_container.rb @@ -0,0 +1,5 @@ +module Block + class BlocksContainer < Block::LayoutBase + alias_method :children, :blocks + end +end diff --git a/app/models/block/card.rb b/app/models/block/card.rb new file mode 100644 index 0000000000..820a753ec3 --- /dev/null +++ b/app/models/block/card.rb @@ -0,0 +1,15 @@ +module Block + CardImage = Data.define(:alt, :source) + + class Card < Block::Base + attr_reader :image, :card_content + + def initialize(block_hash) + super(block_hash) + + alt, source = data.fetch("image").values_at("alt", "source") + @image = CardImage.new(alt:, source:) + @card_content = BlockFactory.build_all(data.dig("card_content", "blocks")) + end + end +end diff --git a/app/models/block/grid_container.rb b/app/models/block/grid_container.rb new file mode 100644 index 0000000000..043cb4ba9b --- /dev/null +++ b/app/models/block/grid_container.rb @@ -0,0 +1,5 @@ +module Block + class GridContainer < Block::LayoutBase + alias_method :children, :blocks + end +end diff --git a/app/views/landing_page/blocks/_blocks_container.html.erb b/app/views/landing_page/blocks/_blocks_container.html.erb new file mode 100644 index 0000000000..36bf2980d5 --- /dev/null +++ b/app/views/landing_page/blocks/_blocks_container.html.erb @@ -0,0 +1,5 @@ +
+ <% block.children.each do |child| %> + <%= render "landing_page/blocks/#{child.type}", block: child %> + <% end %> +
diff --git a/app/views/landing_page/blocks/_card.html.erb b/app/views/landing_page/blocks/_card.html.erb new file mode 100644 index 0000000000..59482f0802 --- /dev/null +++ b/app/views/landing_page/blocks/_card.html.erb @@ -0,0 +1,16 @@ +<% + add_view_stylesheet("landing_page/card") + + link_classes = %w(app-b-card__link govuk-link gem-print-link) +%> + +
+
+ <% block.card_content.each do |subblock| %> + <%= render "landing_page/blocks/#{subblock.type}", block: subblock, inverse: true %> + <% end %> +
+
+ <%= image_tag(block.image.source, alt: block.image.alt, class: "app-b-card__image") %> +
+
diff --git a/app/views/landing_page/blocks/_grid_container.html.erb b/app/views/landing_page/blocks/_grid_container.html.erb new file mode 100644 index 0000000000..259dd6c179 --- /dev/null +++ b/app/views/landing_page/blocks/_grid_container.html.erb @@ -0,0 +1,9 @@ +<% + add_view_stylesheet("landing_page/grid") +%> + +
+ <% block.children.each do |child| %> + <%= render "landing_page/blocks/#{child.type}", block: child %> + <% end %> +
diff --git a/config/initializers/dartsass.rb b/config/initializers/dartsass.rb index 319313ee33..f30afa4438 100644 --- a/config/initializers/dartsass.rb +++ b/config/initializers/dartsass.rb @@ -13,8 +13,10 @@ "views/_place-list.scss" => "views/_place-list.css", "views/_popular_links.scss" => "views/_popular_links.css", "views/_travel-advice.scss" => "views/_travel-advice.css", + "views/_landing_page/card.scss" => "views/_landing_page/card.css", "views/_landing_page/hero.scss" => "views/_landing_page/hero.css", "views/_landing_page/featured.scss" => "views/_landing_page/featured.css", + "views/_landing_page/grid.scss" => "views/_landing_page/grid.css", }.freeze all_stylesheets = APP_STYLESHEETS.merge(GovukPublishingComponents::Config.all_stylesheets) diff --git a/lib/data/landing_page_content_items/landing_page.yaml b/lib/data/landing_page_content_items/landing_page.yaml index 46db0e4e18..d5e7a2fc86 100644 --- a/lib/data/landing_page_content_items/landing_page.yaml +++ b/lib/data/landing_page_content_items/landing_page.yaml @@ -75,4 +75,52 @@ blocks: - type: big_number number: £43 label: Cost of a cup of coffee in Covent Garden - +- type: grid_container + blocks: + - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 1 govspeak title goes here

+ - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 2 govspeak title goes here

+ - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 3 govspeak title

+- type: two_column_layout + theme: one_third_two_thirds + blocks: + - type: govspeak + content:

Left content!

+ - type: blocks_container + blocks: + - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 1 govspeak title goes here

+ - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 2 govspeak title goes here

diff --git a/spec/fixtures/landing_page.yaml b/spec/fixtures/landing_page.yaml index fb248829e5..d5e7a2fc86 100644 --- a/spec/fixtures/landing_page.yaml +++ b/spec/fixtures/landing_page.yaml @@ -1,14 +1,14 @@ blocks: - type: hero image: - alt: "todo alt text" + alt: "Placeholder alt text" sources: - desktop_2x: "landing_page/placeholder/desktop_2x.png" desktop: "landing_page/placeholder/desktop.png" - tablet_2x: "landing_page/placeholder/tablet_2x.png" - tablet: "landing_page/placeholder/tablet.png" - mobile_2x: "landing_page/placeholder/mobile_2x.png" + desktop_2x: "landing_page/placeholder/desktop_2x.png" mobile: "landing_page/placeholder/mobile.png" + mobile_2x: "landing_page/placeholder/mobile_2x.png" + tablet: "landing_page/placeholder/tablet.png" + tablet_2x: "landing_page/placeholder/tablet_2x.png" hero_content: blocks: - type: govspeak @@ -18,6 +18,22 @@ blocks: - type: action_link text: "See the missions" href: "todo" +- type: featured + image: + alt: example alt text + sources: + desktop: "landing_page/placeholder/desktop.png" + desktop_2x: "landing_page/placeholder/desktop_2x.png" + mobile: "landing_page/placeholder/mobile.png" + mobile_2x: "landing_page/placeholder/mobile_2x.png" + tablet: "landing_page/placeholder/tablet.png" + tablet_2x: "landing_page/placeholder/tablet_2x.png" + featured_content: + blocks: + - type: govspeak + content: | +

Title of the content

+

Lorem ipsum dolor sit amet. In voluptas dolorum vel veniam nisi et voluptate dolores id voluptatem distinctio. Et quia accusantium At ducimus quis aut voluptates iusto aut esse suscipit.

- type: govspeak content: |

Here's a heading

@@ -43,7 +59,7 @@ blocks: theme: two_thirds_one_third blocks: - type: govspeak - content:

Left content!

+ content: https://www.youtube.com/watch?v=dQw4w9WgXcQ - type: govspeak content:

Right content!

- type: govspeak @@ -59,4 +75,52 @@ blocks: - type: big_number number: £43 label: Cost of a cup of coffee in Covent Garden - +- type: grid_container + blocks: + - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 1 govspeak title goes here

+ - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 2 govspeak title goes here

+ - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 3 govspeak title

+- type: two_column_layout + theme: one_third_two_thirds + blocks: + - type: govspeak + content:

Left content!

+ - type: blocks_container + blocks: + - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 1 govspeak title goes here

+ - type: card + image: + alt: "Placeholder alt text" + source: "landing_page/placeholder/chart.png" + card_content: + blocks: + - type: govspeak + content:

Title 2 govspeak title goes here

diff --git a/spec/models/block/card_spec.rb b/spec/models/block/card_spec.rb new file mode 100644 index 0000000000..27a6cd8470 --- /dev/null +++ b/spec/models/block/card_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe Block::Card do + let(:blocks_hash) do + { "type" => "card", + "image" => { + "alt" => "some alt text", + "source" => "landing_page/placeholder/chart.png", + }, + "card_content" => { + "blocks" => [ + { "type" => "govspeak", "content" => "

Title

" }, + { "type" => "govspeak", "content" => "

Some content!

" }, + ], + } } + end + + describe "#image" do + it "returns the properties of the image" do + result = described_class.new(blocks_hash).image + expect(result.alt).to eq "some alt text" + expect(result.source).to eq "landing_page/placeholder/chart.png" + end + end + + describe "#card_content" do + it "returns an array of instantiated blocks" do + result = described_class.new(blocks_hash).card_content + expect(result.size).to eq 2 + expect(result.first.data).to eq("type" => "govspeak", "content" => "

Title

") + expect(result.second.data).to eq("type" => "govspeak", "content" => "

Some content!

") + end + end +end diff --git a/spec/system/landing_page_spec.rb b/spec/system/landing_page_spec.rb index 81154073b7..8bf88d7c58 100644 --- a/spec/system/landing_page_spec.rb +++ b/spec/system/landing_page_spec.rb @@ -41,5 +41,26 @@ assert_selector ".govuk-block__hero picture" assert_selector ".govuk-block__hero .app-b-hero__textbox" end + + it "renders a card" do + visit base_path + + assert_selector ".landing-page .app-b-card" + assert_selector ".app-b-card .app-b-card__textbox" + assert_selector ".app-b-card .app-b-card__figure" + assert_selector ".app-b-card__figure .app-b-card__image" + end + + it "renders a grid container" do + visit base_path + + assert_selector ".landing-page .grid-container" + end + + it "renders a blocks container" do + visit base_path + + assert_selector ".landing-page .blocks-container" + end end end