fix: migrate toasts from daisyui to tailwind
This commit was merged in pull request #54.
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
function getClass(type) {
|
||||
switch (type) {
|
||||
case "error":
|
||||
return "alert-error";
|
||||
return ["bg-amber-900", "text-white"];
|
||||
case "warning":
|
||||
return "alert-warning";
|
||||
return ["bg-yellow-200", "text-gray-800"];
|
||||
case "success":
|
||||
return "alert-success";
|
||||
// case "info":
|
||||
return ["bg-green-900", "text-white"];
|
||||
default:
|
||||
return "alert-info";
|
||||
return ["bg-gray-800", "text-white"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,20 +20,22 @@ htmx.on("toast", (e) => {
|
||||
|
||||
const template = document.getElementById("toast");
|
||||
const toast = template.cloneNode(true);
|
||||
const parent = document.getElementById("toasts");
|
||||
const list = document.getElementById("toasts");
|
||||
|
||||
toast.id = ""
|
||||
toast.classList.remove("hidden");
|
||||
toast.classList.add(getClass(type));
|
||||
toast.classList.add(...getClass(type));
|
||||
toast.innerText = message;
|
||||
|
||||
parent.appendChild(toast);
|
||||
list.appendChild(toast);
|
||||
setTimeout(() => {
|
||||
toast.classList.remove("opacity-0");
|
||||
}, 0);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.add("animate-fade");
|
||||
toast.classList.add("opacity-0");
|
||||
setTimeout(() => {
|
||||
parent.removeChild(toast);
|
||||
list.removeChild(toast);
|
||||
}, 250);
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user