Skip to content

Commit

Permalink
Implement the smart toolbar for The block's toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Aug 23, 2018
1 parent f0524c7 commit b67ffcf
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 41 deletions.
6 changes: 5 additions & 1 deletion edit-post/components/header/header-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
}

.edit-post-header-toolbar {
display: inline-flex;
display: flex;
align-items: center;
flex-grow: 1;

@include break-large() {
.editor-block-switcher .components-toolbar {
Expand All @@ -28,9 +29,12 @@
background: $white;
min-height: $block-toolbar-height;
border-bottom: $border-width solid $light-gray-500;
flex-grow: 1;

.editor-block-toolbar {
border-left: none;
border-top: 0;
border-bottom: 0;
}

.editor-block-toolbar .components-toolbar {
Expand Down
18 changes: 18 additions & 0 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ class ParagraphBlock extends Component {
setAttributes( { align: nextAlign } );
} }
/>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Text Settings' ) } className="blocks-font-size">
Expand Down
29 changes: 20 additions & 9 deletions packages/components/src/responsive-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ class ResponsiveToolbar extends Component {
}

render() {
const { children, instanceId, className, ...props } = this.props;
const defaultRenderToggle = ( { onToggle, isOpen } ) => (
<IconButton
icon="arrow-down-alt2"
onClick={ onToggle }
aria-expanded={ isOpen }
/>
);
const {
children,
instanceId,
className,
extraContentClassName,
renderToggle = defaultRenderToggle,
...props
} = this.props;
const { countHiddenChildren } = this.state;

return (
Expand All @@ -124,14 +138,11 @@ class ResponsiveToolbar extends Component {
noArrow
position="bottom left"
className="components-responsive-toolbar__dropdown"
contentClassName={ `components-responsive-toolbar__dropdown-content-${ instanceId }` }
renderToggle={ ( { onToggle, isOpen } ) => (
<IconButton
icon="arrow-down-alt2"
onClick={ onToggle }
aria-expanded={ isOpen }
/>
) }
contentClassName={ classnames(
extraContentClassName,
`components-responsive-toolbar__dropdown-content-${ instanceId }` )
}
renderToggle={ renderToggle }
renderContent={ () => {
return Children.map( children, ( child, index ) => {
return cloneElement( child, { key: index } );
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/slot-fill/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { noop, map, isString, isFunction } from 'lodash';
/**
* WordPress dependencies
*/
import { Component, Children, cloneElement } from '@wordpress/element';
import { Component, Children, cloneElement, Fragment } from '@wordpress/element';

class Slot extends Component {
constructor() {
Expand Down Expand Up @@ -67,9 +67,9 @@ class Slot extends Component {
} );

return (
<div ref={ this.bindNode } role="presentation">
<Fragment>
{ isFunction( children ) ? children( fills.filter( Boolean ) ) : fills }
</div>
</Fragment>
);
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
margin: 0;
border: $border-width solid $light-gray-500;
background-color: $white;
display: inline-flex;
}

div.components-toolbar {
Expand Down
16 changes: 0 additions & 16 deletions packages/editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -847,22 +847,6 @@
left: 0;
right: 0;

// Paint the borders on the toolbar itself on mobile.
border-top: $border-width solid $light-gray-500;
.components-toolbar {
border-top: none;
border-bottom: none;

}

@include break-small() {
border-top: none;
.components-toolbar {
border-top: $border-width solid $light-gray-500;
border-bottom: $border-width solid $light-gray-500;
}
}

// Floated items have special needs for the contextual toolbar position.
.editor-block-list__block[data-align="left"] &,
.editor-block-list__block[data-align="right"] & {
Expand Down
26 changes: 20 additions & 6 deletions packages/editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* WordPress Dependencies
*/
import { withSelect } from '@wordpress/data';
import { ResponsiveToolbar } from '@wordpress/components';
import { Toolbar, ResponsiveToolbar } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal Dependencies
Expand All @@ -27,12 +28,25 @@ function BlockToolbar( { blockClientIds, isValid, mode } ) {
}

return (
<ResponsiveToolbar className="editor-block-toolbar">
<BlockSwitcher clientIds={ blockClientIds } />
<BlockControls.Slot />
<BlockFormatControls.Slot />
<div className="editor-block-toolbar">
<ResponsiveToolbar
className="editor-block-toolbar__tools"
extraContentClassName="editor-block-toolbar__tools-dropdown"
renderToggle={ ( { onToggle, isOpen } ) => (
<Toolbar controls={ [ {
icon: 'arrow-down-alt2',
title: __( 'More Tools' ),
onClick: onToggle,
extraProps: { 'aria-expanded': isOpen },
} ] } />
) }
>
<BlockSwitcher clientIds={ blockClientIds } />
<BlockControls.Slot />
<BlockFormatControls.Slot />
</ResponsiveToolbar>
<BlockSettingsMenu clientIds={ blockClientIds } />
</ResponsiveToolbar>
</div>
);
}

Expand Down
21 changes: 16 additions & 5 deletions packages/editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
width: 100%;
overflow: auto; // Allow horizontal scrolling on mobile.
position: relative;
background: $white;

// Avoid right border on the container
border-top: $border-width solid $light-gray-500;
border-bottom: $border-width solid $light-gray-500;
border-left: $border-width solid $light-gray-500;

// Allow overflow on desktop.
@include break-small() {
overflow: inherit;
}

// Show a left border on the parent container.
border-left: $border-width solid $light-gray-500;

// The component is born with a border, but we only need some of them.
.components-toolbar {
border: 0;
border-top: $border-width solid $light-gray-500;
border-bottom: $border-width solid $light-gray-500;

// Add a right border to show as separator in the block toolbar.
border-right: $border-width solid $light-gray-500;
Expand All @@ -32,3 +33,13 @@
}
}
}

.editor-block-toolbar__tools {
display: inline-block;
width: calc(100% - 36px);
}

.editor-block-toolbar__tools-dropdown .components-popover__content {
display: flex;
flex-wrap: wrap;
}

0 comments on commit b67ffcf

Please sign in to comment.