This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSplitButton.js
105 lines (91 loc) · 2.71 KB
/
SplitButton.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
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
var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var BootstrapMixin = require('./BootstrapMixin');
var DropdownStateMixin = require('./DropdownStateMixin');
var Button = require('./Button');
var ButtonGroup = require('./ButtonGroup');
var DropdownMenu = require('./DropdownMenu');
var SplitButton = React.createClass({displayName: "SplitButton",
mixins: [BootstrapMixin, DropdownStateMixin],
propTypes: {
pullRight: React.PropTypes.bool,
title: React.PropTypes.node,
href: React.PropTypes.string,
target: React.PropTypes.string,
dropdownTitle: React.PropTypes.node,
onClick: React.PropTypes.func,
onSelect: React.PropTypes.func,
disabled: React.PropTypes.bool
},
getDefaultProps: function () {
return {
dropdownTitle: 'Toggle dropdown'
};
},
render: function () {
var groupClasses = {
'open': this.state.open,
'dropup': this.props.dropup
};
var button = (
React.createElement(Button, React.__spread({},
this.props,
{ref: "button",
onClick: this.handleButtonClick,
title: null,
id: null}),
this.props.title
)
);
var dropdownButton = (
React.createElement(Button, React.__spread({},
this.props,
{ref: "dropdownButton",
className: joinClasses(this.props.className, 'dropdown-toggle'),
onClick: this.handleDropdownClick,
title: null,
href: null,
target: null,
id: null}),
React.createElement("span", {className: "sr-only"}, this.props.dropdownTitle),
React.createElement("span", {className: "caret"})
)
);
return (
React.createElement(ButtonGroup, {
bsSize: this.props.bsSize,
className: classSet(groupClasses),
id: this.props.id},
button,
dropdownButton,
React.createElement(DropdownMenu, {
ref: "menu",
onSelect: this.handleOptionSelect,
"aria-labelledby": this.props.id,
pullRight: this.props.pullRight},
this.props.children
)
)
);
},
handleButtonClick: function (e) {
if (this.state.open) {
this.setDropdownState(false);
}
if (this.props.onClick) {
this.props.onClick(e, this.props.href, this.props.target);
}
},
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 = SplitButton;