From ea76a8611bab329ca982744aaad65dd4f83b6456 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:44:37 +1000 Subject: [PATCH] Use new block styles control --- .../src/components/block-styles/index.js | 72 +++++-------------- .../src/components/block-styles/style.scss | 4 ++ 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/packages/block-editor/src/components/block-styles/index.js b/packages/block-editor/src/components/block-styles/index.js index a9fdbe94356ef..978c966d06889 100644 --- a/packages/block-editor/src/components/block-styles/index.js +++ b/packages/block-editor/src/components/block-styles/index.js @@ -1,22 +1,14 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - /** * WordPress dependencies */ import { useState } from '@wordpress/element'; import { debounce, useViewportMatch } from '@wordpress/compose'; -import { - Button, - __experimentalTruncate as Truncate, - Popover, -} from '@wordpress/components'; +import { Popover } from '@wordpress/components'; /** * Internal dependencies */ +import BlockStylesControl from './block-styles-control'; import BlockStylesPreviewPanel from './preview-panel'; import useStylesForBlocks from './use-styles-for-block'; @@ -30,10 +22,7 @@ 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 +32,31 @@ 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 ); }; return (
-
- { stylesToRender.map( ( style ) => { - const buttonText = style.label || style.name; - - return ( - - ); - } ) } -
+ { hoveredStyle && ! isMobileViewport && (
styleItemHandler( null ) } + onMouseLeave={ () => hoverStyleHandler( null ) } >