Skip to content
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 32 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ea74f88
First pass.
shaunandrews Mar 20, 2020
849fc12
Adding the BlockIcon
shaunandrews Mar 22, 2020
97ae63d
Adjust the position to match the overall grid.
shaunandrews Mar 23, 2020
dde200e
Removing the delay on the Parent button transition.
shaunandrews Mar 23, 2020
9c7e661
Update the tooltip to display the parent block's title.
shaunandrews Mar 24, 2020
e9acd35
Adjust code indentation.
shaunandrews Mar 24, 2020
7ca1bb0
Don't show the Parent button if multiple blocks are selected.
shaunandrews Mar 24, 2020
170edc5
Some auto spacing nonsense.
shaunandrews Mar 24, 2020
409868b
Moving the parent button to change its tab order.
shaunandrews Mar 26, 2020
b6d53c9
Clean up the spacing in the code to make the code-gods happy.
shaunandrews Mar 26, 2020
ba5efad
Cleaning up some CSS.
shaunandrews Apr 2, 2020
0f8aaf6
Using a className for shouldShowMovers instead of the inline styles.
shaunandrews Apr 2, 2020
ac1990a
Hide the Parent button in Top Toolbar mode.
shaunandrews Apr 2, 2020
5e88bb6
Moving the z-index for the block toolbar so it renders above the top …
shaunandrews Apr 2, 2020
90be934
Use the CSS variables for the spacing.
shaunandrews Apr 6, 2020
e2e407d
Update the tooltip to use the word "parent" at a hope of making it mo…
shaunandrews Apr 6, 2020
6e14ab4
Renaming the component to be more descriptive by adding "Selector".
shaunandrews Apr 16, 2020
c3da3d2
Updating the padding a height of the parent button so it matches the …
shaunandrews Apr 20, 2020
89aec24
Making Travis CI happy.
shaunandrews Apr 20, 2020
0a56fd3
Cleaning up some unused code, and fixing some copy/paste mistakes in …
shaunandrews May 19, 2020
5fad39f
Moving some padding around so the focus state of the button appears m…
shaunandrews May 19, 2020
a816121
Making the d lowercase.
shaunandrews May 19, 2020
6cf0c65
Sentence case, and a short way to do the check.
shaunandrews May 19, 2020
2f535e0
Reducing down to a single useSelect.
shaunandrews May 20, 2020
e8489c7
Using the `firstParentClientId` rather than `parents` to do the retur…
shaunandrews May 20, 2020
0708275
No need to prefix parents with an underscore since it's not conflicti…
shaunandrews May 20, 2020
f093b85
Adding an explicit undefined check.
shaunandrews May 20, 2020
f35d345
Adding the reduce-motion mixin to respect user settings around animat…
shaunandrews May 21, 2020
91529a3
This shouldn't be needed.
shaunandrews May 21, 2020
0d4789d
I've been told this should be a Component not an Element.
shaunandrews May 22, 2020
349b08f
Fix BlockSwitch tooltip
May 25, 2020
b05b2ba
Update BlockSwitch test snapshot
May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ $z-layers: (
// .edit-post-header { z-index: 30 }
".components-notice-list": 29,

// Above the block list, under the header.
".block-editor-block-list__block-popover": 29,
// Above the block list and the header.
".block-editor-block-list__block-popover": 31,

// Under the block popover (block toolbar).
".block-editor-block-list__insertion-point-popover": 28,
Expand Down
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,
};
}, [] );
ZebulanStanphill marked this conversation as resolved.
Show resolved Hide resolved

if ( firstParentClientId !== undefined ) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
}
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class BlockSwitcher extends Component {
<ToolbarButton
disabled
className="block-editor-block-switcher__no-switcher-icon"
label={ __( 'Block icon' ) }
title={ __( 'Block icon' ) }
icon={ <BlockIcon icon={ icon } showColors /> }
/>
</ToolbarGroup>
Expand Down Expand Up @@ -140,7 +140,7 @@ export class BlockSwitcher extends Component {
onClick={ onToggle }
aria-haspopup="true"
aria-expanded={ isOpen }
label={ label }
title={ label }
onKeyDown={ openOnArrowDown }
showTooltip
icon={ <BlockIcon icon={ icon } showColors /> }
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useViewportMatch } from '@wordpress/compose';
* Internal dependencies
*/
import BlockMover from '../block-mover';
import BlockParentSelector from '../block-parent-selector';
import BlockSwitcher from '../block-switcher';
import BlockControls from '../block-controls';
import BlockFormatControls from '../block-format-controls';
Expand Down Expand Up @@ -88,6 +89,7 @@ export default function BlockToolbar( { hideDragHandle } ) {

const classes = classnames(
'block-editor-block-toolbar',
shouldShowMovers && 'is-showing-movers',
! displayHeaderToolbar && 'has-responsive-movers'
);

Expand All @@ -97,6 +99,12 @@ export default function BlockToolbar( { hideDragHandle } ) {
className="block-editor-block-toolbar__mover-switcher-container"
ref={ nodeRef }
>
{ ! isMultiToolbar && (
<div className="block-editor-block-toolbar__block-parent-selector-wrapper">
<BlockParentSelector clientIds={ blockClientIds } />
</div>
) }

<div
className="block-editor-block-toolbar__mover-trigger-container"
{ ...showMoversGestures }
Expand All @@ -112,6 +120,7 @@ export default function BlockToolbar( { hideDragHandle } ) {
/>
</div>
</div>

{ ( shouldShowVisualToolbar || isMultiToolbar ) && (
<div
{ ...showMoversGestures }
Expand All @@ -121,6 +130,7 @@ export default function BlockToolbar( { hideDragHandle } ) {
</div>
) }
</div>

{ shouldShowVisualToolbar && ! isMultiToolbar && (
<>
<BlockControls.Slot
Expand Down
22 changes: 21 additions & 1 deletion packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@
}
}

.block-editor-block-toolbar__block-parent-selector-wrapper {
position: absolute;
top: -1px;
left: -1px;
opacity: 0;
transition: all 60ms linear;
shaunandrews marked this conversation as resolved.
Show resolved Hide resolved
z-index: -1; // This makes it slide out from underneath the toolbar.

@include reduce-motion("transition");

.is-showing-movers & {
opacity: 1;
transform: translateY(-($block-toolbar-height + $grid-unit-15));
}

// Hide the Parent button in Top Toolbar mode.
.edit-post-header-toolbar__block-toolbar & {
display: none;
}
}

.block-editor-block-toolbar__mover-switcher-container {
display: flex;
}
Expand Down Expand Up @@ -112,4 +133,3 @@
@include reduce-motion("transition");
}
}

1 change: 1 addition & 0 deletions packages/block-editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import "./components/block-mobile-toolbar/style.scss";
@import "./components/block-mover/style.scss";
@import "./components/block-navigation/style.scss";
@import "./components/block-parent-selector/style.scss";
@import "./components/block-preview/style.scss";
@import "./components/block-settings-menu/style.scss";
@import "./components/block-styles/style.scss";
Expand Down