1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/toast/toast.js

47 lines
975 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
2022-01-17 23:27:28 +03:00
let toastContainer;
function getToastContainer() {
if (!toastContainer) {
toastContainer = document.createElement('div');
toastContainer.classList.add('toastContainer');
document.body.appendChild(toastContainer);
}
return toastContainer;
}
function remove(elem) {
setTimeout(function () {
elem.parentNode.removeChild(elem);
}, 300);
}
2018-10-23 01:05:09 +03:00
function animateRemove(elem) {
setTimeout(function () {
2022-01-17 23:27:28 +03:00
elem.classList.add('toastHide');
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;
2022-01-17 23:27:28 +03:00
getToastContainer().appendChild(elem);
setTimeout(function () {
elem.classList.add('toastVisible');
animateRemove(elem);
}, 300);
}