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

Convert core toolbar buttons into ToolbarButton #20008

Merged
merged 54 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6061ecd
SlotFill initial implementation
diegohaz Dec 19, 2019
7e38b5a
Add manifest-devhub.json
diegohaz Dec 19, 2019
d032bee
Accept as prop on Slot
diegohaz Dec 19, 2019
13b60ef
Update stories
diegohaz Dec 19, 2019
0c77a8a
Update README.md
diegohaz Dec 20, 2019
bd84603
Update code
diegohaz Dec 20, 2019
23d3abc
Add slot-fill2 entries to components index file
diegohaz Dec 20, 2019
229d432
Add unit tests
diegohaz Dec 20, 2019
7aff149
Merge branch 'master' into update/slot-fill
diegohaz Jan 29, 2020
e8bbb9b
Fix git conflicts
diegohaz Jan 29, 2020
df31e9c
Merge branch 'master' into update/slot-fill
diegohaz Feb 3, 2020
861e8ec
Convert fixed toolbar buttons into ToolbarButton
diegohaz Feb 3, 2020
1fc8026
Lint code
diegohaz Feb 3, 2020
68d76db
Merge branch 'update/slot-fill' into update/fixed-toolbar-buttons
diegohaz Feb 3, 2020
cee615e
Merge branch 'master' into update/fixed-toolbar-buttons
diegohaz Feb 27, 2020
4b7b0fa
Update code
diegohaz Feb 27, 2020
94f25bb
Adjustments
diegohaz Feb 27, 2020
ec33aa0
Temporarily fix toolbar buttons styles
diegohaz Mar 2, 2020
60c5702
Merge branch 'master' into update/fixed-toolbar-buttons
diegohaz Mar 2, 2020
41d9576
Revert block toolbar styles
diegohaz Mar 2, 2020
f4d0b89
Fix styles
diegohaz Mar 2, 2020
17dc36b
Lint code
diegohaz Mar 2, 2020
bb63270
Update e2e-tests
diegohaz Mar 11, 2020
b2bbbf2
Update styles
diegohaz Mar 12, 2020
1be7460
Merge branch 'master' into update/fixed-toolbar-buttons
diegohaz Mar 12, 2020
d33c988
Merge branch 'master' into update/fixed-toolbar-buttons
diegohaz Apr 28, 2020
014578d
Update styles
diegohaz Apr 29, 2020
2999c85
Fix unit tests
diegohaz Apr 29, 2020
be9564a
Fix some e2e tests
diegohaz Apr 29, 2020
11b3104
Update NavigableToolbar
diegohaz Apr 29, 2020
c87d1f2
Attempt to fix e2e tests
diegohaz Apr 29, 2020
3794091
Revert Attempt to fix e2e tests
diegohaz Apr 29, 2020
51b1153
Fix navigable-toolbar tests
diegohaz Apr 29, 2020
c8f4773
Upgrade reakit
diegohaz Apr 29, 2020
1bb519c
Fix e2e tests
diegohaz Apr 29, 2020
83f7eba
Update styles
diegohaz Apr 29, 2020
750914c
Update ToolbarGroup styles
diegohaz Apr 30, 2020
47ceb49
Update NavigableToolbar
diegohaz Apr 30, 2020
e740adb
Refactor Block Controlls Fill/Slot code
diegohaz Apr 30, 2020
12477f9
Update NavigableToolbar
diegohaz Apr 30, 2020
67289f7
Update styles
diegohaz Apr 30, 2020
2d01cda
Add comment on block-toolbar/utils.js
diegohaz Apr 30, 2020
70937da
Refactor format-toolbar code
diegohaz Apr 30, 2020
5bb5f49
Fix styles on horizontal movers
diegohaz May 1, 2020
9b60075
Update trailing dropdown toolbar button styles
diegohaz May 1, 2020
0709c04
Use MutationObserver instead of relying on the next repaint
diegohaz May 1, 2020
ed633cc
Fix drag and drop
diegohaz May 1, 2020
2399dbd
useUpdateLayoutEffect for MutationObserver
diegohaz May 1, 2020
790eb22
Update NavigableToolbar code
diegohaz May 1, 2020
d5378c5
Update NavigableToolbar code
diegohaz May 1, 2020
369f2fe
Add comment on Toolbar
diegohaz May 6, 2020
ca40ffd
Move bubblesVirtually prop so React Native still works
diegohaz May 6, 2020
48c1fbe
Merge branch 'master' into update/fixed-toolbar-buttons
diegohaz May 7, 2020
2b5c5f0
Remove missing comment from styles
diegohaz May 7, 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
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { find } from 'lodash';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Toolbar } from '@wordpress/components';
import { ToolbarGroup } from '@wordpress/components';
import { alignLeft, alignRight, alignCenter } from '@wordpress/icons';

const DEFAULT_ALIGNMENT_CONTROLS = [
Expand Down Expand Up @@ -58,7 +58,7 @@ export function AlignmentToolbar( props ) {
}

return (
<Toolbar
<ToolbarGroup
isCollapsed={ isCollapsed }
icon={ setIcon() }
label={ label }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AlignmentToolbar should allow custom alignment controls to be specified 1`] = `
<Toolbar
<ToolbarGroup
controls={
Array [
Object {
Expand Down Expand Up @@ -58,7 +58,7 @@ exports[`AlignmentToolbar should allow custom alignment controls to be specified
`;

exports[`AlignmentToolbar should match snapshot 1`] = `
<Toolbar
<ToolbarGroup
controls={
Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Toolbar } from '@wordpress/components';
import { ToolbarGroup } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import {
Expand Down Expand Up @@ -67,7 +67,7 @@ export function BlockAlignmentToolbar( {
BLOCK_ALIGNMENTS_CONTROLS[ DEFAULT_CONTROL ];

return (
<Toolbar
<ToolbarGroup
isCollapsed={ isCollapsed }
icon={
activeAlignmentControl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BlockAlignmentToolbar should match snapshot 1`] = `
<Toolbar
<ToolbarGroup
controls={
Array [
Object {
Expand Down
43 changes: 35 additions & 8 deletions packages/block-editor/src/components/block-controls/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import { createSlotFill, Toolbar } from '@wordpress/components';
import { useContext } from '@wordpress/element';
import {
__experimentalToolbarContext as ToolbarContext,
createSlotFill,
ToolbarGroup,
} from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -10,15 +20,32 @@ import { ifBlockEditSelected } from '../block-edit/context';

const { Fill, Slot } = createSlotFill( 'BlockControls' );

const BlockControlsFill = ( { controls, children } ) => (
<Fill>
<Toolbar controls={ controls } />
{ children }
</Fill>
);
function BlockControlsSlot( props ) {
const accessibleToolbarState = useContext( ToolbarContext );
return <Slot { ...props } fillProps={ accessibleToolbarState } />;
}

function BlockControlsFill( { controls, children } ) {
return (
<Fill>
{ ( fillProps ) => {
// Children passed to BlockControlsFill will not have access to any
// React Context whose Provider is part of the BlockControlsSlot tree.
// So we re-create the Provider in this subtree.
const value = ! isEmpty( fillProps ) ? fillProps : null;
return (
<ToolbarContext.Provider value={ value }>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember having to do the same trick in the past for other fills. It's a bit unfortunate that we need this trick but as long it works it feels like a good trade-off.

<ToolbarGroup controls={ controls } />
{ children }
</ToolbarContext.Provider>
);
} }
</Fill>
);
}

const BlockControls = ifBlockEditSelected( BlockControlsFill );

BlockControls.Slot = Slot;
BlockControls.Slot = BlockControlsSlot;

export default BlockControls;
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';
import { useContext } from '@wordpress/element';
import {
__experimentalToolbarContext as ToolbarContext,
createSlotFill,
} from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -10,8 +19,28 @@ import { ifBlockEditSelected } from '../block-edit/context';

const { Fill, Slot } = createSlotFill( 'BlockFormatControls' );

const BlockFormatControls = ifBlockEditSelected( Fill );
function BlockFormatControlsSlot( props ) {
const accessibleToolbarState = useContext( ToolbarContext );
return <Slot { ...props } fillProps={ accessibleToolbarState } />;
}

function BlockFormatControlsFill( props ) {
return (
<Fill>
{ ( fillProps ) => {
const value = ! isEmpty( fillProps ) ? fillProps : null;
return (
<ToolbarContext.Provider value={ value }>
{ props.children }
</ToolbarContext.Provider>
);
} }
</Fill>
);
}

const BlockFormatControls = ifBlockEditSelected( BlockFormatControlsFill );

BlockFormatControls.Slot = Slot;
BlockFormatControls.Slot = BlockFormatControlsSlot;

export default BlockFormatControls;
1 change: 1 addition & 0 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@
border-radius: $radius-block-ui;
background-color: $white;

.block-editor-block-toolbar .components-toolbar-group,
.block-editor-block-toolbar .components-toolbar {
border-right-color: $dark-gray-primary;
}
Expand Down
17 changes: 11 additions & 6 deletions packages/block-editor/src/components/block-mover/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { castArray, first, last, partial } from 'lodash';
import { castArray, first, last } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -121,9 +121,14 @@ const BlockMoverButton = forwardRef(
);
const moverFunction =
direction === 'up' ? moveBlocksUp : moveBlocksDown;
const onClick = isDisabled
? null
: partial( moverFunction, clientIds, rootClientId );

const onClick = ( event ) => {
moverFunction( clientIds, rootClientId );
if ( props.onClick ) {
props.onClick( event );
}
};

const descriptionId = `block-editor-block-mover-button__description-${ instanceId }`;

return (
Expand All @@ -141,9 +146,9 @@ const BlockMoverButton = forwardRef(
isRTL
) }
aria-describedby={ descriptionId }
onClick={ onClick }
aria-disabled={ isDisabled }
{ ...props }
onClick={ isDisabled ? null : onClick }
aria-disabled={ isDisabled }
/>
<span
id={ descriptionId }
Expand Down
29 changes: 22 additions & 7 deletions packages/block-editor/src/components/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { ToolbarGroup } from '@wordpress/components';
import {
ToolbarGroup,
__experimentalToolbarItem as ToolbarItem,
} from '@wordpress/components';
import { getBlockType } from '@wordpress/blocks';
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
Expand Down Expand Up @@ -73,16 +76,28 @@ export class BlockMover extends Component {
onDragEnd={ onDraggableEnd }
>
<ToolbarGroup>
<BlockMoverUpButton
clientIds={ clientIds }
<ToolbarItem
onFocus={ this.onFocus }
onBlur={ this.onBlur }
/>
<BlockMoverDownButton
clientIds={ clientIds }
>
{ ( itemProps ) => (
<BlockMoverUpButton
clientIds={ clientIds }
{ ...itemProps }
/>
) }
</ToolbarItem>
<ToolbarItem
onFocus={ this.onFocus }
onBlur={ this.onBlur }
/>
>
{ ( itemProps ) => (
<BlockMoverDownButton
clientIds={ clientIds }
{ ...itemProps }
/>
) }
</ToolbarItem>
</ToolbarGroup>
</div>
) }
Expand Down
Loading