-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add new Parent block selector to child blocks (mahjong) #21056
Changes from 27 commits
ea74f88
849fc12
97ae63d
dde200e
9c7e661
e9acd35
7ca1bb0
170edc5
409868b
b6d53c9
ba5efad
0f8aaf6
ac1990a
5e88bb6
90be934
e2e407d
6e14ab4
c3da3d2
89aec24
0a56fd3
5fad39f
a816121
6cf0c65
2f535e0
e8489c7
0708275
f093b85
f35d345
91529a3
0d4789d
349b08f
b05b2ba
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getBlockType } from '@wordpress/blocks'; | ||
import { Button } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
|
||
/** | ||
* Block parent selector component, displaying the hierarchy of the | ||
* current block selection as a single icon to "go up" a level. | ||
* | ||
* @return {WPElement} Parent block selector. | ||
*/ | ||
export default function BlockParentSelector() { | ||
const { selectBlock } = useDispatch( 'core/block-editor' ); | ||
const { parentBlockType, firstParentClientId } = useSelect( ( select ) => { | ||
const { | ||
getBlockName, | ||
getBlockParents, | ||
getSelectedBlockClientId, | ||
} = select( 'core/block-editor' ); | ||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
const parents = getBlockParents( selectedBlockClientId ); | ||
const _firstParentClientId = parents[ parents.length - 1 ]; | ||
const parentBlockName = getBlockName( _firstParentClientId ); | ||
return { | ||
parentBlockType: getBlockType( parentBlockName ), | ||
firstParentClientId: _firstParentClientId, | ||
}; | ||
}, [] ); | ||
ZebulanStanphill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if ( firstParentClientId !== undefined ) { | ||
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. Should we invert the condition and return early, it's a bit better in terms of readability |
||
return ( | ||
<div | ||
className="block-editor-block-parent-selector" | ||
key={ firstParentClientId } | ||
> | ||
<Button | ||
className="block-editor-block-parent-selector__button" | ||
onClick={ () => selectBlock( firstParentClientId ) } | ||
label={ sprintf( | ||
/* translators: %s: Name of the block's parent. */ | ||
__( 'Select parent (%s)' ), | ||
parentBlockType.title | ||
) } | ||
showTooltip | ||
icon={ <BlockIcon icon={ parentBlockType.icon } /> } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return null; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.block-editor-block-parent-selector { | ||
background: $white; | ||
border: 1px solid $dark-gray-primary; | ||
border-radius: $radius-block-ui; | ||
padding: 8px; | ||
line-height: 1; | ||
|
||
.block-editor-block-parent-selector__button { | ||
youknowriad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
width: 32px; | ||
min-width: auto; | ||
height: 32px; | ||
padding: 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ export class BlockSwitcher extends Component { | |
label={ label } | ||
onKeyDown={ openOnArrowDown } | ||
showTooltip | ||
tooltipPosition="bottom" | ||
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. Was this intended? I'm not sure it works well in all situations (mobile, top toolbar, full-width blocks...) 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. Ah, I forgot about this... I added it because at one point the tooltip wasn't showing without it. Now it seems that the tooltip doesn't show regardless. There some conflict being caused by the |
||
icon={ <BlockIcon icon={ icon } showColors /> } | ||
/> | ||
</ToolbarGroup> | ||
|
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'm pretty sure this should be
WPComponent
, notWPElement
?