Skip to content

Commit

Permalink
Login/Logout Block: Refactor settings panel to use ToolsPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
Infinite-Null committed Dec 13, 2024
1 parent 82fa9be commit fbaf1d2
Showing 1 changed file with 49 additions and 19 deletions.
68 changes: 49 additions & 19 deletions packages/block-library/src/loginout/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* WordPress dependencies
*/
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, ToggleControl } from '@wordpress/components';
import {
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export default function LoginOutEdit( { attributes, setAttributes } ) {
Expand All @@ -11,28 +15,54 @@ export default function LoginOutEdit( { attributes, setAttributes } ) {
return (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
displayLoginAsForm: false,
redirectToCurrent: true,
} );
} }
>
<ToolsPanelItem
label={ __( 'Display login as form' ) }
checked={ displayLoginAsForm }
onChange={ () =>
setAttributes( {
displayLoginAsForm: ! displayLoginAsForm,
} )
isShownByDefault
hasValue={ () => displayLoginAsForm }
onDeselect={ () =>
setAttributes( { displayLoginAsForm: false } )
}
/>
<ToggleControl
__nextHasNoMarginBottom
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Display login as form' ) }
checked={ displayLoginAsForm }
onChange={ () =>
setAttributes( {
displayLoginAsForm: ! displayLoginAsForm,
} )
}
/>
</ToolsPanelItem>
<ToolsPanelItem
label={ __( 'Redirect to current URL' ) }
checked={ redirectToCurrent }
onChange={ () =>
setAttributes( {
redirectToCurrent: ! redirectToCurrent,
} )
isShownByDefault
hasValue={ () => ! redirectToCurrent }
onDeselect={ () =>
setAttributes( { redirectToCurrent: true } )
}
/>
</PanelBody>
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Redirect to current URL' ) }
checked={ redirectToCurrent }
onChange={ () =>
setAttributes( {
redirectToCurrent: ! redirectToCurrent,
} )
}
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<div
{ ...useBlockProps( {
Expand Down

0 comments on commit fbaf1d2

Please sign in to comment.