forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToast.js
42 lines (39 loc) · 819 Bytes
/
Toast.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
import React from 'react';
import './Toast.css';
export default class Toast extends React.Component {
state = {
active: true,
};
close = () => {
clearTimeout(this.timeout);
this.setState({
active: false,
});
};
componentDidMount() {
this.timeout = setTimeout(
() => {
this.setState({
active: false,
});
},
this.props.timeout
);
}
componentWillUnmount() {
clearTimeout(this.timeout);
}
render() {
return (
<div className={`Toast ${this.state.active ? 'active' : 'inactive'}`}>
<span className="Toast-text">
{this.props.children}
</span>
<button className="Toast-button" onClick={this.close}>Dismiss</button>
</div>
);
}
}
Toast.defaultProps = {
timeout: 3000,
};