Skip to content

Commit

Permalink
BlockSwitcher: Refactor to use Button layout properly (WordPress#67502)
Browse files Browse the repository at this point in the history
Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored and im3dabasia committed Dec 4, 2024
1 parent 263ac92 commit 6194aec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
40 changes: 19 additions & 21 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import { copy } from '@wordpress/icons';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand Down Expand Up @@ -185,21 +186,6 @@ function BlockSwitcherDropdownMenuContents( {
);
}

const BlockIndicator = ( { icon, showTitle, blockTitle } ) => (
<>
<BlockIcon
className="block-editor-block-switcher__toggle"
icon={ icon }
showColors
/>
{ showTitle && blockTitle && (
<span className="block-editor-block-switcher__toggle-text">
{ blockTitle }
</span>
) }
</>
);

export const BlockSwitcher = ( { clientIds } ) => {
const {
hasContentOnlyLocking,
Expand Down Expand Up @@ -272,6 +258,11 @@ export const BlockSwitcher = ( { clientIds } ) => {
clientId: clientIds?.[ 0 ],
maximumLength: 35,
} );
const showIconLabels = useSelect(
( select ) =>
select( preferencesStore ).get( 'core', 'showIconLabels' ),
[]
);

if ( invalidBlocks ) {
return null;
Expand All @@ -282,6 +273,11 @@ export const BlockSwitcher = ( { clientIds } ) => {
? blockTitle
: __( 'Multiple blocks selected' );

const blockIndicatorText =
( isReusable || isTemplate ) && ! showIconLabels && blockTitle
? blockTitle
: undefined;

const hideDropdown =
isDisabled ||
( ! hasBlockStyles && ! canRemove ) ||
Expand All @@ -295,12 +291,13 @@ export const BlockSwitcher = ( { clientIds } ) => {
className="block-editor-block-switcher__no-switcher-icon"
title={ blockSwitcherLabel }
icon={
<BlockIndicator
<BlockIcon
className="block-editor-block-switcher__toggle"
icon={ icon }
showTitle={ isReusable || isTemplate }
blockTitle={ blockTitle }
showColors
/>
}
text={ blockIndicatorText }
/>
</ToolbarGroup>
);
Expand Down Expand Up @@ -329,12 +326,13 @@ export const BlockSwitcher = ( { clientIds } ) => {
className: 'block-editor-block-switcher__popover',
} }
icon={
<BlockIndicator
<BlockIcon
className="block-editor-block-switcher__toggle"
icon={ icon }
showTitle={ isReusable || isTemplate }
blockTitle={ blockTitle }
showColors
/>
}
text={ blockIndicatorText }
toggleProps={ {
description: blockSwitcherDescription,
...toggleProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@
}
}

.block-editor-block-switcher__toggle-text {
margin-left: $grid-unit-10;

// Account for double label when show-text-buttons is set.
.show-icon-labels & {
display: none;
}
}

.components-button.block-editor-block-switcher__no-switcher-icon {
display: flex;

Expand Down

0 comments on commit 6194aec

Please sign in to comment.