AdGuardHome/client/src/components/Toasts/Toast.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-09-14 15:37:35 +03:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class Toast extends Component {
componentDidMount() {
2018-09-14 16:41:34 +03:00
const timeoutTime = this.props.type === 'error' ? 30000 : 5000;
2018-09-14 15:37:35 +03:00
setTimeout(() => {
this.props.removeToast(this.props.id);
2018-09-14 16:41:34 +03:00
}, timeoutTime);
2018-09-14 15:37:35 +03:00
}
shouldComponentUpdate() {
return false;
}
render() {
return (
<div className={`toast toast--${this.props.type}`}>
<p className="toast__content">
{this.props.message}
</p>
<button className="toast__dismiss" onClick={() => this.props.removeToast(this.props.id)}>
<svg stroke="#fff" fill="none" width="20" height="20" strokeWidth="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m18 6-12 12"/><path d="m6 6 12 12"/></svg>
</button>
</div>
);
}
}
Toast.propTypes = {
id: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
removeToast: PropTypes.func.isRequired,
};
export default Toast;