Skip to content

Commit 18d2d93

Browse files
Add Media object Align Start modifier (#1791)
1 parent 2caeddb commit 18d2d93

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

.changeset/green-fishes-hug.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 Media object Align Start modifier

src/objects/media/media.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
order: -1; /* 2 */
2828
}
2929

30+
/**
31+
* Modifier: Align Start
32+
*
33+
* Uses `align-items: start` instead of `align-items: center`
34+
*/
35+
36+
.o-media--align-start {
37+
align-items: start;
38+
}
39+
3040
/**
3141
* Modifier: Generous Gap
3242
*

src/objects/media/media.stories.mdx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,43 @@ const imageDemoTransformSource = (_src, storyContext) => {
4747
}}
4848
argTypes={{
4949
imgSrc: { type: { name: 'string', required: true } },
50+
tag_name: {
51+
type: { name: 'string' },
52+
description: 'The root tag for the component',
53+
table: {
54+
defaultValue: {
55+
summary: 'div',
56+
},
57+
},
58+
},
59+
inner_tag_name: {
60+
type: { name: 'string' },
61+
description:
62+
'The tag for both the media content and media object elements',
63+
table: {
64+
defaultValue: {
65+
summary: 'div',
66+
},
67+
},
68+
},
69+
content_tag_name: {
70+
type: { name: 'string' },
71+
description: 'The tag for the media content element',
72+
table: {
73+
defaultValue: {
74+
summary: '`inner_tag_name`',
75+
},
76+
},
77+
},
78+
object_tag_name: {
79+
type: { name: 'string' },
80+
description: 'The tag for the media object element',
81+
table: {
82+
defaultValue: {
83+
summary: '`inner_tag_name`',
84+
},
85+
},
86+
},
5087
text: { type: { name: 'string' } },
5188
class: { type: { name: 'string' } },
5289
reverse: { type: { name: 'boolean' } },
@@ -175,3 +212,61 @@ By adding the `o-media--jaunty` class, the media object will have a fun little r
175212
{(args) => imageDemo(args)}
176213
</Story>
177214
</Canvas>
215+
216+
## Alignment
217+
218+
By default, the Media object optimizes its alignment based on its content alone.
219+
This may result in inconsistent alignment when multiple Media objects with
220+
inconsistent content lengths are displayed side by side.
221+
222+
You may add the `o-media--align-start` modifier to force consistent alignment
223+
between adjacent Media objects. This pairs nicely with [the Deck object modifier
224+
of the same name](/docs/objects-deck--block-alignment).
225+
226+
<Canvas>
227+
<Story
228+
name="Align Default"
229+
args={{
230+
text: 'Default alignment',
231+
}}
232+
parameters={{
233+
docs: {
234+
transformSource: imageDemoTransformSource,
235+
},
236+
}}
237+
>
238+
{(args) => imageDemo(args)}
239+
</Story>
240+
<Story
241+
name="Align Start"
242+
args={{
243+
align_start: true,
244+
text: 'Align start alignment',
245+
}}
246+
parameters={{
247+
docs: {
248+
transformSource: imageDemoTransformSource,
249+
},
250+
}}
251+
>
252+
{(args) => imageDemo(args)}
253+
</Story>
254+
</Canvas>
255+
256+
## Template Properties
257+
258+
- `class` (string): Appends to the CSS class of the root element
259+
- `tag_name` (string, default `'div'`): The root tag for the component
260+
- `inner_tag_name` (string, default `'div'`): The tag for both the media content and media object elements
261+
- `object_tag_name` (string, default `inner_tag_name`): The tag for the media object element
262+
- `content_tag_name` (string, default `inner_tag_name`): The tag for the media content element
263+
- `align_start` (boolean, default `false`): Adds the `o-media--align-start` CSS class modifier
264+
- `jaunty` (boolean, default `false`): Adds the `o-media--jaunty` CSS class modifier
265+
- `generous` (boolean, default `false`): Adds the `o-media--generous` CSS class modifier
266+
- `reverse` (boolean, default `false`): Adds the `o-media--reverse` CSS class modifier
267+
- `reverse_markup` (boolean, default `false`): Flips the order of the object and content markup so that the content is first
268+
269+
## Template Blocks
270+
271+
- `object`: Block for the static object (the image, checkbox, etc.)
272+
- `content`: Block for the wrapping content (typically text)

src/objects/media/media.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{#
2727
Vary where `object_block` outputs based on the `reverse_markup` property.
2828
#}
29-
<{{ tag_name }} class="o-media{% if jaunty %} o-media--jaunty{% endif %}{% if generous %} o-media--generous{% endif %}{% if reverse %} o-media--reverse{% endif %}{% if class %} {{ class }}{% endif %}">
29+
<{{ tag_name }} class="o-media{% if align_start %} o-media--align-start{% endif %}{% if jaunty %} o-media--jaunty{% endif %}{% if generous %} o-media--generous{% endif %}{% if reverse %} o-media--reverse{% endif %}{% if class %} {{ class }}{% endif %}">
3030
{% if not reverse_markup %}
3131
{{ object_block }}
3232
{% endif %}

0 commit comments

Comments
 (0)