|
1 | 1 | import * as React from 'react'; |
2 | | -import { CloseIcon, InfoCircleFilledIcon, CheckCircleFilledIcon } from 'tdesign-icons-react'; |
| 2 | +import { CheckCircleFilledIcon, CloseIcon, InfoCircleFilledIcon } from 'tdesign-icons-react'; |
3 | 3 | import noop from '../_util/noop'; |
4 | 4 | import useConfig from '../_util/useConfig'; |
5 | 5 |
|
6 | | -import { |
7 | | - NotificationCloseMethod, |
8 | | - NotificationErrorMethod, |
9 | | - NotificationInfoMethod, |
10 | | - NotificationSuccessMethod, |
11 | | - NotificationWarningMethod, |
12 | | - TdNotificationProps, |
13 | | - NotificationThemeList, |
14 | | - NotificationInfoOptions, |
15 | | - NotificationInstance, |
16 | | - NotificationPlacementList, |
17 | | - NotificationCloseAllMethod, |
18 | | -} from './type'; |
| 6 | +import { NotificationInstance, TdNotificationProps } from './type'; |
19 | 7 | import { Styles } from '../common'; |
20 | | -import { fetchListInstance, listMap } from './NotificationList'; |
21 | 8 |
|
22 | 9 | const blockName = 'notification'; |
23 | 10 |
|
24 | | -// 扩展接口声明的结构,用户使用时可得到 .info 的 ts 提示 |
25 | | -interface Notification extends React.FC<TdNotificationProps> { |
26 | | - info: NotificationInfoMethod; |
27 | | - success: NotificationSuccessMethod; |
28 | | - warning: NotificationWarningMethod; |
29 | | - error: NotificationErrorMethod; |
30 | | - closeAll: NotificationCloseAllMethod; |
31 | | - close: NotificationCloseMethod; |
32 | | -} |
33 | | - |
34 | | -interface NotificationProps extends TdNotificationProps { |
| 11 | +export interface NotificationProps extends TdNotificationProps { |
35 | 12 | style?: Styles; |
36 | 13 | } |
37 | 14 |
|
@@ -150,58 +127,4 @@ export const NotificationComponent = React.forwardRef<any, NotificationProps>((p |
150 | 127 | ); |
151 | 128 | }); |
152 | 129 |
|
153 | | -/** |
154 | | - * @author kenzyyang |
155 | | - * @date 2021-05-30 22:54:39 |
156 | | - * @desc 函数调用时的渲染函数 |
157 | | - * @param theme 主题类型 |
158 | | - * @param options 通知的参数 |
159 | | - */ |
160 | | -const renderNotification = (theme: NotificationThemeList, options: NotificationInfoOptions) => { |
161 | | - if (typeof options !== 'object') return; |
162 | | - |
163 | | - const placement: NotificationPlacementList = (() => { |
164 | | - if (['top-left', 'top-right', 'bottom-left', 'bottom-right'].indexOf(options.placement) >= 0) { |
165 | | - return options.placement; |
166 | | - } |
167 | | - return 'top-right'; |
168 | | - })(); |
169 | | - |
170 | | - const attach: HTMLElement = (() => { |
171 | | - if (options.attach && typeof options.attach === 'string') { |
172 | | - const element: Element = document.querySelector(options.attach); |
173 | | - if (element instanceof HTMLElement) return element; |
174 | | - } |
175 | | - |
176 | | - if (options.attach instanceof HTMLElement) return options.attach; |
177 | | - |
178 | | - const containerId = `tdesign-notification-${placement}`; |
179 | | - const container = document.querySelector(`#${containerId}`); |
180 | | - if (container && container instanceof HTMLElement) { |
181 | | - return container; |
182 | | - } |
183 | | - |
184 | | - const element: HTMLDivElement = document.createElement('div'); |
185 | | - element.setAttribute('id', containerId); |
186 | | - document.body.appendChild(element); |
187 | | - return element; |
188 | | - })(); |
189 | | - |
190 | | - const zIndex = options.zIndex || 6000; |
191 | | - |
192 | | - return fetchListInstance(placement, attach, zIndex).then((listInstance) => listInstance.push(theme, options)); |
193 | | -}; |
194 | | - |
195 | | -// eslint-disable-next-line @typescript-eslint/ban-ts-comment |
196 | | -// @ts-ignore |
197 | | -const Notification: Notification = NotificationComponent; |
198 | | - |
199 | | -['info', 'success', 'warning', 'error'].forEach((theme: NotificationThemeList) => { |
200 | | - Notification[theme] = (options) => renderNotification(theme, options); |
201 | | -}); |
202 | | - |
203 | | -Notification.close = (promise) => promise.then((instance) => instance.close()); |
204 | | - |
205 | | -Notification.closeAll = () => listMap.forEach((list) => list.removeAll()); |
206 | | - |
207 | | -export default Notification; |
| 130 | +export default NotificationComponent; |
0 commit comments