forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropdownButton.jsx
99 lines (83 loc) · 2.36 KB
/
DropdownButton.jsx
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/** @jsx React.DOM */
import React from './react-es6';
import classSet from './react-es6/lib/cx';
import BootstrapMixin from './BootstrapMixin';
import DropdownStateMixin from './DropdownStateMixin';
import Button from './Button';
import ButtonGroup from './ButtonGroup';
import DropdownMenu from './DropdownMenu';
var DropdownButton = React.createClass({
mixins: [BootstrapMixin, DropdownStateMixin],
propTypes: {
pullRight: React.PropTypes.bool,
title: React.PropTypes.renderable,
href: React.PropTypes.string,
onClick: React.PropTypes.func,
onSelect: React.PropTypes.func,
navItem: React.PropTypes.bool
},
render: function () {
var className = this.props.className ?
this.props.className + ' dropdown-toggle' : 'dropdown-toggle';
var renderMethod = this.props.navItem ?
'renderNavItem' : 'renderButtonGroup';
return this[renderMethod]([
<Button
ref="dropdownButton"
href={this.props.href}
bsStyle={this.props.bsStyle}
className={className}
onClick={this.handleOpenClick}
id={this.props.id}
key={0}
navDropdown={this.props.navItem}>
{this.props.title}{' '}
<span className="caret" />
</Button>,
<DropdownMenu
ref="menu"
aria-labelledby={this.props.id}
onSelect={this.handleOptionSelect}
pullRight={this.props.pullRight}
key={1}>
{this.props.children}
</DropdownMenu>
]);
},
renderButtonGroup: function (children) {
var groupClasses = {
'open': this.state.open,
'dropup': this.props.dropup
};
return (
<ButtonGroup
bsSize={this.props.bsSize}
className={classSet(groupClasses)}>
{children}
</ButtonGroup>
);
},
renderNavItem: function (children) {
var classes = {
'dropdown': true,
'open': this.state.open,
'dropup': this.props.dropup
};
return (
<li className={classSet(classes)}>
{children}
</li>
);
},
handleOpenClick: function (e) {
this.setDropdownState(true);
e.preventDefault();
},
handleOptionSelect: function (key) {
if (this.props.onSelect) {
this.props.onSelect(key);
}
this.setDropdownState(false);
}
});
export default = DropdownButton;