diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js
index b3bf7e94accb08..ea068d8126526c 100644
--- a/packages/block-editor/src/components/block-toolbar/index.js
+++ b/packages/block-editor/src/components/block-toolbar/index.js
@@ -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';
/**
@@ -72,6 +73,7 @@ export function PrivateBlockToolbar( {
showSlots,
showGroupButtons,
showLockButtons,
+ showSwitchSectionStyleButton,
} = useSelect( ( select ) => {
const {
getBlockName,
@@ -141,6 +143,7 @@ export function PrivateBlockToolbar( {
showSlots: ! isZoomOut(),
showGroupButtons: ! isZoomOut(),
showLockButtons: ! isZoomOut(),
+ showSwitchSectionStyleButton: isZoomOut(),
};
}, [] );
@@ -222,6 +225,9 @@ export function PrivateBlockToolbar( {
{ showShuffleButton && (
) }
+ { showSwitchSectionStyleButton && (
+
+ ) }
{ shouldShowVisualToolbar && showSlots && (
<>
+
+
+
+);
+
+function SwitchSectionStyle( { clientId } ) {
+ const { stylesToRender, activeStyle, className } = useStylesForBlocks( {
+ clientId,
+ } );
+ const { updateBlockAttributes } = useDispatch( blockEditorStore );
+
+ // Get global styles data
+ const { merged: mergedConfig } = useContext( GlobalStylesContext );
+ const { globalSettings, globalStyles, blockName } = useSelect(
+ ( select ) => {
+ const settings = select( blockEditorStore ).getSettings();
+ return {
+ globalSettings: settings.__experimentalFeatures,
+ globalStyles: settings[ globalStylesDataKey ],
+ blockName: select( blockEditorStore ).getBlockName( clientId ),
+ };
+ },
+ [ clientId ]
+ );
+
+ // Get the background color for the active style
+ const activeStyleBackground = activeStyle?.name
+ ? getVariationStylesWithRefValues(
+ {
+ settings: mergedConfig?.settings ?? globalSettings,
+ styles: mergedConfig?.styles ?? globalStyles,
+ },
+ blockName,
+ activeStyle.name
+ )?.color?.background
+ : undefined;
+
+ if ( ! stylesToRender || stylesToRender.length === 0 ) {
+ return null;
+ }
+
+ const handleStyleSwitch = () => {
+ const currentIndex = stylesToRender.findIndex(
+ ( style ) => style.name === activeStyle.name
+ );
+
+ const nextIndex = ( currentIndex + 1 ) % stylesToRender.length;
+ const nextStyle = stylesToRender[ nextIndex ];
+
+ const styleClassName = replaceActiveStyle(
+ className,
+ activeStyle,
+ nextStyle
+ );
+
+ updateBlockAttributes( clientId, {
+ className: styleClassName,
+ } );
+ };
+
+ return (
+
+
+
+
+
+ );
+}
+
+export default SwitchSectionStyle;