1/* 2 * Copyright (c) 2021-2023 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 './@ohos.base'; 19import { Resource } from 'GlobalResource'; 20 21/** 22 * @namespace promptAction 23 * @syscap SystemCapability.ArkUI.ArkUI.Full 24 * @since 9 25 */ 26/** 27 * @namespace promptAction 28 * @syscap SystemCapability.ArkUI.ArkUI.Full 29 * @crossplatform 30 * @since 10 31 */ 32declare namespace promptAction { 33 /** 34 * @typedef ShowToastOptions 35 * @syscap SystemCapability.ArkUI.ArkUI.Full 36 * @since 9 37 */ 38 /** 39 * @typedef ShowToastOptions 40 * @syscap SystemCapability.ArkUI.ArkUI.Full 41 * @crossplatform 42 * @since 10 43 */ 44 interface ShowToastOptions { 45 46 /** 47 * Text to display. 48 * 49 * @type { string | Resource } 50 * @syscap SystemCapability.ArkUI.ArkUI.Full 51 * @since 9 52 */ 53 /** 54 * Text to display. 55 * 56 * @type { string | Resource } 57 * @syscap SystemCapability.ArkUI.ArkUI.Full 58 * @crossplatform 59 * @since 10 60 */ 61 message: string | Resource; 62 63 /** 64 * Duration of toast dialog box. The default value is 1500. 65 * The recommended value ranges from 1500ms to 10000ms. 66 * NOTE: A value less than 1500 is automatically changed to 1500. The maximum value is 10000ms. 67 * 68 * @type { ?number } 69 * @syscap SystemCapability.ArkUI.ArkUI.Full 70 * @since 9 71 */ 72 /** 73 * Duration of toast dialog box. The default value is 1500. 74 * The recommended value ranges from 1500ms to 10000ms. 75 * NOTE: A value less than 1500 is automatically changed to 1500. The maximum value is 10000ms. 76 * 77 * @type { ?number } 78 * @syscap SystemCapability.ArkUI.ArkUI.Full 79 * @crossplatform 80 * @since 10 81 */ 82 duration?: number; 83 84 /** 85 * The distance between toast dialog box and the bottom of screen. 86 * 87 * @type { ?string | number } 88 * @syscap SystemCapability.ArkUI.ArkUI.Full 89 * @since 9 90 */ 91 /** 92 * The distance between toast dialog box and the bottom of screen. 93 * 94 * @type { ?string | number } 95 * @syscap SystemCapability.ArkUI.ArkUI.Full 96 * @crossplatform 97 * @since 10 98 */ 99 bottom?: string | number; 100 } 101 102 /** 103 * @typedef Button 104 * @syscap SystemCapability.ArkUI.ArkUI.Full 105 * @since 9 106 */ 107 /** 108 * @typedef Button 109 * @syscap SystemCapability.ArkUI.ArkUI.Full 110 * @crossplatform 111 * @since 10 112 */ 113 interface Button { 114 115 /** 116 * The text displayed in the button. 117 * 118 * @type { string | Resource } 119 * @syscap SystemCapability.ArkUI.ArkUI.Full 120 * @since 9 121 */ 122 /** 123 * The text displayed in the button. 124 * 125 * @type { string | Resource } 126 * @syscap SystemCapability.ArkUI.ArkUI.Full 127 * @crossplatform 128 * @since 10 129 */ 130 text: string | Resource; 131 132 /** 133 * The foreground color of button. 134 * 135 * @type { string | Resource } 136 * @syscap SystemCapability.ArkUI.ArkUI.Full 137 * @since 9 138 */ 139 /** 140 * The foreground color of button. 141 * 142 * @type { string | Resource } 143 * @syscap SystemCapability.ArkUI.ArkUI.Full 144 * @crossplatform 145 * @since 10 146 */ 147 color: string | Resource; 148 } 149 150 /** 151 * @typedef ShowDialogSuccessResponse 152 * @syscap SystemCapability.ArkUI.ArkUI.Full 153 * @since 9 154 */ 155 /** 156 * @typedef ShowDialogSuccessResponse 157 * @syscap SystemCapability.ArkUI.ArkUI.Full 158 * @crossplatform 159 * @since 10 160 */ 161 interface ShowDialogSuccessResponse { 162 163 /** 164 * Index of the selected button, starting from 0. 165 * 166 * @type { number } 167 * @syscap SystemCapability.ArkUI.ArkUI.Full 168 * @since 9 169 */ 170 /** 171 * Index of the selected button, starting from 0. 172 * 173 * @type { number } 174 * @syscap SystemCapability.ArkUI.ArkUI.Full 175 * @crossplatform 176 * @since 10 177 */ 178 index: number; 179 } 180 181 /** 182 * @typedef ShowDialogOptions 183 * @syscap SystemCapability.ArkUI.ArkUI.Full 184 * @since 9 185 */ 186 /** 187 * @typedef ShowDialogOptions 188 * @syscap SystemCapability.ArkUI.ArkUI.Full 189 * @crossplatform 190 * @since 10 191 */ 192 interface ShowDialogOptions { 193 194 /** 195 * Title of the text to display. 196 * 197 * @type { ?string | Resource } 198 * @syscap SystemCapability.ArkUI.ArkUI.Full 199 * @since 9 200 */ 201 /** 202 * Title of the text to display. 203 * 204 * @type { ?string | Resource } 205 * @syscap SystemCapability.ArkUI.ArkUI.Full 206 * @crossplatform 207 * @since 10 208 */ 209 title?: string | Resource; 210 211 /** 212 * Text body. 213 * 214 * @type { ?string | Resource } 215 * @syscap SystemCapability.ArkUI.ArkUI.Full 216 * @since 9 217 */ 218 /** 219 * Text body. 220 * 221 * @type { ?string | Resource } 222 * @syscap SystemCapability.ArkUI.ArkUI.Full 223 * @crossplatform 224 * @since 10 225 */ 226 message?: string | Resource; 227 228 /** 229 * Array of buttons in the dialog box. 230 * The array structure is {text:'button', color: '#666666'}. 231 * One to three buttons are supported. 232 * The first button is of the positiveButton type, the second is of the negativeButton type, and the third is of the neutralButton type. 233 * 234 * @type { ?Array<Button> } 235 * @syscap SystemCapability.ArkUI.ArkUI.Full 236 * @since 9 237 */ 238 /** 239 * Array of buttons in the dialog box. 240 * The array structure is {text:'button', color: '#666666'}. 241 * More than one buttons are supported. 242 * 243 * @type { ?Array<Button> } 244 * @syscap SystemCapability.ArkUI.ArkUI.Full 245 * @crossplatform 246 * @since 10 247 */ 248 buttons?: Array<Button>; 249 250 /** 251 * Mask Region of dialog. The size can't exceed the main window. 252 * 253 * @type { ?Rectangle } 254 * @syscap SystemCapability.ArkUI.ArkUI.Full 255 * @crossplatform 256 * @since 10 257 */ 258 maskRect?: Rectangle; 259 260 /** 261 * Defines the dialog alignment of the screen. 262 * 263 * @type { ?DialogAlignment } 264 * @syscap SystemCapability.ArkUI.ArkUI.Full 265 * @crossplatform 266 * @since 10 267 */ 268 alignment?: DialogAlignment; 269 270 /** 271 * Defines the dialog offset. 272 * 273 * @type { ?Offset } 274 * @syscap SystemCapability.ArkUI.ArkUI.Full 275 * @crossplatform 276 * @since 10 277 */ 278 offset?: Offset; 279 } 280 281 /** 282 * @typedef ActionMenuSuccessResponse 283 * @syscap SystemCapability.ArkUI.ArkUI.Full 284 * @since 9 285 */ 286 /** 287 * @typedef ActionMenuSuccessResponse 288 * @syscap SystemCapability.ArkUI.ArkUI.Full 289 * @crossplatform 290 * @since 10 291 */ 292 interface ActionMenuSuccessResponse { 293 /** 294 * Index of the selected button, starting from 0. 295 * 296 * @type { number } 297 * @syscap SystemCapability.ArkUI.ArkUI.Full 298 * @since 9 299 */ 300 /** 301 * Index of the selected button, starting from 0. 302 * 303 * @type { number } 304 * @syscap SystemCapability.ArkUI.ArkUI.Full 305 * @crossplatform 306 * @since 10 307 */ 308 index: number; 309 } 310 311 /** 312 * @typedef ActionMenuOptions 313 * @syscap SystemCapability.ArkUI.ArkUI.Full 314 * @since 9 315 */ 316 /** 317 * @typedef ActionMenuOptions 318 * @syscap SystemCapability.ArkUI.ArkUI.Full 319 * @crossplatform 320 * @since 10 321 */ 322 interface ActionMenuOptions { 323 /** 324 * Title of the text to display. 325 * 326 * @type { ?string | Resource } 327 * @syscap SystemCapability.ArkUI.ArkUI.Full 328 * @since 9 329 */ 330 /** 331 * Title of the text to display. 332 * 333 * @type { ?string | Resource } 334 * @syscap SystemCapability.ArkUI.ArkUI.Full 335 * @crossplatform 336 * @since 10 337 */ 338 title?: string | Resource; 339 340 /** 341 * Array of buttons in the dialog box. 342 * The array structure is {text:'button', color: '#666666'}. 343 * One to six buttons are supported. 344 * 345 * @syscap SystemCapability.ArkUI.ArkUI.Full 346 * @since 9 347 */ 348 /** 349 * Array of buttons in the dialog box. 350 * The array structure is {text:'button', color: '#666666'}. 351 * One to six buttons are supported. 352 * 353 * @syscap SystemCapability.ArkUI.ArkUI.Full 354 * @crossplatform 355 * @since 10 356 */ 357 buttons: [Button, Button?, Button?, Button?, Button?, Button?]; 358 } 359 360 /** 361 * Displays the notification text. 362 * 363 * @param { ShowToastOptions } options - Options. 364 * @throws { BusinessError } 401 - if the type of message is incorrect. 365 * @throws { BusinessError } 100001 - if UI execution context not found. 366 * @syscap SystemCapability.ArkUI.ArkUI.Full 367 * @since 9 368 */ 369 /** 370 * Displays the notification text. 371 * 372 * @param { ShowToastOptions } options - Options. 373 * @throws { BusinessError } 401 - if the type of message is incorrect. 374 * @throws { BusinessError } 100001 - if UI execution context not found. 375 * @syscap SystemCapability.ArkUI.ArkUI.Full 376 * @crossplatform 377 * @since 10 378 */ 379 function showToast(options: ShowToastOptions): void; 380 381 /** 382 * Displays the dialog box. 383 * 384 * @param { ShowDialogOptions } options - Options. 385 * @param { AsyncCallback<ShowDialogSuccessResponse> } callback - the callback of showDialog. 386 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 387 * @throws { BusinessError } 100001 - if UI execution context not found. 388 * @syscap SystemCapability.ArkUI.ArkUI.Full 389 * @since 9 390 */ 391 /** 392 * Displays the dialog box. 393 * 394 * @param { ShowDialogOptions } options - Options. 395 * @param { AsyncCallback<ShowDialogSuccessResponse> } callback - the callback of showDialog. 396 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 397 * @throws { BusinessError } 100001 - if UI execution context not found. 398 * @syscap SystemCapability.ArkUI.ArkUI.Full 399 * @crossplatform 400 * @since 10 401 */ 402 function showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>): void; 403 404 /** 405 * Displays the dialog box. 406 * 407 * @param { ShowDialogOptions } options - Options. 408 * @returns { Promise<ShowDialogSuccessResponse> } the promise returned by the function. 409 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 410 * @throws { BusinessError } 100001 - if UI execution context not found. 411 * @syscap SystemCapability.ArkUI.ArkUI.Full 412 * @since 9 413 */ 414 /** 415 * Displays the dialog box. 416 * 417 * @param { ShowDialogOptions } options - Options. 418 * @returns { Promise<ShowDialogSuccessResponse> } the promise returned by the function. 419 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 420 * @throws { BusinessError } 100001 - if UI execution context not found. 421 * @syscap SystemCapability.ArkUI.ArkUI.Full 422 * @crossplatform 423 * @since 10 424 */ 425 function showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse>; 426 427 /** 428 * Displays the menu. 429 * 430 * @param { ActionMenuOptions } options - Options. 431 * @param { AsyncCallback<ActionMenuSuccessResponse> } callback - the callback of showActionMenu. 432 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 433 * @throws { BusinessError } 100001 - if UI execution context not found. 434 * @syscap SystemCapability.ArkUI.ArkUI.Full 435 * @since 9 436 */ 437 /** 438 * Displays the menu. 439 * 440 * @param { ActionMenuOptions } options - Options. 441 * @param { AsyncCallback<ActionMenuSuccessResponse> } callback - the callback of showActionMenu. 442 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 443 * @throws { BusinessError } 100001 - if UI execution context not found. 444 * @syscap SystemCapability.ArkUI.ArkUI.Full 445 * @crossplatform 446 * @since 10 447 */ 448 function showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>): void; 449 450 /** 451 * Displays the dialog box. 452 * 453 * @param { ActionMenuOptions } options - Options. 454 * @returns { Promise<ActionMenuSuccessResponse> } the promise returned by the function. 455 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 456 * @throws { BusinessError } 100001 - if UI execution context not found. 457 * @syscap SystemCapability.ArkUI.ArkUI.Full 458 * @since 9 459 */ 460 /** 461 * Displays the dialog box. 462 * 463 * @param { ActionMenuOptions } options - Options. 464 * @returns { Promise<ActionMenuSuccessResponse> } the promise returned by the function. 465 * @throws { BusinessError } 401 - if the number of parameters is not 1 or the type of parameters is incorrect. 466 * @throws { BusinessError } 100001 - if UI execution context not found. 467 * @syscap SystemCapability.ArkUI.ArkUI.Full 468 * @crossplatform 469 * @since 10 470 */ 471 function showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse>; 472} 473 474export default promptAction; 475