Step.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default
  21. });
  22. module.exports = __toCommonJS(stdin_exports);
  23. var import_vue = require("vue");
  24. var import_utils = require("../utils");
  25. var import_Steps = require("../steps/Steps");
  26. var import_use = require("@vant/use");
  27. var import_icon = require("../icon");
  28. const [name, bem] = (0, import_utils.createNamespace)("step");
  29. var stdin_default = (0, import_vue.defineComponent)({
  30. name,
  31. setup(props, {
  32. slots
  33. }) {
  34. const {
  35. parent,
  36. index
  37. } = (0, import_use.useParent)(import_Steps.STEPS_KEY);
  38. if (!parent) {
  39. if (process.env.NODE_ENV !== "production") {
  40. console.error("[Vant] <Step> must be a child component of <Steps>.");
  41. }
  42. return;
  43. }
  44. const parentProps = parent.props;
  45. const getStatus = () => {
  46. const active = +parentProps.active;
  47. if (index.value < active) {
  48. return "finish";
  49. }
  50. return index.value === active ? "process" : "waiting";
  51. };
  52. const isActive = () => getStatus() === "process";
  53. const lineStyle = (0, import_vue.computed)(() => ({
  54. background: getStatus() === "finish" ? parentProps.activeColor : parentProps.inactiveColor
  55. }));
  56. const titleStyle = (0, import_vue.computed)(() => {
  57. if (isActive()) {
  58. return {
  59. color: parentProps.activeColor
  60. };
  61. }
  62. if (getStatus() === "waiting") {
  63. return {
  64. color: parentProps.inactiveColor
  65. };
  66. }
  67. });
  68. const onClickStep = () => parent.onClickStep(index.value);
  69. const renderCircle = () => {
  70. const {
  71. iconPrefix,
  72. finishIcon,
  73. activeIcon,
  74. activeColor,
  75. inactiveIcon
  76. } = parentProps;
  77. if (isActive()) {
  78. if (slots["active-icon"]) {
  79. return slots["active-icon"]();
  80. }
  81. return (0, import_vue.createVNode)(import_icon.Icon, {
  82. "class": bem("icon", "active"),
  83. "name": activeIcon,
  84. "color": activeColor,
  85. "classPrefix": iconPrefix
  86. }, null);
  87. }
  88. if (getStatus() === "finish" && (finishIcon || slots["finish-icon"])) {
  89. if (slots["finish-icon"]) {
  90. return slots["finish-icon"]();
  91. }
  92. return (0, import_vue.createVNode)(import_icon.Icon, {
  93. "class": bem("icon", "finish"),
  94. "name": finishIcon,
  95. "color": activeColor,
  96. "classPrefix": iconPrefix
  97. }, null);
  98. }
  99. if (slots["inactive-icon"]) {
  100. return slots["inactive-icon"]();
  101. }
  102. if (inactiveIcon) {
  103. return (0, import_vue.createVNode)(import_icon.Icon, {
  104. "class": bem("icon"),
  105. "name": inactiveIcon,
  106. "classPrefix": iconPrefix
  107. }, null);
  108. }
  109. return (0, import_vue.createVNode)("i", {
  110. "class": bem("circle"),
  111. "style": lineStyle.value
  112. }, null);
  113. };
  114. return () => {
  115. var _a;
  116. const status = getStatus();
  117. return (0, import_vue.createVNode)("div", {
  118. "class": [import_utils.BORDER, bem([parentProps.direction, {
  119. [status]: status
  120. }])]
  121. }, [(0, import_vue.createVNode)("div", {
  122. "class": bem("title", {
  123. active: isActive()
  124. }),
  125. "style": titleStyle.value,
  126. "onClick": onClickStep
  127. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]), (0, import_vue.createVNode)("div", {
  128. "class": bem("circle-container"),
  129. "onClick": onClickStep
  130. }, [renderCircle()]), (0, import_vue.createVNode)("div", {
  131. "class": bem("line"),
  132. "style": lineStyle.value
  133. }, null)]);
  134. };
  135. }
  136. });