message-box.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import Vue from 'vue'
  2. import { MessageType } from './message'
  3. export type MessageBoxCloseAction = 'confirm' | 'cancel'
  4. export type MessageBoxData = MessageBoxCloseAction | MessageBoxInputData
  5. export interface MessageBoxInputData {
  6. value: string,
  7. action: MessageBoxCloseAction
  8. }
  9. export interface MessageBoxInputValidator {
  10. (value: string): boolean | string
  11. }
  12. export declare class ElMessageBoxComponent extends Vue {
  13. title: string
  14. message: string
  15. type: MessageType
  16. customClass: string
  17. showInput: boolean
  18. inputValue: string
  19. inputPlaceholder: string
  20. inputPattern: RegExp
  21. inputValidator: MessageBoxInputValidator
  22. inputErrorMessage: string
  23. showConfirmButton: boolean
  24. showCancelButton: boolean
  25. action: MessageBoxCloseAction
  26. confirmButtonText: string
  27. cancelButtonText: string
  28. confirmButtonLoading: boolean
  29. cancelButtonLoading: boolean
  30. confirmButtonClass: string
  31. confirmButtonDisabled: boolean
  32. cancelButtonClass: string
  33. editorErrorMessage: string
  34. }
  35. /** Options used in MessageBox */
  36. export interface ElMessageBoxOptions {
  37. /** Title of the MessageBox */
  38. title?: string
  39. /** Content of the MessageBox */
  40. message?: string
  41. /** Message type, used for icon display */
  42. type?: MessageType
  43. /** Custom class name for MessageBox */
  44. customClass?: string
  45. /** MessageBox closing callback if you don't prefer Promise */
  46. callback?: (action: MessageBoxCloseAction, instance: ElMessageBoxComponent) => void
  47. /** Callback before MessageBox closes, and it will prevent MessageBox from closing */
  48. beforeClose?: (action: MessageBoxCloseAction, instance: ElMessageBoxComponent, done: (() => void)) => void
  49. /** Whether to lock body scroll when MessageBox prompts */
  50. lockScroll?: boolean
  51. /** Whether to show a cancel button */
  52. showCancelButton?: boolean
  53. /** Whether to show a confirm button */
  54. showConfirmButton?: boolean
  55. /** Text content of cancel button */
  56. cancelButtonText?: string
  57. /** Text content of confirm button */
  58. confirmButtonText?: string
  59. /** Custom class name of cancel button */
  60. cancelButtonClass?: string
  61. /** Custom class name of confirm button */
  62. confirmButtonClass?: string
  63. /** Whether MessageBox can be closed by clicking the mask */
  64. closeOnClickModal?: boolean
  65. /** Whether MessageBox can be closed by pressing the ESC */
  66. closeOnPressEscape?: boolean
  67. /** Whether to show an input */
  68. showInput?: boolean
  69. /** Placeholder of input */
  70. inputPlaceholder?: string
  71. /** Initial value of input */
  72. inputValue?: string
  73. /** Regexp for the input */
  74. inputPattern?: RegExp
  75. /** Validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage */
  76. inputValidator?: MessageBoxInputValidator
  77. /** Error message when validation fails */
  78. inputErrorMessage?: string
  79. }
  80. export interface ElMessageBoxShortcutMethod {
  81. (message: string, title: string, options?: ElMessageBoxOptions): Promise<MessageBoxData>
  82. (message: string, options?: ElMessageBoxOptions): Promise<MessageBoxData>
  83. }
  84. export interface ElMessageBox {
  85. /** Show a message box */
  86. (message: string, title?: string, type?: string): Promise<MessageBoxData>
  87. /** Show a message box */
  88. (options: ElMessageBoxOptions): Promise<MessageBoxData>
  89. /** Show an alert message box */
  90. alert: ElMessageBoxShortcutMethod
  91. /** Show a comfirm message box */
  92. confirm: ElMessageBoxShortcutMethod
  93. /** Show a prompt message box */
  94. prompt: ElMessageBoxShortcutMethod
  95. /** Set default options of message boxes */
  96. setDefaults (defaults: ElMessageBoxOptions)
  97. /** Close current message box */
  98. close ()
  99. }
  100. declare module 'vue/types/vue' {
  101. interface Vue {
  102. /** Show a message box */
  103. $msgbox: ElMessageBox
  104. /** Show an alert message box */
  105. $alert: ElMessageBoxShortcutMethod
  106. /** Show a confirm message box */
  107. $confirm: ElMessageBoxShortcutMethod
  108. /** Show a prompt message box */
  109. $prompt: ElMessageBoxShortcutMethod
  110. }
  111. }