Skip to content

Commit

Permalink
Archive Title Block: Refactor settings panel to use ToolsPanel (#67915)
Browse files Browse the repository at this point in the history
* Image size fix in lightbox

* Revert "Image size fix in lightbox"

This reverts commit 63f81c1.

* Update toolspanel to archive title block

* Feedback changes updated

* Feedback changes updated

* Feedback changes updated

* Feedback updates

Co-authored-by: karthick-murugan <karthickmurugan@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
4 people authored Jan 14, 2025
1 parent 669662c commit 994bc80
Showing 1 changed file with 60 additions and 19 deletions.
79 changes: 60 additions & 19 deletions packages/block-library/src/query-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ import {
Warning,
HeadingLevelDropdown,
} from '@wordpress/block-editor';
import { ToggleControl, PanelBody } from '@wordpress/components';
import {
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __, _x, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useArchiveLabel } from './use-archive-label';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const SUPPORTED_TYPES = [ 'archive', 'search' ];

Expand All @@ -36,6 +41,7 @@ export default function QueryTitleEdit( {
setAttributes,
} ) {
const { archiveTypeLabel, archiveNameLabel } = useArchiveLabel();
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

const TagName = `h${ level }`;
const blockProps = useBlockProps( {
Expand Down Expand Up @@ -89,16 +95,35 @@ export default function QueryTitleEdit( {
titleElement = (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () =>
setAttributes( {
showPrefix: true,
} )
}
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
hasValue={ () => ! showPrefix }
label={ __( 'Show archive type in title' ) }
onChange={ () =>
setAttributes( { showPrefix: ! showPrefix } )
onDeselect={ () =>
setAttributes( { showPrefix: true } )
}
checked={ showPrefix }
/>
</PanelBody>
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show archive type in title' ) }
onChange={ () =>
setAttributes( {
showPrefix: ! showPrefix,
} )
}
checked={ showPrefix }
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<TagName { ...blockProps }>{ title }</TagName>
</>
Expand All @@ -109,18 +134,34 @@ export default function QueryTitleEdit( {
titleElement = (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () =>
setAttributes( {
showSearchTerm: true,
} )
}
>
<ToolsPanelItem
hasValue={ () => ! showSearchTerm }
label={ __( 'Show search term in title' ) }
onChange={ () =>
setAttributes( {
showSearchTerm: ! showSearchTerm,
} )
onDeselect={ () =>
setAttributes( { showSearchTerm: true } )
}
checked={ showSearchTerm }
/>
</PanelBody>
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show search term in title' ) }
onChange={ () =>
setAttributes( {
showSearchTerm: ! showSearchTerm,
} )
}
checked={ showSearchTerm }
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>

<TagName { ...blockProps }>
Expand Down

0 comments on commit 994bc80

Please sign in to comment.