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

Product Gallery: CSS styling tightening up #10867

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d79da70
WIP
gigitux Sep 5, 2023
cd3e0f1
Product Gallery: Fix conflicts between block settings and CSS
danieldudzic Sep 6, 2023
675c590
Product Gallery: Final CSS polishes
danieldudzic Sep 7, 2023
10faf34
Product Gallery: Minor CSS refactor
danieldudzic Sep 7, 2023
e94a6f6
Product Gallery: Revert the minor css refactor
danieldudzic Sep 7, 2023
91c67ce
add custom class on the main div
gigitux Sep 8, 2023
99979ab
Product Gallery: Combine inner block styles and optimize them
danieldudzic Sep 14, 2023
17c3719
Product Gallery Inner Blocks: Remove imports to no longer existing st…
danieldudzic Sep 14, 2023
9b8e28e
Product Gallery: Change all references from wp-block to wc-block
danieldudzic Sep 18, 2023
a5ae048
Product Gallery Inner Blocks: Remove loading of non-existent inner bl…
danieldudzic Sep 19, 2023
42bed8b
Product Gallery: Add additional class to ensure correct width for sin…
danieldudzic Sep 19, 2023
3b6cf99
Merge branch 'trunk' of github.com:woocommerce/woocommerce-blocks int…
gigitux Sep 20, 2023
d4195c5
Merge branch 'trunk' into 10750-product-gallery-block-different-icons…
danieldudzic Sep 20, 2023
516fd79
Product Gallery: Add final polishing
danieldudzic Sep 20, 2023
009beb0
fix zoom
gigitux Sep 20, 2023
ffaf38c
Product Gallery Thumbnails: Fix css
danieldudzic Sep 20, 2023
1711013
Merge branch '10750-product-gallery-block-different-icons-for-next-pr…
danieldudzic Sep 20, 2023
7190438
Merge branch 'trunk' into 10750-product-gallery-block-different-icons…
danieldudzic Sep 20, 2023
886e954
Merge branch 'trunk' into 10750-product-gallery-block-different-icons…
danieldudzic Sep 20, 2023
3dfc002
Product Gallery Large Image Next Previous Buttons: Skip failing tests
danieldudzic Sep 20, 2023
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
7 changes: 6 additions & 1 deletion assets/js/blocks/product-gallery/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ) => ( {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/blocks/product-gallery/editor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wp-block-woocommerce-product-gallery {
.wc-block-product-gallery {
.block-editor-inner-blocks {
width: fit-content;
}
Expand Down
1 change: 1 addition & 0 deletions assets/js/blocks/product-gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 (
Expand All @@ -64,11 +62,15 @@ export const Edit = ( {
<div
className={ classNames(
'wc-block-product-gallery-large-image-next-previous-container',
`wc-block-product-gallery-large-image-next-previous--${ suffixClass }`
`wc-block-product-gallery-large-image-next-previous--${ previousNextImage?.classname }`
) }
>
<PrevButton suffixClass={ suffixClass } />
<NextButton suffixClass={ suffixClass } />
{ previousNextImage?.PrevButtonImage && (
<previousNextImage.PrevButtonImage />
) }
{ previousNextImage?.NextButtonImage && (
<previousNextImage.NextButtonImage />
) }
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const Icon = () => (
</svg>
);

export const NextButton = ( { suffixClass }: { suffixClass: string } ) => (
export const NextButtonInsideImage = () => (
<SVG
xmlns="http://www.w3.org/2000/svg"
width="49"
height="48"
viewBox="0 0 49 48"
fill="none"
className={ `wc-block-product-gallery-large-image-next-previous-right--${ suffixClass }` }
className={ `wc-block-product-gallery-large-image-next-previous-right--inside-image` }
>
<g filter="url(#filter0_b_397_11354)">
<rect
Expand Down Expand Up @@ -71,14 +71,14 @@ export const NextButton = ( { suffixClass }: { suffixClass: string } ) => (
</SVG>
);

export const PrevButton = ( { suffixClass }: { suffixClass: string } ) => (
export const PrevButtonInsideImage = () => (
<SVG
xmlns="http://www.w3.org/2000/svg"
width="49"
height="48"
viewBox="0 0 49 48"
fill="none"
className={ `wc-block-product-gallery-large-image-next-previous-left--${ suffixClass }` }
className={ `wc-block-product-gallery-large-image-next-previous-left--inside-image` }
>
<g filter="url(#filter0_b_397_11356)">
<rect
Expand Down Expand Up @@ -122,6 +122,38 @@ export const PrevButton = ( { suffixClass }: { suffixClass: string } ) => (
</SVG>
);

export const NextButtonOutsideImage = () => (
<SVG
width="22"
height="38"
viewBox="0 0 22 38"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={ `wc-block-product-gallery-large-image-next-previous-right--outside-image` }
>
<path
d="M4.56666 0L0.766663 3.16667L15.3333 19L0.766663 34.8333L4.56666 38L21.6667 19L4.56666 0Z"
fill="black"
/>
</SVG>
);

export const PrevButtonOutsideImage = () => (
<SVG
width="22"
height="38"
viewBox="0 0 22 38"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={ `wc-block-product-gallery-large-image-next-previous-left--outside-image` }
>
<path
d="M17.7 0L21.5 3.16667L6.93334 19L21.5 34.8333L17.7 38L0.600002 19L17.7 0Z"
fill="black"
/>
</SVG>
);

export const InsideTheImage = () => (
<SVG
xmlns="http://www.w3.org/2000/svg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { isExperimentalBuild } from '@woocommerce/block-settings';
*/
import { Edit } from './edit';
import metadata from './block.json';
import './style.scss';
import { Save } from './save';
import { Icon } from './icons';

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Internal dependencies
*/
import {
PrevButtonInsideImage,
NextButtonInsideImage,
PrevButtonOutsideImage,
NextButtonOutsideImage,
} from './icons';
import { NextPreviousButtonSettingValues } from './types';

export const getNextPreviousImagesWithClassName = (
nextPreviousButtonsPosition: NextPreviousButtonSettingValues
) => {
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;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
*/
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
*/
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 ],
Expand All @@ -19,7 +21,7 @@ const getInnerBlocksTemplate = () => [

const Placeholder = memo( () => {
return (
<div className="wc-block-editor-product-gallery-large-image">
<div className="wc-block-product-gallery-large-image wc-block-editor-product-gallery-large-image">
<img
src={ `${ WC_BLOCKS_IMAGE_URL }block-placeholders/product-image-gallery.svg` }
alt="Placeholder"
Expand All @@ -28,7 +30,11 @@ const Placeholder = memo( () => {
);
} );

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',
Expand All @@ -38,8 +44,34 @@ export const Edit = (): JSX.Element => {
templateInsertUpdatesSelection: true,
}
);

const previousNextImage = useMemo( () => {
danieldudzic marked this conversation as resolved.
Show resolved Hide resolved
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 (
Expand Down
Loading