Product Gallery block: Move inner block settings around to match the order from the design (https://github.com/woocommerce/woocommerce-blocks/pull/11170)
* Rearrange block settings to correct position * Remove unnecessary comments * Remove unused imports * Fix e2e tests
This commit is contained in:
parent
27ae9acafc
commit
a6ddae9dc3
|
@ -9,14 +9,48 @@ import { __ } from '@wordpress/i18n';
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import type { ProductGallerySettingsProps } from '../types';
|
import type { ProductGallerySettingsProps } from '../types';
|
||||||
|
import { ProductGalleryThumbnailsBlockSettings } from '../inner-blocks/product-gallery-thumbnails/block-settings';
|
||||||
|
import { ProductGalleryPagerBlockSettings } from '../inner-blocks/product-gallery-pager/settings';
|
||||||
|
import { ProductGalleryNextPreviousBlockSettings } from '../inner-blocks/product-gallery-large-image-next-previous/settings';
|
||||||
|
|
||||||
export const ProductGalleryBlockSettings = ( {
|
export const ProductGalleryBlockSettings = ( {
|
||||||
attributes,
|
attributes,
|
||||||
setAttributes,
|
setAttributes,
|
||||||
|
context,
|
||||||
}: ProductGallerySettingsProps ) => {
|
}: ProductGallerySettingsProps ) => {
|
||||||
const { cropImages, hoverZoom, fullScreenOnClick } = attributes;
|
const { cropImages, hoverZoom, fullScreenOnClick } = attributes;
|
||||||
|
const {
|
||||||
|
productGalleryClientId,
|
||||||
|
pagerDisplayMode,
|
||||||
|
nextPreviousButtonsPosition,
|
||||||
|
thumbnailsNumberOfThumbnails,
|
||||||
|
thumbnailsPosition,
|
||||||
|
} = context;
|
||||||
return (
|
return (
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
|
<PanelBody
|
||||||
|
title={ __(
|
||||||
|
'Gallery Navigation',
|
||||||
|
'woo-gutenberg-products-block'
|
||||||
|
) }
|
||||||
|
>
|
||||||
|
<ProductGalleryPagerBlockSettings
|
||||||
|
context={ { productGalleryClientId, pagerDisplayMode } }
|
||||||
|
/>
|
||||||
|
<ProductGalleryNextPreviousBlockSettings
|
||||||
|
context={ {
|
||||||
|
productGalleryClientId,
|
||||||
|
nextPreviousButtonsPosition,
|
||||||
|
} }
|
||||||
|
/>
|
||||||
|
<ProductGalleryThumbnailsBlockSettings
|
||||||
|
context={ {
|
||||||
|
productGalleryClientId,
|
||||||
|
thumbnailsNumberOfThumbnails,
|
||||||
|
thumbnailsPosition,
|
||||||
|
} }
|
||||||
|
/>
|
||||||
|
</PanelBody>
|
||||||
<PanelBody
|
<PanelBody
|
||||||
title={ __( 'Media Settings', 'woo-gutenberg-products-block' ) }
|
title={ __( 'Media Settings', 'woo-gutenberg-products-block' ) }
|
||||||
>
|
>
|
||||||
|
|
|
@ -19,11 +19,8 @@ import {
|
||||||
getInnerBlocksLockAttributes,
|
getInnerBlocksLockAttributes,
|
||||||
getClassNameByNextPreviousButtonsPosition,
|
getClassNameByNextPreviousButtonsPosition,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { ProductGalleryThumbnailsBlockSettings } from './inner-blocks/product-gallery-thumbnails/block-settings';
|
|
||||||
import { ProductGalleryPagerBlockSettings } from './inner-blocks/product-gallery-pager/settings';
|
|
||||||
import { ProductGalleryBlockSettings } from './block-settings/index';
|
import { ProductGalleryBlockSettings } from './block-settings/index';
|
||||||
import type { ProductGalleryAttributes } from './types';
|
import type { ProductGalleryAttributes } from './types';
|
||||||
import { ProductGalleryNextPreviousBlockSettings } from './inner-blocks/product-gallery-large-image-next-previous/settings';
|
|
||||||
|
|
||||||
const TEMPLATE: InnerBlockTemplate[] = [
|
const TEMPLATE: InnerBlockTemplate[] = [
|
||||||
[
|
[
|
||||||
|
@ -137,35 +134,18 @@ export const Edit = ( {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<InspectorControls>
|
|
||||||
<ProductGalleryPagerBlockSettings
|
|
||||||
context={ {
|
|
||||||
productGalleryClientId: clientId,
|
|
||||||
pagerDisplayMode: attributes.pagerDisplayMode,
|
|
||||||
} }
|
|
||||||
/>
|
|
||||||
<ProductGalleryThumbnailsBlockSettings
|
|
||||||
attributes={ attributes }
|
|
||||||
setAttributes={ setAttributes }
|
|
||||||
context={ {
|
|
||||||
productGalleryClientId: clientId,
|
|
||||||
thumbnailsPosition: attributes.thumbnailsPosition,
|
|
||||||
thumbnailsNumberOfThumbnails:
|
|
||||||
attributes.thumbnailsNumberOfThumbnails,
|
|
||||||
} }
|
|
||||||
/>
|
|
||||||
</InspectorControls>
|
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
<ProductGalleryBlockSettings
|
<ProductGalleryBlockSettings
|
||||||
attributes={ attributes }
|
attributes={ attributes }
|
||||||
setAttributes={ setAttributes }
|
setAttributes={ setAttributes }
|
||||||
/>
|
|
||||||
</InspectorControls>
|
|
||||||
<InspectorControls>
|
|
||||||
<ProductGalleryNextPreviousBlockSettings
|
|
||||||
context={ {
|
context={ {
|
||||||
...attributes,
|
|
||||||
productGalleryClientId: clientId,
|
productGalleryClientId: clientId,
|
||||||
|
pagerDisplayMode: attributes.pagerDisplayMode,
|
||||||
|
thumbnailsPosition: attributes.thumbnailsPosition,
|
||||||
|
thumbnailsNumberOfThumbnails:
|
||||||
|
attributes.thumbnailsNumberOfThumbnails,
|
||||||
|
nextPreviousButtonsPosition:
|
||||||
|
attributes.nextPreviousButtonsPosition,
|
||||||
} }
|
} }
|
||||||
/>
|
/>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
||||||
import { useMemo } from '@wordpress/element';
|
import { useMemo } from '@wordpress/element';
|
||||||
import { BlockAttributes } from '@wordpress/blocks';
|
import { BlockAttributes } from '@wordpress/blocks';
|
||||||
|
import { PanelBody } from '@wordpress/components';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +58,11 @@ export const Edit = ( {
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
<ProductGalleryNextPreviousBlockSettings context={ context } />
|
<PanelBody>
|
||||||
|
<ProductGalleryNextPreviousBlockSettings
|
||||||
|
context={ context }
|
||||||
|
/>
|
||||||
|
</PanelBody>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
<div
|
<div
|
||||||
className={ classNames(
|
className={ classNames(
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { __ } from '@wordpress/i18n';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
import { store as blockEditorStore } from '@wordpress/block-editor';
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
||||||
import {
|
import {
|
||||||
PanelBody,
|
|
||||||
// @ts-expect-error `__experimentalToggleGroupControl` is not yet in the type definitions.
|
// @ts-expect-error `__experimentalToggleGroupControl` is not yet in the type definitions.
|
||||||
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
|
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
|
||||||
__experimentalToggleGroupControl as ToggleGroupControl,
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
||||||
|
@ -19,7 +18,7 @@ import {
|
||||||
*/
|
*/
|
||||||
import { NextPreviousButtonSettingValues } from './types';
|
import { NextPreviousButtonSettingValues } from './types';
|
||||||
import { InsideTheImage, OutsideTheImage } from './icons';
|
import { InsideTheImage, OutsideTheImage } from './icons';
|
||||||
import { Context } from '../../types';
|
import { ProductGalleryLargeImageNextPreviousContext } from '../../types';
|
||||||
|
|
||||||
const NextPreviousButtonIcons = {
|
const NextPreviousButtonIcons = {
|
||||||
[ NextPreviousButtonSettingValues.insideTheImage ]: <InsideTheImage />,
|
[ NextPreviousButtonSettingValues.insideTheImage ]: <InsideTheImage />,
|
||||||
|
@ -54,17 +53,15 @@ const getHelpText = ( buttonPosition: NextPreviousButtonSettingValues ) => {
|
||||||
export const ProductGalleryNextPreviousBlockSettings = ( {
|
export const ProductGalleryNextPreviousBlockSettings = ( {
|
||||||
context,
|
context,
|
||||||
}: {
|
}: {
|
||||||
context: Context;
|
context: ProductGalleryLargeImageNextPreviousContext;
|
||||||
} ) => {
|
} ) => {
|
||||||
const { productGalleryClientId, nextPreviousButtonsPosition } = context;
|
const { productGalleryClientId, nextPreviousButtonsPosition } = context;
|
||||||
// @ts-expect-error @wordpress/block-editor/store types not provided
|
// @ts-expect-error @wordpress/block-editor/store types not provided
|
||||||
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
||||||
return (
|
return (
|
||||||
<PanelBody
|
|
||||||
className="wc-block-editor-product-gallery-large-image-next-previous-settings"
|
|
||||||
title={ __( 'Next/Prev Buttons', 'woo-gutenberg-products-block' ) }
|
|
||||||
>
|
|
||||||
<ToggleGroupControl
|
<ToggleGroupControl
|
||||||
|
label={ __( 'Next/Prev Buttons', 'woo-gutenberg-products-block' ) }
|
||||||
|
className="wc-block-editor-product-gallery-large-image-next-previous-settings"
|
||||||
style={ {
|
style={ {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
} }
|
} }
|
||||||
|
@ -89,6 +86,5 @@ export const ProductGalleryNextPreviousBlockSettings = ( {
|
||||||
label={ NextPreviousButtonIcons.outsideTheImage }
|
label={ NextPreviousButtonIcons.outsideTheImage }
|
||||||
/>
|
/>
|
||||||
</ToggleGroupControl>
|
</ToggleGroupControl>
|
||||||
</PanelBody>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import { Icon } from '@wordpress/icons';
|
import { Icon } from '@wordpress/icons';
|
||||||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
||||||
|
import { PanelBody } from '@wordpress/components';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +98,9 @@ export const Edit = ( props: EditProps ): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
|
<PanelBody>
|
||||||
<ProductGalleryPagerBlockSettings context={ context } />
|
<ProductGalleryPagerBlockSettings context={ context } />
|
||||||
|
</PanelBody>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
|
|
||||||
<Pager pagerDisplayMode={ context.pagerDisplayMode } />
|
<Pager pagerDisplayMode={ context.pagerDisplayMode } />
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import {
|
import {
|
||||||
PanelBody,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions.
|
// @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions.
|
||||||
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
|
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
|
||||||
|
@ -58,11 +57,8 @@ export const ProductGalleryPagerBlockSettings = ( {
|
||||||
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PanelBody
|
|
||||||
className="wc-block-editor-product-gallery-pager-settings"
|
|
||||||
title={ __( 'Pager', 'woo-gutenberg-products-block' ) }
|
|
||||||
>
|
|
||||||
<ToggleGroupControl
|
<ToggleGroupControl
|
||||||
|
label={ __( 'Pager', 'woo-gutenberg-products-block' ) }
|
||||||
style={ {
|
style={ {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
} }
|
} }
|
||||||
|
@ -87,6 +83,5 @@ export const ProductGalleryPagerBlockSettings = ( {
|
||||||
label={ <PagerSettingsDigitsIcon /> }
|
label={ <PagerSettingsDigitsIcon /> }
|
||||||
/>
|
/>
|
||||||
</ToggleGroupControl>
|
</ToggleGroupControl>
|
||||||
</PanelBody>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import {
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
||||||
InspectorControls,
|
|
||||||
store as blockEditorStore,
|
|
||||||
} from '@wordpress/block-editor';
|
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Icon } from '@wordpress/icons';
|
import { Icon } from '@wordpress/icons';
|
||||||
import {
|
import {
|
||||||
|
@ -14,7 +11,6 @@ import {
|
||||||
} from '@woocommerce/icons';
|
} from '@woocommerce/icons';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
import {
|
import {
|
||||||
PanelBody,
|
|
||||||
RangeControl,
|
RangeControl,
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore - Ignoring because `__experimentalToggleGroupControlOption` is not yet in the type definitions.
|
// @ts-ignore - Ignoring because `__experimentalToggleGroupControlOption` is not yet in the type definitions.
|
||||||
|
@ -61,10 +57,7 @@ export const ProductGalleryThumbnailsBlockSettings = ( {
|
||||||
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InspectorControls>
|
<>
|
||||||
<PanelBody
|
|
||||||
title={ __( 'Settings', 'woo-gutenberg-products-block' ) }
|
|
||||||
>
|
|
||||||
<ToggleGroupControl
|
<ToggleGroupControl
|
||||||
className="wc-block-editor-product-gallery-thumbnails__position-toggle"
|
className="wc-block-editor-product-gallery-thumbnails__position-toggle"
|
||||||
isBlock={ true }
|
isBlock={ true }
|
||||||
|
@ -94,19 +87,13 @@ export const ProductGalleryThumbnailsBlockSettings = ( {
|
||||||
<ToggleGroupControlOption
|
<ToggleGroupControlOption
|
||||||
value={ ThumbnailsPosition.BOTTOM }
|
value={ ThumbnailsPosition.BOTTOM }
|
||||||
label={
|
label={
|
||||||
<Icon
|
<Icon size={ 32 } icon={ thumbnailsPositionBottom } />
|
||||||
size={ 32 }
|
|
||||||
icon={ thumbnailsPositionBottom }
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<ToggleGroupControlOption
|
<ToggleGroupControlOption
|
||||||
value={ ThumbnailsPosition.RIGHT }
|
value={ ThumbnailsPosition.RIGHT }
|
||||||
label={
|
label={
|
||||||
<Icon
|
<Icon size={ 32 } icon={ thumbnailsPositionRight } />
|
||||||
size={ 32 }
|
|
||||||
icon={ thumbnailsPositionRight }
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</ToggleGroupControl>
|
</ToggleGroupControl>
|
||||||
|
@ -130,7 +117,6 @@ export const ProductGalleryThumbnailsBlockSettings = ( {
|
||||||
min={ minNumberOfThumbnails }
|
min={ minNumberOfThumbnails }
|
||||||
/>
|
/>
|
||||||
) }
|
) }
|
||||||
</PanelBody>
|
</>
|
||||||
</InspectorControls>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
||||||
import { Disabled } from '@wordpress/components';
|
import { Disabled, PanelBody } from '@wordpress/components';
|
||||||
import type { BlockEditProps } from '@wordpress/blocks';
|
import type { BlockEditProps } from '@wordpress/blocks';
|
||||||
import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings';
|
import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
@ -55,11 +55,13 @@ export const Edit = ( { attributes, setAttributes, context }: EditProps ) => {
|
||||||
<>
|
<>
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
|
<PanelBody>
|
||||||
<ProductGalleryThumbnailsBlockSettings
|
<ProductGalleryThumbnailsBlockSettings
|
||||||
attributes={ attributes }
|
attributes={ attributes }
|
||||||
setAttributes={ setAttributes }
|
setAttributes={ setAttributes }
|
||||||
context={ context }
|
context={ context }
|
||||||
/>
|
/>
|
||||||
|
</PanelBody>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
<Disabled>
|
<Disabled>
|
||||||
<Placeholder />
|
<Placeholder />
|
||||||
|
|
|
@ -33,14 +33,11 @@ export interface ProductGalleryBlockEditProps {
|
||||||
export interface ProductGallerySettingsProps {
|
export interface ProductGallerySettingsProps {
|
||||||
attributes: ProductGalleryBlockAttributes;
|
attributes: ProductGalleryBlockAttributes;
|
||||||
setAttributes: ( attributes: ProductGalleryBlockAttributes ) => void;
|
setAttributes: ( attributes: ProductGalleryBlockAttributes ) => void;
|
||||||
|
context: ProductGalleryContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProductGalleryThumbnailsSettingsProps {
|
export interface ProductGalleryThumbnailsSettingsProps {
|
||||||
attributes: ProductGalleryThumbnailsBlockAttributes;
|
context: ProductGalleryThumbnailsContext;
|
||||||
setAttributes: (
|
|
||||||
attributes: ProductGalleryThumbnailsBlockAttributes
|
|
||||||
) => void;
|
|
||||||
context: ProductGalleryThumbnailsBlockAttributes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductGalleryContext = {
|
export type ProductGalleryContext = {
|
||||||
|
@ -55,6 +52,18 @@ export type ProductGalleryPagerContext = Pick<
|
||||||
'productGalleryClientId' | 'pagerDisplayMode'
|
'productGalleryClientId' | 'pagerDisplayMode'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export type ProductGalleryLargeImageNextPreviousContext = Pick<
|
||||||
|
ProductGalleryContext,
|
||||||
|
'productGalleryClientId' | 'nextPreviousButtonsPosition'
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type ProductGalleryThumbnailsContext = Pick<
|
||||||
|
ProductGalleryContext,
|
||||||
|
| 'productGalleryClientId'
|
||||||
|
| 'thumbnailsPosition'
|
||||||
|
| 'thumbnailsNumberOfThumbnails'
|
||||||
|
>;
|
||||||
|
|
||||||
export type ProductGalleryAttributes = ProductGalleryThumbnailsBlockAttributes &
|
export type ProductGalleryAttributes = ProductGalleryThumbnailsBlockAttributes &
|
||||||
ProductGalleryBlockAttributes &
|
ProductGalleryBlockAttributes &
|
||||||
ProductGalleryPagerBlockAttributes &
|
ProductGalleryPagerBlockAttributes &
|
||||||
|
|
|
@ -20,8 +20,7 @@ const blockData = {
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
settings: {
|
settings: {
|
||||||
pagerSettingsContainer:
|
pagerSettingsContainer: 'div[aria-label="Pager"]',
|
||||||
'.wc-block-editor-product-gallery-pager-settings',
|
|
||||||
displayModeOffOption: 'button[data-value=off]',
|
displayModeOffOption: 'button[data-value=off]',
|
||||||
displayModeDotsOption: 'button[data-value=dots]',
|
displayModeDotsOption: 'button[data-value=dots]',
|
||||||
displayModeDigitsOption: 'button[data-value=digits]',
|
displayModeDigitsOption: 'button[data-value=digits]',
|
||||||
|
|
Loading…
Reference in New Issue