Skip to content

Commit 6458615

Browse files
Merge pull request #2338 from NCCE/2990-strapi-component---horizontal-card-with-aside
Strapi component - Horizontal card with asides
2 parents 36af78b + 430c33e commit 6458615

File tree

12 files changed

+238
-0
lines changed

12 files changed

+238
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::HorizontalCardWithAsidesComponent < Cms::WithAsidesComponent
4+
delegate :cms_color_theme_class, to: :helpers
5+
6+
def initialize(text:, aside_sections:, button: nil, background_color: nil, color_theme: nil)
7+
super(aside_sections:)
8+
@text = text
9+
@button = button
10+
@background_color = background_color
11+
@color_theme = color_theme
12+
end
13+
14+
def wrapper_classes
15+
classes = ["horizontal-card-with-asides-component__wrapper white-bg"]
16+
classes << cms_color_theme_class(@color_theme, "left") if @color_theme
17+
classes
18+
end
19+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%= render GovGridRowComponent.new(background_color: @background_color) do |row| %>
2+
<%= row.with_column("two-thirds") do %>
3+
<%= content_tag :div, class: wrapper_classes do %>
4+
<%= render @text.render %>
5+
<% if @button %>
6+
<%= render @button.render %>
7+
<% end %>
8+
<% end %>
9+
<% end %>
10+
11+
<%= row.with_column("one-third") do %>
12+
<%= render_parent %>
13+
<% end %>
14+
<% end %>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.horizontal-card-with-asides-component {
2+
&__wrapper {
3+
border-width: 10px;
4+
padding: 30px;
5+
}
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Cms
2+
module DynamicComponents
3+
class HorizontalCardWithAsides
4+
attr_accessor :text, :button, :aside_sections, :background_color, :color_theme
5+
6+
def initialize(text:, button:, aside_sections:, background_color:, color_theme:)
7+
@text = text
8+
@button = button
9+
@aside_sections = aside_sections
10+
@background_color = background_color
11+
@color_theme = color_theme
12+
end
13+
14+
def render
15+
Cms::HorizontalCardWithAsidesComponent.new(text:, button:, aside_sections:, background_color:, color_theme:)
16+
end
17+
end
18+
end
19+
end

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def self.generate_component(component_name, strapi_data)
5353
to_card_wrapper(strapi_data, to_video_card_array(strapi_data[:videoCards]))
5454
when "full-width-image-banner"
5555
to_full_width_image_banner(strapi_data)
56+
when "horizontal-card-with-asides"
57+
to_horizontal_card_with_asides(strapi_data)
5658
end
5759
end
5860

@@ -76,6 +78,16 @@ def self.to_full_width_image_banner(strapi_data)
7678
)
7779
end
7880

81+
def self.to_horizontal_card_with_asides(strapi_data)
82+
DynamicComponents::HorizontalCardWithAsides.new(
83+
text: to_content_block(strapi_data[:textContent]),
84+
button: to_ncce_button(strapi_data[:button]),
85+
aside_sections: extract_aside_sections(strapi_data, param_name: :asides),
86+
background_color: extract_color_name(strapi_data, :bkColor),
87+
color_theme: extract_color_name(strapi_data, :theme)
88+
)
89+
end
90+
7991
def self.to_icon_row(strapi_data)
8092
DynamicComponents::IconRow.new(
8193
icons: strapi_data[:icons].map { to_icon(_1) }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
module DynamicComponents
6+
class HorizontalCardWithAsides < StrapiMock
7+
strapi_component "blocks.horizontal-card-with-asides"
8+
9+
attribute(:textContent) { RichBlocks.generate_data }
10+
attribute(:bkColor) { ColorScheme.generate_data(name: "light_grey") }
11+
attribute(:theme) { ColorScheme.generate_data(name: "light_grey") }
12+
attribute(:button) { Cms::Mocks::NcceButton.generate_data }
13+
attribute(:asides) { Cms::Mocks::AsideSection.generate_aside_list }
14+
end
15+
end
16+
end
17+
end
18+
end
19+
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 HorizontalCardWithAsides < BaseComponentQuery
8+
def self.name = "ComponentBlocksHorizontalCardWithAsides"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
textContent
13+
#{SharedFields.aside_sections(:asides)}
14+
#{Buttons::NcceButton.embed(:button)}
15+
#{SharedFields.color_theme("theme")}
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
@@ -12,6 +12,7 @@ class DynamicZone
1212
Components::Blocks::FullWidthImageBanner,
1313
Components::Blocks::FullWidthText,
1414
Components::Blocks::HorizontalCard,
15+
Components::Blocks::HorizontalCardWithAsides,
1516
Components::Blocks::IconRow,
1617
Components::Blocks::NumberedIconList,
1718
Components::Blocks::NumericCardsSection,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Cms::HorizontalCardWithAsidesComponentPreview < ViewComponent::Preview
2+
layout "full-width"
3+
4+
def default
5+
render(Cms::HorizontalCardWithAsidesComponent.new(
6+
text: Cms::Mocks::RichBlocks.as_model,
7+
aside_sections: [],
8+
background_color: "light-grey",
9+
color_theme: "standard"
10+
))
11+
end
12+
end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Cms::HorizontalCardWithAsidesComponent, type: :component do
6+
context "with aside" do
7+
before do
8+
stub_strapi_aside_section("test-aside")
9+
10+
render_inline(described_class.new(
11+
text: Cms::Mocks::RichBlocks.as_model,
12+
aside_sections: [{slug: "test-aside"}]
13+
))
14+
end
15+
16+
it "renders the aside" do
17+
expect(page).to have_css(".aside-component")
18+
end
19+
20+
it "renders the rich text" do
21+
expect(page).to have_css(".cms-rich-text-block-component")
22+
end
23+
end
24+
25+
context "with multiple asides" do
26+
before do
27+
stub_strapi_aside_section("test-aside")
28+
stub_strapi_aside_section("test-aside2")
29+
30+
render_inline(described_class.new(
31+
text: Cms::Mocks::RichBlocks.as_model,
32+
aside_sections: [{slug: "test-aside"}, {slug: "test-aside2"}]
33+
))
34+
end
35+
36+
it "renders multiple asides" do
37+
expect(page).to have_css(".aside-component", count: 2)
38+
end
39+
40+
context "with background color" do
41+
before do
42+
stub_strapi_aside_section("test-aside")
43+
44+
render_inline(described_class.new(
45+
text: Cms::Mocks::RichBlocks.as_model,
46+
aside_sections: [{slug: "test-aside"}],
47+
background_color: "orange"
48+
))
49+
end
50+
51+
it "renders the background color class" do
52+
expect(page).to have_css(".orange-bg")
53+
end
54+
end
55+
56+
context "with color theme" do
57+
before do
58+
stub_strapi_aside_section("test-aside")
59+
60+
render_inline(described_class.new(
61+
text: Cms::Mocks::RichBlocks.as_model,
62+
aside_sections: [{slug: "test-aside"}],
63+
color_theme: "standard"
64+
))
65+
end
66+
67+
it "renders the cms theme class" do
68+
expect(page).to have_css(".cms-color-theme__border--standard-left")
69+
end
70+
end
71+
72+
context "with button" do
73+
before do
74+
stub_strapi_aside_section("test-aside")
75+
76+
render_inline(described_class.new(
77+
text: Cms::Mocks::RichBlocks.as_model,
78+
aside_sections: [{slug: "test-aside"}],
79+
button: Cms::Mocks::NcceButton.as_model
80+
))
81+
end
82+
83+
it "renders the button" do
84+
expect(page).to have_css(".govuk-button")
85+
end
86+
end
87+
end
88+
end

0 commit comments

Comments
 (0)