Skip to content

Commit

Permalink
Author Name: Refactor settings panel to use ToolsPanel (#67953)
Browse files Browse the repository at this point in the history
* Author Name: Refactor settings panel to use ToolsPanel

* Author Name: Add dropdownMenuProps for consistency

Co-authored-by: SainathPoojary <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
4 people authored Jan 13, 2025
1 parent dc76c9a commit 88b4e1d
Showing 1 changed file with 53 additions and 15 deletions.
68 changes: 53 additions & 15 deletions packages/block-library/src/post-author-name/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -61,6 +70,8 @@ function PostAuthorNameEdit( {
displayName
);

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

return (
<>
<BlockControls group="block">
Expand All @@ -72,26 +83,53 @@ function PostAuthorNameEdit( {
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
isLink: false,
linkTarget: '_self',
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
label={ __( 'Link to author archive' ) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
{ isLink && (
isShownByDefault
hasValue={ () => isLink }
onDeselect={ () => setAttributes( { isLink: false } ) }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
label={ __( 'Link to author archive' ) }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
}
checked={ linkTarget === '_blank' }
checked={ isLink }
/>
</ToolsPanelItem>
{ isLink && (
<ToolsPanelItem
label={ __( 'Open in new tab' ) }
isShownByDefault
hasValue={ () => linkTarget !== '_self' }
onDeselect={ () =>
setAttributes( { linkTarget: '_self' } )
}
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
}
checked={ linkTarget === '_blank' }
/>
</ToolsPanelItem>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
<div { ...blockProps }>
{ supportsAuthor
Expand Down

0 comments on commit 88b4e1d

Please sign in to comment.