-
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
Merged
Merged
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ea74f88
First pass.
shaunandrews 849fc12
Adding the BlockIcon
shaunandrews 97ae63d
Adjust the position to match the overall grid.
shaunandrews dde200e
Removing the delay on the Parent button transition.
shaunandrews 9c7e661
Update the tooltip to display the parent block's title.
shaunandrews e9acd35
Adjust code indentation.
shaunandrews 7ca1bb0
Don't show the Parent button if multiple blocks are selected.
shaunandrews 170edc5
Some auto spacing nonsense.
shaunandrews 409868b
Moving the parent button to change its tab order.
shaunandrews b6d53c9
Clean up the spacing in the code to make the code-gods happy.
shaunandrews ba5efad
Cleaning up some CSS.
shaunandrews 0f8aaf6
Using a className for shouldShowMovers instead of the inline styles.
shaunandrews ac1990a
Hide the Parent button in Top Toolbar mode.
shaunandrews 5e88bb6
Moving the z-index for the block toolbar so it renders above the top …
shaunandrews 90be934
Use the CSS variables for the spacing.
shaunandrews e2e407d
Update the tooltip to use the word "parent" at a hope of making it mo…
shaunandrews 6e14ab4
Renaming the component to be more descriptive by adding "Selector".
shaunandrews c3da3d2
Updating the padding a height of the parent button so it matches the …
shaunandrews 89aec24
Making Travis CI happy.
shaunandrews 0a56fd3
Cleaning up some unused code, and fixing some copy/paste mistakes in …
shaunandrews 5fad39f
Moving some padding around so the focus state of the button appears m…
shaunandrews a816121
Making the d lowercase.
shaunandrews 6cf0c65
Sentence case, and a short way to do the check.
shaunandrews 2f535e0
Reducing down to a single useSelect.
shaunandrews e8489c7
Using the `firstParentClientId` rather than `parents` to do the retur…
shaunandrews 0708275
No need to prefix parents with an underscore since it's not conflicti…
shaunandrews f093b85
Adding an explicit undefined check.
shaunandrews f35d345
Adding the reduce-motion mixin to respect user settings around animat…
shaunandrews 91529a3
This shouldn't be needed.
shaunandrews 0d4789d
I've been told this should be a Component not an Element.
shaunandrews 349b08f
Fix BlockSwitch tooltip
b05b2ba
Update BlockSwitch test snapshot
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
60 changes: 60 additions & 0 deletions
60
packages/block-editor/src/components/block-parent-selector/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,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; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/block-editor/src/components/block-parent-selector/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,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; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
?