diff --git a/lib/block-editor-settings.php b/lib/block-editor-settings.php index 53668e114e04cb..ba726ffe2ad5b9 100644 --- a/lib/block-editor-settings.php +++ b/lib/block-editor-settings.php @@ -78,6 +78,7 @@ function gutenberg_get_block_editor_settings( $settings ) { $settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); + $settings['__experimentalStyles'] = gutenberg_get_global_styles(); $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); // These settings may need to be updated based on data coming from theme.json sources. if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) { diff --git a/lib/experimental/class-wp-rest-block-editor-settings-controller.php b/lib/experimental/class-wp-rest-block-editor-settings-controller.php index 510ae573e3de8e..ae6c4852166700 100644 --- a/lib/experimental/class-wp-rest-block-editor-settings-controller.php +++ b/lib/experimental/class-wp-rest-block-editor-settings-controller.php @@ -157,7 +157,7 @@ public function get_item_schema() { '__experimentalStyles' => array( 'description' => __( 'Styles consolidated from core, theme, and user origins.', 'gutenberg' ), 'type' => 'object', - 'context' => array( 'mobile' ), + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor', 'mobile' ), ), '__experimentalEnableQuoteBlockV2' => array( 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 ) } >