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: add gap support #34608

Closed
wants to merge 6 commits into from
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
8 changes: 7 additions & 1 deletion packages/block-library/src/gallery/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@
},
"supports": {
"anchor": true,
"align": true
"align": true,
"spacing": {
"blockGap": true,
"__experimentalDefaultControls": {
"blockGap": true
}
}
},
"editorStyle": "wp-block-gallery-editor",
"style": "wp-block-gallery"
Expand Down
39 changes: 11 additions & 28 deletions packages/block-library/src/gallery/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@

// Styles for current version of gallery block.
.wp-block-gallery.has-nested-images {
--gallery-block--gap: var(--wp--style--block-gap, #{$grid-unit-20});
display: flex;
gap: var(--gallery-block--gap);
flex-wrap: wrap;
// Need bogus :not(#individual-image) to override long :not()
// specificity chain on default image block on front end.
figure.wp-block-image:not(#individual-image) {
// Add space between thumbnails, and unset right most thumbnails later.
margin: 0 var(--gallery-block--gutter-size, #{$grid-unit-20}) var(--gallery-block--gutter-size, #{$grid-unit-20}) 0;
margin: 0;

&:last-of-type:not(#individual-image) {
margin-right: 0;
}

width: calc(50% - (var(--gallery-block--gutter-size, #{$grid-unit-20}) / 2));

&:nth-of-type(even) {
margin-right: 0;
}
width: calc(50% - (var(--gallery-block--gap) / 2));
}

figure.wp-block-image {
Expand Down Expand Up @@ -94,11 +92,11 @@
margin-top: 0;
margin-bottom: auto;
img {
margin-bottom: var(--gallery-block--gutter-size, #{$grid-unit-20});
margin-bottom: var(--gallery-block--gap);
}

figcaption {
bottom: var(--gallery-block--gutter-size, #{$grid-unit-20});
bottom: var(--gallery-block--gap);
}
}
}
Expand All @@ -121,43 +119,28 @@
}

&.columns-1 figure.wp-block-image:not(#individual-image) {
margin-right: 0;
width: 100%;
}

// Beyond mobile viewports, we allow up to 8 columns.
@include break-small {
@for $i from 3 through 8 {
&.columns-#{ $i } figure.wp-block-image:not(#individual-image) {
margin-right: var(--gallery-block--gutter-size, #{$grid-unit-20});
width: calc(#{math.div(100%, $i)} - (var(--gallery-block--gutter-size, #{$grid-unit-20}) * #{math.div($i - 1, $i)}));

}
width: calc(#{math.div(100%, $i)} - (var(--gallery-block--gap) * #{math.div($i - 1, $i)}));

// Prevent collapsing margin while sibling is being dragged.
&.columns-#{$i} figure.wp-block-image:not(#individual-image).is-dragging ~ figure.wp-block-image:not(#individual-image) {
margin-right: var(--gallery-block--gutter-size, #{$grid-unit-20});
}
}
// Unset the right margin on every rightmost gallery item to ensure center balance.
@for $column-count from 1 through 8 {
&.columns-#{$column-count} figure.wp-block-image:not(#individual-image):nth-of-type(#{ $column-count }n) {
margin-right: 0;
}
}

// If number of columns not explicitly set default to 3 columns if 3 or more images.
&.columns-default {
figure.wp-block-image:not(#individual-image) {
margin-right: var(--gallery-block--gutter-size, #{$grid-unit-20});
width: calc(33.33% - (var(--gallery-block--gutter-size, 16px) * #{math.div(2, 3)}));
}
figure.wp-block-image:not(#individual-image):nth-of-type(3n+3) {
margin-right: 0;
width: calc(33.33% - (var(--gallery-block--gap) * #{math.div(2, 3)}));
}

// If only 2 child images use 2 columns.
figure.wp-block-image:not(#individual-image):first-child:nth-last-child(2),
figure.wp-block-image:not(#individual-image):first-child:nth-last-child(2) ~ figure.wp-block-image:not(#individual-image) {
width: calc(50% - (var(--gallery-block--gutter-size, 16px) * 0.5));
width: calc(50% - (var(--gallery-block--gap) * 0.5));
}
// For a single image set to 100%.
figure.wp-block-image:not(#individual-image):first-child:nth-last-child(1) {
Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/gallery/v1/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ function GalleryEdit( props ) {
blockEditorStore
);

// Remove the tools panel for v1 Gallery so we only have to support
// any new dimension settings, etc. for the new gallery format.
const toolsPanel = document.querySelector(
'.block-editor-block-inspector .components-tools-panel'
);

useEffect( () => {
if ( toolsPanel && isSelected ) {
toolsPanel.style.display = 'none';
}
}, [ toolsPanel ] );

const {
imageSizes,
mediaUpload,
Expand Down