-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Template Parts & Reusable Blocks - try overlay element for clickthrou…
…gh to edit pattern. (#31109) * clickthrough for template part * make store names more consistent and accurate * remove unnecessary selector change * move color from hover to selected, add opacity value * Add hover overlay * bleh resizing issues * kind of working... * remove unnecessary popover goo * fix for nested template parts and selection bleeding out of boundary * remove unnecessary effect/state * fix resizing issue * try only selected color when focused * cleanup css * try overlay for initial selection only * enable drag and drop * only show borders on drag and drop * ensure background color not on drag and drop * apply to reusable blocks * fix e2e tests * try add basic test * try fix test * only use the afterEach where needed * use css vars * fix border color * fix block toolbar issue * fix width on classic themes * fix width by moving overlay inside block wrapper * fix bug with selection from list view * add condition to dismissing * show overlay when highlighting list view * use selector for highlight style * refactor and comments * position overlay above resize containers * fix nested entity test * fix template part test * fix intermittent errors on conversion tests * remove box shadow on hover - block hover style will already be present * add border back to overlay * use blockProps in innerBlockProps as well * cleanup which blockProps are passed to innerBlockProps * use component as wrapper * remove unnecessary layout selectors on TP e2es * fix reusable blocks test xpath Co-authored-by: James Koster <[email protected]>
- Loading branch information
1 parent
1be1059
commit afee31e
Showing
14 changed files
with
227 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Converts a hex value into the rgb equivalent. | ||
* | ||
* @param {string} hex - the hexadecimal value to convert | ||
* @return {string} comma separated rgb values | ||
*/ | ||
@function hex-to-rgb($hex) { | ||
@return red($hex), green($hex), blue($hex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/block-editor/src/components/block-content-overlay/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
export default function BlockContentOverlay( { | ||
clientId, | ||
tagName: TagName = 'div', | ||
wrapperProps, | ||
className, | ||
} ) { | ||
const baseClassName = 'block-editor-block-content-overlay'; | ||
const [ isOverlayActive, setIsOverlayActive ] = useState( true ); | ||
const [ isHovered, setIsHovered ] = useState( false ); | ||
|
||
const { | ||
isParentSelected, | ||
hasChildSelected, | ||
isDraggingBlocks, | ||
isParentHighlighted, | ||
} = useSelect( | ||
( select ) => { | ||
const { | ||
isBlockSelected, | ||
hasSelectedInnerBlock, | ||
isDraggingBlocks: _isDraggingBlocks, | ||
isBlockHighlighted, | ||
} = select( blockEditorStore ); | ||
return { | ||
isParentSelected: isBlockSelected( clientId ), | ||
hasChildSelected: hasSelectedInnerBlock( clientId, true ), | ||
isDraggingBlocks: _isDraggingBlocks(), | ||
isParentHighlighted: isBlockHighlighted( clientId ), | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
|
||
const classes = classnames( | ||
baseClassName, | ||
wrapperProps?.className, | ||
className, | ||
{ | ||
'overlay-active': isOverlayActive, | ||
'parent-highlighted': isParentHighlighted, | ||
'is-dragging-blocks': isDraggingBlocks, | ||
} | ||
); | ||
|
||
useEffect( () => { | ||
// Reenable when blocks are not in use. | ||
if ( ! isParentSelected && ! hasChildSelected && ! isOverlayActive ) { | ||
setIsOverlayActive( true ); | ||
} | ||
// Disable if parent selected by another means (such as list view). | ||
// We check hover to ensure the overlay click interaction is not taking place. | ||
// Trying to click the overlay will select the parent block via its 'focusin' | ||
// listener on the wrapper, so if the block is selected while hovered we will | ||
// let the mouseup disable the overlay instead. | ||
if ( isParentSelected && ! isHovered && isOverlayActive ) { | ||
setIsOverlayActive( false ); | ||
} | ||
// Ensure overlay is disabled if a child block is selected. | ||
if ( hasChildSelected && isOverlayActive ) { | ||
setIsOverlayActive( false ); | ||
} | ||
}, [ isParentSelected, hasChildSelected, isOverlayActive, isHovered ] ); | ||
|
||
// Disabled because the overlay div doesn't actually have a role or functionality | ||
// as far as the a11y is concerned. We're just catching the first click so that | ||
// the block can be selected without interacting with its contents. | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
return ( | ||
<TagName | ||
{ ...wrapperProps } | ||
className={ classes } | ||
onMouseEnter={ () => setIsHovered( true ) } | ||
onMouseLeave={ () => setIsHovered( false ) } | ||
> | ||
{ isOverlayActive && ( | ||
<div | ||
className={ `${ baseClassName }__overlay` } | ||
onMouseUp={ () => setIsOverlayActive( false ) } | ||
/> | ||
) } | ||
{ wrapperProps?.children } | ||
</TagName> | ||
); | ||
} | ||
/* eslint-enable jsx-a11y/no-static-element-interactions */ |
41 changes: 41 additions & 0 deletions
41
packages/block-editor/src/components/block-content-overlay/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Specificity required to ensure overlay width is not restricted to that | ||
// of standard block content. The overlay's width should be as wide as | ||
// its children require. | ||
.editor-styles-wrapper .wp-block .block-editor-block-content-overlay__overlay { | ||
max-width: none; | ||
} | ||
|
||
.block-editor-block-content-overlay { | ||
.block-editor-block-content-overlay__overlay { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background: transparent; | ||
border: none; | ||
border-radius: $radius-block-ui; | ||
z-index: z-index(".block-editor-block-content-overlay__overlay"); | ||
} | ||
|
||
&:hover:not(.is-dragging-blocks), | ||
&.parent-highlighted { | ||
> .block-editor-block-content-overlay__overlay { | ||
background: rgba(var(--wp-admin-theme-color--rgb), 0.1); | ||
box-shadow: 0 0 0 $border-width var(--wp-admin-theme-color) inset; | ||
} | ||
} | ||
|
||
&.overlay-active:not(.is-dragging-blocks) { | ||
*:not(.block-editor-block-content-overlay__overlay) { | ||
pointer-events: none; | ||
} | ||
} | ||
|
||
&.is-dragging-blocks { | ||
box-shadow: 0 0 0 $border-width var(--wp-admin-theme-color); | ||
.block-editor-block-content-overlay__overlay { | ||
pointer-events: none; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.