Toast
Last updated
async function showToast(options: Toast.Options): Promise<Toast>;import { showToast, Toast } from "@raycast/api";
export default async function Command() {
const success = false;
if (success) {
await showToast({ title: "Dinner is ready", message: "Pizza margherita" });
} else {
await showToast({
style: Toast.Style.Failure,
title: "Dinner isn't ready",
message: "Pizza dropped on the floor",
});
}
}import { showToast, Toast } from "@raycast/api";
import { setTimeout } from "timers/promises";
export default async function Command() {
const toast = await showToast({
style: Toast.Style.Animated,
title: "Uploading image",
});
try {
// upload the image
await setTimeout(1000);
toast.style = Toast.Style.Success;
toast.title = "Uploaded image";
} catch (err) {
toast.style = Toast.Style.Failure;
toast.title = "Failed to upload image";
if (err instanceof Error) {
toast.message = err.message;
}
}
}import { showToast, Toast } from "@raycast/api";
export default async function Command() {
const options: Toast.Options = {
style: Toast.Style.Success,
title: "Finished cooking",
message: "Delicious pasta for lunch",
primaryAction: {
title: "Do something",
onAction: (toast) => {
console.log("The toast action has been triggered");
toast.hide();
},
},
};
await showToast(options);
}