From f5959ccdbab3fab3f95525c2d711e419cffe7d0a Mon Sep 17 00:00:00 2001 From: Amit Raj <77401999+amitraj2203@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:39:42 +0530 Subject: [PATCH] Latests Posts: Used ToggleGroupControl instead for Image alignment (#64352) * Used ToggleGroupControl instead of BlockAlignmentToolbar * Addressed feedback * Use position icons instead of align * Remove isBlock prop from ToggleGroupControl Co-authored-by: amitraj2203 Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: t-hamano --- .../block-library/src/latest-posts/edit.js | 76 ++++++++++++++----- .../src/latest-posts/editor.scss | 6 -- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/packages/block-library/src/latest-posts/edit.js b/packages/block-library/src/latest-posts/edit.js index 49a24b08f68d77..533e9621fd4f2b 100644 --- a/packages/block-library/src/latest-posts/edit.js +++ b/packages/block-library/src/latest-posts/edit.js @@ -7,7 +7,6 @@ import clsx from 'clsx'; * WordPress dependencies */ import { - BaseControl, PanelBody, Placeholder, QueryControls, @@ -16,19 +15,28 @@ import { Spinner, ToggleControl, ToolbarGroup, + __experimentalToggleGroupControl as ToggleGroupControl, + __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, } from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; import { dateI18n, format, getSettings } from '@wordpress/date'; import { InspectorControls, - BlockAlignmentToolbar, BlockControls, __experimentalImageSizeControl as ImageSizeControl, useBlockProps, store as blockEditorStore, } from '@wordpress/block-editor'; import { useSelect, useDispatch } from '@wordpress/data'; -import { pin, list, grid } from '@wordpress/icons'; +import { + pin, + list, + grid, + alignNone, + positionLeft, + positionCenter, + positionRight, +} from '@wordpress/icons'; import { store as coreStore } from '@wordpress/core-data'; import { store as noticeStore } from '@wordpress/notices'; import { useInstanceId } from '@wordpress/compose'; @@ -197,6 +205,29 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) { setAttributes( { categories: allCategories } ); }; + const imageAlignmentOptions = [ + { + value: 'none', + icon: alignNone, + label: __( 'None' ), + }, + { + value: 'left', + icon: positionLeft, + label: __( 'Left' ), + }, + { + value: 'center', + icon: positionCenter, + label: __( 'Center' ), + }, + { + value: 'right', + icon: positionRight, + label: __( 'Right' ), + }, + ]; + const hasPosts = !! latestPosts?.length; const inspectorControls = ( @@ -303,21 +334,32 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) { } ) } /> - - - { __( 'Image alignment' ) } - - - setAttributes( { - featuredImageAlign: value, - } ) + + setAttributes( { + featuredImageAlign: + value !== 'none' ? value : undefined, + } ) + } + > + { imageAlignmentOptions.map( + ( { value, icon, label } ) => { + return ( + + ); } - controls={ [ 'left', 'center', 'right' ] } - isCollapsed={ false } - /> - + ) } +