Skip to content

Commit 33ac25f

Browse files
Merge pull request #2356 from NCCE/2998-strapi-component---resource-card-title-optional
Make resource card title optional
2 parents 6458615 + 1f8c085 commit 33ac25f

File tree

7 files changed

+97
-18
lines changed

7 files changed

+97
-18
lines changed

app/components/cms/image_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ def initialize(image, show_caption: true, link: nil, classes: [])
77
@image = image
88
@show_caption = show_caption
99
@link = link
10-
@classes = classes
10+
@classes = ["cms-image"] + Array.wrap(classes)
1111
end
1212
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<div class="cms-image <%= @classes %>">
1+
<%= content_tag :div, class: @classes do %>
22
<%= link_to_if(@link, cms_image(@image), @link) %>
33
<% if @show_caption && !@image.caption.blank?%>
44
<p class="govuk-body-s govuk-!-margin-bottom-0">
55
<%= @image.caption %>
66
</p>
77
<% end %>
8-
</div>
8+
<% end %>

app/components/cms/resource_card_component/resource_card_component.html.erb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<%= content_tag :div, class: wrapper_classes do %>
2-
<div class="cms-resource-card__top-content">
3-
<div class="cms-resource-card__top-content-title">
4-
<h2 class="govuk-heading-m"><%= @title %></h1>
2+
<% if @title %>
3+
<div class="cms-resource-card__top-content">
4+
<div class="cms-resource-card__top-content-title">
5+
<h2 class="govuk-heading-m"><%= @title %></h1>
6+
</div>
7+
<% if @icon %>
8+
<div class="cms-resource-card__top-content-image">
9+
<%= render Cms::ImageComponent.new(@icon) %>
10+
</div>
11+
<% end %>
512
</div>
6-
<div class="cms-resource-card__top-content-image">
7-
<%= render Cms::ImageComponent.new(@icon) if @icon %>
8-
</div>
9-
</div>
13+
<% end %>
14+
1015
<div class="cms-resource-card__body-text">
1116
<%= render @body_text.render %>
1217
</div>

app/components/cms/resource_card_component/resource_card_component.scss

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
display: flex;
1313
justify-content: space-between;
1414
margin-bottom: 10px;
15+
gap: 10px;
1516

16-
&-image img {
17-
max-width: 100%;
18-
height: auto;
17+
&-image {
18+
.cms-image {
19+
width: 50px;
20+
21+
img {
22+
width: 100%;
23+
height: auto;
24+
object-fit: contain;
25+
}
26+
}
1927
}
2028

2129
@include govuk-media-query($until: tablet) {
@@ -28,10 +36,6 @@
2836
object-position: center;
2937
}
3038
}
31-
32-
&-title {
33-
padding-right: 10px;
34-
}
3539
}
3640

3741
&__body-text {

previews/components/cms/resource_card_component_preview.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,40 @@ def default
1818
))
1919
end
2020

21+
def with_icons
22+
card_section = Cms::Mocks::ResourceCardSection.as_model(
23+
resource_cards: Array.new(3) {
24+
Cms::Mocks::ResourceCard.generate_data(
25+
color_theme: {data: Cms::Mocks::ColorScheme.generate_data(name: "standard")},
26+
icon: {data: Cms::Mocks::Image.generate_raw_data}
27+
)
28+
}
29+
)
30+
render(Cms::CardWrapperComponent.new(
31+
title: card_section.title,
32+
cards_block: card_section.cards_block,
33+
background_color: nil,
34+
cards_per_row: 3
35+
))
36+
end
37+
38+
def no_title
39+
card_section = Cms::Mocks::ResourceCardSection.as_model(
40+
resource_cards: Array.new(3) {
41+
Cms::Mocks::ResourceCard.generate_data(
42+
color_theme: {data: Cms::Mocks::ColorScheme.generate_data(name: "standard")},
43+
title: nil
44+
)
45+
}
46+
)
47+
render(Cms::CardWrapperComponent.new(
48+
title: card_section.title,
49+
cards_block: card_section.cards_block,
50+
background_color: nil,
51+
cards_per_row: 3
52+
))
53+
end
54+
2155
def with_color_theme
2256
card_section = Cms::Mocks::ResourceCardSection.as_model(
2357
resource_cards: Array.new(3) {

spec/components/cms/image_component_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
expect(page).to have_css("img")
1818
end
1919

20+
it "should set default class" do
21+
expect(page).to have_css(".cms-image")
22+
end
23+
2024
it "should have link" do
2125
expect(page).to have_link(href: "https://www.google.com")
2226
end
@@ -68,4 +72,32 @@
6872
expect(page).not_to have_text(caption)
6973
end
7074
end
75+
76+
context "with additional classes" do
77+
context "as string" do
78+
before do
79+
render_inline(described_class.new(
80+
Cms::Mocks::Image.as_model(caption:),
81+
classes: "another-class"
82+
))
83+
end
84+
85+
it "should add both classes" do
86+
expect(page).to have_css(".cms-image.another-class")
87+
end
88+
end
89+
90+
context "as array" do
91+
before do
92+
render_inline(described_class.new(
93+
Cms::Mocks::Image.as_model(caption:),
94+
classes: ["another-class", "second-class"]
95+
))
96+
end
97+
98+
it "should add both of them" do
99+
expect(page).to have_css(".cms-image.another-class.second-class")
100+
end
101+
end
102+
end
71103
end

spec/components/cms/resource_card_component_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
context "has only the required values" do
4242
before do
4343
render_inline(described_class.new(
44-
title: "Card title",
44+
title: nil,
4545
icon: nil,
4646
color_theme: nil,
4747
body_text: body_text,
@@ -50,6 +50,10 @@
5050
))
5151
end
5252

53+
it "does not render header section" do
54+
expect(page).to_not have_css(".cms-resource-card__top-content")
55+
end
56+
5357
it "does not render an icon" do
5458
expect(page).to_not have_css("img")
5559
end

0 commit comments

Comments
 (0)