jellyfish-web/src/components/toast/toast.js

35 lines
696 B
JavaScript
Raw Normal View History

2021-01-26 16:25:38 -05:00
import './toast.scss';
2018-10-23 01:05:09 +03:00
function remove(elem) {
setTimeout(function () {
elem.parentNode.removeChild(elem);
}, 300);
}
2018-10-23 01:05:09 +03:00
function animateRemove(elem) {
setTimeout(function () {
elem.classList.remove('toastVisible');
remove(elem);
}, 3300);
}
export default function (options) {
if (typeof options === 'string') {
options = {
text: options
};
}
2020-07-27 10:30:24 +01:00
const elem = document.createElement('div');
2020-09-08 15:43:19 -04:00
elem.classList.add('toast');
2021-05-21 00:24:59 -04:00
elem.textContent = options.text;
document.body.appendChild(elem);
setTimeout(function () {
elem.classList.add('toastVisible');
animateRemove(elem);
}, 300);
}