Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
* Internal dependencies
*/
import { isInsideRootBlock } from '../../utils/dom';
import useMovingAnimation from './moving-animation';
import useMovingAnimation from '../use-moving-animation';
import { Context, BlockNodes } from './root-container';
import { BlockContext } from './block';
import ELEMENTS from './block-elements';
Expand Down
65 changes: 65 additions & 0 deletions packages/block-editor/src/components/block-navigation/item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* External dependencies
*/
import { animated } from 'react-spring/web.cjs';
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { Button, VisuallyHidden } from '@wordpress/components';
import { useRef } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import useMovingAnimation from '../use-moving-animation';

const AnimatedListItem = animated( 'li' );

export default function BlockNavigationItem( {
blockIndex,
children,
icon,
isSelected,
label,
onClick,
} ) {
const wrapper = useRef( null );
const adjustScrolling = false;
const enableAnimation = true;
const animateOnChange = blockIndex;
const style = useMovingAnimation(
wrapper,
isSelected,
adjustScrolling,
enableAnimation,
animateOnChange
);

return (
<AnimatedListItem ref={ wrapper } style={ style }>
<div className="block-editor-block-navigation__item-inner">
<Button
className={ classnames(
'block-editor-block-navigation__item-button',
{
'is-selected': isSelected,
}
) }
onClick={ onClick }
>
<BlockIcon icon={ icon } showColors />
{ label }
{ isSelected && (
<VisuallyHidden as="span">
{ __( '(selected block)' ) }
</VisuallyHidden>
) }
</Button>
</div>
{ children }
</AnimatedListItem>
);
}
39 changes: 12 additions & 27 deletions packages/block-editor/src/components/block-navigation/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
* External dependencies
*/
import { isNil, map, omitBy } from 'lodash';
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { Button, VisuallyHidden } from '@wordpress/components';
import {
__experimentalGetBlockLabel as getBlockLabel,
getBlockType,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import ButtonBlockAppender from '../button-block-appender';
import BlockNavigationItem from './item';

export default function BlockNavigationList( {
blocks,
Expand All @@ -39,31 +36,19 @@ export default function BlockNavigationList( {
*/
/* eslint-disable jsx-a11y/no-redundant-roles */
<ul className="block-editor-block-navigation__list" role="list">
{ map( omitBy( blocks, isNil ), ( block ) => {
{ map( omitBy( blocks, isNil ), ( block, index ) => {
const blockType = getBlockType( block.name );
const isSelected = block.clientId === selectedBlockClientId;

return (
<li key={ block.clientId }>
<div className="block-editor-block-navigation__item">
<Button
className={ classnames(
'block-editor-block-navigation__item-button',
{
'is-selected': isSelected,
}
) }
onClick={ () => selectBlock( block.clientId ) }
>
<BlockIcon icon={ blockType.icon } showColors />
{ getBlockLabel( blockType, block.attributes ) }
{ isSelected && (
<VisuallyHidden as="span">
{ __( '(selected block)' ) }
</VisuallyHidden>
) }
</Button>
</div>
<BlockNavigationItem
key={ block.clientId }
blockIndex={ index }
icon={ blockType.icon }
isSelected={ isSelected }
label={ getBlockLabel( blockType, block.attributes ) }
onClick={ () => selectBlock( block.clientId ) }
>
{ showNestedBlocks &&
!! block.innerBlocks &&
!! block.innerBlocks.length && (
Expand All @@ -78,12 +63,12 @@ export default function BlockNavigationList( {
showNestedBlocks
/>
) }
</li>
</BlockNavigationItem>
);
} ) }
{ shouldShowAppender && (
<li>
<div className="block-editor-block-navigation__item">
<div className="block-editor-block-navigation__item-inner">
<ButtonBlockAppender
rootClientId={ parentBlockClientId }
__experimentalSelectBlockOnInsert={ false }
Expand Down
27 changes: 26 additions & 1 deletion packages/block-editor/src/components/block-navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $tree-item-height: 36px;
margin-left: 1.5em;
}

.block-editor-block-navigation__item {
.block-editor-block-navigation__item-inner {
position: relative;

&::before {
Expand Down Expand Up @@ -93,3 +93,28 @@ $tree-item-height: 36px;
.components-popover.block-editor-block-navigation__popover {
z-index: z-index(".components-popover.block-editor-block-navigation__popover");
}

.block-editor-block-navigation-toolbar {
display: flex;
flex-direction: row;
height: 48px;
margin-bottom: 16px;
border: 1px solid #e2e4e7;

.components-toolbar {
background: none;
// IE11 has thick paddings without this.
line-height: 0;

// These margins make the buttons themselves overlap the chrome of the toolbar.
// This helps make them square, and maximize the hit area.
margin-top: -$border-width;
margin-bottom: -$border-width;

// The component is born with a border, but we only need some of them.
border: 0;

// Add a border after item groups to show as separator in the block toolbar.
border-right: $border-width solid $light-gray-500;
}
}
50 changes: 50 additions & 0 deletions packages/block-editor/src/components/block-navigation/toolbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { Button, ToolbarGroup } from '@wordpress/components';
import { insertAfter, trash } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BlockActions from '../block-actions';
import BlockMover from '../block-mover';

export default function BlockNavigationToolbar() {
const blockClientIds = useSelect(
( select ) => select( 'core/block-editor' ).getSelectedBlockClientIds(),
[]
);

return (
<BlockActions clientIds={ blockClientIds }>
{ ( { canDuplicate, isLocked, onDuplicate, onRemove } ) => (
<div className="block-editor-block-navigation-toolbar">
<BlockMover
clientIds={ blockClientIds }
__experimentalOrientation="vertical"
hideDragHandle
/>
{ ! isLocked && (
<ToolbarGroup>
{ canDuplicate && (
<Button
onClick={ onDuplicate }
label={ __( 'Duplicate block' ) }
icon={ insertAfter }
/>
) }
<Button
onClick={ onRemove }
label={ __( 'Remove block' ) }
icon={ trash }
/>
</ToolbarGroup>
) }
</div>
) }
</BlockActions>
);
}
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as BlockFormatControls } from './block-format-controls';
export { default as BlockIcon } from './block-icon';
export { default as BlockNavigationDropdown } from './block-navigation/dropdown';
export { default as __experimentalBlockNavigationList } from './block-navigation/list';
export { default as __experimentalBlockNavigationToolbar } from './block-navigation/toolbar';
export { default as __experimentalBlockVariationPicker } from './block-variation-picker';
export { default as BlockVerticalAlignmentToolbar } from './block-vertical-alignment-toolbar';
export { default as ButtonBlockerAppender } from './button-block-appender';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
/**
* WordPress dependencies
*/
import { __experimentalBlockNavigationList } from '@wordpress/block-editor';
import {
__experimentalBlockNavigationToolbar as BlockNavigationToolbar,
__experimentalBlockNavigationList as BlockNavigationList,
NavigableToolbar,
} from '@wordpress/block-editor';
import { Panel, PanelBody } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

export default function NavigationStructurePanel( { blocks, initialOpen } ) {
const selectedBlockClientIds = useSelect(
( select ) => select( 'core/block-editor' ).getSelectedBlockClientIds(),
[]
);
const { selectBlock } = useDispatch( 'core/block-editor' );

return (
<Panel className="edit-navigation-menu-editor__navigation-structure-panel">
<PanelBody
title={ __( 'Navigation structure' ) }
initialOpen={ initialOpen }
>
{ !! blocks.length && (
<__experimentalBlockNavigationList
blocks={ blocks }
selectedBlockClientId={ blocks[ 0 ].clientId }
selectBlock={ () => {} }
showNestedBlocks
showAppender
/>
<>
<NavigableToolbar
aria-label={ __( 'Navigation structure tools' ) }
>
<BlockNavigationToolbar />
</NavigableToolbar>
<BlockNavigationList
blocks={ blocks }
selectedBlockClientId={
selectedBlockClientIds[ 0 ]
}
selectBlock={ selectBlock }
showNestedBlocks
showAppender
/>
</>
) }
</PanelBody>
</Panel>
Expand Down