-
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.
Add new Parent block selector to child blocks (mahjong) (#21056)
* First pass. * Adding the BlockIcon * Adjust the position to match the overall grid. * Removing the delay on the Parent button transition. * Update the tooltip to display the parent block's title. Cleaning a bunch of stuff from pre-commit hooks I had been ignoring. * Adjust code indentation. * Don't show the Parent button if multiple blocks are selected. * Some auto spacing nonsense. * Moving the parent button to change its tab order. * Clean up the spacing in the code to make the code-gods happy. * Cleaning up some CSS. * Using a className for shouldShowMovers instead of the inline styles. * Hide the Parent button in Top Toolbar mode. * Moving the z-index for the block toolbar so it renders above the top bar. Adjusting the position so it appears centered in the top bar. * Use the CSS variables for the spacing. * Update the tooltip to use the word "parent" at a hope of making it more helpful. * Renaming the component to be more descriptive by adding "Selector". This component isn't the block's parent, its a way to select the block's parent. * Updating the padding a height of the parent button so it matches the size of other toolbar buttons. * Making Travis CI happy. * Cleaning up some unused code, and fixing some copy/paste mistakes in the code comments. * Moving some padding around so the focus state of the button appears more like other toolbar buttons. * Making the d lowercase. * Sentence case, and a short way to do the check. * Reducing down to a single useSelect. * Using the `firstParentClientId` rather than `parents` to do the return check. * No need to prefix parents with an underscore since it's not conflicting with anything in the upper scope. Co-authored-by: Zebulan Stanphill <zebulanstanphill@protonmail.com> * Adding an explicit undefined check. * Adding the reduce-motion mixin to respect user settings around animations. * This shouldn't be needed. * I've been told this should be a Component not an Element. * Fix BlockSwitch tooltip * Update BlockSwitch test snapshot Co-authored-by: Zebulan Stanphill <zebulanstanphill@protonmail.com> Co-authored-by: Jon Q <hello@jonquach.com>
- Loading branch information
1 parent
cdf70c2
commit 7e4b0d0
Showing
8 changed files
with
111 additions
and
6 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
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 {WPComponent} 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, | ||
}; | ||
}, [] ); | ||
|
||
if ( firstParentClientId !== undefined ) { | ||
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 { | ||
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
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