Skip to content

Commit

Permalink
better handling of inserter
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Aug 18, 2019
1 parent 868ecfb commit f18e3fa
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import {
get,
} from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Dropdown, IconButton, Button, Icon } from '@wordpress/components';
import { Dropdown, IconButton } from '@wordpress/components';
import { Component } from '@wordpress/element';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose, ifCondition } from '@wordpress/compose';
Expand Down Expand Up @@ -66,9 +65,15 @@ class Inserter extends Component {
renderToggle( { onToggle, isOpen } ) {
const {
disabled,
hasOneAllowedItem,
createIfOne,
renderToggle = defaultRenderToggle,
} = this.props;

if ( hasOneAllowedItem ) {
onToggle = createIfOne;
}

return renderToggle( { onToggle, isOpen, disabled } );
}

Expand All @@ -95,23 +100,8 @@ class Inserter extends Component {
}

render() {
const { position, hasOneAllowedItem, createIfOne } = this.props;
let toggle = null;
if ( hasOneAllowedItem ) {
toggle = () => {
return (
<Button
className={ classnames( 'block-editor-button-block-appender' ) }
onClick={ createIfOne }
>
<span className="screen-reader-text">{ __( 'Add Block' ) }</span>
<Icon icon="insert" />
</Button>
);
};
} else {
toggle = this.renderToggle;
}
const { position } = this.props;
const toggle = this.renderToggle;

return (
<Dropdown
Expand Down

0 comments on commit f18e3fa

Please sign in to comment.