File size: 3,247 Bytes
5941ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type * as React from 'react';

import type { SemanticClassNamesType, SemanticStylesType } from '../_util/hooks';

export type NoticeType = 'info' | 'success' | 'error' | 'warning' | 'loading';

export type MessageSemanticName = keyof MessageSemanticClassNames & keyof MessageSemanticStyles;

export type MessageSemanticClassNames = {
  root?: string;
  icon?: string;
  content?: string;
};

export type MessageSemanticStyles = {
  root?: React.CSSProperties;
  icon?: React.CSSProperties;
  content?: React.CSSProperties;
};

export type ArgsClassNamesType = SemanticClassNamesType<ArgsProps, MessageSemanticClassNames>;

export type ArgsStylesType = SemanticStylesType<ArgsProps, MessageSemanticStyles>;

export interface ConfigOptions {
  top?: string | number;
  duration?: number;
  prefixCls?: string;
  getContainer?: () => HTMLElement;
  transitionName?: string;
  maxCount?: number;
  rtl?: boolean;
  /**
   * @descCN 悬停时是否暂停计时器
   * @descEN keep the timer running or not on hover
   */
  pauseOnHover?: boolean;
  classNames?: ArgsClassNamesType;
  styles?: ArgsStylesType;
}

export interface ArgsProps {
  /**
   * @descCN 消息通知的内容,接收组件或者字符串
   * @descEN The content of the message notification, receiving component or string
   */
  content: React.ReactNode;
  /**
   * @descCN 消息通知持续显示的时间
   * @descEN How long the message notification remains displayed
   */
  duration?: number;
  /**
   * @descCN 消息通知的类型,可以是 'info'、'success'、'error'、'warning' 或 'loading'
   * @descEN The type of message notification, which can be 'info', 'success', 'error', 'warning' or 'loading'
   */
  type?: NoticeType;
  /**
   * @descCN 消息通知关闭时进行调用的回调函数
   * @descEN The callback function called when the message notification is closed
   */
  onClose?: () => void;
  icon?: React.ReactNode;
  key?: string | number;
  style?: React.CSSProperties;
  className?: string;
  classNames?: ArgsClassNamesType;
  styles?: ArgsStylesType;
  /**
   * @descCN 消息通知点击时的回调函数
   * @descEN Callback function when message notification is clicked
   */
  onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
  /**
   * @descCN 悬停时是否暂停计时器
   * @descEN keep the timer running or not on hover
   */
  pauseOnHover?: boolean;
}

export type JointContent = React.ReactNode | ArgsProps;

export interface MessageType extends PromiseLike<boolean> {
  (): void;
}

export type TypeOpen = (
  content: JointContent,
  /**
   * @descCN 消息通知持续显示的时间,也可以直接使用 onClose。
   * @descEN You can also use onClose directly to determine how long the message notification continues to be displayed.
   */
  duration?: number | VoidFunction,
  /**
   * @descCN 消息通知关闭时进行调用的回调函数
   * @descEN The callback function called when the message notification is closed
   */
  onClose?: VoidFunction,
) => MessageType;

export interface MessageInstance {
  info: TypeOpen;
  success: TypeOpen;
  error: TypeOpen;
  warning: TypeOpen;
  loading: TypeOpen;
  open: (args: ArgsProps) => MessageType;
  destroy: (key?: React.Key) => void;
}