Skip to content

Commit d779cb0

Browse files
Merge pull request #2357 from NCCE/3004-strapi-component---icon-row-background-colours
Adding background colour to the Icon Row component
2 parents 63b81d9 + d0b3b54 commit d779cb0

File tree

11 files changed

+32
-9
lines changed

11 files changed

+32
-9
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
22

33
class Cms::IconRowComponent < ViewComponent::Base
4-
def initialize(icons:)
4+
def initialize(icons:, background_color:)
55
@icons = icons
6+
@background_color = background_color
67
end
78
end

app/components/cms/icon_row_component/icon_row_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= render GovGridRowComponent.new do |row| %>
1+
<%= render GovGridRowComponent.new(background_color: @background_color) do |row| %>
22
<%= row.with_column("full") do %>
33
<div class="cms-icon-row-component">
44
<% @icons.each do |icon| %>

app/services/cms/dynamic_components/icon_row.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module Cms
22
module DynamicComponents
33
class IconRow
4-
attr_accessor :icons
4+
attr_accessor :icons, :background_color
55

6-
def initialize(icons:)
6+
def initialize(icons:, background_color:)
77
@icons = icons
8+
@background_color = background_color
89
end
910

1011
def render
11-
Cms::IconRowComponent.new(icons:)
12+
Cms::IconRowComponent.new(icons:, background_color:)
1213
end
1314
end
1415
end

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def self.to_horizontal_card_with_asides(strapi_data)
9090

9191
def self.to_icon_row(strapi_data)
9292
DynamicComponents::IconRow.new(
93-
icons: strapi_data[:icons].map { to_icon(_1) }
93+
icons: strapi_data[:icons].map { to_icon(_1) },
94+
background_color: extract_color_name(strapi_data, :bkColor)
9495
)
9596
end
9697

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def self.as_model
99

1010
def self.generate_data
1111
{
12-
iconText: Faker::Lorem.word,
12+
iconText: Faker::Lorem.sentence(word_count: 3),
1313
iconImage: {data: Image.generate_raw_data}
1414
}
1515
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class IconRow < StrapiMock
66
strapi_component "blocks.icon-row"
77

88
attribute(:icons) { Array.new(2) { Icon.generate_data } }
9+
attribute(:background_color) { {data: ColorScheme.generate_data} }
910
end
1011
end
1112
end

app/services/cms/providers/strapi/queries/components/blocks/icon_row.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def self.name = "ComponentBlocksIconRow"
1010
def self.base_fields
1111
<<~GRAPHQL.freeze
1212
#{SharedFields.icon_block("icons")}
13+
#{SharedFields.color_theme("bkColor")}
1314
GRAPHQL
1415
end
1516
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Cms::IconRowComponentPreview < ViewComponent::Preview
2+
def default
3+
render(Cms::IconRowComponent.new(icons: Array.new(5) { Cms::Mocks::Icon.as_model }, background_color: nil))
4+
end
5+
6+
def dark_background
7+
render(Cms::IconRowComponent.new(icons: Array.new(5) { Cms::Mocks::Icon.as_model }, background_color: "purple"))
8+
end
9+
end

spec/components/cms/icon_row_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
RSpec.describe Cms::IconRowComponent, type: :component do
66
before do
7-
render_inline(described_class.new(icons: Array.new(2) { Cms::Mocks::Icon.as_model }))
7+
render_inline(described_class.new(icons: Array.new(2) { Cms::Mocks::Icon.as_model }, background_color: nil))
88
end
99

1010
it "should render images" do
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Cms::Providers::Strapi::Queries::Components::Blocks::IconRow do
4+
it_should_behave_like "a strapi graphql component",
5+
%w[
6+
icons
7+
bkColor
8+
]
9+
end

0 commit comments

Comments
 (0)