Skip to content

Commit

Permalink
Refactor "Settings" panel of Site Title block to use ToolsPanel inste…
Browse files Browse the repository at this point in the history
…ad of PanelBody (WordPress#67898)

Co-authored-by: Sukhendu2002 <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent 3d17c61 commit c8cdff3
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions packages/block-library/src/site-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
useBlockProps,
HeadingLevelDropdown,
} from '@wordpress/block-editor';
import { ToggleControl, PanelBody } from '@wordpress/components';
import {
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { decodeEntities } from '@wordpress/html-entities';

Expand Down Expand Up @@ -109,26 +113,52 @@ export default function SiteTitleEdit( {
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
isLink: false,
linkTarget: '_self',
} );
} }
>
<ToolsPanelItem
hasValue={ () => isLink !== false }
label={ __( 'Make title link to home' ) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
{ isLink && (
onDeselect={ () => setAttributes( { isLink: false } ) }
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
label={ __( 'Make title link to home' ) }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
}
checked={ linkTarget === '_blank' }
checked={ isLink }
/>
</ToolsPanelItem>
{ isLink && (
<ToolsPanelItem
hasValue={ () => linkTarget !== '_self' }
label={ __( 'Open in new tab' ) }
onDeselect={ () =>
setAttributes( { linkTarget: '_self' } )
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
}
checked={ linkTarget === '_blank' }
/>
</ToolsPanelItem>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
{ siteTitleContent }
</>
Expand Down

0 comments on commit c8cdff3

Please sign in to comment.