forked from react-bootstrap/react-bootstrap-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlert.js
More file actions
60 lines (49 loc) · 1.44 KB
/
Alert.js
File metadata and controls
60 lines (49 loc) · 1.44 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
define(function (require, exports, module) {var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var BootstrapMixin = require('./BootstrapMixin');
var Alert = React.createClass({displayName: 'Alert',
mixins: [BootstrapMixin],
propTypes: {
onDismiss: React.PropTypes.func,
dismissAfter: React.PropTypes.number
},
getDefaultProps: function () {
return {
bsClass: 'alert',
bsStyle: 'info'
};
},
renderDismissButton: function () {
return (
React.createElement("button", {
type: "button",
className: "close",
onClick: this.props.onDismiss,
'aria-hidden': "true"},
"×"
)
);
},
render: function () {
var classes = this.getBsClassSet();
var isDismissable = !!this.props.onDismiss;
classes['alert-dismissable'] = isDismissable;
return (
React.createElement("div", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}),
isDismissable ? this.renderDismissButton() : null,
this.props.children
)
);
},
componentDidMount: function() {
if (this.props.dismissAfter && this.props.onDismiss) {
this.dismissTimer = setTimeout(this.props.onDismiss, this.props.dismissAfter);
}
},
componentWillUnmount: function() {
clearTimeout(this.dismissTimer);
}
});
module.exports = Alert;
});