Skip to content

Commit a4047b5

Browse files
authored
Improve Cloud Cover with Subscribe Combo (#1855)
This PR modifies the Subscribe and Cloud Cover components to play nicer together. It updates the Subscribe component to make the headings optional, and tweaks the layout to switch to horizontal once there's enough space for two buttons, rather than at a fixed breakpoint. It updates the Cloud Cover component to switch layout at a custom breakpoint (45em) rather than m, and adjusts the proportion of space between the content and extra cells to give the extra content a bit more room to breathe at mid-size viewports. Fixes #1769
1 parent b1a6c3d commit a4047b5

File tree

10 files changed

+93
-47
lines changed

10 files changed

+93
-47
lines changed

.changeset/fuzzy-beds-breathe.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cloudfour/patterns": major
3+
---
4+
5+
This change improves the Cloud Cover component's layout when used with the Subscribe component. It makes the Subscribe headings optional, and improved the layout to switch to horizontal when there's enough room for two buttons, rather than a fixed breakpoint.
6+
7+
This is a breaking change because it removes the default values of the Subscribe component's headings.

src/components/cloud-cover/cloud-cover.scss

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
@use '../../mixins/ms';
66
@use '../../mixins/fluid';
77

8+
/// Setting the breakpoint to `m` (40em) results in an awkward layout
9+
/// when using the Subscribe form in the `extra` slot. However, setting
10+
/// the breakpoint to `l` (60em) results in the transition happening too
11+
/// late. As a result, we're using a custom breakpoint optimized for the
12+
/// Cloud Cover component.
13+
14+
$_cloud-cover-breakpoint: 45em;
15+
816
/// We can't use `grid-gap` exclusively due to some containers only being present
917
/// some of the time, so we re-use this value for `grid-gap` and for `margin`
1018
/// later on.
@@ -71,7 +79,7 @@ $_gap: ms.step(1);
7179
pointer-events: none;
7280
position: absolute;
7381

74-
@media (width >= breakpoint.$m) {
82+
@media (width >= $_cloud-cover-breakpoint) {
7583
inline-size: 50%;
7684
}
7785
}
@@ -159,7 +167,7 @@ $_gap: ms.step(1);
159167
* overlap.
160168
*/
161169

162-
@media (width >= breakpoint.$m) {
170+
@media (width >= $_cloud-cover-breakpoint) {
163171
grid-template-areas:
164172
'. .'
165173
'. scene'
@@ -172,6 +180,18 @@ $_gap: ms.step(1);
172180
auto
173181
repeat(2, _cloud-space(0.5)); /* 1 */
174182
}
183+
184+
/**
185+
* Modified styles for Cloud Cover with Extra content
186+
*
187+
* 1. Give the `extra` content a bit more space relative to the content
188+
* until the viewport is wide enough for the default evenly split layout.
189+
*/
190+
.c-cloud-cover--with-extra & {
191+
@media (width >= $_cloud-cover-breakpoint) and (width < breakpoint.$xl) {
192+
grid-template-columns: 3fr 4fr; /* 1 */
193+
}
194+
}
175195
}
176196

177197
/**
@@ -181,7 +201,7 @@ $_gap: ms.step(1);
181201
*/
182202

183203
.c-cloud-cover--horizon-scene .c-cloud-cover__inner {
184-
@media (width < breakpoint.$m) {
204+
@media (width < $_cloud-cover-breakpoint) {
185205
grid-template-areas:
186206
'.'
187207
'content'
@@ -221,7 +241,7 @@ $_gap: ms.step(1);
221241
* use margin to avoid this running up against adjacent content.
222242
*/
223243

224-
@media (width < breakpoint.$m) {
244+
@media (width < $_cloud-cover-breakpoint) {
225245
margin-block-start: $_gap;
226246
}
227247
}
@@ -245,7 +265,7 @@ $_gap: ms.step(1);
245265
* large as the clouds.
246266
*/
247267

248-
@media (width < breakpoint.$m) {
268+
@media (width < $_cloud-cover-breakpoint) {
249269
block-size: _cloud-space(2);
250270
margin-block-end: $_gap;
251271
}
@@ -255,7 +275,7 @@ $_gap: ms.step(1);
255275
* and size based on available space.
256276
*/
257277

258-
@media (width >= breakpoint.$m) {
278+
@media (width >= $_cloud-cover-breakpoint) {
259279
block-size: 100%;
260280
grid-row-end: span 3;
261281
}
@@ -273,7 +293,7 @@ $_gap: ms.step(1);
273293
* the reverse of the default).
274294
*/
275295

276-
@media (width < breakpoint.$m) {
296+
@media (width < $_cloud-cover-breakpoint) {
277297
block-size: _cloud-space(3);
278298
margin-block: $_gap 0;
279299
}
@@ -283,7 +303,7 @@ $_gap: ms.step(1);
283303
* on areas alone to do this since the `scene` and `extra` areas overlap.
284304
*/
285305

286-
@media (width >= breakpoint.$m) {
306+
@media (width >= $_cloud-cover-breakpoint) {
287307
grid-row-end: span 4;
288308
}
289309
}
@@ -309,7 +329,7 @@ $_gap: ms.step(1);
309329
* to the right rather than on both sides.
310330
*/
311331

312-
@media (width >= breakpoint.$m) {
332+
@media (width >= $_cloud-cover-breakpoint) {
313333
object-position: left center;
314334
}
315335
}
@@ -322,7 +342,7 @@ $_gap: ms.step(1);
322342
.c-cloud-cover--horizon-scene .c-cloud-cover__scene-object {
323343
object-position: center bottom;
324344

325-
@media (width >= breakpoint.$m) {
345+
@media (width >= $_cloud-cover-breakpoint) {
326346
object-position: left bottom;
327347
}
328348
}

src/components/cloud-cover/cloud-cover.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% set _extra_block %}{% block extra %}{% endblock %}{% endset %}
44
{% set _scene_block %}{% block scene %}{% endblock %}{% endset %}
55

6-
<div class="c-cloud-cover t-dark{% if class %} {{ class }}{% endif %}">
6+
<div class="c-cloud-cover t-dark{% if class %} {{ class }}{% endif %}{% if _extra_block is not empty %} c-cloud-cover--with-extra{% endif %}">
77
<div class="o-container o-container--pad-inline">
88
<div class="o-container__content c-cloud-cover__inner">
99
<div class="c-cloud-cover__content">

src/components/cloud-cover/demo/extra.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
</p>
1818
{% endblock %}
1919
{% block extra %}
20-
<p>(Imagine a nifty newsletter signup form here 👀)</p>
20+
{% embed '@cloudfour/components/subscribe/subscribe.twig' with {
21+
form_id: 'cloud-cover-test'
22+
} only %}{% endembed %}
2123
{% endblock %}
2224
{% endembed %}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% embed '@cloudfour/components/subscribe/subscribe.twig' with {
2-
form_id: 'test'
2+
form_id: 'test',
3+
weekly_digests_heading: 'Get Weekly Digests',
4+
subscribe_heading: 'Never miss an article!',
35
} only %}{% endembed %}
46

57
<p>This is only for demo purposes. <a href="#">I am a link</a></p>

src/components/subscribe/subscribe.scss

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
position: relative;
1313
}
1414

15+
.c-subscribe__heading {
16+
margin-block-end: size.$rhythm-default-rem;
17+
}
18+
19+
///
20+
/// 1. `12em` is a magic number based on the default button text values.
21+
/// It may need to be tweaked if the text values change in the future.
22+
/// Ideally we'd use `min-content`, but you can't pair that with `1fr`,
23+
/// plus it doesn't seem to work since we're setting `inline-size:100%`.
24+
///
1525
.c-subscribe__controls {
1626
display: grid;
1727
gap: 1em;
18-
margin: size.$rhythm-default 0;
19-
20-
@media (min-width: breakpoint.$s) {
21-
grid-template-columns: 1fr 1fr;
22-
}
28+
grid-template-columns: repeat(auto-fit, minmax(12em, 1fr)); // 1
2329
}
2430

2531
.c-subscribe__control {
@@ -50,7 +56,3 @@
5056
@include a11y.sr-only;
5157
}
5258
}
53-
54-
.c-subscribe__form-input-group {
55-
margin: size.$rhythm-default 0;
56-
}

src/components/subscribe/subscribe.stories.mdx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ const templateStory = (args) => {
4848
},
4949
heading_tag: {
5050
type: 'string',
51-
description: 'Sets the heading value',
51+
description: 'Sets the heading tag',
5252
table: {
5353
defaultValue: { summary: 'h2' },
5454
},
5555
options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
5656
control: 'select',
5757
},
58-
never_miss_article_heading: {
58+
subscribe_heading: {
5959
type: 'string',
60-
description: "The heading seen in the component's default state",
60+
description: 'The overall subscribe component heading',
6161
table: {
6262
defaultValue: {
63-
summary: 'Never miss an article!',
63+
summary: '',
6464
},
6565
},
6666
},
@@ -130,9 +130,9 @@ const templateStory = (args) => {
130130
},
131131
weekly_digests_heading: {
132132
type: 'string',
133-
description: 'The subscription form heading',
133+
description: 'The weekly digests subscription form heading',
134134
table: {
135-
defaultValue: { summary: 'Get Weekly Digests' },
135+
defaultValue: { summary: '' },
136136
},
137137
},
138138
email_input_label: {
@@ -177,6 +177,8 @@ This component embeds the [Button Swap component](/?path=/docs/components-button
177177
name="Default"
178178
args={{
179179
form_id: 'example-demo',
180+
subscribe_heading: 'Never miss an article!',
181+
weekly_digests_heading: 'Get Weekly Digests',
180182
}}
181183
parameters={{
182184
docs: {
@@ -185,6 +187,8 @@ This component embeds the [Button Swap component](/?path=/docs/components-button
185187
'@cloudfour/components/subscribe/subscribe.twig',
186188
{
187189
form_id: 'example-demo',
190+
subscribe_heading: 'Never miss an article!',
191+
weekly_digests_heading: 'Get Weekly Digests',
188192
}
189193
),
190194
},

src/components/subscribe/subscribe.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ describe('Subscription', () => {
6060
withBrowser(async ({ utils, page }) => {
6161
await loadGlobalCSS(utils);
6262
await utils.loadCSS('./subscribe.scss');
63-
await utils.injectHTML(await componentMarkup());
63+
await utils.injectHTML(
64+
await componentMarkup({
65+
weekly_digests_heading: 'Get Weekly Digests',
66+
subscribe_heading: 'Never miss an article!',
67+
})
68+
);
6469
await initJS(utils);
6570

6671
expect(await getAccessibilityTree(page)).toMatchInlineSnapshot(`
@@ -196,15 +201,9 @@ describe('Subscription', () => {
196201
// No customization
197202
await utils.injectHTML(await componentMarkup({ form_id: 'test' }));
198203

199-
// Confirm default heading tag
200-
await screen.getByRole('heading', {
201-
name: 'Never miss an article!',
202-
level: 2,
203-
});
204-
await screen.getByRole('heading', {
205-
name: 'Get Weekly Digests',
206-
level: 2,
207-
});
204+
// Confirm default heading tags are not set
205+
const anyHeading = await screen.queryByRole('heading');
206+
expect(anyHeading).not.toBeInTheDocument();
208207

209208
// Confirm default form values
210209
let emailInput = await screen.getByRole('textbox', { name: 'Email' });
@@ -217,7 +216,7 @@ describe('Subscription', () => {
217216
form_action: 'test-action.com',
218217
heading_tag: 'h3',
219218
weekly_digests_heading: 'Weekly digests available',
220-
never_miss_article_heading: "Don't miss out!",
219+
subscribe_heading: "Don't miss out!",
221220
notifications_btn_class: 'hello',
222221
notifications_btn_initial_visual_label: 'Yes to notifications',
223222
weekly_digests_btn_class: 'world',

src/components/subscribe/subscribe.twig

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{% set _heading_tag = heading_tag|default('h2') %}
22

33
<div class="c-subscribe js-subscribe {{class}}">
4-
<{{_heading_tag}}>
5-
{{never_miss_article_heading|default('Never miss an article!')}}
6-
</{{_heading_tag}}>
4+
{% if subscribe_heading %}
5+
<{{_heading_tag}} class="c-subscribe__heading">
6+
{{subscribe_heading}}
7+
</{{_heading_tag}}>
8+
{% endif %}
79

810
<div class="c-subscribe__controls">
911
{% include '@cloudfour/components/button-swap/button-swap.twig' with {
@@ -41,11 +43,18 @@
4143
method="post"
4244
target="_blank"
4345
class="c-subscribe__form"
44-
aria-labelledby="get-weekly-digests-{{form_id}}"
46+
{% if weekly_digests_heading %}
47+
aria-labelledby="get-weekly-digests-{{form_id}}"
48+
{% endif %}
4549
>
46-
<{{_heading_tag}} id="get-weekly-digests-{{form_id}}">
47-
{{weekly_digests_heading|default('Get Weekly Digests')}}
48-
</{{_heading_tag}}>
50+
{% if weekly_digests_heading %}
51+
<{{_heading_tag}}
52+
id="get-weekly-digests-{{form_id}}"
53+
class="c-subscribe__heading"
54+
>
55+
{{weekly_digests_heading}}
56+
</{{_heading_tag}}>
57+
{% endif %}
4958

5059
<label
5160
class="c-subscribe__form-input-label"

src/tokens/size/rhythm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const { modularEm } = require('../../scripts/modular-scale');
1+
const { modularEm, modularRem } = require('../../scripts/modular-scale');
22

33
module.exports = {
44
size: {
55
rhythm: {
66
compact: { value: modularEm(-6) },
77
condensed: { value: modularEm(-1) },
88
default: { value: modularEm(1) },
9+
default_rem: { value: modularRem(1) },
910
generous: { value: modularEm(3) },
1011
},
1112
},

0 commit comments

Comments
 (0)