1# @ohos.prompt (Prompt)
2
3The **Prompt** module provides APIs for creating and showing toasts, dialog boxes, and action menus.
4
5> **NOTE**
6> The APIs of this module are deprecated since API Version 9. You are advised to use [@ohos.promptAction](js-apis-promptAction.md) instead.
7>
8> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9
10## Modules to Import
11
12```ts
13import prompt from '@ohos.prompt'
14```
15
16## prompt.showToast
17
18showToast(options: ShowToastOptions): void
19
20Shows a toast.
21
22**System capability**: SystemCapability.ArkUI.ArkUI.Full
23
24**Parameters**
25
26| Name    | Type                                   | Mandatory  | Description     |
27| ------- | ------------------------------------- | ---- | ------- |
28| options | [ShowToastOptions](#showtoastoptions) | Yes   | Toast options. |
29
30**Example**
31
32```ts
33import prompt from '@ohos.prompt'
34prompt.showToast({
35  message: 'Message Info',
36    duration: 2000
37});
38```
39
40![en-us_image_0001](figures/en-us_image_0001.gif)
41
42## ShowToastOptions
43
44Describes the options for showing the toast.
45
46**System capability**: SystemCapability.ArkUI.ArkUI.Full
47
48| Name    | Type           | Mandatory | Description                                                        |
49| -------- | --------------- | ---- | ------------------------------------------------------------ |
50| message  | string          | Yes  | Text to display.                                            |
51| duration | number          | No  | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used. |
52| bottom   | string\| number | No  | Distance between the toast border and the bottom of the screen. It does not have an upper limit. The default unit is vp.      |
53
54## prompt.showDialog
55
56showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse>
57
58Shows a dialog box. This API uses a promise to return the result synchronously.
59
60**System capability**: SystemCapability.ArkUI.ArkUI.Full
61
62**Parameters**
63
64| Name    | Type                                     | Mandatory  | Description    |
65| ------- | --------------------------------------- | ---- | ------ |
66| options | [ShowDialogOptions](#showdialogoptions) | Yes   | Dialog box options. |
67
68**Return value**
69
70| Type                                      | Description      |
71| ---------------------------------------- | -------- |
72| Promise<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Promise used to return the dialog box response result. |
73
74**Example**
75
76```ts
77import prompt from '@ohos.prompt'
78prompt.showDialog({
79  title: 'Title Info',
80  message: 'Message Info',
81  buttons: [
82    {
83      text: 'button1',
84      color: '#000000'
85    },
86    {
87      text: 'button2',
88      color: '#000000'
89    }
90  ],
91})
92  .then(data => {
93    console.info('showDialog success, click button: ' + data.index);
94  })
95  .catch((err:Error) => {
96    console.info('showDialog error: ' + err);
97  })
98```
99
100![en-us_image_0002](figures/en-us_image_0002.gif)
101
102## prompt.showDialog
103
104showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void
105
106Shows a dialog box. This API uses an asynchronous callback to return the result.
107
108**System capability**: SystemCapability.ArkUI.ArkUI.Full
109
110**Parameters**
111
112| Name     | Type                                      | Mandatory  | Description          |
113| -------- | ---------------------------------------- | ---- | ------------ |
114| options  | [ShowDialogOptions](#showdialogoptions)  | Yes   | Dialog box options. |
115| callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Yes   | Callback used to return the dialog box response result.  |
116
117**Example**
118
119```ts
120import prompt from '@ohos.prompt'
121prompt.showDialog({
122  title: 'showDialog Title Info',
123  message: 'Message Info',
124  buttons: [
125    {
126      text: 'button1',
127      color: '#000000'
128    },
129    {
130      text: 'button2',
131      color: '#000000'
132    }
133  ]
134}, (err, data) => {
135  if (err) {
136    console.info('showDialog err: ' + err);
137    return;
138  }
139  console.info('showDialog success callback, click button: ' + data.index);
140});
141```
142
143![en-us_image_0004](figures/en-us_image_0004.gif)
144
145## ShowDialogOptions
146
147Describes the options for showing the dialog box.
148
149**System capability**: SystemCapability.ArkUI.ArkUI.Full
150
151| Name   | Type                                                     | Mandatory | Description                                                        |
152| ------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
153| title   | string                                                    | No  | Title of the dialog box.                                                  |
154| message | string                                                    | No  | Text body.                                                  |
155| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?] | No  | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type. |
156
157## ShowDialogSuccessResponse
158
159Describes the dialog box response result.
160
161**System capability**: SystemCapability.ArkUI.ArkUI.Full
162
163| Name | Type  | Mandatory | Description                           |
164| ----- | ------ | ---- | ------------------------------- |
165| index | number | Yes  | Index of the selected button in the **buttons** array. |
166
167
168## prompt.showActionMenu
169
170showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void
171
172Shows an action menu. This API uses a callback to return the result asynchronously.
173
174**System capability**: SystemCapability.ArkUI.ArkUI.Full
175
176**Parameters**
177
178| Name     | Type                                      | Mandatory  | Description       |
179| -------- | ---------------------------------------- | ---- | --------- |
180| options  | [ActionMenuOptions](#actionmenuoptions)  | Yes   | Action menu options.  |
181| callback | AsyncCallback<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes   | Callback used to return the action menu response result. |
182
183**Example**
184
185```ts
186import prompt from '@ohos.prompt'
187prompt.showActionMenu({
188  title: 'Title Info',
189  buttons: [
190    {
191      text: 'item1',
192      color: '#666666'
193    },
194    {
195      text: 'item2',
196      color: '#000000'
197    },
198  ]
199}, (err, data) => {
200  if (err) {
201    console.info('showActionMenu err: ' + err);
202    return;
203  }
204  console.info('showActionMenu success callback, click button: ' + data.index);
205})
206```
207
208![en-us_image_0005](figures/en-us_image_0005.gif)
209
210## prompt.showActionMenu
211
212showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse>
213
214Shows an action menu. This API uses a promise to return the result synchronously.
215
216**System capability**: SystemCapability.ArkUI.ArkUI.Full
217
218**Parameters**
219
220| Name    | Type                                     | Mandatory  | Description     |
221| ------- | --------------------------------------- | ---- | ------- |
222| options | [ActionMenuOptions](#actionmenuoptions) | Yes   | Action menu options. |
223
224**Return value**
225
226| Type                                      | Description     |
227| ---------------------------------------- | ------- |
228| Promise<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Promise used to return the action menu response result. |
229
230**Example**
231
232```ts
233import prompt from '@ohos.prompt'
234prompt.showActionMenu({
235  title: 'showActionMenu Title Info',
236  buttons: [
237    {
238      text: 'item1',
239      color: '#666666'
240    },
241    {
242      text: 'item2',
243      color: '#000000'
244    },
245  ]
246})
247  .then(data => {
248    console.info('showActionMenu success, click button: ' + data.index);
249  })
250  .catch((err:Error) => {
251    console.info('showActionMenu error: ' + err);
252  })
253```
254![en-us_image_0006](figures/en-us_image_0006.gif)
255
256## ActionMenuOptions
257
258Describes the options for showing the action menu.
259
260**System capability**: SystemCapability.ArkUI.ArkUI.Full
261
262| Name   | Type                                                        | Mandatory | Description                                                        |
263| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
264| title   | string                                                       | No  | Title of the text to display.                                                  |
265| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?] | Yes  | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed. |
266
267## ActionMenuSuccessResponse
268
269Describes the action menu response result.
270
271**System capability**: SystemCapability.ArkUI.ArkUI.Full
272
273| Name | Type  | Mandatory | Description                                    |
274| ----- | ------ | ---- | ---------------------------------------- |
275| index | number | Yes  | Index of the selected button in the **buttons** array, starting from **0**. |
276
277## Button
278
279Describes the menu item button in the action menu.
280
281**System capability**: SystemCapability.ArkUI.ArkUI.Full
282
283| Name | Type  | Mandatory | Description          |
284| ----- | ------ | ---- | -------------- |
285| text  | string | Yes  | Button text. |
286| color | string | Yes  | Text color of the button. |
287