Repository navigation
Make inspector style transform previews consistent with toolbar transforms #75989
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,11 @@ import clsx from 'clsx'; | |
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useState } from '@wordpress/element'; | ||
| import { debounce, useViewportMatch } from '@wordpress/compose'; | ||
| import { useState, useMemo } from '@wordpress/element'; | ||
| import { debounce } from '@wordpress/compose'; | ||
| import { | ||
| Button, | ||
| __experimentalTruncate as Truncate, | ||
| Popover, | ||
| __experimentalToolsPanel as ToolsPanel, | ||
| __experimentalToolsPanelItem as ToolsPanelItem, | ||
| } from '@wordpress/components'; | ||
|
|
@@ -20,10 +19,10 @@ import { __ } from '@wordpress/i18n'; | |
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import BlockStylesPreviewPanel from './preview-panel'; | ||
| import PreviewBlockPopover from '../block-switcher/preview-block-popover'; | ||
| import useStylesForBlocks from './use-styles-for-block'; | ||
| import { useToolsPanelDropdownMenuProps } from '../global-styles/utils'; | ||
| import { getDefaultStyle } from './utils'; | ||
| import { getDefaultStyle, replaceActiveStyle } from './utils'; | ||
|
|
||
| const noop = () => {}; | ||
|
|
||
|
|
@@ -34,15 +33,35 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) { | |
| stylesToRender, | ||
| activeStyle, | ||
| genericPreviewBlock, | ||
| className: previewClassName, | ||
| className, | ||
| } = useStylesForBlocks( { | ||
| clientId, | ||
| onSwitch, | ||
| } ); | ||
| const [ hoveredStyle, setHoveredStyle ] = useState( null ); | ||
| const isMobileViewport = useViewportMatch( 'medium', '<' ); | ||
| const [ blockStylesAnchor, setBlockStylesAnchor ] = useState( null ); | ||
| const dropdownMenuProps = useToolsPanelDropdownMenuProps(); | ||
|
|
||
| const previewBlocks = useMemo( () => { | ||
| if ( ! hoveredStyle || ! genericPreviewBlock ) { | ||
| return null; | ||
| } | ||
| const previewClassName = replaceActiveStyle( | ||
| className, | ||
| activeStyle, | ||
| hoveredStyle | ||
| ); | ||
| return [ | ||
| { | ||
| ...genericPreviewBlock, | ||
| attributes: { | ||
| ...( genericPreviewBlock.attributes || {} ), | ||
| className: previewClassName, | ||
| }, | ||
| }, | ||
| ]; | ||
| }, [ hoveredStyle, genericPreviewBlock, className, activeStyle ] ); | ||
|
Comment on lines
+45
to
+63
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking comment. https://github.com/WordPress/gutenberg/blob/try/consistent-transform-previews/packages/block-editor/src/components/block-switcher/block-styles-menu.js#L29-L47 has the same code block. Could be a candidate for extraction into a small hook
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I wondered whether it would be worth a hook or a wrapper for |
||
|
|
||
| if ( ! stylesToRender || stylesToRender.length === 0 ) { | ||
| return null; | ||
| } | ||
|
|
@@ -90,7 +109,10 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) { | |
| isShownByDefault | ||
| panelId={ clientId } | ||
| > | ||
| <div className="block-editor-block-styles"> | ||
| <div | ||
| ref={ setBlockStylesAnchor } | ||
| className="block-editor-block-styles" | ||
| > | ||
| <div className="block-editor-block-styles__variants"> | ||
| { stylesToRender.map( ( style ) => { | ||
| const buttonText = style.label || style.name; | ||
|
|
@@ -133,24 +155,13 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) { | |
| ); | ||
| } ) } | ||
| </div> | ||
| { hoveredStyle && ! isMobileViewport && ( | ||
| <Popover | ||
| { previewBlocks && ( | ||
| <PreviewBlockPopover | ||
| blocks={ previewBlocks } | ||
| placement="left-start" | ||
| offset={ 34 } | ||
| focusOnMount={ false } | ||
| > | ||
| <div | ||
| className="block-editor-block-styles__preview-panel" | ||
| onMouseLeave={ () => styleItemHandler( null ) } | ||
| > | ||
| <BlockStylesPreviewPanel | ||
| activeStyle={ activeStyle } | ||
| className={ previewClassName } | ||
| genericPreviewBlock={ genericPreviewBlock } | ||
| style={ hoveredStyle } | ||
| /> | ||
| </div> | ||
| </Popover> | ||
| anchor={ blockStylesAnchor } | ||
| /> | ||
| ) } | ||
| </div> | ||
| </ToolsPanelItem> | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is now no longer used and can be deleted, possibly the accompanying styles in
.block-editor-block-styles__preview-panelThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this should be safe to delete because it's not exported outside of the block styles component, well spotted!