Skip to content

Commit 36af78b

Browse files
Merge pull request #2351 from NCCE/2999-strapi-component---full-width-image-banner
Full Width Image Banner
2 parents 8c82a6f + 381236e commit 36af78b

File tree

15 files changed

+266
-6
lines changed

15 files changed

+266
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::FullWidthImageBannerComponent < ViewComponent::Base
4+
delegate :cms_url, to: :helpers
5+
6+
def initialize(background_image:, overlay_title:, overlay_text:, overlay_icon:, overlay_side:)
7+
@background_image = background_image
8+
@overlay_title = overlay_title
9+
@overlay_text = overlay_text
10+
@overlay_icon = overlay_icon
11+
@overlay_side = overlay_side
12+
end
13+
14+
def show_overlay?
15+
!@overlay_text.nil? || !@overlay_title.nil?
16+
end
17+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="cms-full-width-image-banner" style="background-image: url(<%= cms_url(@background_image.image_url) %>)">
2+
<% if show_overlay? %>
3+
<%= render GovGridRowComponent.new(padding: {top: 0, bottom: 0}) do |row| %>
4+
<%= row.with_column("full") do %>
5+
<div class="cms-full-width-image-banner__overlay cms-full-width-image-banner__overlay--<%= @overlay_side %>">
6+
<%= render SectionTitleWithIconComponent.new(text: @overlay_title, icon: @overlay_icon, text_size: :small) %>
7+
<%= render @overlay_text.render %>
8+
</div>
9+
<% end %>
10+
<% end %>
11+
<% end %>
12+
</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.cms-full-width-image-banner {
2+
background-repeat: no-repeat;
3+
background-size: cover;
4+
aspect-ratio: 7/2;
5+
min-height: 100px;
6+
7+
@include govuk-media-query($until: tablet) {
8+
aspect-ratio: 3/2;
9+
}
10+
11+
&__overlay {
12+
width: 30%;
13+
min-width: 235px;
14+
max-width: 300px;
15+
background-color: $light-blue;
16+
padding: 15px;
17+
top: 0;
18+
margin: 0;
19+
position: absolute;
20+
21+
&--right {
22+
right: 15px;
23+
}
24+
25+
&--left {
26+
left: 15px;
27+
}
28+
}
29+
30+
.govuk-grid-column-full {
31+
position: relative;
32+
}
33+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Cms
2+
module DynamicComponents
3+
module Blocks
4+
class FullWidthImageBanner
5+
attr_accessor :background_image, :overlay_title, :overlay_text, :overlay_icon, :overlay_side
6+
7+
def initialize(background_image:, overlay_title:, overlay_text:, overlay_icon:, overlay_side:)
8+
@background_image = background_image
9+
@overlay_title = overlay_title
10+
@overlay_text = overlay_text
11+
@overlay_icon = overlay_icon
12+
@overlay_side = overlay_side
13+
end
14+
15+
def render
16+
Cms::FullWidthImageBannerComponent.new(background_image:, overlay_title:, overlay_text:, overlay_icon:, overlay_side:)
17+
end
18+
end
19+
end
20+
end
21+
end

app/services/cms/models/image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(url:, alt:, caption:, formats:, default_size:)
1313
end
1414

1515
def image_url
16-
if formats&.has_key? default_size.to_sym
16+
if formats&.has_key?(default_size.to_sym)
1717
formats[default_size.to_sym][:url]
1818
else
1919
url

app/services/cms/providers/strapi/factories/blocks_factory.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def self.generate_component(component_name, strapi_data)
5151
to_two_column_picture_section(strapi_data)
5252
when "video-cards-section"
5353
to_card_wrapper(strapi_data, to_video_card_array(strapi_data[:videoCards]))
54+
when "full-width-image-banner"
55+
to_full_width_image_banner(strapi_data)
5456
end
5557
end
5658

@@ -64,6 +66,16 @@ def self.to_text_with_testimonial(strapi_data)
6466
)
6567
end
6668

69+
def self.to_full_width_image_banner(strapi_data)
70+
DynamicComponents::Blocks::FullWidthImageBanner.new(
71+
background_image: to_image(strapi_data, :backgroundImage, default_size: :original),
72+
overlay_title: strapi_data[:overlayTitle],
73+
overlay_text: to_content_block(strapi_data[:overlayText], paragraph_class: "govuk-body-s"),
74+
overlay_icon: to_image(strapi_data, :overlayIcon, default_size: :small),
75+
overlay_side: strapi_data[:overlaySide]
76+
)
77+
end
78+
6779
def self.to_icon_row(strapi_data)
6880
DynamicComponents::IconRow.new(
6981
icons: strapi_data[:icons].map { to_icon(_1) }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
module DynamicComponents
6+
module Blocks
7+
class FullWidthImageBanner < StrapiMock
8+
strapi_component "blocks.full-width-image-banner"
9+
10+
attribute(:backgroundImage) { Cms::Mocks::Image.generate_raw_data }
11+
attribute(:overlayTitle) { Faker::Lorem.sentence }
12+
attribute(:overlayText) { Cms::Mocks::RichBlocks.generate_data }
13+
attribute(:overlayIcon) { Cms::Mocks::Image.generate_raw_data }
14+
attribute(:overlaySide) { "right" }
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Queries
5+
module Components
6+
module Blocks
7+
class FullWidthImageBanner < BaseComponentQuery
8+
def self.name = "ComponentBlocksFullWidthImageBanner"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
#{SharedFields.image_fields(:backgroundImage)}
13+
overlayTitle
14+
overlayText
15+
#{SharedFields.image_fields(:overlayIcon)}
16+
overlaySide
17+
GRAPHQL
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end
24+
end
25+
end

app/services/cms/providers/strapi/queries/dynamic_zone.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class DynamicZone
99
Components::Blocks::EnrolmentSplitCourseCard,
1010
Components::Blocks::EnrolmentTestimonial,
1111
Components::Blocks::FullWidthBanner,
12+
Components::Blocks::FullWidthImageBanner,
1213
Components::Blocks::FullWidthText,
1314
Components::Blocks::HorizontalCard,
1415
Components::Blocks::IconRow,

lib/generators/strapi/component_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def create_data_text
4949
def run_view_component_generator
5050
Rails::Generators.invoke(
5151
"component",
52-
["Cms::#{@component_name_class}", *@rails_param_names, "--test-framework=rspec", "--sidecar"].compact,
52+
["Cms::#{@component_name_class}", *@rails_param_names, "--test-framework=rspec", "--sidecar", "--preview"].compact,
5353
behaviour: :invoke,
5454
destination_root:
5555
)
@@ -84,15 +84,15 @@ def print_method_defintions
8484

8585
def factory_key
8686
<<~RUBY
87-
when "#{@component_strapi_name}":
87+
when "#{@component_strapi_name}"
8888
to_#{@component_filename}(strapi_data)
8989
RUBY
9090
end
9191

9292
def method_defintion
9393
<<~RUBY
94-
def to_#{@component_filename}(strapi_data)
95-
DynamicsComponents::Blocks::#{@component_name_class}.new(
94+
def self.to_#{@component_filename}(strapi_data)
95+
DynamicComponents::Blocks::#{@component_name_class}.new(
9696
#{@strapi_params.map { "#{_1.underscore}: strapi_data[:#{_1}]" }.join(",\n\s\s\s\s")}
9797
)
9898
end

0 commit comments

Comments
 (0)