Skip to content

Commit 9ed4e00

Browse files
SainathPoojarySainathPoojaryt-hamanofabiankaegy
authored andcommitted
Read More Block: Refactor settings panel to use ToolsPanel (WordPress#67925)
Co-authored-by: SainathPoojary <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: fabiankaegy <[email protected]>
1 parent 2d372fc commit 9ed4e00

File tree

1 file changed

+35
-11
lines changed
  • packages/block-library/src/read-more

1 file changed

+35
-11
lines changed

packages/block-library/src/read-more/edit.js

+35-11
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,55 @@ import {
66
RichText,
77
useBlockProps,
88
} from '@wordpress/block-editor';
9-
import { ToggleControl, PanelBody } from '@wordpress/components';
9+
import {
10+
ToggleControl,
11+
__experimentalToolsPanel as ToolsPanel,
12+
__experimentalToolsPanelItem as ToolsPanelItem,
13+
} from '@wordpress/components';
1014
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
1115
import { __ } from '@wordpress/i18n';
1216

17+
/**
18+
* Internal dependencies
19+
*/
20+
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
21+
1322
export default function ReadMore( {
1423
attributes: { content, linkTarget },
1524
setAttributes,
1625
insertBlocksAfter,
1726
} ) {
1827
const blockProps = useBlockProps();
28+
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
29+
1930
return (
2031
<>
2132
<InspectorControls>
22-
<PanelBody title={ __( 'Settings' ) }>
23-
<ToggleControl
24-
__nextHasNoMarginBottom
33+
<ToolsPanel
34+
label={ __( 'Settings' ) }
35+
resetAll={ () => setAttributes( { linkTarget: '_self' } ) }
36+
dropdownMenuProps={ dropdownMenuProps }
37+
>
38+
<ToolsPanelItem
2539
label={ __( 'Open in new tab' ) }
26-
onChange={ ( value ) =>
27-
setAttributes( {
28-
linkTarget: value ? '_blank' : '_self',
29-
} )
40+
isShownByDefault
41+
hasValue={ () => linkTarget !== '_self' }
42+
onDeselect={ () =>
43+
setAttributes( { linkTarget: '_self' } )
3044
}
31-
checked={ linkTarget === '_blank' }
32-
/>
33-
</PanelBody>
45+
>
46+
<ToggleControl
47+
__nextHasNoMarginBottom
48+
label={ __( 'Open in new tab' ) }
49+
onChange={ ( value ) =>
50+
setAttributes( {
51+
linkTarget: value ? '_blank' : '_self',
52+
} )
53+
}
54+
checked={ linkTarget === '_blank' }
55+
/>
56+
</ToolsPanelItem>
57+
</ToolsPanel>
3458
</InspectorControls>
3559
<RichText
3660
identifier="content"

0 commit comments

Comments
 (0)