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

Gallery block: prototype managing gap changes without css var #38015

Closed
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: 0 additions & 6 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
if ( $has_block_gap_support ) {
$gap_style = $gap_value ? $gap_value : 'var( --wp--style--block-gap, 0.5em )';
$style .= "gap: $gap_style;";

/*
* In some contexts a flex container's children may be need to recalculate their width
* based on the current gap so this value is made available as a css var.
*/
$style .= "--wp--style--block-scoped-flex-gap: $gap_style;";
} else {
$style .= 'gap: 0.5em;';
}
Expand Down
3 changes: 0 additions & 3 deletions packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ export default {
${ appendSelectors( selector ) } {
display: flex;
gap: ${ hasBlockGapStylesSupport ? blockGapValue : '0.5em' };
--wp--style--block-scoped-flex-gap: ${
hasBlockGapStylesSupport ? blockGapValue : '0.5em'
};
flex-wrap: ${ flexWrap };
${ orientation === 'horizontal' ? rowOrientation : columnOrientation }
}
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/gallery/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
"providesContext": {
"allowResize": "allowResize",
"imageCrop": "imageCrop",
"fixedHeight": "fixedHeight"
"fixedHeight": "fixedHeight",
"style": "style",
"columns": "columns"
},
"supports": {
"anchor": true,
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"name": "core/image",
"title": "Image",
"category": "media",
"usesContext": [ "allowResize", "imageCrop", "fixedHeight" ],
"usesContext": [
"allowResize",
"imageCrop",
"fixedHeight",
"style",
"columns"
],
"description": "Insert an image to make a visual statement.",
"keywords": [ "img", "photo", "picture" ],
"textdomain": "default",
Expand Down
15 changes: 14 additions & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export function ImageEdit( {
height,
sizeSlug,
} = attributes;

const parentGap = context?.style?.spacing?.blockGap;
const columns = context?.columns ? context?.columns : 3;

const [ temporaryURL, setTemporaryURL ] = useState();

const altRef = useRef();
Expand Down Expand Up @@ -349,8 +353,17 @@ export function ImageEdit( {
className: classes,
} );

const newWidth =
columns && parentGap
? `calc((100% / ${ columns }) - ${ parentGap })`
: 'initial';
return (
<figure { ...blockProps }>
<figure
{ ...blockProps }
style={ {
width: newWidth,
} }
>
{ ( temporaryURL || url ) && (
<Image
temporaryURL={ temporaryURL }
Expand Down