Alert.js
1.5 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
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './Custom.scss';
class Alert extends React.Component {
constructor(props) {
super(props);
this.minusSecond=this.minusSecond.bind(this);
this.state={
second:17,
style:{}
}
}
static propTypes = {
autoHide:PropTypes.bool
}
static defaultProps={
messageBlock:'success', //success|info|warning|danger
autoHide:false
}
minusSecond(){
let {second}=this.state;
if(second>0){
this.setState({
'second':second-1,
style:{opacity:second*0.059}
});
}
}
componentDidMount(){
const {autoHide}=this.props;
const {second}=this.state,self=this;
if(autoHide){
this.timer=setInterval(this.minusSecond,300);
}
}
componentWillReceiveProps(nextProps){
}
componentDidUpdate(prevProps,prevState){
}
componentWillUnmount() {
clearInterval(this.timer);
}
render(){
const {messageBlock,autoHide}=this.props;
const {second,style}=this.state;
if(autoHide&&second<=0){
return null;
}else{
return (<div className={cx(s.alert,s['alert_'+messageBlock])} style={style}>
{this.props.children}
</div>)
}
}
}
export default Alert;