Skip to content

Commit f1cf519

Browse files
Merge pull request #2332 from NCCE/2995-strapi-component-update---page-title
Update Strapi page title with background colour and I belong flag
2 parents fbd3945 + 106376f commit f1cf519

File tree

11 files changed

+101
-8
lines changed

11 files changed

+101
-8
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: true
22

33
class Cms::PageTitleComponent < ViewComponent::Base
4-
def initialize(title:, sub_text: nil, title_image: nil, title_video_url: nil, status_message: nil)
4+
def initialize(title:, sub_text: nil, title_image: nil, title_video_url: nil, status_message: nil, background_color: nil, i_belong_flag: false)
55
@title = title
66
@sub_text = sub_text
77
@title_image = title_image
88
@title_video_url = title_video_url
99
@status_message = status_message
10+
@background_color = background_color.presence || "lime-green"
11+
@i_belong_flag = i_belong_flag
1012
end
1113
end

app/components/cms/page_title_component/page_title_component.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= render GovGridRowComponent.new(background_color: "lime-green", padding: {top: 7, bottom: 7}) do |row| %>
1+
<%= render GovGridRowComponent.new(background_color: @background_color, padding: {top: 7, bottom: 7}) do |row| %>
22
<%= row.with_column("full") do %>
33

44
<div class="page-title__wrapper">
@@ -26,6 +26,10 @@
2626
<div class="page-title__media">
2727
<%= render Cms::ImageComponent.new(@title_image, show_caption: false) %>
2828
</div>
29+
<% elsif @i_belong_flag %>
30+
<div class="page-title__i-belong-flag">
31+
<%= render IBelongFlagComponent.new %>
32+
</div>
2933
<% end %>
3034
</div>
3135
</div>

app/components/cms/page_title_component/page_title_component.scss

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
background-color: $white;
2323
display: flex;
2424
flex-direction: column;
25-
25+
2626
@include govuk-media-query($from: tablet) {
2727
flex-direction: row;
2828
}
@@ -87,4 +87,23 @@
8787
}
8888
}
8989
}
90+
91+
&__i-belong-flag {
92+
display: none; // no logo in mobile
93+
grid-area: logo;
94+
.i-belong-flag {
95+
position: relative;
96+
}
97+
@include govuk-media-query($from: desktop) {
98+
display: block;
99+
text-align: right;
100+
img {
101+
margin: 0 2rem 2rem auto;
102+
}
103+
}
104+
105+
img {
106+
display: block;
107+
}
108+
}
90109
}

app/services/cms/models/page_title.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
module Cms
22
module Models
33
class PageTitle
4-
attr_accessor :title, :sub_text, :title_image, :title_video_url
4+
attr_accessor :title, :sub_text, :title_image, :title_video_url, :background_color, :i_belong_flag
55

6-
def initialize(title:, sub_text:, title_image: nil, title_video_url: nil)
6+
def initialize(title:, sub_text:, title_image: nil, title_video_url: nil, background_color: nil, i_belong_flag: false)
77
@title = title
88
@sub_text = sub_text
99
@title_image = title_image
1010
@title_video_url = title_video_url
11+
@background_color = background_color
12+
@i_belong_flag = i_belong_flag
1113
end
1214

1315
def render
14-
Cms::PageTitleComponent.new(title:, sub_text:, title_image:, title_video_url:)
16+
Cms::PageTitleComponent.new(title:, sub_text:, title_image:, title_video_url:, background_color:, i_belong_flag:)
1517
end
1618
end
1719
end

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def self.process_model(mapping, all_data)
4545
title: strapi_data[:title],
4646
sub_text: strapi_data[:subText],
4747
title_image: to_image(strapi_data, :titleImage),
48-
title_video_url: strapi_data[:titleVideoUrl]
48+
title_video_url: strapi_data[:titleVideoUrl],
49+
background_color: extract_color_name(strapi_data, :bkColor),
50+
i_belong_flag: strapi_data[:iBelongFlag]
4951
)
5052
elsif model_class == Models::BlogPreview
5153
to_blog_preview(strapi_data)

app/services/cms/providers/strapi/mocks/page_title.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module Mocks
55
class PageTitle < StrapiMock
66
attribute(:title) { Faker::Lorem.words(number: 5) }
77
attribute(:subText) { nil }
8+
attribute(:titleImage) { nil }
9+
attribute(:titleVideoUrl) { nil }
10+
attribute(:bkColor) { nil }
11+
attribute(:iBelongFlag) { false }
812
end
913
end
1014
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def self.embed(name)
1010
subText
1111
titleVideoUrl
1212
#{SharedFields.image_fields("titleImage")}
13+
#{SharedFields.color_theme(:bkColor)}
14+
iBelongFlag
1315
}
1416
GRAPHQL
1517
end

previews/components/cms/page_title_component_preview.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@ def with_video
2424
title_video_url: "https://www.youtube.com/watch?v=-fTboqiyjxk&list=PLwcV67XMdDdJT0TkvZo6cTDSR0uJgP3Ku"
2525
))
2626
end
27+
28+
def with_background_color
29+
render(Cms::PageTitleComponent.new(
30+
title: "Page title",
31+
sub_text: "Welcome to the page",
32+
background_color: "orange"
33+
))
34+
end
35+
36+
def with_i_belong_flag
37+
render(Cms::PageTitleComponent.new(
38+
title: "Page title",
39+
sub_text: "Welcome to the page",
40+
background_color: "orange",
41+
i_belong_flag: true
42+
))
43+
end
2744
end

spec/components/cms/page_title_component_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
it "doesnt render status_message container when non present" do
2424
expect(page).not_to have_css(".page-title__status-message")
2525
end
26+
27+
it "applies the default background color" do
28+
expect(page).to have_css(".lime-green-bg")
29+
end
30+
31+
it "doesnt render i belong flag when false" do
32+
expect(page).to_not have_css(".i-belong-flag")
33+
end
2634
end
2735

2836
context "With Media" do
@@ -82,4 +90,24 @@
8290
expect(page).to have_css(".page-title__status-message", text: "You completed")
8391
end
8492
end
93+
94+
context "with background color" do
95+
before do
96+
render_inline(described_class.new(title: "Page title", background_color: "orange"))
97+
end
98+
99+
it "applies the background class" do
100+
expect(page).to have_css(".orange-bg")
101+
end
102+
end
103+
104+
context "with i belong flag" do
105+
before do
106+
render_inline(described_class.new(title: "Page title", i_belong_flag: true))
107+
end
108+
109+
it "renders the i belong image" do
110+
expect(page).to have_css(".i-belong-flag")
111+
end
112+
end
85113
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Cms::Providers::Strapi::Queries::PageTitle do
4+
it_should_behave_like "a strapi graphql embed", {key: "pageTitle",
5+
required_fields: %w[
6+
title
7+
subText
8+
titleImage
9+
titleVideoUrl
10+
bkColor
11+
iBelongFlag
12+
]}
13+
end

0 commit comments

Comments
 (0)