UNPKG

4.47 kBJavaScriptView Raw
1"use client";
2
3var __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};
11import * as React from 'react';
12import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
13import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
14import CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined";
15import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
16import InfoCircleFilled from "@ant-design/icons/es/icons/InfoCircleFilled";
17import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
18import classNames from 'classnames';
19import { Notice } from 'rc-notification';
20import { ConfigContext } from '../config-provider';
21import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
22import useStyle from './style';
23import PurePanelStyle from './style/pure-panel';
24export const TypeIcon = {
25 info: /*#__PURE__*/React.createElement(InfoCircleFilled, null),
26 success: /*#__PURE__*/React.createElement(CheckCircleFilled, null),
27 error: /*#__PURE__*/React.createElement(CloseCircleFilled, null),
28 warning: /*#__PURE__*/React.createElement(ExclamationCircleFilled, null),
29 loading: /*#__PURE__*/React.createElement(LoadingOutlined, null)
30};
31export function getCloseIcon(prefixCls, closeIcon) {
32 if (closeIcon === null || closeIcon === false) {
33 return null;
34 }
35 return closeIcon || /*#__PURE__*/React.createElement(CloseOutlined, {
36 className: `${prefixCls}-close-icon`
37 });
38}
39const typeToIcon = {
40 success: CheckCircleFilled,
41 info: InfoCircleFilled,
42 error: CloseCircleFilled,
43 warning: ExclamationCircleFilled
44};
45export 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 = /*#__PURE__*/React.createElement("span", {
58 className: `${prefixCls}-icon`
59 }, icon);
60 } else if (type) {
61 iconNode = /*#__PURE__*/React.createElement(typeToIcon[type] || null, {
62 className: classNames(`${prefixCls}-icon`, `${prefixCls}-icon-${type}`)
63 });
64 }
65 return /*#__PURE__*/React.createElement("div", {
66 className: classNames({
67 [`${prefixCls}-with-icon`]: iconNode
68 }),
69 role: role
70 }, iconNode, /*#__PURE__*/React.createElement("div", {
71 className: `${prefixCls}-message`
72 }, message), /*#__PURE__*/React.createElement("div", {
73 className: `${prefixCls}-description`
74 }, description), btn && /*#__PURE__*/React.createElement("div", {
75 className: `${prefixCls}-btn`
76 }, btn));
77};
78/** @private Internal Component. Do not use in your production. */
79const 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( /*#__PURE__*/React.createElement("div", {
101 className: classNames(`${noticePrefixCls}-pure-panel`, hashId, className, cssVarCls, rootCls)
102 }, /*#__PURE__*/React.createElement(PurePanelStyle, {
103 prefixCls: prefixCls
104 }), /*#__PURE__*/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: /*#__PURE__*/React.createElement(PureContent, {
114 prefixCls: noticePrefixCls,
115 icon: icon,
116 type: type,
117 message: message,
118 description: description,
119 btn: btn
120 })
121 }))));
122};
123export default PurePanel;
\No newline at end of file