Skip to content

Commit

Permalink
Table of Contents Block: Refactor settings panel to use ToolsPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukhendu2002 committed Dec 13, 2024
1 parent 8d6b8c5 commit fb06c23
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions packages/block-library/src/table-of-contents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
} from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import {
PanelBody,
Placeholder,
ToggleControl,
ToolbarButton,
ToolbarGroup,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { renderToString } from '@wordpress/element';
Expand Down Expand Up @@ -108,25 +109,41 @@ export default function TableOfContentsEdit( {

const inspectorControls = (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
onlyIncludeCurrentPage: false,
} );
} }
>
<ToolsPanelItem
hasValue={ () => onlyIncludeCurrentPage !== false }
label={ __( 'Only include current page' ) }
checked={ onlyIncludeCurrentPage }
onChange={ ( value ) =>
setAttributes( { onlyIncludeCurrentPage: value } )
onDeselect={ () =>
setAttributes( { onlyIncludeCurrentPage: false } )
}
help={
onlyIncludeCurrentPage
? __(
'Only including headings from the current page (if the post is paginated).'
)
: __(
'Toggle to only include headings from the current page (if the post is paginated).'
)
}
/>
</PanelBody>
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Only include current page' ) }
checked={ onlyIncludeCurrentPage }
onChange={ ( value ) =>
setAttributes( { onlyIncludeCurrentPage: value } )
}
help={
onlyIncludeCurrentPage
? __(
'Only including headings from the current page (if the post is paginated).'
)
: __(
'Toggle to only include headings from the current page (if the post is paginated).'
)
}
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
);

Expand Down

0 comments on commit fb06c23

Please sign in to comment.