import React from "react";
import { toast } from "sonner";
import { AlertOptions, ToastOptions } from "./types";
import { getHasMountedWebToaster } from "./web";
function getIcon(options: ToastOptions | AlertOptions) {
return options.preset === "custom" ? (
options.icon.web
) : options.preset === "done" ? (
) : options.preset === "error" ? (
) : undefined;
}
export default {
toastAsync(options: ToastOptions) {
if (!getHasMountedWebToaster()) {
console.error(
`[burnt] toast() error: You need to add the component to the root of your app for toasts to display on Web. There was no found.`
);
} else {
toast(options.title, {
description: options.message,
icon: getIcon(options),
duration: (options.duration ?? 5) * 1000,
});
}
},
alertAsync(options: AlertOptions) {
if (!getHasMountedWebToaster()) {
console.error(
`[burnt] toast() error: You need to add the component to the root of your app for toasts to display on Web. There was no found.`
);
} else {
if (options.preset === "spinner") {
toast.promise(
async () =>
new Promise((resolve) =>
setTimeout(resolve, options.duration * 1000)
),
{
// this behavior may be kinda weird, we don't have a success state with the ios alert() call...
loading: options.title,
description: options.message,
error: options.title,
success: options.title,
}
);
} else {
toast(options.title, {
description: options.message,
icon: getIcon(options),
duration: (options.duration ?? 5) * 1000,
});
}
}
},
dismissAllAlertsAsync() {
toast.dismiss();
},
};
const DoneIcon = () => (
);
const XIcon = () => {
return (
);
};