message-box.d.ts 4.4 KB

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