message-box.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import Vue from 'vue'
  2. import { MessageType } from './message'
  3. export type MessageBoxCloseAction = 'confirm' | 'cancel' | 'close'
  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. 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
  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. /** Text content of cancel button */
  62. cancelButtonText?: string
  63. /** Text content of confirm button */
  64. confirmButtonText?: string
  65. /** Custom class name of cancel button */
  66. cancelButtonClass?: string
  67. /** Custom class name of confirm button */
  68. confirmButtonClass?: string
  69. /** Whether to align the content in center */
  70. center?: boolean
  71. /** Whether message is treated as HTML string */
  72. dangerouslyUseHTMLString?: boolean
  73. /** Whether to use round button */
  74. roundButton?: boolean
  75. /** Whether MessageBox can be closed by clicking the mask */
  76. closeOnClickModal?: boolean
  77. /** Whether MessageBox can be closed by pressing the ESC */
  78. closeOnPressEscape?: boolean
  79. /** Whether to close MessageBox when hash changes */
  80. closeOnHashChange?: boolean
  81. /** Whether to show an input */
  82. showInput?: boolean
  83. /** Placeholder of input */
  84. inputPlaceholder?: string
  85. /** Initial value of input */
  86. inputValue?: string
  87. /** Regexp for the input */
  88. inputPattern?: RegExp
  89. /** Input Type: text, textArea, password or number */
  90. inputType?: string
  91. /** Validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage */
  92. inputValidator?: MessageBoxInputValidator
  93. /** Error message when validation fails */
  94. inputErrorMessage?: string
  95. }
  96. export interface ElMessageBoxShortcutMethod {
  97. (message: string, title: string, options?: ElMessageBoxOptions): Promise<MessageBoxData>
  98. (message: string, options?: ElMessageBoxOptions): Promise<MessageBoxData>
  99. }
  100. export interface ElMessageBox {
  101. /** Show a message box */
  102. (message: string, title?: string, type?: string): Promise<MessageBoxData>
  103. /** Show a message box */
  104. (options: ElMessageBoxOptions): Promise<MessageBoxData>
  105. /** Show an alert message box */
  106. alert: ElMessageBoxShortcutMethod
  107. /** Show a confirm message box */
  108. confirm: ElMessageBoxShortcutMethod
  109. /** Show a prompt message box */
  110. prompt: ElMessageBoxShortcutMethod
  111. /** Set default options of message boxes */
  112. setDefaults (defaults: ElMessageBoxOptions): void
  113. /** Close current message box */
  114. close (): void
  115. }
  116. declare module 'vue/types/vue' {
  117. interface Vue {
  118. /** Show a message box */
  119. $msgbox: ElMessageBox
  120. /** Show an alert message box */
  121. $alert: ElMessageBoxShortcutMethod
  122. /** Show a confirm message box */
  123. $confirm: ElMessageBoxShortcutMethod
  124. /** Show a prompt message box */
  125. $prompt: ElMessageBoxShortcutMethod
  126. }
  127. }