Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section styles switch button in block toolbar in zoom out mode #67140

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import __unstableBlockNameContext from './block-name-context';
import NavigableToolbar from '../navigable-toolbar';
import { useHasBlockToolbar } from './use-has-block-toolbar';
import ChangeDesign from './change-design';
import SwitchSectionStyle from './switch-section-style';
import { unlock } from '../../lock-unlock';

/**
Expand Down Expand Up @@ -72,6 +73,7 @@ export function PrivateBlockToolbar( {
showSlots,
showGroupButtons,
showLockButtons,
showSwitchSectionStyleButton,
} = useSelect( ( select ) => {
const {
getBlockName,
Expand Down Expand Up @@ -141,6 +143,7 @@ export function PrivateBlockToolbar( {
showSlots: ! isZoomOut(),
showGroupButtons: ! isZoomOut(),
showLockButtons: ! isZoomOut(),
showSwitchSectionStyleButton: isZoomOut(),
};
}, [] );

Expand Down Expand Up @@ -222,6 +225,9 @@ export function PrivateBlockToolbar( {
{ showShuffleButton && (
<ChangeDesign clientId={ blockClientIds[ 0 ] } />
) }
{ showSwitchSectionStyleButton && (
<SwitchSectionStyle clientId={ blockClientIds[ 0 ] } />
) }
{ shouldShowVisualToolbar && showSlots && (
<>
<BlockControls.Slot
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* WordPress dependencies
*/
import {
ToolbarButton,
ToolbarGroup,
Dropdown,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
Icon,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { color } from '@wordpress/icons';

/**
* Internal dependencies
*/
import BlockStyles from '../block-styles';
import useStylesForBlocks from '../block-styles/use-styles-for-block';

const POPOVER_PROPS = {
placement: 'bottom-start',
};

function SwitchSectionStyle( { clientId } ) {
const { stylesToRender } = useStylesForBlocks( { clientId } );

if ( ! stylesToRender || stylesToRender.length === 0 ) {
return null;
}

return (
<Dropdown
popoverProps={ POPOVER_PROPS }
renderToggle={ ( { onToggle, isOpen } ) => {
return (
<ToolbarGroup>
<ToolbarButton
onClick={ () => onToggle( ! isOpen ) }
aria-expanded={ isOpen }
label={ __( 'Styles' ) }
>
<Icon icon={ color } />
</ToolbarButton>
</ToolbarGroup>
);
} }
renderContent={ () => (
<DropdownContentWrapper
className="block-editor-block-toolbar-change-design-content-wrapper"
paddingSize="none"
>
<BlockStyles clientId={ clientId } />
</DropdownContentWrapper>
) }
/>
);
}

export default SwitchSectionStyle;
Loading