index.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 React, { useContext } from 'react';
  11. import RCTour from '@rc-component/tour';
  12. import classNames from 'classnames';
  13. import { useZIndex } from '../_util/hooks/useZIndex';
  14. import getPlacements from '../_util/placements';
  15. import zIndexContext from '../_util/zindexContext';
  16. import { ConfigContext } from '../config-provider';
  17. import { useToken } from '../theme/internal';
  18. import TourPanel from './panelRender';
  19. import PurePanel from './PurePanel';
  20. import useStyle from './style';
  21. const Tour = props => {
  22. const {
  23. prefixCls: customizePrefixCls,
  24. type,
  25. rootClassName,
  26. indicatorsRender,
  27. actionsRender,
  28. steps,
  29. closeIcon
  30. } = props,
  31. restProps = __rest(props, ["prefixCls", "type", "rootClassName", "indicatorsRender", "actionsRender", "steps", "closeIcon"]);
  32. const {
  33. getPrefixCls,
  34. direction,
  35. tour
  36. } = useContext(ConfigContext);
  37. const prefixCls = getPrefixCls('tour', customizePrefixCls);
  38. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
  39. const [, token] = useToken();
  40. const mergedSteps = React.useMemo(() => steps === null || steps === void 0 ? void 0 : steps.map(step => {
  41. var _a;
  42. return Object.assign(Object.assign({}, step), {
  43. className: classNames(step.className, {
  44. [`${prefixCls}-primary`]: ((_a = step.type) !== null && _a !== void 0 ? _a : type) === 'primary'
  45. })
  46. });
  47. }), [steps, type]);
  48. const builtinPlacements = config => {
  49. var _a;
  50. return getPlacements({
  51. arrowPointAtCenter: (_a = config === null || config === void 0 ? void 0 : config.arrowPointAtCenter) !== null && _a !== void 0 ? _a : true,
  52. autoAdjustOverflow: true,
  53. offset: token.marginXXS,
  54. arrowWidth: token.sizePopupArrow,
  55. borderRadius: token.borderRadius
  56. });
  57. };
  58. const customClassName = classNames({
  59. [`${prefixCls}-rtl`]: direction === 'rtl'
  60. }, hashId, cssVarCls, rootClassName);
  61. const mergedRenderPanel = (stepProps, stepCurrent) => (/*#__PURE__*/React.createElement(TourPanel, {
  62. type: type,
  63. stepProps: stepProps,
  64. current: stepCurrent,
  65. indicatorsRender: indicatorsRender,
  66. actionsRender: actionsRender
  67. }));
  68. // ============================ zIndex ============================
  69. const [zIndex, contextZIndex] = useZIndex('Tour', restProps.zIndex);
  70. return wrapCSSVar(/*#__PURE__*/React.createElement(zIndexContext.Provider, {
  71. value: contextZIndex
  72. }, /*#__PURE__*/React.createElement(RCTour, Object.assign({}, restProps, {
  73. closeIcon: closeIcon !== null && closeIcon !== void 0 ? closeIcon : tour === null || tour === void 0 ? void 0 : tour.closeIcon,
  74. zIndex: zIndex,
  75. rootClassName: customClassName,
  76. prefixCls: prefixCls,
  77. animated: true,
  78. renderPanel: mergedRenderPanel,
  79. builtinPlacements: builtinPlacements,
  80. steps: mergedSteps
  81. }))));
  82. };
  83. if (process.env.NODE_ENV !== 'production') {
  84. Tour.displayName = 'Tour';
  85. }
  86. Tour._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
  87. export default Tour;