Skip to content

Commit c547f4d

Browse files
SainathPoojarySainathPoojaryt-hamanotroychaplin
authored
Post Navigation Link: Refactor settings panel to use ToolsPanel (#70276)
Co-authored-by: SainathPoojary <sainathpoojary@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: troychaplin <areziaal@git.wordpress.org>
1 parent cf57e20 commit c547f4d

File tree

1 file changed

+96
-51
lines changed

1 file changed

+96
-51
lines changed

packages/block-library/src/post-navigation-link/edit.js

Lines changed: 96 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import clsx from 'clsx';
99
import {
1010
__experimentalToggleGroupControl as ToggleGroupControl,
1111
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
12+
__experimentalToolsPanel as ToolsPanel,
13+
__experimentalToolsPanelItem as ToolsPanelItem,
1214
ToggleControl,
1315
SelectControl,
14-
PanelBody,
1516
} from '@wordpress/components';
1617
import {
1718
InspectorControls,
@@ -25,6 +26,11 @@ import { __, _x } from '@wordpress/i18n';
2526
import { useSelect } from '@wordpress/data';
2627
import { store as coreStore } from '@wordpress/core-data';
2728

29+
/**
30+
* Internal dependencies
31+
*/
32+
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
33+
2834
export default function PostNavigationLinkEdit( {
2935
context: { postType },
3036
attributes: {
@@ -94,73 +100,112 @@ export default function PostNavigationLinkEdit( {
94100
return [ selectOption, ...taxonomyOptions ];
95101
};
96102

103+
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
104+
97105
return (
98106
<>
99107
<InspectorControls>
100-
<PanelBody>
101-
<ToggleControl
102-
__nextHasNoMarginBottom
108+
<ToolsPanel
109+
label={ __( 'Settings' ) }
110+
resetAll={ () => {
111+
setAttributes( {
112+
showTitle: false,
113+
linkLabel: false,
114+
arrow: 'none',
115+
} );
116+
} }
117+
dropdownMenuProps={ dropdownMenuProps }
118+
>
119+
<ToolsPanelItem
103120
label={ __( 'Display the title as a link' ) }
104-
help={ __(
105-
'If you have entered a custom label, it will be prepended before the title.'
106-
) }
107-
checked={ !! showTitle }
108-
onChange={ () =>
109-
setAttributes( {
110-
showTitle: ! showTitle,
111-
} )
121+
isShownByDefault
122+
hasValue={ () => showTitle }
123+
onDeselect={ () =>
124+
setAttributes( { showTitle: false } )
112125
}
113-
/>
114-
{ showTitle && (
126+
>
115127
<ToggleControl
116128
__nextHasNoMarginBottom
117-
label={ __(
118-
'Include the label as part of the link'
129+
label={ __( 'Display the title as a link' ) }
130+
help={ __(
131+
'If you have entered a custom label, it will be prepended before the title.'
119132
) }
120-
checked={ !! linkLabel }
133+
checked={ !! showTitle }
121134
onChange={ () =>
122135
setAttributes( {
123-
linkLabel: ! linkLabel,
136+
showTitle: ! showTitle,
124137
} )
125138
}
126139
/>
140+
</ToolsPanelItem>
141+
{ showTitle && (
142+
<ToolsPanelItem
143+
label={ __(
144+
'Include the label as part of the link'
145+
) }
146+
isShownByDefault
147+
hasValue={ () => !! linkLabel }
148+
onDeselect={ () =>
149+
setAttributes( { linkLabel: false } )
150+
}
151+
>
152+
<ToggleControl
153+
__nextHasNoMarginBottom
154+
label={ __(
155+
'Include the label as part of the link'
156+
) }
157+
checked={ !! linkLabel }
158+
onChange={ () =>
159+
setAttributes( {
160+
linkLabel: ! linkLabel,
161+
} )
162+
}
163+
/>
164+
</ToolsPanelItem>
127165
) }
128-
<ToggleGroupControl
129-
__next40pxDefaultSize
130-
__nextHasNoMarginBottom
166+
<ToolsPanelItem
131167
label={ __( 'Arrow' ) }
132-
value={ arrow }
133-
onChange={ ( value ) => {
134-
setAttributes( { arrow: value } );
135-
} }
136-
help={ __(
137-
'A decorative arrow for the next and previous link.'
138-
) }
139-
isBlock
168+
isShownByDefault
169+
hasValue={ () => arrow !== 'none' }
170+
onDeselect={ () => setAttributes( { arrow: 'none' } ) }
140171
>
141-
<ToggleGroupControlOption
142-
value="none"
143-
label={ _x(
144-
'None',
145-
'Arrow option for Next/Previous link'
146-
) }
147-
/>
148-
<ToggleGroupControlOption
149-
value="arrow"
150-
label={ _x(
151-
'Arrow',
152-
'Arrow option for Next/Previous link'
153-
) }
154-
/>
155-
<ToggleGroupControlOption
156-
value="chevron"
157-
label={ _x(
158-
'Chevron',
159-
'Arrow option for Next/Previous link'
172+
<ToggleGroupControl
173+
__next40pxDefaultSize
174+
__nextHasNoMarginBottom
175+
label={ __( 'Arrow' ) }
176+
value={ arrow }
177+
onChange={ ( value ) => {
178+
setAttributes( { arrow: value } );
179+
} }
180+
help={ __(
181+
'A decorative arrow for the next and previous link.'
160182
) }
161-
/>
162-
</ToggleGroupControl>
163-
</PanelBody>
183+
isBlock
184+
>
185+
<ToggleGroupControlOption
186+
value="none"
187+
label={ _x(
188+
'None',
189+
'Arrow option for Next/Previous link'
190+
) }
191+
/>
192+
<ToggleGroupControlOption
193+
value="arrow"
194+
label={ _x(
195+
'Arrow',
196+
'Arrow option for Next/Previous link'
197+
) }
198+
/>
199+
<ToggleGroupControlOption
200+
value="chevron"
201+
label={ _x(
202+
'Chevron',
203+
'Arrow option for Next/Previous link'
204+
) }
205+
/>
206+
</ToggleGroupControl>
207+
</ToolsPanelItem>
208+
</ToolsPanel>
164209
</InspectorControls>
165210
<InspectorControls group="advanced">
166211
<SelectControl

0 commit comments

Comments
 (0)