Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add circle-crop variation to Image block. #16475

Merged
merged 4 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/block-library/src/image/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, _x } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -25,6 +25,10 @@ export const settings = {
'img', // "img" is not translated as it is intended to reflect the HTML <img> tag.
__( 'photo' ),
],
styles: [
{ name: 'default', label: _x( 'Default', 'block style' ), isDefault: true },
{ name: 'circle-mask', label: _x( 'Circle Mask', 'block style' ) },
],
transforms,
getEditWrapperProps( attributes ) {
const { align, width } = attributes;
Expand Down
20 changes: 20 additions & 0 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,23 @@
margin-right: auto;
}
}

// Variations
.is-style-circle-mask img {
// We use an absolute pixel to prevent the oval shape that a value of 50% would give
// to rectangular images. A pill-shape is better than otherwise.
border-radius: 9999px;
kjellr marked this conversation as resolved.
Show resolved Hide resolved

// If a browser supports it, we will switch to using a circular SVG mask.
// The stylelint override is necessary to use the SVG inline here.
@supports (mask-image: none) or (-webkit-mask-image: none) {
/* stylelint-disable */
mask-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50"/></svg>');
/* stylelint-enable */
mask-mode: alpha;
mask-repeat: no-repeat;
mask-size: contain;
mask-position: center;
border-radius: none;
}
}