UNPKG

17.9 kBTypeScriptView Raw
1import React from 'react';
2import { type CommonProps } from '../util';
3import { type ButtonProps } from '../button';
4import { type OverlayProps } from '../overlay';
5import { type MessageProps } from '../message';
6import ConfigProvider from '../config-provider';
7export type CloseMode = 'close' | 'mask' | 'esc';
8interface HTMLAttributes extends React.HTMLAttributes<HTMLElement> {
9}
10/**
11 * @api Dialog
12 */
13export interface DialogV1Props extends Omit<HTMLAttributes, 'content' | 'title'>, CommonProps {
14 /**
15 * 是否显示
16 * @en Whether to show
17 * @defaultValue false
18 */
19 visible?: boolean;
20 /**
21 * 标题
22 * @en Title
23 */
24 title?: React.ReactNode;
25 /**
26 * 内容
27 * @en Content
28 */
29 children?: React.ReactNode;
30 /**
31 * 底部内容,设置为 false,则不进行显示
32 * @en Footer content, set to false to hide
33 */
34 footer?: boolean | React.ReactNode;
35 /**
36 * 底部按钮的对齐方式
37 * @en Footer button alignment
38 * @defaultValue 'right'
39 */
40 footerAlign?: 'left' | 'center' | 'right';
41 /**
42 * 指定确定按钮和取消按钮是否存在以及如何排列
43 * @en Specify whether to exist and how to arrange the confirm and cancel buttons
44 * @defaultValue ['ok', 'cancel']
45 * @remarks
46 * **可选值**:
47 * ['ok', 'cancel'](确认取消按钮同时存在,确认按钮在左),
48 * ['cancel', 'ok'](确认取消按钮同时存在,确认按钮在右),
49 * ['ok'](只存在确认按钮),
50 * ['cancel'](只存在取消按钮).
51 * -
52 * ['ok', 'cancel'] (Confirm and cancel buttons exist at the same time, the confirm button is on the left),
53 * ['cancel', 'ok'] (Confirm and cancel buttons exist at the same time, the confirm button is on the right),
54 * ['ok'] (Only the confirm button exists),
55 * ['cancel'] (Only the cancel button exists).
56 */
57 footerActions?: Array<'ok' | 'cancel'>;
58 /**
59 * 隐藏时是否保留子节点,不销毁
60 * @en Whether to retain the child node when hiding
61 * @version 1.23
62 * @defaultValue false
63 */
64 cache?: boolean;
65 /**
66 * 在点击确定按钮时触发的回调函数
67 * @en Callback function when the confirm button is clicked
68 */
69 onOk?: (event: React.MouseEvent) => void;
70 /**
71 * 在点击取消按钮时触发的回调函数
72 * @en Callback function when the cancel button is clicked
73 */
74 onCancel?: (event: React.MouseEvent) => void;
75 /**
76 * 应用于确定按钮的属性对象
77 * @en Properties for the confirm button
78 */
79 okProps?: ButtonProps;
80 /**
81 * 应用于取消按钮的属性对象
82 * @en Properties for the cancel button
83 */
84 cancelProps?: ButtonProps;
85 /**
86 * [废弃] 同 closeMode, 控制对话框关闭的方式
87 * @en [Deprecated] Control the way the dialog is closed
88 * @deprecated use closeMode instead
89 * @defaultValue 'esc,close'
90 * @remarks
91 * 值可以为字符串或者布尔值,其中字符串是由以下值组成:
92 * **close** 表示点击关闭按钮可以关闭对话框,
93 * **mask** 表示点击遮罩区域可以关闭对话框,
94 * **esc** 表示按下 esc 键可以关闭对话框,
95 * 如 'close' 或 'close,esc,mask',
96 * 如果设置为 true,则以上关闭方式全部生效,
97 * 如果设置为 false,则以上关闭方式全部失效。
98 * -
99 * The value can be a string or boolean, where the string is composed of the following values:
100 * **close** (Click the close button to close the dialog),
101 * **mask** (Click the mask area to close the dialog),
102 * **esc** (Press the esc key to close the dialog),
103 * For example: 'close' or 'close,esc,mask', [],
104 * If set to true, the above close modes are all effective,
105 * If set to false, the above close modes are all invalid.
106 */
107 closeable?: 'close' | 'mask' | 'esc' | boolean | 'close,mask' | 'close,esc' | 'mask,esc';
108 /**
109 * [推荐] 控制对话框关闭的方式
110 * @en Control the way the dialog is closed
111 * @version 1.21
112 * @remarks
113 * 值可以为字符串或者数组,其中字符串、数组均为以下值的枚举:
114 * **close** 表示点击关闭按钮可以关闭对话框,
115 * **mask** 表示点击遮罩区域可以关闭对话框,
116 * **esc** 表示按下 esc 键可以关闭对话框,
117 * 如 'close' 或 ['close','esc','mask'], []。
118 * -
119 * The value can be a string or array, where the string and array are enumerated values of the following:
120 * **close** (Click the close button to close the dialog),
121 * **mask** (Click the mask area to close the dialog),
122 * **esc** (Press the esc key to close the dialog),
123 * For example: 'close' or ['close','esc','mask'], [].
124 */
125 closeMode?: CloseMode[] | CloseMode;
126 /**
127 * 对话框关闭时触发的回调函数
128 * @en Callback function when the dialog is closed
129 */
130 onClose?: (trigger: string, event: React.MouseEvent | KeyboardEvent) => void;
131 /**
132 * 对话框关闭后触发的回调函数,如果有动画,则在动画结束后触发
133 * @en Callback function after the dialog is closed, if there is an animation, it will be triggered after the animation ends
134 */
135 afterClose?: () => void;
136 /**
137 * 是否显示遮罩
138 * @en Whether to show the mask
139 * @defaultValue true
140 */
141 hasMask?: boolean;
142 /**
143 * 显示隐藏时动画的播放方式
144 * @en Animation playback method when showing and hiding
145 * @defaultValue \{ in: 'fadeInUp', out: 'fadeOutUp' \}
146 */
147 animation?: Record<'in' | 'out', string> | false;
148 /**
149 * 对话框弹出时是否自动获得焦点
150 * @en Whether to automatically obtain focus when the dialog is displayed
151 * @defaultValue false
152 */
153 autoFocus?: boolean;
154 /**
155 * [v2 废弃] 对话框对齐方式,具体见 Overlay 文档
156 * @en [v2 Deprecated] Dialog alignment, see Overlay documentation
157 */
158 align?: string | boolean;
159 /**
160 * [v2 废弃] 当对话框高度超过浏览器视口高度时,是否显示所有内容而不是出现滚动条以保证对话框完整显示在浏览器视口内,该属性仅在对话框垂直水平居中时生效,即 align 被设置为 'cc cc' 时
161 * @en [v2 Deprecated] Whether to display all content instead of appearing a scroll bar to ensure that the dialog is displayed completely in the browser viewport, and this attribute only takes effect when the dialog is vertically and horizontally centered, that is, when align is set to 'cc cc'
162 */
163 isFullScreen?: boolean;
164 /**
165 * [v2 废弃] 是否在对话框重新渲染时及时更新对话框位置,一般用于对话框高度变化后依然能保证原来的对齐方式
166 * @en [v2 Deprecated] Whether to update the dialog position immediately when the dialog is re-rendered, generally used for dialog height changes that still ensure the original alignment
167 */
168 shouldUpdatePosition?: boolean;
169 /**
170 * [v2 废弃] 对话框距离浏览器顶部和底部的最小间距,align 被设置为 'cc cc' 并且 isFullScreen 被设置为 true 时不生效
171 * @en [v2 Deprecated] The minimum spacing between the dialog and the top and bottom of the browser, and the isFullScreen property is set to true and the align property is set to 'cc cc' is not effective
172 * @defaultValue 40
173 */
174 minMargin?: number;
175 /**
176 * 透传到弹层组件的属性对象
177 * @en Properties for the overlay component
178 */
179 overlayProps?: OverlayProps;
180 /**
181 * 自定义国际化文案对象
182 * @en Customized internationalized text
183 */
184 locale?: Partial<{
185 ok: string;
186 cancel: string;
187 }>;
188 /**
189 * 对话框的高度样式属性
190 * @en Dialog height style
191 */
192 height?: string | number;
193 /**
194 * 弹窗宽度
195 * @en Dialog width
196 * @version 1.25
197 */
198 width?: string | number;
199 /**
200 * 自定义弹窗挂载位置
201 * @en Custom mount position
202 */
203 popupContainer?: string | HTMLElement | ((target?: HTMLElement) => HTMLElement);
204 /**
205 * 开启 v2 版本弹窗
206 * @en Enable v2 version
207 * @defaultValue false
208 */
209 v2?: false | undefined;
210 /**
211 * 去除 body 内间距
212 * @en Remove body spacing
213 * @version 1.26
214 * @defaultValue false
215 */
216 noPadding?: boolean;
217 /**
218 * 定制关闭按钮 icon
219 * @en Customize the close button icon
220 * @version 1.25
221 */
222 closeIcon?: React.ReactNode;
223}
224/**
225 * @api Dialog V2
226 */
227export interface DialogV2Props extends Omit<HTMLAttributes, 'content' | 'title'>, CommonProps {
228 /**
229 * 是否显示
230 * @en Whether to show
231 * @defaultValue false
232 */
233 visible?: boolean;
234 /**
235 * 标题
236 * @en Title
237 */
238 title?: React.ReactNode;
239 /**
240 * 内容
241 * @en Content
242 */
243 children?: React.ReactNode;
244 /**
245 * 底部内容,设置为 false,则不进行显示
246 * @en Footer content, set to false to hide
247 */
248 footer?: boolean | React.ReactNode;
249 /**
250 * 底部按钮的对齐方式
251 * @en Footer button alignment
252 * @defaultValue 'right'
253 */
254 footerAlign?: 'left' | 'center' | 'right';
255 /**
256 * 指定确定按钮和取消按钮是否存在以及如何排列
257 * @en Specify whether to exist and how to arrange the confirm and cancel buttons
258 * @defaultValue ['ok', 'cancel']
259 * @remarks
260 * **可选值**:
261 * ['ok', 'cancel'](确认取消按钮同时存在,确认按钮在左),
262 * ['cancel', 'ok'](确认取消按钮同时存在,确认按钮在右),
263 * ['ok'](只存在确认按钮),
264 * ['cancel'](只存在取消按钮).
265 * -
266 * ['ok', 'cancel'] (Confirm and cancel buttons exist at the same time, the confirm button is on the left),
267 * ['cancel', 'ok'] (Confirm and cancel buttons exist at the same time, the confirm button is on the right),
268 * ['ok'] (Only the confirm button exists),
269 * ['cancel'] (Only the cancel button exists).
270 */
271 footerActions?: Array<'ok' | 'cancel'>;
272 /**
273 * 隐藏时是否保留子节点,不销毁
274 * @en Whether to retain the child node when hiding
275 * @version 1.23
276 * @defaultValue false
277 */
278 cache?: boolean;
279 /**
280 * 在点击确定按钮时触发的回调函数
281 * @en Callback function when the confirm button is clicked
282 */
283 onOk?: (event: React.MouseEvent) => void;
284 /**
285 * 在点击取消按钮时触发的回调函数
286 * @en Callback function when the cancel button is clicked
287 */
288 onCancel?: (event: React.MouseEvent) => void;
289 /**
290 * 应用于确定按钮的属性对象
291 * @en Properties for the confirm button
292 */
293 okProps?: ButtonProps;
294 /**
295 * 应用于取消按钮的属性对象
296 * @en Properties for the cancel button
297 */
298 cancelProps?: ButtonProps;
299 /**
300 * [推荐] 控制对话框关闭的方式
301 * @en Control the way the dialog is closed
302 * @version 1.21
303 * @remarks
304 * 值可以为字符串或者数组,其中字符串、数组均为以下值的枚举:
305 * **close** 表示点击关闭按钮可以关闭对话框,
306 * **mask** 表示点击遮罩区域可以关闭对话框,
307 * **esc** 表示按下 esc 键可以关闭对话框,
308 * 如 'close' 或 ['close','esc','mask'], []。
309 * -
310 * The value can be a string or array, where the string and array are enumerated values of the following:
311 * **close** (Click the close button to close the dialog),
312 * **mask** (Click the mask area to close the dialog),
313 * **esc** (Press the esc key to close the dialog),
314 * For example: 'close' or ['close','esc','mask'], [].
315 */
316 closeMode?: CloseMode[] | CloseMode;
317 /**
318 * 对话框关闭时触发的回调函数
319 * @en Callback function when the dialog is closed
320 */
321 onClose?: (trigger: string, event: React.MouseEvent | KeyboardEvent) => void;
322 /**
323 * 对话框关闭后触发的回调函数,如果有动画,则在动画结束后触发
324 * @en Callback function after the dialog is closed, if there is an animation, it will be triggered after the animation ends
325 */
326 afterClose?: () => void;
327 /**
328 * 是否显示遮罩
329 * @en Whether to show the mask
330 * @defaultValue true
331 */
332 hasMask?: boolean;
333 /**
334 * 显示隐藏时动画的播放方式
335 * @en Animation playback method when showing and hiding
336 * @defaultValue \{ in: 'fadeInUp', out: 'fadeOutUp' \}
337 */
338 animation?: Record<'in' | 'out', string> | false;
339 /**
340 * 对话框弹出时是否自动获得焦点
341 * @en Whether to automatically obtain focus when the dialog is displayed
342 * @defaultValue false
343 */
344 autoFocus?: boolean;
345 /**
346 * [v2 废弃] 当对话框高度超过浏览器视口高度时,是否显示所有内容而不是出现滚动条以保证对话框完整显示在浏览器视口内,该属性仅在对话框垂直水平居中时生效,即 align 被设置为 'cc cc' 时
347 * @en [v2 Deprecated] Whether to display all content instead of appearing a scroll bar to ensure that the dialog is displayed completely in the browser viewport, and this attribute only takes effect when the dialog is vertically and horizontally centered, that is, when align is set to 'cc cc'
348 * @deprecated v2 废弃 - v2 deprecated
349 */
350 isFullScreen?: boolean;
351 /**
352 * [v2 废弃] 对话框距离浏览器顶部和底部的最小间距,align 被设置为 'cc cc' 并且 isFullScreen 被设置为 true 时不生效
353 * @en [v2 Deprecated] The minimum spacing between the dialog and the top and bottom of the browser, and the isFullScreen property is set to true and the align property is set to 'cc cc' is not effective
354 * @deprecated v2 废弃 - v2 deprecated
355 * @defaultValue 40
356 */
357 minMargin?: number;
358 /**
359 * 透传到弹层组件的属性对象
360 * @en Properties for the overlay component
361 */
362 overlayProps?: OverlayProps;
363 /**
364 * 自定义国际化文案对象
365 * @en Customized internationalized text
366 */
367 locale?: Partial<{
368 ok: string;
369 cancel: string;
370 }>;
371 /**
372 * 对话框的高度样式属性
373 * @en Dialog height style
374 */
375 height?: string | number;
376 /**
377 * 自定义弹窗挂载位置
378 * @en Custom mount position
379 */
380 popupContainer?: string | HTMLElement | ((target?: HTMLElement) => HTMLElement);
381 /**
382 * 开启 v2 版本弹窗
383 * @en Enable v2 version
384 * @defaultValue false
385 */
386 v2?: true;
387 /**
388 * 定制关闭按钮 icon
389 * @en Customize the close button icon
390 * @version 1.25
391 */
392 closeIcon?: React.ReactNode;
393 /**
394 * 弹窗宽度
395 * @en Dialog width
396 * @version 1.25
397 */
398 width?: string | number;
399 /**
400 * 去除 body 内间距
401 * @en Remove body spacing
402 * @version 1.26
403 * @defaultValue false
404 */
405 noPadding?: boolean;
406 /**
407 * [v2] 弹窗上边距。默认 100,设置 centered=true 后默认 40
408 * @en [v2] Dialog top margin, default 100, when centered=true, default 40
409 * @version 1.25
410 */
411 top?: number;
412 /**
413 * [v2] 弹窗下边距
414 * @en [v2] Dialog bottom margin
415 * @defaultValue 40
416 * @version 1.25
417 */
418 bottom?: number;
419 /**
420 * [v2] 对话框高度超过浏览器视口高度时,对话框是否展示滚动条。关闭此功后对话框会随高度撑开页面
421 * @en [v2] Whether to display a scroll bar when the dialog height exceeds the browser viewport height
422 * @version 1.25
423 */
424 overflowScroll?: boolean;
425 /**
426 * [v2] 弹窗居中对齐
427 * @en [v2] Dialog center alignment
428 * @version 1.25
429 */
430 centered?: boolean;
431 /**
432 * [v2] 自定义渲染弹窗
433 * @en [v2] Custom rendering the dialog
434 */
435 dialogRender?: (modal: React.ReactNode) => React.ReactNode;
436 /**
437 * [v2] 最外包裹层 className
438 * @en [v2] The className of the outer wrapper
439 * @version 1.26
440 */
441 wrapperClassName?: string;
442 /**
443 * [v2] 最外包裹层 style
444 * @en [v2] The style of the outer wrapper
445 * @version 1.26
446 */
447 wrapperStyle?: React.CSSProperties;
448}
449export type DialogProps = DialogV1Props | DialogV2Props;
450export interface InnerProps extends Omit<HTMLAttributes, 'title'>, CommonProps, Pick<DialogProps, 'footer' | 'footerAlign' | 'footerActions' | 'onOk' | 'onCancel' | 'v2' | 'okProps' | 'cancelProps' | 'closeIcon' | 'title'> {
451 closeable?: boolean;
452 height?: string | number;
453 noPadding?: boolean;
454 onClose?: (event: React.MouseEvent) => void;
455}
456export interface ModalState {
457 visible?: boolean;
458 loading?: boolean;
459 okLoading?: boolean;
460 cancelLoading?: boolean;
461}
462interface CommonModelProps {
463 type?: string;
464 needWrapper?: boolean;
465}
466interface ModelV1Props extends DialogV1Props, CommonModelProps, Omit<ShowModalInnerProps, 'locale'> {
467}
468interface ModelV2Props extends DialogV2Props, CommonModelProps, Omit<ShowModalInnerProps, 'locale'> {
469}
470interface CommonConfig {
471 afterClose?: () => void;
472 contextConfig?: Partial<ReturnType<typeof ConfigProvider.getContext>>;
473}
474export interface ShowConfigV1 extends ModelV1Props, CommonConfig {
475}
476export interface ShowConfigV2 extends ModelV2Props, CommonConfig {
477}
478export type ShowConfig = ShowConfigV1 | ShowConfigV2;
479export type ModelProps = ModelV1Props | ModelV2Props;
480export interface ShowModalInnerProps extends CommonProps, Pick<MessageProps, 'title'> {
481 messageProps?: MessageProps;
482 content?: MessageProps['children'];
483}
484export {};