panelRender.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. "use client";
  2. import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
  3. import React from 'react';
  4. import CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined";
  5. import classNames from 'classnames';
  6. import pickAttrs from "rc-util/es/pickAttrs";
  7. import Button from '../button';
  8. import { useLocale } from '../locale';
  9. import defaultLocale from '../locale/en_US';
  10. function isValidNode(node) {
  11. return node !== undefined && node !== null;
  12. }
  13. // Due to the independent design of Panel, it will be too coupled to put in rc-tour,
  14. // so a set of Panel logic is implemented separately in antd.
  15. const TourPanel = props => {
  16. var _a, _b;
  17. const {
  18. stepProps,
  19. current,
  20. type,
  21. indicatorsRender,
  22. actionsRender
  23. } = props;
  24. const {
  25. prefixCls,
  26. total = 1,
  27. title,
  28. onClose,
  29. onPrev,
  30. onNext,
  31. onFinish,
  32. cover,
  33. description,
  34. nextButtonProps,
  35. prevButtonProps,
  36. type: stepType,
  37. closable
  38. } = stepProps;
  39. const mergedType = stepType !== null && stepType !== void 0 ? stepType : type;
  40. const ariaProps = pickAttrs(closable !== null && closable !== void 0 ? closable : {}, true);
  41. const [contextLocaleGlobal] = useLocale('global', defaultLocale.global);
  42. const [contextLocaleTour] = useLocale('Tour', defaultLocale.Tour);
  43. const mergedCloseIcon = /*#__PURE__*/React.createElement("button", Object.assign({
  44. type: "button",
  45. onClick: onClose,
  46. className: `${prefixCls}-close`,
  47. "aria-label": contextLocaleGlobal === null || contextLocaleGlobal === void 0 ? void 0 : contextLocaleGlobal.close
  48. }, ariaProps), (closable === null || closable === void 0 ? void 0 : closable.closeIcon) || /*#__PURE__*/React.createElement(CloseOutlined, {
  49. className: `${prefixCls}-close-icon`
  50. }));
  51. const isLastStep = current === total - 1;
  52. const prevBtnClick = () => {
  53. var _a;
  54. onPrev === null || onPrev === void 0 ? void 0 : onPrev();
  55. (_a = prevButtonProps === null || prevButtonProps === void 0 ? void 0 : prevButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(prevButtonProps);
  56. };
  57. const nextBtnClick = () => {
  58. var _a;
  59. if (isLastStep) {
  60. onFinish === null || onFinish === void 0 ? void 0 : onFinish();
  61. } else {
  62. onNext === null || onNext === void 0 ? void 0 : onNext();
  63. }
  64. (_a = nextButtonProps === null || nextButtonProps === void 0 ? void 0 : nextButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(nextButtonProps);
  65. };
  66. const headerNode = isValidNode(title) ? (/*#__PURE__*/React.createElement("div", {
  67. className: `${prefixCls}-header`
  68. }, /*#__PURE__*/React.createElement("div", {
  69. className: `${prefixCls}-title`
  70. }, title))) : null;
  71. const descriptionNode = isValidNode(description) ? (/*#__PURE__*/React.createElement("div", {
  72. className: `${prefixCls}-description`
  73. }, description)) : null;
  74. const coverNode = isValidNode(cover) ? /*#__PURE__*/React.createElement("div", {
  75. className: `${prefixCls}-cover`
  76. }, cover) : null;
  77. let mergedIndicatorNode;
  78. if (indicatorsRender) {
  79. mergedIndicatorNode = indicatorsRender(current, total);
  80. } else {
  81. mergedIndicatorNode = _toConsumableArray(Array.from({
  82. length: total
  83. }).keys()).map((stepItem, index) => (/*#__PURE__*/React.createElement("span", {
  84. key: stepItem,
  85. className: classNames(index === current && `${prefixCls}-indicator-active`, `${prefixCls}-indicator`)
  86. })));
  87. }
  88. const mainBtnType = mergedType === 'primary' ? 'default' : 'primary';
  89. const secondaryBtnProps = {
  90. type: 'default',
  91. ghost: mergedType === 'primary'
  92. };
  93. const defaultActionsNode = /*#__PURE__*/React.createElement(React.Fragment, null, current !== 0 ? (/*#__PURE__*/React.createElement(Button, Object.assign({
  94. size: "small"
  95. }, secondaryBtnProps, prevButtonProps, {
  96. onClick: prevBtnClick,
  97. className: classNames(`${prefixCls}-prev-btn`, prevButtonProps === null || prevButtonProps === void 0 ? void 0 : prevButtonProps.className)
  98. }), (_a = prevButtonProps === null || prevButtonProps === void 0 ? void 0 : prevButtonProps.children) !== null && _a !== void 0 ? _a : contextLocaleTour === null || contextLocaleTour === void 0 ? void 0 : contextLocaleTour.Previous)) : null, /*#__PURE__*/React.createElement(Button, Object.assign({
  99. size: "small",
  100. type: mainBtnType
  101. }, nextButtonProps, {
  102. onClick: nextBtnClick,
  103. className: classNames(`${prefixCls}-next-btn`, nextButtonProps === null || nextButtonProps === void 0 ? void 0 : nextButtonProps.className)
  104. }), (_b = nextButtonProps === null || nextButtonProps === void 0 ? void 0 : nextButtonProps.children) !== null && _b !== void 0 ? _b : isLastStep ? contextLocaleTour === null || contextLocaleTour === void 0 ? void 0 : contextLocaleTour.Finish : contextLocaleTour === null || contextLocaleTour === void 0 ? void 0 : contextLocaleTour.Next));
  105. return /*#__PURE__*/React.createElement("div", {
  106. className: `${prefixCls}-content`
  107. }, /*#__PURE__*/React.createElement("div", {
  108. className: `${prefixCls}-inner`
  109. }, closable && mergedCloseIcon, coverNode, headerNode, descriptionNode, /*#__PURE__*/React.createElement("div", {
  110. className: `${prefixCls}-footer`
  111. }, total > 1 && /*#__PURE__*/React.createElement("div", {
  112. className: `${prefixCls}-indicators`
  113. }, mergedIndicatorNode), /*#__PURE__*/React.createElement("div", {
  114. className: `${prefixCls}-buttons`
  115. }, actionsRender ? actionsRender(defaultActionsNode, {
  116. current,
  117. total
  118. }) : defaultActionsNode))));
  119. };
  120. export default TourPanel;