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 an alternative block appender when the container doesn't support the default block #10136

Merged
merged 7 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion packages/editor/src/components/block-list-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { last } from 'lodash';
*/
import { withSelect } from '@wordpress/data';
import { getDefaultBlockName } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { Button, Dashicon } from '@wordpress/components';

/**
* Internal dependencies
Expand Down Expand Up @@ -47,7 +49,22 @@ function BlockListAppender( {

return (
<div className="block-list-appender">
<Inserter rootClientId={ rootClientId } layout={ defaultLayout } />
<Inserter
rootClientId={ rootClientId }
layout={ defaultLayout }
renderToggle={ ( { onToggle, disabled, isOpen } ) => (
<Button
aria-label={ __( 'Add block' ) }
onClick={ onToggle }
className="block-list-appender__toggle"
aria-haspopup="true"
aria-expanded={ isOpen }
disabled={ disabled }
>
<Dashicon icon="insert" />
</Button>
) }
/>
</div>
);
}
Expand Down
15 changes: 12 additions & 3 deletions packages/editor/src/components/block-list-appender/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
.block-list-appender {
.block-list-appender > .editor-inserter {
display: block;
}

.block-list-appender__toggle {
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
border: 1px dotted $light-gray-500;
padding: 20px;
outline: 2px dotted $light-gray-500;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "dashed" horrible looking? 😅

(if it is, that's fine, but I like the idea of the line being dashed because that feels more "fill this in" to me)

Also, can you use $grid-size-large instead of 20px? I'm slowly trying to introduce a base8 grid across Gutenberg.

width: 100%;

&:hover {
outline: 1px solid $dark-gray-500;
}
}
28 changes: 14 additions & 14 deletions packages/editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import InserterMenu from './menu';

export { default as InserterResultsPortal } from './results-portal';

const defaultRenderToggle = ( { onToggle, disabled, isOpen } ) => (
<IconButton
icon="insert"
label={ __( 'Add block' ) }
onClick={ onToggle }
className="editor-inserter__toggle"
aria-haspopup="true"
aria-expanded={ isOpen }
disabled={ disabled }
/>
);

class Inserter extends Component {
constructor() {
super( ...arguments );
Expand All @@ -36,10 +48,10 @@ class Inserter extends Component {
items,
position,
title,
children,
onInsertBlock,
rootClientId,
disabled,
renderToggle = defaultRenderToggle,
} = this.props;

if ( items.length === 0 ) {
Expand All @@ -54,19 +66,7 @@ class Inserter extends Component {
onToggle={ this.onToggle }
expandOnMobile
headerTitle={ title }
renderToggle={ ( { onToggle, isOpen } ) => (
<IconButton
icon="insert"
label={ __( 'Add block' ) }
onClick={ onToggle }
className="editor-inserter__toggle"
aria-haspopup="true"
aria-expanded={ isOpen }
disabled={ disabled }
>
{ children }
</IconButton>
) }
renderToggle={ ( { onToggle, isOpen } ) => renderToggle( { onToggle, isOpen, disabled } ) }
renderContent={ ( { onClose } ) => {
const onSelect = ( item ) => {
onInsertBlock( item );
Expand Down