Skip to content

Commit 5fd84cd

Browse files
committed
Add CSS for Outlined style for WP Image block
This PR adds the styles for the new "Outlined" block style we added to the Image block in the WordPress theme. Ideally, we would just add the `u-border-small` class directly, but WordPress adds the class to the outermost element — in this case, the `figure` — and we only want the border to apply to the nested `img` element. Fixes #862
1 parent 0af371c commit 5fd84cd

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
22
import blockImageDemo from './demo/image.twig';
33
import blockCodeDemo from './demo/code.twig';
44
import blockGroupDemo from './demo/group.twig';
5-
const alignmentClasses = {
6-
None: '',
7-
Left: 'alignleft',
8-
Center: 'aligncenter',
9-
Right: 'alignright',
10-
Full: 'alignfull',
11-
Wide: 'alignwide',
12-
};
135

146
<Meta title="Vendor/WordPress/Core Blocks" />
157

@@ -397,12 +389,28 @@ closing wrapper tag.
397389
name="Image"
398390
argTypes={{
399391
alignment: {
400-
options: alignmentClasses,
392+
options: {
393+
None: '',
394+
Left: 'alignleft',
395+
Center: 'aligncenter',
396+
Right: 'alignright',
397+
Full: 'alignfull',
398+
Wide: 'alignwide',
399+
},
400+
defaultValue: '',
401+
control: { type: 'select' },
402+
},
403+
style: {
404+
options: {
405+
None: 'is-style-default',
406+
Outlined: 'is-style-outlined',
407+
},
408+
defaultValue: 'is-style-default',
401409
control: { type: 'select' },
402410
},
403411
}}
404412
>
405-
{(args) => blockImageDemo({ class: args.alignment })}
413+
{(args) => blockImageDemo({ alignment: args.alignment, style: args.style })}
406414
</Story>
407415
</Canvas>
408416

src/vendor/wordpress/demo/image.twig

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
style="max-width: 40rem; margin: 0 auto; padding: 0 1.25rem"
44
>
55
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec id elit non mi porta gravida at eget metus. Vestibulum id ligula porta felis euismod semper.</p>
6-
{%
7-
if class == 'alignleft' or class == 'aligncenter' or class == 'alignright'
8-
%}
9-
<div class="wp-block-image">
6+
{% if alignment in ['alignleft', 'aligncenter', 'alignright'] %}
7+
<div class="wp-block-image {{style}}">
108
{% endif %}
11-
<figure class="{% if class == 'alignfull' or class == 'alignwide' or class == '' %}wp-block-image {% endif %}size-large is-style-default {{class}}">
9+
<figure class="
10+
{% if alignment in ['alignfull', 'alignwide', ''] %}wp-block-image {{style}}{% endif %}
11+
size-large {{alignment}}
12+
">
1213
<img
1314
src="/media/MtBlanc1.jpg"
1415
alt="Mont Blanc"
@@ -21,9 +22,7 @@
2122
/>
2223
<figcaption>Mont Blanc appears—still, snowy, and serene.</figcaption>
2324
</figure>
24-
{%
25-
if class == 'alignleft' or class == 'aligncenter' or class == 'alignright'
26-
%}
25+
{% if alignment in ['alignleft', 'aligncenter', 'alignright'] %}
2726
</div>
2827
{% endif %}
2928
<p>Etiam porta sem malesuada magna mollis euismod. Maecenas sed diam eget risus varius blandit sit amet non magna. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ $wp-button-gap: size.$spacing-gap-button-group-default;
157157
margin-block-start: 0; // 1
158158
max-inline-size: calc(50% - 0.5em); // 2
159159
}
160+
161+
/// Apply border only to image
162+
/// match .u-border-small
163+
&.is-style-outlined img {
164+
border-color: var(--theme-color-border-text-group);
165+
border-style: solid;
166+
border-width: size.$edge-small;
167+
}
160168
}
161169

162170
/// Because WordPress changes the structure of the Image block markup depending

0 commit comments

Comments
 (0)