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

Image lightbox: Remove duplicate image when lightbox is opened #63381

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {
// contain a caption, and we don't want to trigger the lightbox when the
// caption is clicked.
$p->set_attribute( 'data-wp-on-async--click', 'actions.showLightbox' );
$p->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' );
$p->set_attribute( 'data-wp-class--show', 'state.isContentVisible' );
luisherranz marked this conversation as resolved.
Show resolved Hide resolved

$body_content = $p->get_updated_html();

Expand Down
22 changes: 22 additions & 0 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
max-width: 100%;
vertical-align: bottom;
box-sizing: border-box;

@media (prefers-reduced-motion: no-preference) {
&.hide {
visibility: hidden;
}

&.show {
animation: show-content-image 0.4s;
}
}
}

// The following style maintains border radius application for deprecated
Expand Down Expand Up @@ -319,6 +329,18 @@
}
}

@keyframes show-content-image {
0% {
visibility: hidden;
}
99% {
visibility: hidden;
}
100% {
visibility: visible;
}
}

@keyframes turn-on-visibility {
0% {
opacity: 0;
Expand Down
15 changes: 14 additions & 1 deletion packages/block-library/src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ const { state, actions, callbacks } = store(
const { imageId } = getContext();
return state.metadata[ imageId ].imageButtonTop;
},
get isContentHidden() {
const ctx = getContext();
return (
state.overlayEnabled && state.currentImageId === ctx.imageId
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
);
},
get isContentVisible() {
const ctx = getContext();
return (
! state.overlayEnabled &&
state.currentImageId === ctx.imageId
);
},
},
actions: {
showLightbox() {
Expand All @@ -75,8 +88,8 @@ const { state, actions, callbacks } = store(
state.scrollLeftReset = document.documentElement.scrollLeft;

// Sets the current expanded image in the state and enables the overlay.
state.currentImageId = imageId;
state.overlayEnabled = true;
state.currentImageId = imageId;

// Computes the styles of the overlay for the animation.
callbacks.setOverlayStyles();
Expand Down
Loading