index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue";
  3. var __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. };
  11. import { computed, defineComponent, toRefs } from 'vue';
  12. import VCTour from '../vc-tour';
  13. import classNames from '../_util/classNames';
  14. import TourPanel from './panelRender';
  15. import { tourProps } from './interface';
  16. import useConfigInject from '../config-provider/hooks/useConfigInject';
  17. import { withInstall } from '../_util/type';
  18. import useMergedType from './useMergedType';
  19. // CSSINJS
  20. import useStyle from './style';
  21. import getPlacements from '../_util/placements';
  22. const Tour = defineComponent({
  23. name: 'ATour',
  24. inheritAttrs: false,
  25. props: tourProps(),
  26. setup(props, _ref) {
  27. let {
  28. attrs,
  29. emit,
  30. slots
  31. } = _ref;
  32. const {
  33. current,
  34. type,
  35. steps,
  36. defaultCurrent
  37. } = toRefs(props);
  38. const {
  39. prefixCls,
  40. direction
  41. } = useConfigInject('tour', props);
  42. // style
  43. const [wrapSSR, hashId] = useStyle(prefixCls);
  44. const {
  45. currentMergedType,
  46. updateInnerCurrent
  47. } = useMergedType({
  48. defaultType: type,
  49. steps,
  50. current,
  51. defaultCurrent
  52. });
  53. return () => {
  54. const {
  55. steps,
  56. current,
  57. type,
  58. rootClassName
  59. } = props,
  60. restProps = __rest(props, ["steps", "current", "type", "rootClassName"]);
  61. const customClassName = classNames({
  62. [`${prefixCls.value}-primary`]: currentMergedType.value === 'primary',
  63. [`${prefixCls.value}-rtl`]: direction.value === 'rtl'
  64. }, hashId.value, rootClassName);
  65. const mergedRenderPanel = (stepProps, stepCurrent) => {
  66. return _createVNode(TourPanel, _objectSpread(_objectSpread({}, stepProps), {}, {
  67. "type": type,
  68. "current": stepCurrent
  69. }), {
  70. indicatorsRender: slots.indicatorsRender
  71. });
  72. };
  73. const onStepChange = stepCurrent => {
  74. updateInnerCurrent(stepCurrent);
  75. emit('update:current', stepCurrent);
  76. emit('change', stepCurrent);
  77. };
  78. const builtinPlacements = computed(() => getPlacements({
  79. arrowPointAtCenter: true,
  80. autoAdjustOverflow: true
  81. }));
  82. return wrapSSR(_createVNode(VCTour, _objectSpread(_objectSpread(_objectSpread({}, attrs), restProps), {}, {
  83. "rootClassName": customClassName,
  84. "prefixCls": prefixCls.value,
  85. "current": current,
  86. "defaultCurrent": props.defaultCurrent,
  87. "animated": true,
  88. "renderPanel": mergedRenderPanel,
  89. "onChange": onStepChange,
  90. "steps": steps,
  91. "builtinPlacements": builtinPlacements.value
  92. }), null));
  93. };
  94. }
  95. });
  96. export default withInstall(Tour);