Skip to content

Commit

Permalink
Refactor "Settings" panel of Tag Cloud block to use ToolsPanel instea…
Browse files Browse the repository at this point in the history
…d of PanelBody (WordPress#67911)

Co-authored-by: Sukhendu2002 <sukhendu2002@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent bae6236 commit 18e4eda
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
61 changes: 53 additions & 8 deletions packages/block-library/src/tag-cloud/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import {
Flex,
FlexItem,
PanelBody,
ToggleControl,
SelectControl,
RangeControl,
__experimentalUnitControl as UnitControl,
__experimentalUseCustomUnits as useCustomUnits,
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
__experimentalVStack as VStack,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
Disabled,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -118,10 +118,25 @@ function TagCloudEdit( { attributes, setAttributes } ) {

const inspectorControls = (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<VStack
spacing={ 4 }
className="wp-block-tag-cloud__inspector-settings"
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
taxonomy: 'post_tag',
showTagCounts: false,
numberOfTags: 45,
smallestFontSize: '8pt',
largestFontSize: '22pt',
} );
} }
>
<ToolsPanelItem
hasValue={ () => taxonomy !== 'post_tag' }
label={ __( 'Taxonomy' ) }
onDeselect={ () =>
setAttributes( { taxonomy: 'post_tag' } )
}
isShownByDefault
>
<SelectControl
__nextHasNoMarginBottom
Expand All @@ -133,6 +148,20 @@ function TagCloudEdit( { attributes, setAttributes } ) {
setAttributes( { taxonomy: selectedTaxonomy } )
}
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () =>
smallestFontSize !== '8pt' || largestFontSize !== '22pt'
}
label={ __( 'Font size' ) }
onDeselect={ () =>
setAttributes( {
smallestFontSize: '8pt',
largestFontSize: '22pt',
} )
}
isShownByDefault
>
<Flex gap={ 4 }>
<FlexItem isBlock>
<UnitControl
Expand Down Expand Up @@ -167,6 +196,13 @@ function TagCloudEdit( { attributes, setAttributes } ) {
/>
</FlexItem>
</Flex>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => numberOfTags !== 45 }
label={ __( 'Number of tags' ) }
onDeselect={ () => setAttributes( { numberOfTags: 45 } ) }
isShownByDefault
>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
Expand All @@ -179,6 +215,15 @@ function TagCloudEdit( { attributes, setAttributes } ) {
max={ MAX_TAGS }
required
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => showTagCounts !== false }
label={ __( 'Show tag counts' ) }
onDeselect={ () =>
setAttributes( { showTagCounts: false } )
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show tag counts' ) }
Expand All @@ -187,8 +232,8 @@ function TagCloudEdit( { attributes, setAttributes } ) {
setAttributes( { showTagCounts: ! showTagCounts } )
}
/>
</VStack>
</PanelBody>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
);

Expand Down
8 changes: 0 additions & 8 deletions packages/block-library/src/tag-cloud/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@
border: none;
border-radius: inherit;
}

.wp-block-tag-cloud__inspector-settings {
.components-base-control,
.components-base-control:last-child {
// Cancel out extra margins added by block inspector
margin-bottom: 0;
}
}

0 comments on commit 18e4eda

Please sign in to comment.