-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathbutton.js
More file actions
45 lines (38 loc) · 809 Bytes
/
button.js
File metadata and controls
45 lines (38 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* External dependencies
*/
import { createElement, Component } from 'wp-elements';
import { AddOutlineIcon } from 'dashicons';
/**
* Internal dependencies
*/
import Inserter from './';
export default class InserterButtonComponent extends Component {
static defaultProps = {
onAdd: () => {}
}
state = {
opened: false
};
toggleInserter = ( event ) => {
event.preventDefault();
event.stopPropagation();
this.setState( {
opened: ! this.state.opened
} );
};
addBlock = ( id ) => {
this.props.onAdd( id );
this.setState( { opened: false } );
}
render() {
return (
<div className="inserter__button">
<a href="" onClick={ this.toggleInserter }>
<AddOutlineIcon />
</a>
{ this.state.opened && <Inserter onAdd={ this.addBlock } /> }
</div>
);
}
}