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

Product Gallery block: Move inner block settings around to match the order from the design #11170

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
34 changes: 34 additions & 0 deletions assets/js/blocks/product-gallery/block-settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,48 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
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 = ( {
attributes,
setAttributes,
context,
}: ProductGallerySettingsProps ) => {
const { cropImages, hoverZoom, fullScreenOnClick } = attributes;
const {
productGalleryClientId,
pagerDisplayMode,
nextPreviousButtonsPosition,
thumbnailsNumberOfThumbnails,
thumbnailsPosition,
} = context;
return (
<InspectorControls>
<PanelBody
title={ __(
'Gallery Navigation',
'woo-gutenberg-products-block'
) }
>
<ProductGalleryPagerBlockSettings
context={ { productGalleryClientId, pagerDisplayMode } }
/>
<ProductGalleryNextPreviousBlockSettings
context={ {
productGalleryClientId,
nextPreviousButtonsPosition,
} }
/>
<ProductGalleryThumbnailsBlockSettings
context={ {
productGalleryClientId,
thumbnailsNumberOfThumbnails,
thumbnailsPosition,
} }
/>
</PanelBody>
<PanelBody
title={ __( 'Media Settings', 'woo-gutenberg-products-block' ) }
>
Expand Down
28 changes: 4 additions & 24 deletions assets/js/blocks/product-gallery/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ import {
getInnerBlocksLockAttributes,
getClassNameByNextPreviousButtonsPosition,
} 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 type { ProductGalleryAttributes } from './types';
import { ProductGalleryNextPreviousBlockSettings } from './inner-blocks/product-gallery-large-image-next-previous/settings';

const TEMPLATE: InnerBlockTemplate[] = [
[
Expand Down Expand Up @@ -138,34 +135,17 @@ export const Edit = ( {
return (
<div { ...blockProps }>
<InspectorControls>
<ProductGalleryPagerBlockSettings
context={ {
productGalleryClientId: clientId,
pagerDisplayMode: attributes.pagerDisplayMode,
} }
/>
<ProductGalleryThumbnailsBlockSettings
<ProductGalleryBlockSettings
attributes={ attributes }
setAttributes={ setAttributes }
context={ {
productGalleryClientId: clientId,
pagerDisplayMode: attributes.pagerDisplayMode,
thumbnailsPosition: attributes.thumbnailsPosition,
thumbnailsNumberOfThumbnails:
attributes.thumbnailsNumberOfThumbnails,
} }
/>
</InspectorControls>
<InspectorControls>
<ProductGalleryBlockSettings
attributes={ attributes }
setAttributes={ setAttributes }
/>
</InspectorControls>
<InspectorControls>
<ProductGalleryNextPreviousBlockSettings
context={ {
...attributes,
productGalleryClientId: clientId,
nextPreviousButtonsPosition:
attributes.nextPreviousButtonsPosition,
} }
/>
</InspectorControls>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { useMemo } from '@wordpress/element';
import { BlockAttributes } from '@wordpress/blocks';
import { PanelBody } from '@wordpress/components';
import classNames from 'classnames';

/**
Expand Down Expand Up @@ -57,7 +58,11 @@ export const Edit = ( {
return (
<div { ...blockProps }>
<InspectorControls>
<ProductGalleryNextPreviousBlockSettings context={ context } />
<PanelBody>
<ProductGalleryNextPreviousBlockSettings
context={ context }
/>
</PanelBody>
</InspectorControls>
<div
className={ classNames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import {
PanelBody,
// @ts-expect-error `__experimentalToggleGroupControl` is not yet in the type definitions.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
__experimentalToggleGroupControl as ToggleGroupControl,
Expand All @@ -19,7 +18,7 @@ import {
*/
import { NextPreviousButtonSettingValues } from './types';
import { InsideTheImage, OutsideTheImage } from './icons';
import { Context } from '../../types';
import { ProductGalleryLargeImageNextPreviousContext } from '../../types';

const NextPreviousButtonIcons = {
[ NextPreviousButtonSettingValues.insideTheImage ]: <InsideTheImage />,
Expand Down Expand Up @@ -54,41 +53,38 @@ const getHelpText = ( buttonPosition: NextPreviousButtonSettingValues ) => {
export const ProductGalleryNextPreviousBlockSettings = ( {
context,
}: {
context: Context;
context: ProductGalleryLargeImageNextPreviousContext;
} ) => {
const { productGalleryClientId, nextPreviousButtonsPosition } = context;
// @ts-expect-error @wordpress/block-editor/store types not provided
const { updateBlockAttributes } = useDispatch( blockEditorStore );
return (
<PanelBody
<ToggleGroupControl
label={ __( 'Next/Prev Buttons', 'woo-gutenberg-products-block' ) }
className="wc-block-editor-product-gallery-large-image-next-previous-settings"
title={ __( 'Next/Prev Buttons', 'woo-gutenberg-products-block' ) }
style={ {
width: '100%',
} }
onChange={ ( value: NextPreviousButtonSettingValues ) =>
updateBlockAttributes( productGalleryClientId, {
nextPreviousButtonsPosition: value,
} )
}
help={ getHelpText( nextPreviousButtonsPosition ) }
value={ nextPreviousButtonsPosition }
>
<ToggleGroupControl
style={ {
width: '100%',
} }
onChange={ ( value: NextPreviousButtonSettingValues ) =>
updateBlockAttributes( productGalleryClientId, {
nextPreviousButtonsPosition: value,
} )
}
help={ getHelpText( nextPreviousButtonsPosition ) }
value={ nextPreviousButtonsPosition }
>
<ToggleGroupControlOption
value={ NextPreviousButtonSettingValues.off }
label={ __( 'Off', 'woo-gutenberg-products-block' ) }
/>
<ToggleGroupControlOption
value={ NextPreviousButtonSettingValues.insideTheImage }
label={ NextPreviousButtonIcons.insideTheImage }
/>
<ToggleGroupControlOption
value={ NextPreviousButtonSettingValues.outsideTheImage }
label={ NextPreviousButtonIcons.outsideTheImage }
/>
</ToggleGroupControl>
</PanelBody>
<ToggleGroupControlOption
value={ NextPreviousButtonSettingValues.off }
label={ __( 'Off', 'woo-gutenberg-products-block' ) }
/>
<ToggleGroupControlOption
value={ NextPreviousButtonSettingValues.insideTheImage }
label={ NextPreviousButtonIcons.insideTheImage }
/>
<ToggleGroupControlOption
value={ NextPreviousButtonSettingValues.outsideTheImage }
label={ NextPreviousButtonIcons.outsideTheImage }
/>
</ToggleGroupControl>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { Icon } from '@wordpress/icons';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody } from '@wordpress/components';
import classNames from 'classnames';

/**
Expand Down Expand Up @@ -97,7 +98,9 @@ export const Edit = ( props: EditProps ): JSX.Element => {
return (
<div { ...blockProps }>
<InspectorControls>
<ProductGalleryPagerBlockSettings context={ context } />
<PanelBody>
<ProductGalleryPagerBlockSettings context={ context } />
</PanelBody>
</InspectorControls>

<Pager pagerDisplayMode={ context.pagerDisplayMode } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import {
PanelBody,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
Expand Down Expand Up @@ -58,35 +57,31 @@ export const ProductGalleryPagerBlockSettings = ( {
const { updateBlockAttributes } = useDispatch( blockEditorStore );

return (
<PanelBody
className="wc-block-editor-product-gallery-pager-settings"
title={ __( 'Pager', 'woo-gutenberg-products-block' ) }
<ToggleGroupControl
label={ __( 'Pager', 'woo-gutenberg-products-block' ) }
style={ {
width: '100%',
} }
onChange={ ( value: PagerDisplayModes ) => {
updateBlockAttributes( productGalleryClientId, {
pagerDisplayMode: value,
} );
} }
help={ getHelpText( pagerDisplayMode ) }
value={ pagerDisplayMode }
>
<ToggleGroupControl
style={ {
width: '100%',
} }
onChange={ ( value: PagerDisplayModes ) => {
updateBlockAttributes( productGalleryClientId, {
pagerDisplayMode: value,
} );
} }
help={ getHelpText( pagerDisplayMode ) }
value={ pagerDisplayMode }
>
<ToggleGroupControlOption
value={ PagerDisplayModes.OFF }
label={ __( 'Off', 'woo-gutenberg-products-block' ) }
/>
<ToggleGroupControlOption
value={ PagerDisplayModes.DOTS }
label={ <PagerSettingsDotIcon /> }
/>
<ToggleGroupControlOption
value={ PagerDisplayModes.DIGITS }
label={ <PagerSettingsDigitsIcon /> }
/>
</ToggleGroupControl>
</PanelBody>
<ToggleGroupControlOption
value={ PagerDisplayModes.OFF }
label={ __( 'Off', 'woo-gutenberg-products-block' ) }
/>
<ToggleGroupControlOption
value={ PagerDisplayModes.DOTS }
label={ <PagerSettingsDotIcon /> }
/>
<ToggleGroupControlOption
value={ PagerDisplayModes.DIGITS }
label={ <PagerSettingsDigitsIcon /> }
/>
</ToggleGroupControl>
);
};
Loading
Loading