Skip to content

Commit

Permalink
BlockSwitcher: Refactor to use Button layout properly (#67502)
Browse files Browse the repository at this point in the history
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
  • Loading branch information
3 people authored Dec 3, 2024
1 parent 7631986 commit 47718ab
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

1 comment on commit 47718ab

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 47718ab.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12144393276
📝 Reported issues:

Please sign in to comment.