Skip to content

Commit

Permalink
Site Title Block: Refactor settings panel to use ToolsPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukhendu2002 committed Dec 12, 2024
1 parent 63b0e7f commit 502b14e
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 502b14e

Please sign in to comment.