Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Product Gallery Dialog: Change names of dialog actions and move them …
Browse files Browse the repository at this point in the history
…from the Large Image to the Product Gallery frontend file
  • Loading branch information
danieldudzic committed Nov 6, 2023
1 parent f0c980d commit 942d9f6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
18 changes: 17 additions & 1 deletion assets/js/blocks/product-gallery/frontend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface Store {
}

interface Event {
target: HTMLElement;
keyCode: number;
}

Expand Down Expand Up @@ -170,9 +171,24 @@ interactivityApiStore( {
},
},
dialog: {
handleCloseButtonClick: ( { context }: Store ) => {
closeDialog: ( { context }: Store ) => {
context.woocommerce.isDialogOpen = false;
},
openDialog: ( {
context,
event,
}: {
context: Context;
event: Event;
} ) => {
if (
( event.target as HTMLElement ).classList.contains(
'wc-block-product-gallery-dialog-on-click'
)
) {
context.woocommerce.isDialogOpen = true;
}
},
},
handleSelectImage: ( { context }: Store ) => {
context.woocommerce.selectedImage = context.woocommerce.imageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ interactivityStore(
context.woocommerce.styles.transform = `scale(1.0)`;
context.woocommerce.styles[ 'transform-origin' ] = '';
},
handleClick: ( {
context,
event,
}: {
context: Context;
event: Event;
} ) => {
if (
( event.target as HTMLElement ).classList.contains(
'wc-block-product-gallery-dialog-on-click'
)
) {
context.woocommerce.isDialogOpen = true;
}
},
},
},
effects: {
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/ProductGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function( $carry, $item ) {
<dialog data-wc-bind--open="selectors.woocommerce.isDialogOpen">
<div class="wc-block-product-gallery-dialog__header">
<div class="wc-block-product-galler-dialog__header-right">
<button class="wc-block-product-gallery-dialog__close" data-wc-on--click="actions.woocommerce.dialog.handleCloseButtonClick">
<button class="wc-block-product-gallery-dialog__close" data-wc-on--click="actions.woocommerce.dialog.closeDialog">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="24" height="24" rx="2"/>
<path d="M13 11.8L19.1 5.5L18.1 4.5L12 10.7L5.9 4.5L4.9 5.5L11 11.8L4.5 18.5L5.5 19.5L12 12.9L18.5 19.5L19.5 18.5L13 11.8Z" fill="black"/>
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/ProductGalleryLargeImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private function get_open_dialog_directives( $block_context ) {
}

return array(
'data-wc-on--click' => 'actions.woocommerce.handleClick',
'data-wc-on--click' => 'actions.woocommerce.dialog.openDialog',
);
}
}
4 changes: 2 additions & 2 deletions src/BlockTypes/ProductGalleryThumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function get_block_type_uses_context() {
* @return string
*/
protected function generate_view_all_html( $remaining_thumbnails_count ) {
$view_all_html = '<div class="wc-block-product-gallery-thumbnails__thumbnail__overlay wc-block-product-gallery-dialog-on-click" data-wc-on--click="actions.woocommerce.handleClick">
$view_all_html = '<div class="wc-block-product-gallery-thumbnails__thumbnail__overlay wc-block-product-gallery-dialog-on-click" data-wc-on--click="actions.woocommerce.dialog.openDialog">
<span class="wc-block-product-gallery-thumbnails__thumbnail__remaining-thumbnails-count wc-block-product-gallery-dialog-on-click">+%1$s</span>
<span class="wc-block-product-gallery-thumbnails__thumbnail__view-all wc-block-product-gallery-dialog-on-click">%2$s</span>
</div>';
Expand Down Expand Up @@ -157,7 +157,7 @@ protected function render( $attributes, $content, $block ) {
if ( $processor->next_tag( 'img' ) ) {
$processor->set_attribute(
'data-wc-on--click',
'actions.woocommerce.thumbnails.handleClick'
'actions.woocommerce.thumbnails.dialog.openDialog'
);

$html .= $processor->get_updated_html();
Expand Down

0 comments on commit 942d9f6

Please sign in to comment.