1 | "use client";
|
2 |
|
3 | var __rest = this && this.__rest || function (s, e) {
|
4 | var t = {};
|
5 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
6 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | import * as React from 'react';
|
12 | import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
|
13 | import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
|
14 | import CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined";
|
15 | import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
|
16 | import InfoCircleFilled from "@ant-design/icons/es/icons/InfoCircleFilled";
|
17 | import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
|
18 | import classNames from 'classnames';
|
19 | import { Notice } from 'rc-notification';
|
20 | import { ConfigContext } from '../config-provider';
|
21 | import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
22 | import useStyle from './style';
|
23 | import PurePanelStyle from './style/pure-panel';
|
24 | export const TypeIcon = {
|
25 | info: React.createElement(InfoCircleFilled, null),
|
26 | success: React.createElement(CheckCircleFilled, null),
|
27 | error: React.createElement(CloseCircleFilled, null),
|
28 | warning: React.createElement(ExclamationCircleFilled, null),
|
29 | loading: React.createElement(LoadingOutlined, null)
|
30 | };
|
31 | export function getCloseIcon(prefixCls, closeIcon) {
|
32 | if (closeIcon === null || closeIcon === false) {
|
33 | return null;
|
34 | }
|
35 | return closeIcon || React.createElement(CloseOutlined, {
|
36 | className: `${prefixCls}-close-icon`
|
37 | });
|
38 | }
|
39 | const typeToIcon = {
|
40 | success: CheckCircleFilled,
|
41 | info: InfoCircleFilled,
|
42 | error: CloseCircleFilled,
|
43 | warning: ExclamationCircleFilled
|
44 | };
|
45 | export const PureContent = props => {
|
46 | const {
|
47 | prefixCls,
|
48 | icon,
|
49 | type,
|
50 | message,
|
51 | description,
|
52 | btn,
|
53 | role = 'alert'
|
54 | } = props;
|
55 | let iconNode = null;
|
56 | if (icon) {
|
57 | iconNode = React.createElement("span", {
|
58 | className: `${prefixCls}-icon`
|
59 | }, icon);
|
60 | } else if (type) {
|
61 | iconNode = React.createElement(typeToIcon[type] || null, {
|
62 | className: classNames(`${prefixCls}-icon`, `${prefixCls}-icon-${type}`)
|
63 | });
|
64 | }
|
65 | return React.createElement("div", {
|
66 | className: classNames({
|
67 | [`${prefixCls}-with-icon`]: iconNode
|
68 | }),
|
69 | role: role
|
70 | }, iconNode, React.createElement("div", {
|
71 | className: `${prefixCls}-message`
|
72 | }, message), React.createElement("div", {
|
73 | className: `${prefixCls}-description`
|
74 | }, description), btn && React.createElement("div", {
|
75 | className: `${prefixCls}-btn`
|
76 | }, btn));
|
77 | };
|
78 |
|
79 | const PurePanel = props => {
|
80 | const {
|
81 | prefixCls: staticPrefixCls,
|
82 | className,
|
83 | icon,
|
84 | type,
|
85 | message,
|
86 | description,
|
87 | btn,
|
88 | closable = true,
|
89 | closeIcon,
|
90 | className: notificationClassName
|
91 | } = props,
|
92 | restProps = __rest(props, ["prefixCls", "className", "icon", "type", "message", "description", "btn", "closable", "closeIcon", "className"]);
|
93 | const {
|
94 | getPrefixCls
|
95 | } = React.useContext(ConfigContext);
|
96 | const prefixCls = staticPrefixCls || getPrefixCls('notification');
|
97 | const noticePrefixCls = `${prefixCls}-notice`;
|
98 | const rootCls = useCSSVarCls(prefixCls);
|
99 | const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
|
100 | return wrapCSSVar( React.createElement("div", {
|
101 | className: classNames(`${noticePrefixCls}-pure-panel`, hashId, className, cssVarCls, rootCls)
|
102 | }, React.createElement(PurePanelStyle, {
|
103 | prefixCls: prefixCls
|
104 | }), React.createElement(Notice, Object.assign({}, restProps, {
|
105 | prefixCls: prefixCls,
|
106 | eventKey: "pure",
|
107 | duration: null,
|
108 | closable: closable,
|
109 | className: classNames({
|
110 | notificationClassName
|
111 | }),
|
112 | closeIcon: getCloseIcon(prefixCls, closeIcon),
|
113 | content: React.createElement(PureContent, {
|
114 | prefixCls: noticePrefixCls,
|
115 | icon: icon,
|
116 | type: type,
|
117 | message: message,
|
118 | description: description,
|
119 | btn: btn
|
120 | })
|
121 | }))));
|
122 | };
|
123 | export default PurePanel; |
\ | No newline at end of file |