-
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.
Flash editable block outlines instead of always showing them
Updates the editable block outlines that appear within content-locked containers (added in #57901) to appear and then fade out after 3s when: - The page loads; or - The user clicks on the content-locked container. This is done via a private useFlashEditableBlocks() hook attached to the container.
- Loading branch information
1 parent
54fc929
commit c0d4e8b
Showing
8 changed files
with
109 additions
and
60 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
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
48 changes: 48 additions & 0 deletions
48
packages/block-editor/src/components/use-flash-editable-blocks/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,48 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRefEffect } from '@wordpress/compose'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
export default function useFlashEditableBlocks( rootClientId = '' ) { | ||
const { getEnabledClientIdsTree } = unlock( useSelect( blockEditorStore ) ); | ||
|
||
return useRefEffect( ( element ) => { | ||
const flashEditableBlocks = () => { | ||
getEnabledClientIdsTree( rootClientId ).forEach( | ||
( { clientId } ) => { | ||
const blockElement = element.querySelector( | ||
`[data-block="${ clientId }"]` | ||
); | ||
if ( ! blockElement ) { | ||
return; | ||
} | ||
blockElement.classList.remove( 'has-editable-outline' ); | ||
// Force reflow to trigger the animation. | ||
// eslint-disable-next-line no-unused-expressions | ||
blockElement.offsetWidth; | ||
blockElement.classList.add( 'has-editable-outline' ); | ||
} | ||
); | ||
}; | ||
|
||
const handleClick = ( event ) => { | ||
if ( event.defaultPrevented ) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
flashEditableBlocks(); | ||
}; | ||
|
||
element.addEventListener( 'click', handleClick ); | ||
return () => { | ||
element.removeEventListener( 'click', handleClick ); | ||
}; | ||
} ); | ||
} |
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