• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/// <reference path="../component/units.d.ts" />
17
18import { AsyncCallback } from './basic';
19import { Resource } from 'GlobalResource';
20
21/**
22 * @namespace promptAction
23 * @syscap SystemCapability.ArkUI.ArkUI.Full
24 * @since 9
25 */
26declare namespace promptAction {
27
28  /**
29   * @typedef ShowToastOptions
30   * @syscap SystemCapability.ArkUI.ArkUI.Full
31   * @since 9
32   */
33  interface ShowToastOptions {
34
35    /**
36     * Text to display.
37     * @type { string | Resource }
38     * @since 9
39     */
40    message: string | Resource;
41
42    /**
43     * Duration of toast dialog box. The default value is 1500.
44     * The recommended value ranges from 1500ms to 10000ms.
45     * NOTE: A value less than 1500 is automatically changed to 1500. The maximum value is 10000ms.
46     * @type { number }
47     * @since 9
48     */
49    duration?: number;
50
51    /**
52     * The distance between toast dialog box and the bottom of screen.
53     * @type { string | number }
54     * @since 9
55     */
56    bottom?: string | number;
57  }
58
59  /**
60   * @typedef Button
61   * @syscap SystemCapability.ArkUI.ArkUI.Full
62   * @since 9
63   */
64  interface Button {
65
66    /**
67     * @type { string | Resource }
68     * @since 9
69     */
70    text: string | Resource;
71
72    /**
73     * @type { string | Resource }
74     * @since 9
75     */
76    color: string | Resource;
77  }
78
79  /**
80   * @typedef ShowDialogSuccessResponse
81   * @syscap SystemCapability.ArkUI.ArkUI.Full
82   * @since 9
83   */
84  interface ShowDialogSuccessResponse {
85
86    /**
87     * Index of the selected button, starting from 0.
88     * @type { number }
89     * @since 9
90     */
91    index: number;
92  }
93
94  /**
95   * @typedef ShowDialogOptions
96   * @syscap SystemCapability.ArkUI.ArkUI.Full
97   * @since 9
98   */
99  interface ShowDialogOptions {
100
101    /**
102     * Title of the text to display.
103     * @type { string | Resource }
104     * @since 9
105     */
106    title?: string | Resource;
107
108    /**
109     * Text body.
110     * @type { string | Resource }
111     * @since 9
112     */
113    message?: string | Resource;
114
115    /**
116     * Array of buttons in the dialog box.
117     * The array structure is {text:'button', color: '#666666'}.
118     * One 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.
119     * @since 9
120     */
121    buttons?: [Button, Button?, Button?];
122  }
123
124  /**
125   * @typedef ActionMenuSuccessResponse
126   * @syscap SystemCapability.ArkUI.ArkUI.Full
127   * @since 9
128   */
129  interface ActionMenuSuccessResponse {
130
131    /**
132     * Index of the selected button, starting from 0.
133     * @type { number }
134     * @since 9
135     */
136    index: number;
137  }
138
139  /**
140   * @typedef ActionMenuOptions
141   * @syscap SystemCapability.ArkUI.ArkUI.Full
142   * @since 9
143   */
144  interface ActionMenuOptions {
145
146    /**
147     * Title of the text to display.
148     * @type { string | Resource }
149     * @since 9
150     */
151    title?: string | Resource;
152
153    /**
154     * Array of buttons in the dialog box.
155     * The array structure is {text:'button', color: '#666666'}.
156     * One to six buttons are supported.
157     * @since 9
158     */
159    buttons: [Button, Button?, Button?, Button?, Button?, Button?];
160  }
161
162  /**
163   * Displays the notification text.
164   * @param { ShowToastOptions } options - Options.
165   * @syscap SystemCapability.ArkUI.ArkUI.Full
166   * @throws { BusinessError } 401 - if the type of message is incorrect.
167   * @throws { BusinessError } 100001 - if UI execution context not found.
168   * @syscap SystemCapability.ArkUI.ArkUI.Full
169   * @since 9
170   */
171  function showToast(options: ShowToastOptions):void;
172
173  /**
174   * Displays the dialog box.
175   * @param { ShowDialogOptions } options - Options.
176   * @param { AsyncCallback<ShowDialogSuccessResponse> } callback - the callback of showDialog.
177   * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect.
178   * @throws { BusinessError } 100001 - if UI execution context not found.
179   * @syscap SystemCapability.ArkUI.ArkUI.Full
180   * @since 9
181   */
182  function showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void;
183
184  /**
185   * Displays the dialog box.
186   * @param { ShowDialogOptions } options - Options.
187   * @returns { Promise<ShowDialogSuccessResponse> } the promise returned by the function.
188   * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect.
189   * @throws { BusinessError } 100001 - if UI execution context not found.
190   * @syscap SystemCapability.ArkUI.ArkUI.Full
191   * @since 9
192   */
193  function showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse>;
194
195  /**
196   * Displays the menu.
197   * @param { ActionMenuOptions } options - Options.
198   * @param { AsyncCallback<ActionMenuSuccessResponse> } callback - the callback of showActionMenu.
199   * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect.
200   * @throws { BusinessError } 100001 - if UI execution context not found.
201   * @syscap SystemCapability.ArkUI.ArkUI.Full
202   * @since 9
203   */
204  function showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void;
205
206  /**
207   * Displays the dialog box.
208   * @param { ActionMenuOptions } options - Options.
209   * @returns { Promise<ActionMenuSuccessResponse> } the promise returned by the function.
210   * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect.
211   * @throws { BusinessError } 100001 - if UI execution context not found.
212   * @syscap SystemCapability.ArkUI.ArkUI.Full
213   * @since 9
214   */
215  function showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse>;
216}
217
218export default promptAction;
219