PurePanel.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
  12. import classNames from 'classnames';
  13. import ActionButton from '../_util/ActionButton';
  14. import { getRenderPropValue } from '../_util/getRenderPropValue';
  15. import Button from '../button';
  16. import { convertLegacyProps } from '../button/buttonHelpers';
  17. import { ConfigContext } from '../config-provider';
  18. import { useLocale } from '../locale';
  19. import defaultLocale from '../locale/en_US';
  20. import PopoverPurePanel from '../popover/PurePanel';
  21. import useStyle from './style';
  22. export const Overlay = props => {
  23. const {
  24. prefixCls,
  25. okButtonProps,
  26. cancelButtonProps,
  27. title,
  28. description,
  29. cancelText,
  30. okText,
  31. okType = 'primary',
  32. icon = /*#__PURE__*/React.createElement(ExclamationCircleFilled, null),
  33. showCancel = true,
  34. close,
  35. onConfirm,
  36. onCancel,
  37. onPopupClick
  38. } = props;
  39. const {
  40. getPrefixCls
  41. } = React.useContext(ConfigContext);
  42. const [contextLocale] = useLocale('Popconfirm', defaultLocale.Popconfirm);
  43. const titleNode = getRenderPropValue(title);
  44. const descriptionNode = getRenderPropValue(description);
  45. return /*#__PURE__*/React.createElement("div", {
  46. className: `${prefixCls}-inner-content`,
  47. onClick: onPopupClick
  48. }, /*#__PURE__*/React.createElement("div", {
  49. className: `${prefixCls}-message`
  50. }, icon && /*#__PURE__*/React.createElement("span", {
  51. className: `${prefixCls}-message-icon`
  52. }, icon), /*#__PURE__*/React.createElement("div", {
  53. className: `${prefixCls}-message-text`
  54. }, titleNode && /*#__PURE__*/React.createElement("div", {
  55. className: `${prefixCls}-title`
  56. }, titleNode), descriptionNode && /*#__PURE__*/React.createElement("div", {
  57. className: `${prefixCls}-description`
  58. }, descriptionNode))), /*#__PURE__*/React.createElement("div", {
  59. className: `${prefixCls}-buttons`
  60. }, showCancel && (/*#__PURE__*/React.createElement(Button, Object.assign({
  61. onClick: onCancel,
  62. size: "small"
  63. }, cancelButtonProps), cancelText || (contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.cancelText))), /*#__PURE__*/React.createElement(ActionButton, {
  64. buttonProps: Object.assign(Object.assign({
  65. size: 'small'
  66. }, convertLegacyProps(okType)), okButtonProps),
  67. actionFn: onConfirm,
  68. close: close,
  69. prefixCls: getPrefixCls('btn'),
  70. quitOnNullishReturnValue: true,
  71. emitEvent: true
  72. }, okText || (contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.okText))));
  73. };
  74. const PurePanel = props => {
  75. const {
  76. prefixCls: customizePrefixCls,
  77. placement,
  78. className,
  79. style
  80. } = props,
  81. restProps = __rest(props, ["prefixCls", "placement", "className", "style"]);
  82. const {
  83. getPrefixCls
  84. } = React.useContext(ConfigContext);
  85. const prefixCls = getPrefixCls('popconfirm', customizePrefixCls);
  86. const [wrapCSSVar] = useStyle(prefixCls);
  87. return wrapCSSVar(/*#__PURE__*/React.createElement(PopoverPurePanel, {
  88. placement: placement,
  89. className: classNames(prefixCls, className),
  90. style: style,
  91. content: /*#__PURE__*/React.createElement(Overlay, Object.assign({
  92. prefixCls: prefixCls
  93. }, restProps))
  94. }));
  95. };
  96. export default PurePanel;