Skip to content

Commit 6bf8f7b

Browse files
authored
Add styles for WordPress Media-Text block (#2151)
1 parent 833b7e3 commit 6bf8f7b

File tree

5 files changed

+121
-12
lines changed

5 files changed

+121
-12
lines changed

.changeset/nine-jokes-guess.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 styles for the "Media-Text" WordPress block

src/vendor/wordpress/core-blocks.stories.mdx

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2-
import blockImageDemo from './demo/image.twig';
32
import blockCodeDemo from './demo/code.twig';
43
import blockEmbedSpeakerDeckDemo from './demo/embed/speakerdeck.twig';
54
import blockEmbedYouTubeDemo from './demo/embed/youtube.twig';
5+
import blockImageDemo from './demo/image.twig';
66
import blockGroupDemo from './demo/group.twig';
7+
import blockMediaTextDemo from './demo/media-text.twig';
78
import blockTableDemo from './demo/table.twig';
89
const blockEmbedDemoArgTypes = {
910
alignment: {
@@ -33,6 +34,42 @@ const blockEmbedDemoArgTypes = {
3334
control: { type: 'text' },
3435
},
3536
};
37+
const blockMediaTextDemoArgTypes = {
38+
alignment: {
39+
options: {
40+
None: '',
41+
Left: 'alignleft',
42+
Center: 'aligncenter',
43+
Right: 'alignright',
44+
Full: 'alignfull',
45+
Wide: 'alignwide',
46+
},
47+
control: { type: 'select' },
48+
},
49+
vertical_alignment: {
50+
options: {
51+
Top: 'top',
52+
Center: 'center',
53+
Bottom: 'bottom',
54+
},
55+
control: { type: 'select' },
56+
},
57+
has_media_on_the_right: {
58+
control: { type: 'boolean' },
59+
},
60+
is_stacked_on_mobile: {
61+
control: { type: 'boolean' },
62+
},
63+
has_background: {
64+
control: { type: 'boolean' },
65+
},
66+
is_image_fill: {
67+
control: { type: 'boolean' },
68+
},
69+
media_width: {
70+
control: { type: 'range', min: 15, max: 85, step: 1 },
71+
},
72+
};
3673

3774
<Meta title="Vendor/WordPress/Core Blocks" />
3875

@@ -461,16 +498,16 @@ padding) class.
461498
Another control toggles the class `is-stacked-on-mobile`.
462499

463500
<Canvas>
464-
<Story name="Media-Text">
465-
{`<div class="wp-block-media-text alignwide is-stacked-on-mobile has-media-on-the-right is-vertically-aligned-center has-background has-subtle-background-background-color">
466-
<figure class="wp-block-media-text__media">
467-
<img src="/media/Biologia_Centrali-Americana_-_Cantorchilus_semibadius_1902.jpg" alt="" />
468-
</figure>
469-
<div class="wp-block-media-text__content">
470-
<p>The wren<br>Earns his living<br>Noiselessly.</p>
471-
<p>— Kobayashi Issa (一茶)</p>
472-
</div>
473-
</div>`}
501+
<Story
502+
name="Media-Text"
503+
parameters={{ layout: 'fullscreen' }}
504+
argTypes={blockMediaTextDemoArgTypes}
505+
args={{
506+
is_stacked_on_mobile: true,
507+
media_width: 33,
508+
}}
509+
>
510+
{(args) => blockMediaTextDemo(args)}
474511
</Story>
475512
</Canvas>
476513

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% embed '@cloudfour/objects/container/container.twig' with {
2+
class: 'o-container--prose o-container--pad-inline u-pad-block-1',
3+
content_class: 'o-rhythm',
4+
alignment: alignment,
5+
has_background: has_background,
6+
vertical_alignment: vertical_alignment,
7+
media_width: media_width,
8+
is_image_fill: is_image_fill,
9+
is_stacked_on_mobile: is_stacked_on_mobile,
10+
has_media_on_the_right: has_media_on_the_right
11+
} only %}
12+
{% block content %}
13+
14+
<p>Let’s start with some text before the block even starts.</p>
15+
16+
<div class="wp-block-media-text
17+
{% if alignment %}{{alignment}}{% endif %}
18+
{% if has_media_on_the_right %}has-media-on-the-right{% endif %}
19+
{% if is_stacked_on_mobile %}is-stacked-on-mobile{% endif %}
20+
{% if is_image_fill %}is-image-fill{% endif %}
21+
{% if vertical_alignment %}is-vertically-aligned-{{ vertical_alignment }}{% endif %}
22+
{% if has_background %}has-gray-lighter-background-color has-background{% endif %}"
23+
{% if media_width and media_width != 50 %}style="
24+
grid-template-columns:
25+
{%- if has_media_on_the_right -%}
26+
auto {{media_width}}%
27+
{%- else -%}
28+
{{media_width}}% auto
29+
{%- endif -%}
30+
"
31+
{%- endif %}>
32+
<figure class="wp-block-media-text__media"
33+
{% if is_image_fill %}style="background-image:url(/media/avatar-buster-b.jpg);background-position:50% 50%"{% endif %}>
34+
<img decoding="async" src="/media/avatar-buster-b.jpg" alt="" class="size-full">
35+
</figure>
36+
<div class="wp-block-media-text__content">
37+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
38+
<p>Suspendisse a est et ex consectetur pulvinar at in tortor. Maecenas id mauris magna.</p>
39+
</div>
40+
</div>
41+
42+
<p>Here is some text that follows this block.</p>
43+
44+
{% endblock %}
45+
{% endembed %}

src/vendor/wordpress/styles/_core-blocks.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ figure.wp-block-image {
259259
}
260260
}
261261

262+
/// Gutenberg block: Media-Text
263+
.wp-block-media-text {
264+
// I'm honestly not sure why the core WordPress block doesn't use `gap` at the
265+
// time of this writing, but it solves a lot of spacing issues.
266+
gap: size.$spacing-gap-inline-medium;
267+
268+
// When an image is set to fill the container, setting a `border-radius` makes
269+
// the cropping feel more visually intentional (similar to card covers).
270+
&.is-image-fill .wp-block-media-text__media {
271+
border-radius: size.$border-radius-medium;
272+
}
273+
274+
.wp-block-media-text__content {
275+
// Maintain vertical rhythm between child elements.
276+
@include spacing.vertical-rhythm;
277+
278+
// We remove the padding since `gap` is already applied to the parent.
279+
padding: 0;
280+
}
281+
}
282+
262283
/// Gutenberg block: Video
263284
/// Styles for videos inserted via Gutenberg blocks.
264285
.wp-block-video {

src/vendor/wordpress/styles/_utilities.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
/// 2. …but if the alignment is not center, we use fluid inline padding instead
4949
/// so that the inner content will align with its siblings.
5050
p,
51-
.wp-block-group {
51+
.wp-block-group,
52+
.wp-block-media-text {
5253
&.has-background {
5354
padding: size.$rhythm-default; // 1
5455

0 commit comments

Comments
 (0)