Skip to content

Commit

Permalink
Read More Block: Refactor settings panel to use ToolsPanel (WordPress…
Browse files Browse the repository at this point in the history
…#67925)

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 17, 2025
1 parent aec60be commit ebab640
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions packages/block-library/src/read-more/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,55 @@ import {
RichText,
useBlockProps,
} 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 { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

export default function ReadMore( {
attributes: { content, linkTarget },
setAttributes,
insertBlocksAfter,
} ) {
const blockProps = useBlockProps();
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

return (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => setAttributes( { linkTarget: '_self' } ) }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
isShownByDefault
hasValue={ () => linkTarget !== '_self' }
onDeselect={ () =>
setAttributes( { linkTarget: '_self' } )
}
checked={ linkTarget === '_blank' }
/>
</PanelBody>
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
}
checked={ linkTarget === '_blank' }
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<RichText
identifier="content"
Expand Down

0 comments on commit ebab640

Please sign in to comment.