forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlert.jsx
60 lines (48 loc) · 1.27 KB
/
Alert.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
/** @jsx React.DOM */
import React from './react-es6';
import classSet from './react-es6/lib/cx';
import BootstrapMixin from './BootstrapMixin';
var Alert = React.createClass({
mixins: [BootstrapMixin],
propTypes: {
onDismiss: React.PropTypes.func,
dismissAfter: React.PropTypes.number
},
getDefaultProps: function () {
return {
bsClass: 'alert',
bsStyle: 'info'
};
},
renderDismissButton: function () {
return (
<button
type="button"
className="close"
onClick={this.props.onDismiss}
aria-hidden="true">
×
</button>
);
},
render: function () {
var classes = this.getBsClassSet();
var isDismissable = !!this.props.onDismiss;
classes['alert-dismissable'] = isDismissable;
return this.transferPropsTo(
<div className={classSet(classes)}>
{isDismissable ? this.renderDismissButton() : null}
{this.props.children}
</div>
);
},
componentDidMount: function() {
if (this.props.dismissAfter && this.props.onDismiss) {
this.dismissTimer = setTimeout(this.props.onDismiss, this.props.dismissAfter);
}
},
componentWillUnmount: function() {
clearTimeout(this.dismissTimer);
}
});
export default = Alert;