From d79da70543c4970039d033332544118d7675ed04 Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 5 Sep 2023 11:50:35 +0200 Subject: [PATCH 01/15] WIP --- .../edit.tsx | 35 ++++-- .../icons.tsx | 40 +++++- .../style.scss | 4 +- .../ProductGalleryLargeImageNextPrevious.php | 115 +++++++++++------- 4 files changed, 134 insertions(+), 60 deletions(-) diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/edit.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/edit.tsx index b2ab03c08cc..39760a574ca 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/edit.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/edit.tsx @@ -9,7 +9,12 @@ import classNames from 'classnames'; /** * Internal dependencies */ -import { NextButton, PrevButton } from './icons'; +import { + NextButtonInsideImage, + NextButtonOutsideImage, + PrevButtonInsideImage, + PrevButtonOutsideImage, +} from './icons'; import './editor.scss'; import { ProductGalleryNextPreviousBlockSettings } from './settings'; import { ProductGalleryContext } from '../../types'; @@ -43,16 +48,24 @@ export const Edit = ( { }, } ); - const suffixClass = useMemo( () => { + const previousNextImage = useMemo( () => { switch ( context.nextPreviousButtonsPosition ) { case 'insideTheImage': - return 'inside-image'; + return { + PrevButtonImage: PrevButtonInsideImage, + NextButtonImage: NextButtonInsideImage, + classname: 'inside-image', + }; case 'outsideTheImage': - return 'outside-image'; + return { + PrevButtonImage: PrevButtonOutsideImage, + NextButtonImage: NextButtonOutsideImage, + classname: 'outside-image', + }; case 'off': - return 'off'; + return null; default: - return 'off'; + return null; } }, [ context.nextPreviousButtonsPosition ] ); @@ -64,11 +77,15 @@ export const Edit = ( {
- - + { previousNextImage?.PrevButtonImage && ( + + ) } + { previousNextImage?.NextButtonImage && ( + + ) }
); diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/icons.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/icons.tsx index 7500497ac8d..43ebb539eec 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/icons.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/icons.tsx @@ -20,14 +20,14 @@ export const Icon = () => ( ); -export const NextButton = ( { suffixClass }: { suffixClass: string } ) => ( +export const NextButtonInsideImage = () => ( ( ); -export const PrevButton = ( { suffixClass }: { suffixClass: string } ) => ( +export const PrevButtonInsideImage = () => ( ( ); +export const NextButtonOutsideImage = () => ( + + + +); + +export const PrevButtonOutsideImage = () => ( + + + +); + export const InsideTheImage = () => ( 'inside-image', + 'prev_button' => ' + + + + + + + + + + + + + ', + 'next_button' => ' + + + + + + + + + + + + + ', + ); case 'outsideTheImage': - return 'outside-image'; + return array( + 'class' => 'outside-image', + 'prev_button' => ' + + ', + 'next_button' => ' + + ', + ); + case 'off': - return 'off'; + return array( + 'class' => 'off', + ); default: - return 'off'; + return array( 'class' => 'off' ); } } /** @@ -71,47 +132,11 @@ protected function render( $attributes, $content, $block ) { } $context = $block->context; - $prev_button = sprintf( - ' - - - - - - - - - - - - - - ', - $this->get_class_suffix( $context ) - ); - - $next_button = sprintf( - ' - - - - - - - - - - - - - - - ', - $this->get_class_suffix( $context ) - ); + $prev_button = $this->get_icons( $block->context )['prev_button']; + $next_button = $this->get_icons( $block->context )['next_button']; $alignment_class = isset( $attributes['layout']['verticalAlignment'] ) ? 'is-vertically-aligned-' . $attributes['layout']['verticalAlignment'] : ''; - $position_class = 'wc-block-product-gallery-large-image-next-previous--' . $this->get_class_suffix( $context ); + $position_class = 'wc-block-product-gallery-large-image-next-previous--' . $this->get_icons( $context )['class']; return strtr( '