message-box.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import Vue, { VNode } from 'vue'
  2. import { MessageType } from './message'
  3. export type MessageBoxCloseAction = 'confirm' | 'cancel' | 'close'
  4. export type MessageBoxData = MessageBoxInputData | MessageBoxCloseAction
  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. iconClass: string
  17. customClass: string
  18. showInput: boolean
  19. showClose: boolean
  20. inputValue: string
  21. inputPlaceholder: string
  22. inputType: string
  23. inputPattern: RegExp
  24. inputValidator: MessageBoxInputValidator
  25. inputErrorMessage: string
  26. showConfirmButton: boolean
  27. showCancelButton: boolean
  28. action: MessageBoxCloseAction
  29. dangerouslyUseHTMLString: boolean
  30. confirmButtonText: string
  31. cancelButtonText: string
  32. confirmButtonLoading: boolean
  33. cancelButtonLoading: boolean
  34. confirmButtonClass: string
  35. confirmButtonDisabled: boolean
  36. cancelButtonClass: string
  37. editorErrorMessage: string
  38. }
  39. /** Options used in MessageBox */
  40. export interface ElMessageBoxOptions {
  41. /** Title of the MessageBox */
  42. title?: string
  43. /** Content of the MessageBox */
  44. message?: string | VNode
  45. /** Message type, used for icon display */
  46. type?: MessageType
  47. /** Custom icon's class */
  48. iconClass?: string
  49. /** Custom class name for MessageBox */
  50. customClass?: string
  51. /** MessageBox closing callback if you don't prefer Promise */
  52. callback?: (action: MessageBoxCloseAction, instance: ElMessageBoxComponent) => void
  53. /** Callback before MessageBox closes, and it will prevent MessageBox from closing */
  54. beforeClose?: (action: MessageBoxCloseAction, instance: ElMessageBoxComponent, done: (() => void)) => void
  55. /** Whether to lock body scroll when MessageBox prompts */
  56. lockScroll?: boolean
  57. /** Whether to show a cancel button */
  58. showCancelButton?: boolean
  59. /** Whether to show a confirm button */
  60. showConfirmButton?: boolean
  61. /** Whether to show a close button */
  62. showClose?: boolean
  63. /** Text content of cancel button */
  64. cancelButtonText?: string
  65. /** Text content of confirm button */
  66. confirmButtonText?: string
  67. /** Custom class name of cancel button */
  68. cancelButtonClass?: string
  69. /** Custom class name of confirm button */
  70. confirmButtonClass?: string
  71. /** Whether to align the content in center */
  72. center?: boolean
  73. /** Whether message is treated as HTML string */
  74. dangerouslyUseHTMLString?: boolean
  75. /** Whether to use round button */
  76. roundButton?: boolean
  77. /** Whether MessageBox can be closed by clicking the mask */
  78. closeOnClickModal?: boolean
  79. /** Whether MessageBox can be closed by pressing the ESC */
  80. closeOnPressEscape?: boolean
  81. /** Whether to close MessageBox when hash changes */
  82. closeOnHashChange?: boolean
  83. /** Whether to show an input */
  84. showInput?: boolean
  85. /** Placeholder of input */
  86. inputPlaceholder?: string
  87. /** Initial value of input */
  88. inputValue?: string
  89. /** Regexp for the input */
  90. inputPattern?: RegExp
  91. /** Input Type: text, textArea, password or number */
  92. inputType?: string
  93. /** Validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage */
  94. inputValidator?: MessageBoxInputValidator
  95. /** Error message when validation fails */
  96. inputErrorMessage?: string
  97. /** Whether to distinguish canceling and closing */
  98. distinguishCancelAndClose?: boolean
  99. }
  100. export interface ElMessageBoxShortcutMethod {
  101. (message: string, title: string, options?: ElMessageBoxOptions): Promise<MessageBoxData>
  102. (message: string, options?: ElMessageBoxOptions): Promise<MessageBoxData>
  103. }
  104. export interface ElMessageBox {
  105. /** Show a message box */
  106. (message: string, title?: string, type?: string): Promise<MessageBoxData>
  107. /** Show a message box */
  108. (options: ElMessageBoxOptions): Promise<MessageBoxData>
  109. /** Show an alert message box */
  110. alert: ElMessageBoxShortcutMethod
  111. /** Show a confirm message box */
  112. confirm: ElMessageBoxShortcutMethod
  113. /** Show a prompt message box */
  114. prompt: ElMessageBoxShortcutMethod
  115. /** Set default options of message boxes */
  116. setDefaults (defaults: ElMessageBoxOptions): void
  117. /** Close current message box */
  118. close (): void
  119. }
  120. declare module 'vue/types/vue' {
  121. interface Vue {
  122. /** Show a message box */
  123. $msgbox: ElMessageBox
  124. /** Show an alert message box */
  125. $alert: ElMessageBoxShortcutMethod
  126. /** Show a confirm message box */
  127. $confirm: ElMessageBoxShortcutMethod
  128. /** Show a prompt message box */
  129. $prompt: ElMessageBoxShortcutMethod
  130. }
  131. }