forked from jsdir/react-ladda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (66 loc) · 1.86 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
75
76
77
78
79
80
var React = require('react/addons');
var laddaOptions = {
buttonStyle: 'data-style',
buttonColor: 'data-color',
buttonSize: 'data-size',
spinnerSize: 'data-spinner-size',
spinnerColor: 'data-spinner-color'
};
var LaddaButton = React.createClass({
displayName: 'LaddaButton',
mixins: [React.addons.PureRenderMixin],
propTypes: {
loading: React.PropTypes.bool,
progress: React.PropTypes.number,
buttonStyle: React.PropTypes.string,
buttonColor: React.PropTypes.string,
buttonSize: React.PropTypes.string,
spinnerSize: React.PropTypes.number,
spinnerColor: React.PropTypes.string
},
getDefaultProps: function() {
return {
loading: false,
buttonStyle: 'expand-left'
};
},
componentDidMount: function() {
this.laddaButton = require('ladda/dist/ladda.min')
.create(React.findDOMNode(this));
},
componentWillUnmount: function() {
if (this.laddaButton.remove) {
this.laddaButton.remove();
}
},
componentDidUpdate: function() {
if (!this.laddaButton) {
return;
}
// Skip if the button was initially disabled.
if (!this.props.loading && this.props.disabled) {
return;
}
if (this.props.loading) {
this.laddaButton.start();
} else {
this.laddaButton.stop();
}
if (typeof this.props.progress !== 'undefined') {
this.laddaButton.setProgress(this.props.progress);
}
},
render: function() {
var props = {};
for (var prop in this.props) {
props[laddaOptions[prop] || prop] = this.props[prop];
}
// Add the ladda-button class to the button.
props.className = 'ladda-button ' + (props.className || '');
return React.DOM.button(props,
React.DOM.span({className: 'ladda-label'}, this.props.children),
React.DOM.span({className: 'ladda-spinner'})
);
}
});
module.exports = LaddaButton;