This repository was archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDropdownButton.js
More file actions
125 lines (106 loc) · 3.48 KB
/
DropdownButton.js
File metadata and controls
125 lines (106 loc) · 3.48 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var cloneWithProps = require('./utils/cloneWithProps');
var createChainedFunction = require('./utils/createChainedFunction');
var BootstrapMixin = require('./BootstrapMixin');
var DropdownStateMixin = require('./DropdownStateMixin');
var Button = require('./Button');
var ButtonGroup = require('./ButtonGroup');
var DropdownMenu = require('./DropdownMenu');
var ValidComponentChildren = require('./utils/ValidComponentChildren');
var DropdownButton = React.createClass({displayName: "DropdownButton",
mixins: [BootstrapMixin, DropdownStateMixin],
propTypes: {
pullRight: React.PropTypes.bool,
dropup: React.PropTypes.bool,
title: React.PropTypes.node,
href: React.PropTypes.string,
onClick: React.PropTypes.func,
onSelect: React.PropTypes.func,
navItem: React.PropTypes.bool,
noCaret: React.PropTypes.bool
},
render: function () {
var renderMethod = this.props.navItem ?
'renderNavItem' : 'renderButtonGroup';
var caret = this.props.noCaret ?
null : (React.createElement("span", {className: "caret"}));
return this[renderMethod]([
React.createElement(Button, React.__spread({},
this.props,
{ref: "dropdownButton",
className: "dropdown-toggle",
onClick: this.handleDropdownClick,
key: 0,
navDropdown: this.props.navItem,
navItem: null,
title: null,
pullRight: null,
dropup: null}),
this.props.title, ' ',
caret
),
React.createElement(DropdownMenu, {
ref: "menu",
"aria-labelledby": this.props.id,
pullRight: this.props.pullRight,
key: 1},
ValidComponentChildren.map(this.props.children, this.renderMenuItem)
)
]);
},
renderButtonGroup: function (children) {
var groupClasses = {
'open': this.state.open,
'dropup': this.props.dropup
};
return (
React.createElement(ButtonGroup, {
bsSize: this.props.bsSize,
className: joinClasses(this.props.className, classSet(groupClasses))},
children
)
);
},
renderNavItem: function (children) {
var classes = {
'dropdown': true,
'open': this.state.open,
'dropup': this.props.dropup
};
return (
React.createElement("li", {className: joinClasses(this.props.className, classSet(classes))},
children
)
);
},
renderMenuItem: function (child, index) {
// Only handle the option selection if an onSelect prop has been set on the
// component or it's child, this allows a user not to pass an onSelect
// handler and have the browser preform the default action.
var handleOptionSelect = this.props.onSelect || child.props.onSelect ?
this.handleOptionSelect : null;
return cloneWithProps(
child,
{
// Capture onSelect events
onSelect: createChainedFunction(child.props.onSelect, handleOptionSelect),
// Force special props to be transferred
key: child.key ? child.key : index,
ref: child.ref
}
);
},
handleDropdownClick: function (e) {
e.preventDefault();
this.setDropdownState(!this.state.open);
},
handleOptionSelect: function (key) {
if (this.props.onSelect) {
this.props.onSelect(key);
}
this.setDropdownState(false);
}
});
module.exports = DropdownButton;