438ec8815874e892ddac64899814d8129724943f8e8f440221c4c4f697257f6fb9b8eaae49a0677a93d65a25657b9e682d07de8a9cf2b07c93c0eae813435a 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import type { AppContext, CSSProperties, Component, VNode } from 'vue';
  2. import type { ComponentSize } from 'element-plus/es/constants';
  3. type MessageType = '' | 'primary' | 'success' | 'warning' | 'info' | 'error';
  4. export type Action = 'confirm' | 'close' | 'cancel';
  5. export type MessageBoxType = '' | 'prompt' | 'alert' | 'confirm';
  6. export type MessageBoxData = MessageBoxInputData & Action;
  7. export interface MessageBoxInputData {
  8. value: string;
  9. action: Action;
  10. }
  11. export type MessageBoxInputValidator = ((value: string) => boolean | string) | undefined;
  12. export declare interface MessageBoxState {
  13. autofocus: boolean;
  14. title: string | undefined;
  15. message: string;
  16. type: MessageType;
  17. icon: string | Component;
  18. closeIcon: string | Component;
  19. customClass: string;
  20. customStyle: CSSProperties;
  21. showInput: boolean;
  22. inputValue: string;
  23. inputPlaceholder: string;
  24. inputType: string;
  25. inputPattern: RegExp | null;
  26. inputValidator: MessageBoxInputValidator;
  27. inputErrorMessage: string;
  28. showConfirmButton: boolean;
  29. showCancelButton: boolean;
  30. action: Action;
  31. dangerouslyUseHTMLString: boolean;
  32. confirmButtonText: string;
  33. cancelButtonText: string;
  34. confirmButtonLoading: boolean;
  35. cancelButtonLoading: boolean;
  36. confirmButtonLoadingIcon: string | Component;
  37. cancelButtonLoadingIcon: string | Component;
  38. confirmButtonClass: string;
  39. confirmButtonDisabled: boolean;
  40. cancelButtonClass: string;
  41. editorErrorMessage: string;
  42. beforeClose: null | ((action: Action, instance: MessageBoxState, done: () => void) => void);
  43. callback: null | Callback;
  44. distinguishCancelAndClose: boolean;
  45. modalFade: boolean;
  46. modalClass: string;
  47. validateError: boolean;
  48. zIndex: number;
  49. }
  50. export type Callback = ((value: string, action: Action) => any) | ((action: Action) => any);
  51. /** Options used in MessageBox */
  52. export interface ElMessageBoxOptions {
  53. /**
  54. * auto focus when open message-box
  55. */
  56. autofocus?: boolean;
  57. /** Callback before MessageBox closes, and it will prevent MessageBox from closing */
  58. beforeClose?: (action: Action, instance: MessageBoxState, done: () => void) => void;
  59. /** Custom class name for MessageBox */
  60. customClass?: string;
  61. /** Custom inline style for MessageBox */
  62. customStyle?: CSSProperties;
  63. /** modal class name for MessageBox */
  64. modalClass?: string;
  65. /** MessageBox closing callback if you don't prefer Promise */
  66. callback?: Callback;
  67. /** Text content of cancel button */
  68. cancelButtonText?: string;
  69. /** Text content of confirm button */
  70. confirmButtonText?: string;
  71. /** Loading Icon content of cancel button */
  72. cancelButtonLoadingIcon?: string | Component;
  73. /** Loading Icon content of confirm button */
  74. confirmButtonLoadingIcon?: string | Component;
  75. /** Custom class name of cancel button */
  76. cancelButtonClass?: string;
  77. /** Custom class name of confirm button */
  78. confirmButtonClass?: string;
  79. /** Whether to align the content in center */
  80. center?: boolean;
  81. /** Whether MessageBox can be drag */
  82. draggable?: boolean;
  83. /** Draggable MessageBox can overflow the viewport */
  84. overflow?: boolean;
  85. /** Content of the MessageBox */
  86. message?: string | VNode | (() => VNode);
  87. /** Title of the MessageBox */
  88. title?: string | ElMessageBoxOptions;
  89. /** Message type, used for icon display */
  90. type?: MessageType;
  91. /** Message box type */
  92. boxType?: MessageBoxType;
  93. /** Custom icon component */
  94. icon?: string | Component;
  95. /** Custom close icon component */
  96. closeIcon?: string | Component;
  97. /** Whether message is treated as HTML string */
  98. dangerouslyUseHTMLString?: boolean;
  99. /** Whether to distinguish canceling and closing */
  100. distinguishCancelAndClose?: boolean;
  101. /** Whether to lock body scroll when MessageBox prompts */
  102. lockScroll?: boolean;
  103. /** Whether to show a cancel button */
  104. showCancelButton?: boolean;
  105. /** Whether to show a confirm button */
  106. showConfirmButton?: boolean;
  107. /** Whether to show a close button */
  108. showClose?: boolean;
  109. /** Whether to use round button */
  110. roundButton?: boolean;
  111. /** Whether MessageBox can be closed by clicking the mask */
  112. closeOnClickModal?: boolean;
  113. /** Whether MessageBox can be closed by pressing the ESC */
  114. closeOnPressEscape?: boolean;
  115. /** Whether to close MessageBox when hash changes */
  116. closeOnHashChange?: boolean;
  117. /** Whether to show an input */
  118. showInput?: boolean;
  119. /** Placeholder of input */
  120. inputPlaceholder?: string;
  121. /** Initial value of input */
  122. inputValue?: string;
  123. /** Regexp for the input */
  124. inputPattern?: RegExp;
  125. /** Input Type: text, textArea, password or number */
  126. inputType?: string;
  127. /** Validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage */
  128. inputValidator?: MessageBoxInputValidator;
  129. /** Error message when validation fails */
  130. inputErrorMessage?: string;
  131. /** Custom size of confirm and cancel buttons */
  132. buttonSize?: ComponentSize;
  133. /** Custom element to append the message box to */
  134. appendTo?: HTMLElement | string;
  135. }
  136. export type ElMessageBoxShortcutMethod = ((message: ElMessageBoxOptions['message'], options?: ElMessageBoxOptions, appContext?: AppContext | null) => Promise<MessageBoxData>) & ((message: ElMessageBoxOptions['message'], title: ElMessageBoxOptions['title'], options?: ElMessageBoxOptions, appContext?: AppContext | null) => Promise<MessageBoxData>);
  137. export interface IElMessageBox {
  138. _context: AppContext | null;
  139. /** Show a message box */
  140. /** Show a message box */
  141. (options: ElMessageBoxOptions, appContext?: AppContext | null): Promise<MessageBoxData>;
  142. /** Show an alert message box */
  143. alert: ElMessageBoxShortcutMethod;
  144. /** Show a confirm message box */
  145. confirm: ElMessageBoxShortcutMethod;
  146. /** Show a prompt message box */
  147. prompt: ElMessageBoxShortcutMethod;
  148. /** Close current message box */
  149. close(): void;
  150. }
  151. export {};