Skip to content

Commit

Permalink
Latests Posts: Used ToggleGroupControl instead for Image alignment (#…
Browse files Browse the repository at this point in the history
…64352)

* Used ToggleGroupControl instead of BlockAlignmentToolbar

* Addressed feedback

* Use position icons instead of align

* Remove isBlock prop from ToggleGroupControl

Co-authored-by: amitraj2203 <amitraj2203@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
4 people authored and getdave committed Aug 14, 2024
1 parent 01f5f22 commit 496a21d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
76 changes: 59 additions & 17 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import clsx from 'clsx';
* WordPress dependencies
*/
import {
BaseControl,
PanelBody,
Placeholder,
QueryControls,
Expand All @@ -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';
Expand Down Expand Up @@ -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 = (
<InspectorControls>
Expand Down Expand Up @@ -303,21 +334,32 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
} )
}
/>
<BaseControl className="editor-latest-posts-image-alignment-control">
<BaseControl.VisualLabel>
{ __( 'Image alignment' ) }
</BaseControl.VisualLabel>
<BlockAlignmentToolbar
value={ featuredImageAlign }
onChange={ ( value ) =>
setAttributes( {
featuredImageAlign: value,
} )
<ToggleGroupControl
className="editor-latest-posts-image-alignment-control"
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Image alignment' ) }
value={ featuredImageAlign || 'none' }
onChange={ ( value ) =>
setAttributes( {
featuredImageAlign:
value !== 'none' ? value : undefined,
} )
}
>
{ imageAlignmentOptions.map(
( { value, icon, label } ) => {
return (
<ToggleGroupControlOptionIcon
key={ value }
value={ value }
icon={ icon }
label={ label }
/>
);
}
controls={ [ 'left', 'center', 'right' ] }
isCollapsed={ false }
/>
</BaseControl>
) }
</ToggleGroupControl>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Add link to featured image' ) }
Expand Down
6 changes: 0 additions & 6 deletions packages/block-library/src/latest-posts/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
display: inline;
}

.editor-latest-posts-image-alignment-control {
.components-toolbar {
border-radius: $radius-block-ui;
}
}

:root :where(.wp-block-latest-posts) {
padding-left: 2.5em;
}
Expand Down

0 comments on commit 496a21d

Please sign in to comment.