From 88b4e1ddd7ba74b0e55eb269891585a8c5423d14 Mon Sep 17 00:00:00 2001 From: Sainath Poojary <53347682+SainathPoojary@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:11:23 +0530 Subject: [PATCH] Author Name: Refactor settings panel to use ToolsPanel (#67953) * Author Name: Refactor settings panel to use ToolsPanel * Author Name: Add dropdownMenuProps for consistency Co-authored-by: SainathPoojary Co-authored-by: t-hamano Co-authored-by: fabiankaegy --- .../src/post-author-name/edit.js | 68 +++++++++++++++---- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/packages/block-library/src/post-author-name/edit.js b/packages/block-library/src/post-author-name/edit.js index 2b4bb0709356b0..8c0281edb5df8a 100644 --- a/packages/block-library/src/post-author-name/edit.js +++ b/packages/block-library/src/post-author-name/edit.js @@ -15,7 +15,16 @@ import { import { useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; import { store as coreStore } from '@wordpress/core-data'; -import { PanelBody, ToggleControl } from '@wordpress/components'; +import { + ToggleControl, + __experimentalToolsPanel as ToolsPanel, + __experimentalToolsPanelItem as ToolsPanelItem, +} from '@wordpress/components'; + +/** + * Internal dependencies + */ +import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; function PostAuthorNameEdit( { context: { postType, postId }, @@ -61,6 +70,8 @@ function PostAuthorNameEdit( { displayName ); + const dropdownMenuProps = useToolsPanelDropdownMenuProps(); + return ( <> @@ -72,26 +83,53 @@ function PostAuthorNameEdit( { /> - - { + setAttributes( { + isLink: false, + linkTarget: '_self', + } ); + } } + dropdownMenuProps={ dropdownMenuProps } + > + setAttributes( { isLink: ! isLink } ) } - checked={ isLink } - /> - { isLink && ( + isShownByDefault + hasValue={ () => isLink } + onDeselect={ () => setAttributes( { isLink: false } ) } + > - setAttributes( { - linkTarget: value ? '_blank' : '_self', - } ) + label={ __( 'Link to author archive' ) } + onChange={ () => + setAttributes( { isLink: ! isLink } ) } - checked={ linkTarget === '_blank' } + checked={ isLink } /> + + { isLink && ( + linkTarget !== '_self' } + onDeselect={ () => + setAttributes( { linkTarget: '_self' } ) + } + > + + setAttributes( { + linkTarget: value ? '_blank' : '_self', + } ) + } + checked={ linkTarget === '_blank' } + /> + ) } - +
{ supportsAuthor