Skip to content

Commit b315bcf

Browse files
SainathPoojarySainathPoojaryMamadukafabiankaegy
authored
Post Title: Refactor settings panel to use ToolsPanel (WordPress#70229)
Co-authored-by: SainathPoojary <sainathpoojary@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
1 parent fc0c798 commit b315bcf

File tree

1 file changed

+76
-24
lines changed
  • packages/block-library/src/post-title

1 file changed

+76
-24
lines changed

packages/block-library/src/post-title/edit.js

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ import {
1515
HeadingLevelDropdown,
1616
useBlockEditingMode,
1717
} from '@wordpress/block-editor';
18-
import { ToggleControl, TextControl, PanelBody } from '@wordpress/components';
18+
import {
19+
ToggleControl,
20+
TextControl,
21+
__experimentalToolsPanel as ToolsPanel,
22+
__experimentalToolsPanelItem as ToolsPanelItem,
23+
} from '@wordpress/components';
1924
import { __ } from '@wordpress/i18n';
2025
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
2126
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
2227
import { useSelect } from '@wordpress/data';
2328

29+
/**
30+
* Internal dependencies
31+
*/
32+
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
33+
2434
export default function PostTitleEdit( {
2535
attributes: { level, levelOptions, textAlign, isLink, rel, linkTarget },
2636
setAttributes,
@@ -66,6 +76,7 @@ export default function PostTitleEdit( {
6676
} ),
6777
} );
6878
const blockEditingMode = useBlockEditingMode();
79+
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
6980

7081
let titleElement = <TagName { ...blockProps }>{ __( 'Title' ) }</TagName>;
7182

@@ -138,41 +149,82 @@ export default function PostTitleEdit( {
138149
/>
139150
</BlockControls>
140151
<InspectorControls>
141-
<PanelBody title={ __( 'Settings' ) }>
142-
<ToggleControl
143-
__nextHasNoMarginBottom
152+
<ToolsPanel
153+
label={ __( 'Settings' ) }
154+
resetAll={ () => {
155+
setAttributes( {
156+
rel: '',
157+
linkTarget: '_self',
158+
isLink: false,
159+
} );
160+
} }
161+
dropdownMenuProps={ dropdownMenuProps }
162+
>
163+
<ToolsPanelItem
144164
label={ __( 'Make title a link' ) }
145-
onChange={ () =>
146-
setAttributes( { isLink: ! isLink } )
165+
isShownByDefault
166+
hasValue={ () => isLink }
167+
onDeselect={ () =>
168+
setAttributes( { isLink: false } )
147169
}
148-
checked={ isLink }
149-
/>
170+
>
171+
<ToggleControl
172+
__nextHasNoMarginBottom
173+
label={ __( 'Make title a link' ) }
174+
onChange={ () =>
175+
setAttributes( { isLink: ! isLink } )
176+
}
177+
checked={ isLink }
178+
/>
179+
</ToolsPanelItem>
150180
{ isLink && (
151181
<>
152-
<ToggleControl
153-
__nextHasNoMarginBottom
182+
<ToolsPanelItem
154183
label={ __( 'Open in new tab' ) }
155-
onChange={ ( value ) =>
184+
isShownByDefault
185+
hasValue={ () =>
186+
linkTarget === '_blank'
187+
}
188+
onDeselect={ () =>
156189
setAttributes( {
157-
linkTarget: value
158-
? '_blank'
159-
: '_self',
190+
linkTarget: '_self',
160191
} )
161192
}
162-
checked={ linkTarget === '_blank' }
163-
/>
164-
<TextControl
165-
__next40pxDefaultSize
166-
__nextHasNoMarginBottom
193+
>
194+
<ToggleControl
195+
__nextHasNoMarginBottom
196+
label={ __( 'Open in new tab' ) }
197+
onChange={ ( value ) =>
198+
setAttributes( {
199+
linkTarget: value
200+
? '_blank'
201+
: '_self',
202+
} )
203+
}
204+
checked={ linkTarget === '_blank' }
205+
/>
206+
</ToolsPanelItem>
207+
<ToolsPanelItem
167208
label={ __( 'Link rel' ) }
168-
value={ rel }
169-
onChange={ ( newRel ) =>
170-
setAttributes( { rel: newRel } )
209+
isShownByDefault
210+
hasValue={ () => !! rel }
211+
onDeselect={ () =>
212+
setAttributes( { rel: '' } )
171213
}
172-
/>
214+
>
215+
<TextControl
216+
__next40pxDefaultSize
217+
__nextHasNoMarginBottom
218+
label={ __( 'Link rel' ) }
219+
value={ rel }
220+
onChange={ ( newRel ) =>
221+
setAttributes( { rel: newRel } )
222+
}
223+
/>
224+
</ToolsPanelItem>
173225
</>
174226
) }
175-
</PanelBody>
227+
</ToolsPanel>
176228
</InspectorControls>
177229
</>
178230
) }

0 commit comments

Comments
 (0)