Skip to content

Commit d9ef714

Browse files
Merge pull request #2333 from NCCE/2989-strapi-component---testimonial-with-text
Creating new text with testimonial component
2 parents fe68fa2 + 58580e9 commit d9ef714

File tree

17 files changed

+289
-1
lines changed

17 files changed

+289
-1
lines changed

app/components/cms/testimonial_component/testimonial_component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@
5454
}
5555
}
5656
}
57+
58+
.purple-bg {
59+
.cms-testimonial__bio-content {
60+
.job-title {
61+
color: $white;
62+
}
63+
}
64+
}
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::TextWithTestimonialComponent < ViewComponent::Base
4+
def initialize(text_content:, buttons:, testimonial_side:, testimonial:, background_color:)
5+
@text_content = text_content
6+
@buttons = buttons
7+
@testimonial_side = testimonial_side
8+
@testimonial = testimonial
9+
@background_color = background_color
10+
end
11+
12+
def row_classes
13+
classes = ["tc-row"]
14+
classes << "testimonial-#{@testimonial_side}"
15+
classes
16+
end
17+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<%= render GovGridRowComponent.new(background_color: @background_color, additional_classes: "cms-text-with-testimonial") do |row| %>
2+
<%= row.with_column("full") do %>
3+
<%= content_tag :div, class: row_classes do %>
4+
<div class="tc-row-half">
5+
<%= render @text_content.render %>
6+
<div class="cms-button-container">
7+
<% @buttons.each do |button| %>
8+
<%= render button.render %>
9+
<% end %>
10+
</div>
11+
</div>
12+
<div class="tc-row-half">
13+
<%= render @testimonial.render %>
14+
</div>
15+
<% end %>
16+
<% end %>
17+
<% end %>
18+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.cms-text-with-testimonial {
2+
.cms-button-container {
3+
width: 80%;
4+
@include govuk-media-query($until: tablet) {
5+
width: 100%;
6+
}
7+
}
8+
9+
.tc-row {
10+
&.testimonial-left {
11+
flex-direction: row-reverse;
12+
@include govuk-media-query($until: tablet) {
13+
flex-direction: column-reverse;
14+
}
15+
}
16+
17+
&.testimonial-right {
18+
flex-direction: row;
19+
@include govuk-media-query($until: tablet) {
20+
flex-direction: column;
21+
}
22+
}
23+
}
24+
}
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 TextWithTestimonial
5+
attr_accessor :text_content, :buttons, :testimonial_side, :testimonial, :background_color
6+
7+
def initialize(text_content:, buttons:, testimonial_side:, testimonial:, background_color:)
8+
@text_content = text_content
9+
@buttons = buttons
10+
@testimonial_side = testimonial_side
11+
@testimonial = testimonial
12+
@background_color = background_color
13+
end
14+
15+
def render
16+
Cms::TextWithTestimonialComponent.new(text_content:, buttons:, testimonial_side:, testimonial:, background_color:)
17+
end
18+
end
19+
end
20+
end
21+
end

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,23 @@ def self.generate_component(component_name, strapi_data)
4343
to_icon_row(strapi_data)
4444
when "two-column-video-section"
4545
to_two_column_video_section(strapi_data)
46+
when "text-with-testimonial"
47+
to_text_with_testimonial(strapi_data)
4648
when "primary-glossary-table"
4749
DynamicComponents::PrimaryGlossaryTable.new(title: strapi_data[:title])
4850
end
4951
end
5052

53+
def self.to_text_with_testimonial(strapi_data)
54+
DynamicComponents::Blocks::TextWithTestimonial.new(
55+
text_content: to_content_block(strapi_data[:textContent]),
56+
background_color: extract_color_name(strapi_data, :bkColor),
57+
testimonial: to_testimonial(strapi_data[:testimonial]),
58+
testimonial_side: strapi_data[:testimonialSide],
59+
buttons: strapi_data[:buttons] ? strapi_data[:buttons].map { to_ncce_button(_1) } : []
60+
)
61+
end
62+
5163
def self.to_icon_row(strapi_data)
5264
DynamicComponents::IconRow.new(
5365
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 TextWithTestimonial < StrapiMock
8+
strapi_component "blocks.text-with-testimonial"
9+
10+
attribute(:textContent) { RichBlocks.generate_data }
11+
attribute(:buttons) { [] }
12+
attribute(:testimonial) { Testimonial.generate_data }
13+
attribute(:testimonialSide) { "left" }
14+
attribute(:bkColor) { nil }
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
class IconRow < StrapiMock
6+
strapi_component "blocks.icon-row"
7+
8+
attribute(:icons) { Array.new(2) { Icon.generate_data } }
9+
end
10+
end
11+
end
12+
end
13+
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 TextWithTestimonial < BaseComponentQuery
8+
def self.name = "ComponentBlocksTextWithTestimonial"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
textContent
13+
testimonialSide
14+
#{Buttons::NcceButton.embed(:buttons)}
15+
#{ContentBlocks::Testimonial.embed(:testimonial)}
16+
#{SharedFields.color_theme(:bkColor)}
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
@@ -22,6 +22,7 @@ class DynamicZone
2222
Components::Blocks::StickyDashboardBar,
2323
Components::Blocks::TestimonialRow,
2424
Components::Blocks::TextWithAsides,
25+
Components::Blocks::TextWithTestimonial,
2526
Components::Blocks::TwoColumnVideoSection
2627
]
2728

0 commit comments

Comments
 (0)