-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
61 lines (52 loc) · 1.11 KB
/
index.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* External dependencies
*/
import clickOutside from 'react-click-outside';
/**
* Internal dependencies
*/
import InserterMenu from './menu';
import IconButton from 'components/icon-button';
class Inserter extends wp.element.Component {
constructor() {
super( ...arguments );
this.toggle = this.toggle.bind( this );
this.close = this.close.bind( this );
this.state = {
opened: false
};
}
toggle() {
this.setState( {
opened: ! this.state.opened
} );
}
close() {
this.setState( {
opened: false
} );
}
handleClickOutside() {
if ( ! this.state.opened ) {
return;
}
this.close();
}
render() {
const { opened } = this.state;
const { position } = this.props;
return (
<div className="editor-inserter">
<IconButton
icon="insert"
label={ wp.i18n.__( 'Insert block' ) }
onClick={ this.toggle }
className="editor-inserter__toggle"
aria-haspopup="true"
aria-expanded={ opened ? 'true' : 'false' } />
{ opened && <InserterMenu position={ position } onSelect={ this.close } /> }
</div>
);
}
}
export default clickOutside( Inserter );