-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Editor: Move 'ParentSelectorMenuItem' into a separate folder
- Loading branch information
Showing
2 changed files
with
55 additions
and
43 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/block-editor/src/components/block-settings-menu/block-parent-selector-menu-item.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,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRef } from '@wordpress/element'; | ||
import { MenuItem } from '@wordpress/components'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
import { useShowHoveredOrFocusedGestures } from '../block-toolbar/utils'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
export default function BlockParentSelectorMenuItem( { | ||
parentClientId, | ||
parentBlockType, | ||
} ) { | ||
const isSmallViewport = useViewportMatch( 'medium', '<' ); | ||
const { selectBlock } = useDispatch( blockEditorStore ); | ||
|
||
// Allows highlighting the parent block outline when focusing or hovering | ||
// the parent block selector within the child. | ||
const menuItemRef = useRef(); | ||
const gesturesProps = useShowHoveredOrFocusedGestures( { | ||
ref: menuItemRef, | ||
highlightParent: true, | ||
} ); | ||
|
||
if ( ! isSmallViewport ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<MenuItem | ||
{ ...gesturesProps } | ||
ref={ menuItemRef } | ||
icon={ <BlockIcon icon={ parentBlockType.icon } /> } | ||
onClick={ () => selectBlock( parentClientId ) } | ||
> | ||
{ sprintf( | ||
/* translators: %s: Name of the block's parent. */ | ||
__( 'Select parent block (%s)' ), | ||
parentBlockType.title | ||
) } | ||
</MenuItem> | ||
); | ||
} |
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