Dialog

1import { Button, List, Navigation, NavigationStack, Script, } from "scripting"
2
3function Example() {
4
5  return <NavigationStack>
6    <List
7      navigationTitle={"Dialog"}
8      navigationBarTitleDisplayMode={"inline"}
9    >
10      <Button
11        title={"Dialog.alert"}
12        action={async () => {
13          await Dialog.alert({
14            message: "This is message",
15            title: "Alert",
16          })
17          console.log("Alert dismissed")
18        }}
19      />
20
21      <Button
22        title={"Dialog.prompt"}
23        action={async () => {
24          const result = await Dialog.prompt({
25            title: "Rename script",
26            placeholder: "Enter script name",
27          })
28
29          Dialog.alert({
30            message: result == null
31              ? "You cancel the prompt"
32              : "The new script name is: " + result
33          })
34        }}
35      />
36
37      <Button
38        title={"Dialog.actionSheet"}
39        action={async () => {
40          const selectedIndex = await Dialog.actionSheet({
41            title: "Are you sure to delete this script?",
42            message: "This operation cannot be undone.",
43            cancelButton: true,
44            actions: [
45              {
46                label: "Delete",
47                destructive: true,
48              }
49            ]
50          })
51
52          if (selectedIndex === 0) {
53            Dialog.alert({
54              message: "The script is deleted."
55            })
56          }
57        }}
58      />
59    </List>
60  </NavigationStack>
61}
62
63async function run() {
64  await Navigation.present({
65    element: <Example />
66  })
67
68  Script.exit()
69}
70
71run()