-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDropdown.js
60 lines (53 loc) · 1.62 KB
/
Dropdown.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
import React from 'react';
import PropTypes from 'prop-types';
import { decl } from 'bem-react-core';
import Stylable from 'b:Stylable';
import Popup from 'b:Popup m:autoclosable m:target=anchor';
export default decl([Stylable], {
block : 'Dropdown',
willInit() {
this._id = this.generateId();
this._onSwitcherClick = this._onSwitcherClick.bind(this);
this._anchorRef = this._anchorRef.bind(this);
},
content({ children, autoclosable, onClose, opened, theme, size }) {
return (
<Popup
key="popup"
mix={{ block : this.block, elem : 'popup' }}
theme={theme}
size={size}
target="anchor"
anchor={this._anchorRef}
autoclosable
onHide={onClose}
visible={opened}>
{children}
</Popup>
);
},
_onSwitcherClick() {
const { opened, onClose, onOpen } = this.props;
opened ? onClose() : onOpen();
},
_anchorRef(anchor) {
if(anchor) this._anchor = anchor;
else return this._anchor;
}
}, {
propTypes : {
text : PropTypes.string,
switcher : PropTypes.oneOf(['button', 'link']),
autoclosable : PropTypes.bool,
disabled : PropTypes.bool,
opened : PropTypes.bool.isRequired,
onOpen : PropTypes.func.isRequired,
onClose : PropTypes.func.isRequired,
focused : PropTypes.bool,
onFocusChange : PropTypes.func
},
defaultProps : {
autoclosable : true,
onFocusChange() {}
}
});