UNPKG

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