PurePanel.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use client";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import * as React from 'react';
  11. import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
  12. import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
  13. import CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined";
  14. import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
  15. import InfoCircleFilled from "@ant-design/icons/es/icons/InfoCircleFilled";
  16. import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
  17. import classNames from 'classnames';
  18. import { Notice } from 'rc-notification';
  19. import { devUseWarning } from '../_util/warning';
  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: /*#__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. };
  31. export 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. }
  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. actions,
  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), description && /*#__PURE__*/React.createElement("div", {
  73. className: `${prefixCls}-description`
  74. }, description), actions && /*#__PURE__*/React.createElement("div", {
  75. className: `${prefixCls}-actions`
  76. }, actions));
  77. };
  78. /** @private Internal Component. Do not use in your production. */
  79. const PurePanel = props => {
  80. const {
  81. prefixCls: staticPrefixCls,
  82. className,
  83. icon,
  84. type,
  85. message,
  86. description,
  87. btn,
  88. actions,
  89. closable = true,
  90. closeIcon,
  91. className: notificationClassName
  92. } = props,
  93. restProps = __rest(props, ["prefixCls", "className", "icon", "type", "message", "description", "btn", "actions", "closable", "closeIcon", "className"]);
  94. const {
  95. getPrefixCls
  96. } = React.useContext(ConfigContext);
  97. const mergedActions = actions !== null && actions !== void 0 ? actions : btn;
  98. if (process.env.NODE_ENV !== 'production') {
  99. const warning = devUseWarning('Notification');
  100. warning.deprecated(!btn, 'btn', 'actions');
  101. }
  102. const prefixCls = staticPrefixCls || getPrefixCls('notification');
  103. const noticePrefixCls = `${prefixCls}-notice`;
  104. const rootCls = useCSSVarCls(prefixCls);
  105. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
  106. return wrapCSSVar(/*#__PURE__*/React.createElement("div", {
  107. className: classNames(`${noticePrefixCls}-pure-panel`, hashId, className, cssVarCls, rootCls)
  108. }, /*#__PURE__*/React.createElement(PurePanelStyle, {
  109. prefixCls: prefixCls
  110. }), /*#__PURE__*/React.createElement(Notice, Object.assign({}, restProps, {
  111. prefixCls: prefixCls,
  112. eventKey: "pure",
  113. duration: null,
  114. closable: closable,
  115. className: classNames({
  116. notificationClassName
  117. }),
  118. closeIcon: getCloseIcon(prefixCls, closeIcon),
  119. content: /*#__PURE__*/React.createElement(PureContent, {
  120. prefixCls: noticePrefixCls,
  121. icon: icon,
  122. type: type,
  123. message: message,
  124. description: description,
  125. actions: mergedActions
  126. })
  127. }))));
  128. };
  129. export default PurePanel;