diff --git a/packages/block-editor/src/components/block-styles/index.js b/packages/block-editor/src/components/block-styles/index.js
index a9fdbe94356ef6..b9d53a3fc2bac1 100644
--- a/packages/block-editor/src/components/block-styles/index.js
+++ b/packages/block-editor/src/components/block-styles/index.js
@@ -1,28 +1,50 @@
-/**
- * External dependencies
- */
-import classnames from 'classnames';
-
/**
* WordPress dependencies
*/
-import { useState } from '@wordpress/element';
-import { debounce, useViewportMatch } from '@wordpress/compose';
import {
- Button,
- __experimentalTruncate as Truncate,
+ ColorIndicator,
+ Flex,
+ FlexItem,
Popover,
+ privateApis as componentsPrivateApis,
+ __experimentalHStack as HStack,
+ __experimentalZStack as ZStack,
} from '@wordpress/components';
+import { debounce, useViewportMatch } from '@wordpress/compose';
+import { useState } from '@wordpress/element';
+import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
+import { unlock } from '../../lock-unlock';
import BlockStylesPreviewPanel from './preview-panel';
import useStylesForBlocks from './use-styles-for-block';
+import { getDefaultStyle } from './utils';
const noop = () => {};
+const { CustomSelect, CustomSelectItem } = unlock( componentsPrivateApis );
+
+const BlockStyleItem = ( { blockStyle } ) => {
+ const indicators = [
+ blockStyle.styles?.color?.background,
+ blockStyle.styles?.color?.text,
+ ];
+
+ return (
+
+
+ { indicators.map( ( indicator, index ) => (
+
+
+
+ ) ) }
+
+ { blockStyle.label }
+
+ );
+};
-// Block Styles component for the Settings Sidebar.
function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) {
const {
onSelect,
@@ -30,10 +52,8 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) {
activeStyle,
genericPreviewBlock,
className: previewClassName,
- } = useStylesForBlocks( {
- clientId,
- onSwitch,
- } );
+ } = useStylesForBlocks( { clientId, onSwitch } );
+
const [ hoveredStyle, setHoveredStyle ] = useState( null );
const isMobileViewport = useViewportMatch( 'medium', '<' );
@@ -43,58 +63,64 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) {
const debouncedSetHoveredStyle = debounce( setHoveredStyle, 250 );
- const onSelectStylePreview = ( style ) => {
- onSelect( style );
+ const handleOnChange = ( style ) => {
+ onSelect( { name: style } );
onHoverClassName( null );
setHoveredStyle( null );
debouncedSetHoveredStyle.cancel();
};
- const styleItemHandler = ( item ) => {
- if ( hoveredStyle === item ) {
+ const hoverStyleHandler = ( style ) => {
+ if ( hoveredStyle === style ) {
debouncedSetHoveredStyle.cancel();
return;
}
- debouncedSetHoveredStyle( item );
- onHoverClassName( item?.name ?? null );
+
+ debouncedSetHoveredStyle( style );
+ onHoverClassName( style?.name ?? null );
+ };
+
+ const renderSelectedBlockStlye = ( currentStyle ) => {
+ const currentBlockStyle = stylesToRender.find(
+ ( style ) => style.name === currentStyle
+ );
+
+ if ( ! currentBlockStyle ) {
+ return null;
+ }
+
+ return ;
};
+ const defaultStyle = getDefaultStyle( stylesToRender );
+
return (
-
- { stylesToRender.map( ( style ) => {
- const buttonText = style.label || style.name;
-
- return (
-
- );
- } ) }
-
+
+ { stylesToRender.map( ( blockStyle, index ) => (
+ hoverStyleHandler( blockStyle ) }
+ onMouseLeave={ () => hoverStyleHandler( null ) }
+ onFocus={ () => hoverStyleHandler( blockStyle ) }
+ onBlur={ () => hoverStyleHandler( null ) }
+ >
+
+
+ ) ) }
+
{ hoveredStyle && ! isMobileViewport && (
styleItemHandler( null ) }
+ onMouseLeave={ () => hoverStyleHandler( null ) }
>
{
- const { getBlock } = select( blockEditorStore );
+ const { getBlock, getSettings } = select( blockEditorStore );
const block = getBlock( clientId );
if ( ! block ) {
return {};
}
+
const blockType = getBlockType( block.name );
const { getBlockStyles } = select( blocksStore );
+ const styles = getBlockStyles( block.name );
+
+ // Add theme.json styles for each block style if available.
+ const variations =
+ getSettings().__experimentalStyles?.blocks?.[ block.name ]
+ ?.variations ?? {};
+
+ if ( variations ) {
+ styles?.forEach( ( style, index ) => {
+ if ( variations[ style.name ] ) {
+ styles[ index ].styles = variations[ style.name ];
+ }
+ } );
+ }
return {
block,
blockType,
- styles: getBlockStyles( block.name ),
+ styles,
className: block.attributes.className || '',
};
};