Skip to content

Commit 73b893c

Browse files
Merge pull request #2371 from NCCE/2985-button-container-in-strapi
Button Container
2 parents 6b395dd + f32571a commit 73b893c

File tree

13 files changed

+316
-6
lines changed

13 files changed

+316
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::ButtonBlockComponent < ViewComponent::Base
4+
def initialize(buttons:, background_color:, padding:, alignment:, full_width:)
5+
@buttons = buttons
6+
@background_color = background_color
7+
@padding = padding
8+
@alignment = alignment
9+
@full_width = full_width
10+
end
11+
12+
def column_size
13+
return "full" if @full_width
14+
"two-thirds"
15+
end
16+
17+
def alignment_class
18+
"cms-button-block--#{@alignment}"
19+
end
20+
21+
def padding
22+
return {all: 0} unless @padding
23+
{}
24+
end
25+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%= render GovGridRowComponent.new(background_color: @background_color, padding:) do |row| %>
2+
<%= row.with_column(column_size) do %>
3+
<div class="cms-button-block <%= alignment_class %>">
4+
<% @buttons.each do |button| %>
5+
<%= render button.render %>
6+
<% end %>
7+
</div>
8+
<% end %>
9+
<% end %>
10+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.cms-button-block {
2+
width: 100%;
3+
display: flex;
4+
flex-direction: row;
5+
gap: 15px;
6+
7+
@include govuk-media-query($until: tablet) {
8+
flex-direction: column;
9+
gap: 10px;
10+
}
11+
12+
&--right {
13+
justify-content: flex-end;
14+
}
15+
16+
&--left {
17+
justify-content: flex-start;
18+
}
19+
20+
&--center {
21+
justify-content: center;
22+
}
23+
}

app/components/cms/resource_card_component/resource_card_component.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@
4141
&__body-text {
4242
flex-grow: 1;
4343
}
44-
}
4544

46-
.ncce-button--white {
47-
width: 100%;
48-
margin: 24px 0 0;
45+
.ncce-button--white {
46+
width: 100%;
47+
margin: 24px 0 0;
4948

50-
@include govuk-media-query($until: tablet) {
51-
margin-top: 12px;
49+
@include govuk-media-query($until: tablet) {
50+
margin-top: 12px;
51+
}
5252
}
5353
}
54+
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 ButtonBlock
5+
attr_accessor :buttons, :background_color, :padding, :alignment, :full_width
6+
7+
def initialize(buttons:, background_color:, padding:, alignment:, full_width:)
8+
@buttons = buttons
9+
@background_color = background_color
10+
@padding = padding
11+
@alignment = alignment
12+
@full_width = full_width
13+
end
14+
15+
def render
16+
Cms::ButtonBlockComponent.new(buttons:, background_color:, padding:, alignment:, full_width:)
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
@@ -65,9 +65,21 @@ def self.generate_component(component_name, strapi_data)
6565
to_programme_card_wrapper(strapi_data)
6666
when "secondary-question-bank"
6767
DynamicComponents::SecondaryQuestionBank.new(title: strapi_data[:title])
68+
when "button-block"
69+
to_button_block(strapi_data)
6870
end
6971
end
7072

73+
def self.to_button_block(strapi_data)
74+
DynamicComponents::Blocks::ButtonBlock.new(
75+
buttons: strapi_data[:buttons].map { to_ncce_button(_1) },
76+
background_color: extract_color_name(strapi_data, :bkColor),
77+
padding: strapi_data[:padding],
78+
alignment: strapi_data[:alignment],
79+
full_width: strapi_data[:fullWidth]
80+
)
81+
end
82+
7183
def self.to_text_with_testimonial(strapi_data)
7284
DynamicComponents::Blocks::TextWithTestimonial.new(
7385
text_content: to_content_block(strapi_data[:textContent]),
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 ButtonBlock < StrapiMock
8+
strapi_component "blocks.button-block"
9+
10+
attribute(:buttons) { Array.new(3) { NcceButton.generate_data } }
11+
attribute(:bkColor) { ColorScheme.generate_data(name: "light_grey") }
12+
attribute(:padding) { false }
13+
attribute(:alignment) { "left" }
14+
attribute(:fullWidth) { false }
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end
21+
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 ButtonBlock < BaseComponentQuery
8+
def self.name = "ComponentBlocksButtonBlock"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
#{Buttons::NcceButton.embed(:buttons)}
13+
#{SharedFields.color_theme(:bkColor)}
14+
padding
15+
alignment
16+
fullWidth
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
@@ -4,6 +4,7 @@ module Strapi
44
module Queries
55
class DynamicZone
66
COMPONENTS = [
7+
Components::Blocks::ButtonBlock,
78
Components::Blocks::CommunityActivityList,
89
Components::Blocks::CourseCardsSection,
910
Components::Blocks::EnrolmentSplitCourseCard,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::ButtonBlockComponentPreview < ViewComponent::Preview
4+
def with_padding_not_full_width_left_align
5+
render(Cms::ButtonBlockComponent.new(
6+
buttons: Array.new(2) { Cms::Mocks::NcceButton.as_model },
7+
background_color: nil,
8+
padding: true,
9+
full_width: false,
10+
alignment: "left"
11+
))
12+
end
13+
14+
def with_padding_full_width_center
15+
render(Cms::ButtonBlockComponent.new(
16+
buttons: Array.new(2) { Cms::Mocks::NcceButton.as_model },
17+
background_color: nil,
18+
padding: true,
19+
full_width: true,
20+
alignment: "center"
21+
))
22+
end
23+
24+
def with_padding_not_full_width_center
25+
render(Cms::ButtonBlockComponent.new(
26+
buttons: Array.new(2) { Cms::Mocks::NcceButton.as_model },
27+
background_color: nil,
28+
padding: true,
29+
full_width: false,
30+
alignment: "center"
31+
))
32+
end
33+
34+
def with_padding_full_width_right
35+
render(Cms::ButtonBlockComponent.new(
36+
buttons: Array.new(2) { Cms::Mocks::NcceButton.as_model },
37+
background_color: nil,
38+
padding: true,
39+
full_width: true,
40+
alignment: "right"
41+
))
42+
end
43+
44+
def with_padding_not_full_width_right
45+
render(Cms::ButtonBlockComponent.new(
46+
buttons: Array.new(2) { Cms::Mocks::NcceButton.as_model },
47+
background_color: nil,
48+
padding: true,
49+
full_width: false,
50+
alignment: "right"
51+
))
52+
end
53+
end

0 commit comments

Comments
 (0)