Skip to content

Commit

Permalink
Refactor "Settings" panel of Excerpt block to use ToolsPanel instead …
Browse files Browse the repository at this point in the history
…of PanelBody (WordPress#67908)

Co-authored-by: Sukhendu2002 <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent c8cdff3 commit 0d7f1e3
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions packages/block-library/src/post-excerpt/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
Warning,
useBlockProps,
} from '@wordpress/block-editor';
import { PanelBody, ToggleControl, RangeControl } from '@wordpress/components';
import {
ToggleControl,
RangeControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

Expand Down Expand Up @@ -219,29 +224,55 @@ export default function PostExcerptEditor( {
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
showMoreOnNewLine: true,
excerptLength: 55,
} );
} }
>
<ToolsPanelItem
hasValue={ () => showMoreOnNewLine !== true }
label={ __( 'Show link on new line' ) }
checked={ showMoreOnNewLine }
onChange={ ( newShowMoreOnNewLine ) =>
setAttributes( {
showMoreOnNewLine: newShowMoreOnNewLine,
} )
onDeselect={ () =>
setAttributes( { showMoreOnNewLine: true } )
}
/>
<RangeControl
__next40pxDefaultSize
__nextHasNoMarginBottom
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show link on new line' ) }
checked={ showMoreOnNewLine }
onChange={ ( newShowMoreOnNewLine ) =>
setAttributes( {
showMoreOnNewLine: newShowMoreOnNewLine,
} )
}
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => excerptLength !== 55 }
label={ __( 'Max number of words' ) }
value={ excerptLength }
onChange={ ( value ) => {
setAttributes( { excerptLength: value } );
} }
min="10"
max="100"
/>
</PanelBody>
onDeselect={ () =>
setAttributes( { excerptLength: 55 } )
}
isShownByDefault
>
<RangeControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Max number of words' ) }
value={ excerptLength }
onChange={ ( value ) => {
setAttributes( { excerptLength: value } );
} }
min="10"
max="100"
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<div { ...blockProps }>
{ excerptContent }
Expand Down

0 comments on commit 0d7f1e3

Please sign in to comment.