Alert
When the user takes an important action (for example when irreversibly deleting something), you can ask for confirmation by using
confirmAlert
.
async function confirmAlert(options: Alert.Options): Promise<boolean>;
import { confirmAlert } from "@raycast/api";
export default async function Command() {
if (await confirmAlert({ title: "Are you sure?" })) {
console.log("confirmed");
// do something
} else {
console.log("canceled");
}
}
Name | Description | Type |
---|---|---|
options* | The options used to create the Alert. |
A Promise that resolves to a boolean when the user triggers one of the actions. It will be
true
for the primary Action, false
for the dismiss Action.The options to create an Alert.
import { Alert, confirmAlert } from "@raycast/api";
export default async function Command() {
const options: Alert.Options = {
title: "Finished cooking",
message: "Delicious pasta for lunch",
primaryAction: {
title: "Do something",
onAction: () => {
// while you can register a handler for an action, it's more elegant
// to use the `if (await confirmAlert(...)) { ... }` pattern
console.log("The alert action has been triggered");
},
},
};
await confirmAlert(options);
}
Property | Description | Type |
---|---|---|
title* | The title of an alert. Displayed below the icon. | string |
dismissAction | The Action to dismiss the alert. There usually shouldn't be any side effects when the user takes this action. | |
icon | The icon of an alert to illustrate the action. Displayed on the top. | |
message | An additional message for an Alert. Useful to show more information, e.g. a confirmation message for a destructive action. | string |
primaryAction | The primary Action the user can take. |
The options to create an Alert Action.
Property | Description | Type |
---|---|---|
title* | The title of the action. | string |
style | The style of the action. | |
onAction | A callback called when the action is triggered. | () => void |
Defines the visual style of an Action of the Alert.
Use Alert.ActionStyle.Default for confirmations of a positive action. Use Alert.ActionStyle.Destructive for confirmations of a destructive action (eg. deleting a file).
Name | Value |
---|---|
Default | ![]() |
Destructive | ![]() |
Cancel | ![]() |
Last modified 4mo ago