Skip to content

Commit 910cd6b

Browse files
authored
Add o-container__fill elements (#1491)
1 parent 79460ba commit 910cd6b

File tree

8 files changed

+444
-324
lines changed

8 files changed

+444
-324
lines changed

.changeset/early-carrots-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add `o-container__fill` and `o-container__fill-pad` elements for content intended to stretch into inline container padding

src/mixins/_fluid.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@
108108
}
109109
}
110110

111+
@mixin margin-inline($min-width, $max-width, $min, $max, $include-min: true) {
112+
@if $include-min {
113+
margin-inline-end: $min;
114+
margin-inline-start: $min;
115+
}
116+
117+
@media (min-width: $min-width) {
118+
margin-inline-end: fluid-calc($min-width, $max-width, $min, $max);
119+
margin-inline-start: fluid-calc($min-width, $max-width, $min, $max);
120+
}
121+
122+
@media (min-width: $max-width) {
123+
margin-inline-end: $max;
124+
margin-inline-start: $max;
125+
}
126+
}
127+
111128
@mixin padding($min-width, $max-width, $min, $max, $include-min: true) {
112129
@if $include-min {
113130
padding: $min;

src/objects/container/container.scss

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,60 @@ $pad-max: size.$padding-container-max;
6262
max-width: size.$max-width-prose;
6363
}
6464
}
65+
66+
/**
67+
* Child elements intended to "fill" the container width. This negates any
68+
* inline padding and border radii.
69+
*/
70+
71+
.o-container__fill,
72+
.o-container__fill-pad {
73+
.o-container--pad &,
74+
.o-container--pad-inline & {
75+
@include fluid.margin-inline(
76+
$pad-breakpoint-min,
77+
$pad-breakpoint-max,
78+
$pad-min * -1,
79+
$pad-max * -1
80+
);
81+
}
82+
83+
.o-container--pad:not(.o-container--prose) &,
84+
.o-container--pad-inline:not(.o-container--prose) & {
85+
// Magic number corresponds to approximate size of fluid padding in addition
86+
// to max width container without fluid font size applied (attempts to boil
87+
// this down to a repeatable equation resulted in my head exploding). If we
88+
// only tested by the max width, the rounded corners would be restored too
89+
// early (before there was visible whitespace to either side).
90+
@media (width < (size.$max-width-spread + 25em)) {
91+
border-radius: 0;
92+
}
93+
}
94+
95+
.o-container--pad.o-container--prose &,
96+
.o-container--pad-inline.o-container--prose & {
97+
// See previous comment about magic number
98+
@media (width < (size.$max-width-prose + 7em)) {
99+
border-radius: 0;
100+
}
101+
}
102+
}
103+
104+
/**
105+
* The `__fill-pad` element differs from the `__fill` element in that it
106+
* restores the parent element's padding (if any). This may be useful for cards
107+
* and theme containers with inner content that wouldn't align with what was
108+
* adjacent otherwise.
109+
*/
110+
111+
.o-container__fill-pad {
112+
.o-container--pad &,
113+
.o-container--pad-inline & {
114+
@include fluid.padding-inline(
115+
$pad-breakpoint-min,
116+
$pad-breakpoint-max,
117+
$pad-min,
118+
$pad-max
119+
);
120+
}
121+
}

src/objects/container/container.stories.mdx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';
1+
import { Story, Canvas, Meta } from '@storybook/addon-docs';
22
import basicDemo from './demo/basic.twig';
3+
// The '!!raw-loader!' syntax is a non-standard, Webpack-specific, syntax.
4+
// See: https://github.com/webpack-contrib/raw-loader#examples
5+
// For now, it seems likely Storybook is pretty tied to Webpack, therefore, we
6+
// are okay with the following Webpack-specific raw loader syntax. It's better
7+
// to leave the ESLint rule enabled globally, and only thoughtfully disable as
8+
// needed (e.g. within a Storybook docs page and not within an actual
9+
// component). This can be revisited in the future if Storybook no longer relies
10+
// on Webpack.
11+
// eslint-disable-next-line @cloudfour/import/no-webpack-loader-syntax
12+
import fillDemoSource from '!!raw-loader!./demo/fill.twig';
13+
import fillDemo from './demo/fill.twig';
314
const basicDemoStory = (args) => {
415
const modifiers = [];
516
if (args.prose) {
@@ -24,7 +35,11 @@ embedded examples.
2435

2536
<Meta
2637
title="Objects/Container"
27-
parameters={{ docs: { inlineStories: false }, paddings: { disable: true } }}
38+
parameters={{
39+
layout: 'fullscreen',
40+
docs: { inlineStories: false },
41+
paddings: { disable: true },
42+
}}
2843
argTypes={{
2944
prose: {
3045
control: {
@@ -117,3 +132,23 @@ Modifiers may be added to apply a consistent amount of responsive padding to con
117132
- `o-container--pad-inline`: Adds horizontal padding.
118133

119134
Custom padding amounts may be applied through the use of [padding utilities](/docs/utilities-spacing--padding).
135+
136+
## Fill
137+
138+
There are times when a child element should attempt to fill the container content width, including padding. This can highlight visual elements (images and embeds) and align content within containers.
139+
140+
Two child element classes exist for this purpose:
141+
142+
- `o-container__fill`: Negates any inline padding so the element will reach the edges of the content container's padding.
143+
- `o-container__fill-pad`: Also applies padding to the element so its content will align with that of the container.
144+
145+
<Canvas>
146+
<Story
147+
name="Fill"
148+
height="500px"
149+
argTypes={{}}
150+
parameters={{ docs: { source: { code: fillDemoSource } } }}
151+
>
152+
{fillDemo.bind({})}
153+
</Story>
154+
</Canvas>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% embed '@cloudfour/objects/container/container.twig' with {
2+
class: 'o-container--prose o-container--pad'
3+
} only %}
4+
{% block content %}
5+
{% embed '@cloudfour/objects/rhythm/rhythm.twig' only %}
6+
{% block content %}
7+
<p>This card simply fills the content element:</p>
8+
{% embed '@cloudfour/components/card/card.twig' with {
9+
class: 'c-card--contained'
10+
} only %}
11+
{% block content %}
12+
<p>.c-card.c-card--contained</p>
13+
{% endblock %}
14+
{% endembed %}
15+
<p>This card attempts to fill the container, padding included:</p>
16+
{% embed '@cloudfour/components/card/card.twig' with {
17+
class: 'c-card--contained o-container__fill'
18+
} only %}
19+
{% block content %}
20+
<p>.c-card.c-card--contained.o-container__fill</p>
21+
{% endblock %}
22+
{% endembed %}
23+
<p>This card fills the container and applies padding to align its content with adjacent elements:</p>
24+
{% embed '@cloudfour/components/card/card.twig' with {
25+
class: 'c-card--contained o-container__fill-pad'
26+
} only %}
27+
{% block content %}
28+
<p>.c-card.c-card--contained.o-container__fill-pad</p>
29+
{% endblock %}
30+
{% endembed %}
31+
{% endblock %}
32+
{% endembed %}
33+
{% endblock %}
34+
{% endembed %}

src/prototypes/single-article/example/example.scss

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)