From fb06c231a0933ea6d6c7bfd92679b7c9998ebd33 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 13 Dec 2024 12:13:18 +0530 Subject: [PATCH 1/3] Table of Contents Block: Refactor settings panel to use ToolsPanel --- .../src/table-of-contents/edit.js | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/packages/block-library/src/table-of-contents/edit.js b/packages/block-library/src/table-of-contents/edit.js index c95b89200cb88..2a545da3ae8bc 100644 --- a/packages/block-library/src/table-of-contents/edit.js +++ b/packages/block-library/src/table-of-contents/edit.js @@ -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'; @@ -108,25 +109,41 @@ export default function TableOfContentsEdit( { const inspectorControls = ( - - { + setAttributes( { + onlyIncludeCurrentPage: false, + } ); + } } + > + 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).' - ) - } - /> - + isShownByDefault + > + + 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).' + ) + } + /> + + ); From 904da77204abff42455b4dfa2efd1833705fb700 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Tue, 17 Dec 2024 12:45:15 +0530 Subject: [PATCH 2/3] Fix: Add dropdown menu props to ToolsPanel component --- packages/block-library/src/table-of-contents/edit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/table-of-contents/edit.js b/packages/block-library/src/table-of-contents/edit.js index 2a545da3ae8bc..0deca1a83abcb 100644 --- a/packages/block-library/src/table-of-contents/edit.js +++ b/packages/block-library/src/table-of-contents/edit.js @@ -30,6 +30,7 @@ import { tableOfContents as icon } from '@wordpress/icons'; import TableOfContentsList from './list'; import { linearToNestedHeadingList } from './utils'; import { useObserveHeadings } from './hooks'; +import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; /** @typedef {import('./utils').HeadingData} HeadingData */ @@ -80,7 +81,7 @@ export default function TableOfContentsEdit( { ); const { replaceBlocks } = useDispatch( blockEditorStore ); - + const dropdownMenuProps = useToolsPanelDropdownMenuProps(); const headingTree = linearToNestedHeadingList( headings ); const toolbarControls = canInsertList && ( @@ -116,6 +117,7 @@ export default function TableOfContentsEdit( { onlyIncludeCurrentPage: false, } ); } } + dropdownMenuProps={ dropdownMenuProps } > onlyIncludeCurrentPage !== false } From ab063f508b5abe6ec40b2bd76a053e0d30058a01 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 20 Dec 2024 11:35:09 +0530 Subject: [PATCH 3/3] Update translated string to avoid 'toggle' --- packages/block-library/src/table-of-contents/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/table-of-contents/edit.js b/packages/block-library/src/table-of-contents/edit.js index 0deca1a83abcb..2abc3a297490b 100644 --- a/packages/block-library/src/table-of-contents/edit.js +++ b/packages/block-library/src/table-of-contents/edit.js @@ -140,7 +140,7 @@ export default function TableOfContentsEdit( { '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).' + 'Include headings from all pages (if the post is paginated).' ) } />