message-box.d.ts 4.3 KB

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