-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
74 lines (65 loc) · 1.51 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
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import {
Popover,
IconButton,
} from '@wordpress/components';
class URLPopover extends Component {
constructor() {
super( ...arguments );
this.toggleSettingsVisibility = this.toggleSettingsVisibility.bind( this );
this.state = {
isSettingsExpanded: false,
};
}
toggleSettingsVisibility() {
this.setState( {
isSettingsExpanded: ! this.state.isSettingsExpanded,
} );
}
render() {
const {
children,
renderSettings,
onClose,
onClickOutside,
position = 'bottom center',
focusOnMount = 'firstElement',
} = this.props;
const {
isSettingsExpanded,
} = this.state;
const showSettings = !! renderSettings && isSettingsExpanded;
return (
<Popover
className="editor-url-popover"
focusOnMount={ focusOnMount }
position={ position }
onClose={ onClose }
onClickOutside={ onClickOutside }
>
<div className="editor-url-popover__row">
{ children }
{ !! renderSettings && (
<IconButton
className="editor-url-popover__settings-toggle"
icon="arrow-down-alt2"
label={ __( 'Link Settings' ) }
onClick={ this.toggleSettingsVisibility }
aria-expanded={ isSettingsExpanded }
/>
) }
</div>
{ showSettings && (
<div className="editor-url-popover__row editor-url-popover__settings">
{ renderSettings() }
</div>
) }
</Popover>
);
}
}
export default URLPopover;