Skip to content

Commit e5025e9

Browse files
Merge pull request #2305 from NCCE/2961-icon-row-strapi-component
Icon Row CMS Component
2 parents 5d605b4 + 84dcd40 commit e5025e9

File tree

13 files changed

+136
-23
lines changed

13 files changed

+136
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::IconRowComponent < ViewComponent::Base
4+
def initialize(icons:)
5+
@icons = icons
6+
end
7+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%= render GovGridRowComponent.new do |row| %>
2+
<%= row.with_column("full") do %>
3+
<div class="cms-icon-row-component">
4+
<% @icons.each do |icon| %>
5+
<div class="cms-icon-row-component__icon">
6+
7+
<%= render Cms::ImageComponent.new(icon.image) %>
8+
<div class="icon-row-component-icon__content">
9+
<p class="govuk-body govuk-!-text-align-centre"><%= icon.text %></p>
10+
</div>
11+
12+
</div>
13+
<% end %>
14+
</div>
15+
<% end %>
16+
<% end %>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
.cms-icon-row-component {
3+
display: flex;
4+
flex-direction: row;
5+
justify-content: space-around;
6+
7+
&__icon {
8+
flex: 0 0 150px;
9+
display: flex;
10+
flex-direction: column;
11+
align-items: center;
12+
13+
img {
14+
height: 30px;
15+
margin-bottom: 1rem;
16+
}
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Cms
2+
module DynamicComponents
3+
class Icon
4+
attr_accessor :text, :image
5+
6+
def initialize(text:, image:)
7+
@text = text
8+
@image = image
9+
end
10+
end
11+
end
12+
end

app/services/cms/dynamic_components/icon_block.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,5 @@ def render
1111
Cms::IconBlockComponent.new(icons:)
1212
end
1313
end
14-
15-
class Icon
16-
attr_accessor :text, :image
17-
18-
def initialize(text:, image:)
19-
@text = text
20-
@image = image
21-
end
22-
end
2314
end
2415
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Cms
2+
module DynamicComponents
3+
class IconRow
4+
attr_accessor :icons
5+
6+
def initialize(icons:)
7+
@icons = icons
8+
end
9+
10+
def render
11+
Cms::IconRowComponent.new(icons:)
12+
end
13+
end
14+
end
15+
end

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ def self.generate_component(component_name, strapi_data)
3939
to_enrolment_testimonial(strapi_data)
4040
when "enrolment-split-course-card"
4141
to_enrolment_split_course_card(strapi_data)
42+
when "icon-row"
43+
to_icon_row(strapi_data)
4244
end
4345
end
4446

47+
def self.to_icon_row(strapi_data)
48+
DynamicComponents::IconRow.new(
49+
icons: strapi_data[:icons].map { to_icon(_1) }
50+
)
51+
end
52+
4553
def self.to_enrolment_split_course_card(strapi_data)
4654
DynamicComponents::EnrolmentSplitCourseCard.new(
4755
card_content: to_content_block(strapi_data[:cardContent]),
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
class Icon
6+
def self.as_model
7+
Factories::BlocksFactory.to_icon(generate_data)
8+
end
9+
10+
def self.generate_data
11+
{
12+
iconText: Faker::Lorem.word,
13+
iconImage: {data: Image.generate_raw_data}
14+
}
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ def self.generate_data(icon_count: 1)
1111
Array.new(icon_count) { Icon.generate_data }
1212
end
1313
end
14-
15-
class Icon
16-
def self.as_model
17-
Factories::BlocksFactory.icon(generate_data)
18-
end
19-
20-
def self.generate_data
21-
{
22-
iconText: Faker::Lorem.word,
23-
iconImage: {data: Image.generate_raw_data}
24-
}
25-
end
26-
end
2714
end
2815
end
2916
end
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 Queries
5+
module Components
6+
module Blocks
7+
class IconRow < BaseComponentQuery
8+
def self.name = "ComponentBlocksIconRow"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
#{SharedFields.icon_block("icons")}
13+
GRAPHQL
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)