receipts/js/alert.ts

29 lines
823 B
TypeScript

import SlAlert from "@shoelace-style/shoelace/dist/components/alert/alert.js";
import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.js";
type AlertVariant = "primary" | "success" | "neutral" | "warning" | "danger";
export function notify(
message: string,
variant: AlertVariant = "primary",
iconName = "info-circle",
duration: number | null = 3000,
) {
const alert = new SlAlert();
const icon = new SlIcon();
icon.slot = "icon";
icon.name = iconName;
alert.variant = variant;
alert.open = true;
alert.style.position = "relative";
alert.closable = true;
if (duration) {
alert.duration = duration;
}
alert.appendChild(icon);
alert.appendChild(document.createTextNode(message));
document.body.append(alert);
alert.toast();
}