diff --git a/assets/js/blocks/product-gallery/edit.tsx b/assets/js/blocks/product-gallery/edit.tsx index 32734ff9e82..e337ebc10cb 100644 --- a/assets/js/blocks/product-gallery/edit.tsx +++ b/assets/js/blocks/product-gallery/edit.tsx @@ -17,6 +17,7 @@ import { useSelect } from '@wordpress/data'; import { moveInnerBlocksToPosition, getInnerBlocksLockAttributes, + getClassNameByNextPreviousButtonsPosition, } from './utils'; import { ProductGalleryThumbnailsBlockSettings } from './inner-blocks/product-gallery-thumbnails/block-settings'; import { ProductGalleryPagerBlockSettings } from './inner-blocks/product-gallery-pager/settings'; @@ -107,7 +108,11 @@ export const Edit = ( { attributes, setAttributes, }: BlockEditProps< ProductGalleryAttributes > ) => { - const blockProps = useBlockProps(); + const blockProps = useBlockProps( { + className: getClassNameByNextPreviousButtonsPosition( + attributes.nextPreviousButtonsPosition + ), + } ); const { currentTemplateId, templateType } = useSelect( ( select ) => ( { diff --git a/assets/js/blocks/product-gallery/editor.scss b/assets/js/blocks/product-gallery/editor.scss index 001a7de19df..13116d7fc2d 100644 --- a/assets/js/blocks/product-gallery/editor.scss +++ b/assets/js/blocks/product-gallery/editor.scss @@ -1,4 +1,4 @@ -.wp-block-woocommerce-product-gallery { +.wc-block-product-gallery { .block-editor-inner-blocks { width: fit-content; } diff --git a/assets/js/blocks/product-gallery/index.tsx b/assets/js/blocks/product-gallery/index.tsx index f16ed90edb2..5fb28bd3ad8 100644 --- a/assets/js/blocks/product-gallery/index.tsx +++ b/assets/js/blocks/product-gallery/index.tsx @@ -12,6 +12,7 @@ import { Save } from './save'; import metadata from './block.json'; import icon from './icon'; import './style.scss'; +import './inner-blocks/product-gallery-large-image'; import './inner-blocks/product-gallery-large-image-next-previous'; import './inner-blocks/product-gallery-pager'; import './inner-blocks/product-gallery-thumbnails'; 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..db146df1f4f 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,10 +9,11 @@ import classNames from 'classnames'; /** * Internal dependencies */ -import { NextButton, PrevButton } from './icons'; + import './editor.scss'; import { ProductGalleryNextPreviousBlockSettings } from './settings'; import { ProductGalleryContext } from '../../types'; +import { getNextPreviousImagesWithClassName } from './utils'; const getAlignmentStyle = ( alignment: string ): string => { switch ( alignment ) { @@ -41,19 +42,16 @@ export const Edit = ( { attributes.layout?.verticalAlignment ), }, + className: classNames( + 'wc-block-editor-product-gallery-large-image-next-previous', + 'wc-block-product-gallery-large-image-next-previous' + ), } ); - const suffixClass = useMemo( () => { - switch ( context.nextPreviousButtonsPosition ) { - case 'insideTheImage': - return 'inside-image'; - case 'outsideTheImage': - return 'outside-image'; - case 'off': - return 'off'; - default: - return 'off'; - } + const previousNextImage = useMemo( () => { + return getNextPreviousImagesWithClassName( + context.nextPreviousButtonsPosition + ); }, [ context.nextPreviousButtonsPosition ] ); return ( @@ -64,11 +62,15 @@ export const Edit = ( {
- - + { previousNextImage?.PrevButtonImage && ( + + ) } + { previousNextImage?.NextButtonImage && ( + + ) }
); diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/editor.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/editor.scss index 50ff7b77fc2..9f557bc69fd 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/editor.scss +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image-next-previous/editor.scss @@ -6,3 +6,8 @@ position: absolute; height: 50px; } + +.wc-block-editor-product-gallery-large-image-next-previous--outside-image .wc-block-product-gallery-large-image-next-previous { + margin-right: 0; + margin-left: 0; +} 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 = () => ( { + switch ( nextPreviousButtonsPosition ) { + case 'insideTheImage': + return { + PrevButtonImage: PrevButtonInsideImage, + NextButtonImage: NextButtonInsideImage, + classname: 'inside-image', + }; + case 'outsideTheImage': + return { + PrevButtonImage: PrevButtonOutsideImage, + NextButtonImage: NextButtonOutsideImage, + classname: 'outside-image', + }; + case 'off': + return null; + default: + return null; + } +}; diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/block.json b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/block.json index 9eaa16af1ac..26e819d92dc 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/block.json +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/block.json @@ -7,7 +7,7 @@ "description": "Display the Large Image of a product.", "category": "woocommerce", "keywords": [ "WooCommerce" ], - "usesContext": [ "postId", "hoverZoom" ], + "usesContext": [ "nextPreviousButtonsPosition", "postId", "hoverZoom"], "supports": { "interactivity": true }, diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/edit.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/edit.tsx index 805c589efc8..473963a1aed 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/edit.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/edit.tsx @@ -3,7 +3,8 @@ */ import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings'; import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; -import { memo } from '@wordpress/element'; +import { memo, useMemo } from '@wordpress/element'; +import classNames from 'classnames'; /** * Internal dependencies @@ -11,6 +12,7 @@ import { memo } from '@wordpress/element'; import largeImageNextPreviousButtonMetadata from '../product-gallery-large-image-next-previous/block.json'; import pagerMetadata from '../product-gallery-pager/block.json'; import './editor.scss'; +import { ProductGalleryContext } from '../../types'; const getInnerBlocksTemplate = () => [ [ largeImageNextPreviousButtonMetadata.name ], @@ -19,7 +21,7 @@ const getInnerBlocksTemplate = () => [ const Placeholder = memo( () => { return ( -
+
Placeholder { ); } ); -export const Edit = (): JSX.Element => { +export const Edit = ( { + context, +}: { + context: ProductGalleryContext; +} ): JSX.Element => { const innerBlocksProps = useInnerBlocksProps( { className: 'wc-block-product-gallery-large-image__inner-blocks', @@ -38,8 +44,34 @@ export const Edit = (): JSX.Element => { templateInsertUpdatesSelection: true, } ); + + const previousNextImage = useMemo( () => { + switch ( context.nextPreviousButtonsPosition ) { + case 'insideTheImage': + return { + className: 'inside-image', + }; + case 'outsideTheImage': + return { + className: 'outside-image', + }; + case 'off': + return { + className: 'off', + }; + default: + return { + className: 'off', + }; + } + }, [ context.nextPreviousButtonsPosition ] ); + const blockProps = useBlockProps( { - className: 'wc-block-editor-product-gallery_large-image', + className: classNames( + 'wc-block-product-gallery-large-image', + 'wc-block-editor-product-gallery-large-image', + `wc-block-editor-product-gallery-large-image-next-previous--${ previousNextImage?.className }` + ), } ); return ( diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/editor.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/editor.scss index 9d648cd306c..64e93fcaa06 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/editor.scss +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/editor.scss @@ -1,7 +1,18 @@ -.wc-block-editor-product-gallery-large-image img { - max-width: 500px; +.wc-block-editor-product-gallery-large-image { + img { + max-width: 100%; + margin: 0 auto; + width: 100%; + } + + .wc-block-editor-product-gallery-large-image-next-previous--outside-image & img { + max-width: calc(100% - 60px); + } } .wc-block-product-gallery-large-image__inner-blocks { - max-width: 500px; + .wc-block-editor-product-gallery-large-image-next-previous--outside-image & > * { + margin-left: 30px; + margin-right: 30px; + } } diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/index.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/index.tsx index 5c426039019..39c6cd30a84 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/index.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/index.tsx @@ -11,7 +11,6 @@ import icon from './icon'; import { Edit } from './edit'; import { Save } from './save'; import metadata from './block.json'; -import './style.scss'; if ( isExperimentalBuild() ) { // @ts-expect-error: `metadata` currently does not have a type definition in WordPress core diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/style.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/style.scss deleted file mode 100644 index 597206fdd56..00000000000 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/style.scss +++ /dev/null @@ -1,30 +0,0 @@ -.wp-block-woocommerce-product-gallery-large-image { - width: fit-content; - height: fit-content; - position: relative; - overflow: hidden; - - img { - display: block; - transition: all 0.1s linear; - - &.wc-block-woocommerce-product-gallery-large-image__image--hoverZoom { - cursor: zoom-in; - } - } - - img[hidden] { - display: none; - } - - .wc-block-product-gallery-large-image__inner-blocks { - pointer-events: none; - display: flex; - flex-direction: column; - position: absolute; - z-index: 1; - width: 100%; - height: 100%; - top: 0; - } -} diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/edit.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/edit.tsx index f938bde632a..698bc6fb971 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/edit.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/edit.tsx @@ -3,6 +3,7 @@ */ import { Icon } from '@wordpress/icons'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import classNames from 'classnames'; /** * Internal dependencies @@ -19,7 +20,7 @@ const DigitsPager = (): JSX.Element => { return (
  • { const { context } = props; const blockProps = useBlockProps( { - className: 'wc-block-editor-product-gallery-pager', + className: classNames( + 'wc-block-editor-product-gallery-pager', + 'wc-block-product-gallery-pager' + ), } ); return ( diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/editor.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/editor.scss index bd2f16e8877..2bd2ea63f70 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/editor.scss +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/editor.scss @@ -6,12 +6,12 @@ padding: 0; } -.wc-block-editor-product-gallery-pager__pager-item { +.wc-block-editor-product-gallery-pager__item { @include font-size(regular); color: $gray-600; } -.wc-block-editor-product-gallery-pager__pager-item.is-active { +.wc-block-editor-product-gallery-pager__item.is-active { font-weight: bold; color: $black; } diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/index.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/index.tsx index 6c54740dc86..8e903c226cb 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/index.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/index.tsx @@ -10,7 +10,6 @@ import { isExperimentalBuild } from '@woocommerce/block-settings'; import { ProductGalleryPagerBlockIcon } from './icons'; import { Edit } from './edit'; import metadata from './block.json'; -import './style.scss'; import './editor.scss'; if ( isExperimentalBuild() ) { diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/style.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/style.scss deleted file mode 100644 index 04ba5026c9b..00000000000 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-pager/style.scss +++ /dev/null @@ -1,17 +0,0 @@ -.wp-block-woocommerce-product-gallery-pager__pager { - display: flex; - justify-content: center; - list-style: none; - gap: $gap-small; - padding: 0; -} - -.wp-block-woocommerce-product-gallery__pager-item { - @include font-size(regular); - color: $gray-600; -} - -.wp-block-woocommerce-product-gallery__pager-item.is-active { - font-weight: bold; - color: $black; -} diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/edit.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/edit.tsx index 23da7eb48b4..f47bca3bb73 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/edit.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/edit.tsx @@ -5,6 +5,7 @@ import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { Disabled } from '@wordpress/components'; import type { BlockEditProps } from '@wordpress/blocks'; import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings'; +import classNames from 'classnames'; /** * Internal dependencies @@ -23,11 +24,18 @@ interface EditProps } export const Edit = ( { attributes, setAttributes, context }: EditProps ) => { - const blockProps = useBlockProps(); + const blockProps = useBlockProps( { + className: 'wc-block-product-gallery-thumbnails', + } ); const Placeholder = () => { return context.thumbnailsPosition !== ThumbnailsPosition.OFF ? ( -
    +
    { [ ...Array( context.thumbnailsNumberOfThumbnails ).keys(), ].map( ( index ) => { diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/editor.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/editor.scss index c4da95f1f87..006c477d7f1 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/editor.scss +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/editor.scss @@ -1,5 +1,13 @@ -.wp-block-woocommerce-product-gallery-thumbnails { +.wc-block-product-gallery-thumbnails { + width: fit-content; .wc-block-editor-product-gallery-thumbnails { + display: flex; + flex-flow: column nowrap; + + &.wc-block-editor-product-gallery-thumbnails--bottom { + flex-flow: row nowrap; + } + img { width: 100px; height: 100px; diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/index.tsx b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/index.tsx index fe3adea2c0d..d15f72e3f2b 100644 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/index.tsx +++ b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/index.tsx @@ -10,7 +10,6 @@ import { isExperimentalBuild } from '@woocommerce/block-settings'; import icon from './icon'; import { Edit } from './edit'; import metadata from './block.json'; -import './style.scss'; if ( isExperimentalBuild() ) { // @ts-expect-error: `metadata` currently does not have a type definition in WordPress core diff --git a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/style.scss b/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/style.scss deleted file mode 100644 index 2dfe7612c13..00000000000 --- a/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/style.scss +++ /dev/null @@ -1,16 +0,0 @@ -.wp-block-woocommerce-product-gallery-thumbnails { - img { - cursor: pointer; - } - - .is-vertical .wc-block-components-product-gallery-thumbnails { - display: flex; - flex-direction: row; - } - - .wc-block-components-product-gallery-thumbnails .woocommerce-product-gallery__image { - width: 100px; - height: 100px; - margin: 5px; - } -} diff --git a/assets/js/blocks/product-gallery/save.tsx b/assets/js/blocks/product-gallery/save.tsx index 49664a3e6bb..31d5960ec92 100644 --- a/assets/js/blocks/product-gallery/save.tsx +++ b/assets/js/blocks/product-gallery/save.tsx @@ -2,9 +2,27 @@ * External dependencies */ import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; +import classnames from 'classnames'; -export const Save = (): JSX.Element => { - const blockProps = useBlockProps.save(); +/** + * Internal dependencies + */ +import { getClassNameByNextPreviousButtonsPosition } from './utils'; +import { ProductGalleryAttributes } from './types'; + +export const Save = ( { + attributes, +}: { + attributes: ProductGalleryAttributes; +} ): JSX.Element => { + const blockProps = useBlockProps.save( { + className: classnames( + 'wc-block-product-gallery', + getClassNameByNextPreviousButtonsPosition( + attributes.nextPreviousButtonsPosition + ) + ), + } ); const innerBlocksProps = useInnerBlocksProps.save( blockProps ); return
    ; }; diff --git a/assets/js/blocks/product-gallery/style.scss b/assets/js/blocks/product-gallery/style.scss index 10129efaa69..674758d30e6 100644 --- a/assets/js/blocks/product-gallery/style.scss +++ b/assets/js/blocks/product-gallery/style.scss @@ -1,4 +1,16 @@ -.wp-block-woocommerce-product-gallery { +$gallery: ".wc-block-product-gallery"; +$large-image: "#{$gallery}-large-image"; +$thumbnails: "#{$gallery}-thumbnails"; +$next-previous: "#{$large-image}-next-previous"; +$next-previous-left-off: "#{$next-previous}-left--off"; +$next-previous-right-off: "#{$next-previous}-right--off"; +$gallery-next-previous-outside-image: "#{$gallery}[data-next-previous-buttons-position='outsideTheImage']:not(.is-single-product-gallery-image)"; + +$outside-image-offset: 30px; +$outside-image-max-width: calc(100% - (2 * $outside-image-offset)); + +// Product Gallery +#{$gallery} { dialog { position: fixed; width: 90vw; @@ -8,3 +20,159 @@ z-index: 9999; } } + +// Large Image +#{$large-image} { + width: 100%; + height: fit-content; + position: relative; + overflow: hidden; + + img { + display: block; + margin: 0 auto; + transition: all 0.1s linear; + + &.wc-block-woocommerce-product-gallery-large-image__image--hoverZoom { + cursor: zoom-in; + } + + &[hidden] { + display: none; + } + + // Restrict the width of the Large Image when the Next/Previous buttons are outside the image. + #{$gallery-next-previous-outside-image} & { + max-width: $outside-image-max-width; + } + } + + .wc-block-product-gallery-large-image__inner-blocks { + display: flex; + flex-direction: column; + position: absolute; + pointer-events: none; + z-index: 1; + width: 100%; + height: 100%; + top: 0; + + // Reset the margin of the inner blocks when the Next/Previous buttons are outside the image. + #{$gallery-next-previous-outside-image} & > * { + margin-left: $outside-image-offset; + margin-right: $outside-image-offset; + } + } +} + +// Next/Previous Buttons +#{$next-previous} { + display: flex; + position: absolute; + flex-direction: row; + justify-content: space-between; + width: 100%; + height: 100%; + + .is-vertically-aligned-top { + align-items: flex-start; + } + + .is-vertically-aligned-center { + align-items: center; + } + + .is-vertically-aligned-bottom { + align-items: flex-end; + } +} + +// Next/Previous Buttons Settings +.wc-block-product-gallery-large-image-next-previous-settings { + width: 100%; +} + +// Next/Previous Buttons Off Setting +#{$next-previous-left-off}, +#{$next-previous-right-off} { + display: none; +} + +// Next/Previous Buttons Inside the Image Settings +.wc-block-product-gallery-large-image-next-previous-left--inside-image { + margin-left: 15px; +} + +.wc-block-product-gallery-large-image-next-previous-right--inside-image { + margin-right: 15px; +} + +// Next/Previous Buttons Outside the Image Settings +#{$gallery-next-previous-outside-image} .wc-block-product-gallery-large-image-next-previous-left--outside-image { + bottom: 0; + left: 0; + position: absolute; +} + +#{$gallery-next-previous-outside-image} .wc-block-product-gallery-large-image-next-previous-right--outside-image { + bottom: 0; + right: 0; + position: absolute; +} + +#{$gallery-next-previous-outside-image} #{$large-image} #{$next-previous} { + margin-right: 0; + margin-left: 0; +} + +.wc-block-product-gallery-large-image-next-previous-container { + display: flex; + flex-direction: row; + justify-content: space-between; + position: absolute; + height: 50px; + width: 100%; + + &.wc-block-product-gallery-large-image-next-previous--inside-image { + margin-top: 15px; + margin-bottom: 15px; + } +} + +// Pager +.wc-block-product-gallery-pager__pager { + display: flex; + justify-content: center; + list-style: none; + gap: $gap-small; +} + +.wc-block-product-gallery-pager__item { + @include font-size(regular); + color: $gray-600; + + &.is-active { + font-weight: bold; + color: $black; + } +} + +// Thumbnails +#{$thumbnails} { + img { + cursor: pointer; + } + + .is-vertical & { + display: flex; + flex-direction: row; + } + + .wc-block-product-gallery-thumbnails__thumbnail { + width: 100px; + height: 100px; + margin: 5px; + + } +} + diff --git a/assets/js/blocks/product-gallery/utils.tsx b/assets/js/blocks/product-gallery/utils.tsx index 48ca7c1d75b..a2e2b5ab307 100644 --- a/assets/js/blocks/product-gallery/utils.tsx +++ b/assets/js/blocks/product-gallery/utils.tsx @@ -8,6 +8,8 @@ import { select, dispatch } from '@wordpress/data'; * Internal dependencies */ import { ThumbnailsPosition } from './inner-blocks/product-gallery-thumbnails/constants'; +import { getNextPreviousImagesWithClassName } from './inner-blocks/product-gallery-large-image-next-previous/utils'; +import { NextPreviousButtonSettingValues } from './inner-blocks/product-gallery-large-image-next-previous/types'; /** * Generates layout attributes based on the position of thumbnails. @@ -22,6 +24,9 @@ export const getGroupLayoutAttributes = ( case 'bottom': // Stack return { type: 'flex', orientation: 'vertical' }; + case 'off': + // Stack + return { type: 'flex', orientation: 'vertical' }; default: // Row return { type: 'flex', flexWrap: 'nowrap' }; @@ -231,3 +236,12 @@ export const moveInnerBlocksToPosition = ( } } }; + +export const getClassNameByNextPreviousButtonsPosition = ( + nextPreviousButtonsPosition: NextPreviousButtonSettingValues +) => { + return `wc-block-product-gallery--has-next-previous-buttons-${ + getNextPreviousImagesWithClassName( nextPreviousButtonsPosition ) + ?.classname + }`; +}; diff --git a/src/BlockTypes/ProductGallery.php b/src/BlockTypes/ProductGallery.php index 7f20f479fb3..fd81e31a02b 100644 --- a/src/BlockTypes/ProductGallery.php +++ b/src/BlockTypes/ProductGallery.php @@ -1,6 +1,7 @@ context['postId'] ?? ''; + $product_gallery_images = ProductGalleryUtils::get_product_gallery_images( $post_id, 'thumbnail', array() ); + $classname_single_image = ''; // This is a temporary solution. We have to refactor this code when the block will have to be addable on every page/post https://github.com/woocommerce/woocommerce-blocks/issues/10882. global $product; + + if ( count( $product_gallery_images ) < 2 ) { + // The gallery consists of a single image. + $classname_single_image = 'is-single-product-gallery-image'; + } + $classname = $attributes['className'] ?? ''; - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( sprintf( 'woocommerce %1$s', $classname ) ) ) ); + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( sprintf( 'wc-block-product-gallery %1$s %2$s', $classname, $classname_single_image ) ) ) ); $gallery = ( true === $attributes['fullScreenOnClick'] && isset( $attributes['mode'] ) && 'full' !== $attributes['mode'] ) ? $this->render_dialog() : ''; $html = sprintf( '
    @@ -73,7 +83,7 @@ protected function render( $attributes, $content, $block ) { %3$s
    ', $wrapper_attributes, - $this->remove_div_wrapper( $content ), + $content, $gallery ); diff --git a/src/BlockTypes/ProductGalleryLargeImage.php b/src/BlockTypes/ProductGalleryLargeImage.php index 86b39cda192..ca5728d9971 100644 --- a/src/BlockTypes/ProductGalleryLargeImage.php +++ b/src/BlockTypes/ProductGalleryLargeImage.php @@ -14,6 +14,16 @@ class ProductGalleryLargeImage extends AbstractBlock { */ protected $block_name = 'product-gallery-large-image'; + + /** + * Get the frontend style handle for this block type. + * + * @return null + */ + protected function get_block_type_style() { + return null; + } + /** * Register the context * @@ -76,7 +86,7 @@ protected function render( $attributes, $content, $block ) { $directives = $this->get_directives( $block->context ); return strtr( - '