Skip to content

Commit

Permalink
Handle duplicate image when closing lightbox as well
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiomorales committed Jul 15, 2024
1 parent d487019 commit af27f53
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +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.overlayOpened' );
$p->set_attribute( 'data-wp-class--hide', 'state.contentImageHide' );
$p->set_attribute( 'data-wp-class--show', 'state.contentImageShow' );

$body_content = $p->get_updated_html();

Expand Down
18 changes: 17 additions & 1 deletion packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
box-sizing: border-box;

&.hide {
opacity: 0;
visibility: hidden;
}

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

Expand Down Expand Up @@ -323,6 +327,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 contentImageHide() {
const ctx = getContext();
return (
state.overlayEnabled && state.currentImageId === ctx.imageId
);
},
get contentImageShow() {
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

0 comments on commit af27f53

Please sign in to comment.