Step.mjs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { createVNode as _createVNode } from "vue";
  2. import { computed, defineComponent } from "vue";
  3. import { BORDER, createNamespace } from "../utils/index.mjs";
  4. import { STEPS_KEY } from "../steps/Steps.mjs";
  5. import { useParent } from "@vant/use";
  6. import { Icon } from "../icon/index.mjs";
  7. const [name, bem] = createNamespace("step");
  8. var stdin_default = defineComponent({
  9. name,
  10. setup(props, {
  11. slots
  12. }) {
  13. const {
  14. parent,
  15. index
  16. } = useParent(STEPS_KEY);
  17. if (!parent) {
  18. if (process.env.NODE_ENV !== "production") {
  19. console.error("[Vant] <Step> must be a child component of <Steps>.");
  20. }
  21. return;
  22. }
  23. const parentProps = parent.props;
  24. const getStatus = () => {
  25. const active = +parentProps.active;
  26. if (index.value < active) {
  27. return "finish";
  28. }
  29. return index.value === active ? "process" : "waiting";
  30. };
  31. const isActive = () => getStatus() === "process";
  32. const lineStyle = computed(() => ({
  33. background: getStatus() === "finish" ? parentProps.activeColor : parentProps.inactiveColor
  34. }));
  35. const titleStyle = computed(() => {
  36. if (isActive()) {
  37. return {
  38. color: parentProps.activeColor
  39. };
  40. }
  41. if (getStatus() === "waiting") {
  42. return {
  43. color: parentProps.inactiveColor
  44. };
  45. }
  46. });
  47. const onClickStep = () => parent.onClickStep(index.value);
  48. const renderCircle = () => {
  49. const {
  50. iconPrefix,
  51. finishIcon,
  52. activeIcon,
  53. activeColor,
  54. inactiveIcon
  55. } = parentProps;
  56. if (isActive()) {
  57. if (slots["active-icon"]) {
  58. return slots["active-icon"]();
  59. }
  60. return _createVNode(Icon, {
  61. "class": bem("icon", "active"),
  62. "name": activeIcon,
  63. "color": activeColor,
  64. "classPrefix": iconPrefix
  65. }, null);
  66. }
  67. if (getStatus() === "finish" && (finishIcon || slots["finish-icon"])) {
  68. if (slots["finish-icon"]) {
  69. return slots["finish-icon"]();
  70. }
  71. return _createVNode(Icon, {
  72. "class": bem("icon", "finish"),
  73. "name": finishIcon,
  74. "color": activeColor,
  75. "classPrefix": iconPrefix
  76. }, null);
  77. }
  78. if (slots["inactive-icon"]) {
  79. return slots["inactive-icon"]();
  80. }
  81. if (inactiveIcon) {
  82. return _createVNode(Icon, {
  83. "class": bem("icon"),
  84. "name": inactiveIcon,
  85. "classPrefix": iconPrefix
  86. }, null);
  87. }
  88. return _createVNode("i", {
  89. "class": bem("circle"),
  90. "style": lineStyle.value
  91. }, null);
  92. };
  93. return () => {
  94. var _a;
  95. const status = getStatus();
  96. return _createVNode("div", {
  97. "class": [BORDER, bem([parentProps.direction, {
  98. [status]: status
  99. }])]
  100. }, [_createVNode("div", {
  101. "class": bem("title", {
  102. active: isActive()
  103. }),
  104. "style": titleStyle.value,
  105. "onClick": onClickStep
  106. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]), _createVNode("div", {
  107. "class": bem("circle-container"),
  108. "onClick": onClickStep
  109. }, [renderCircle()]), _createVNode("div", {
  110. "class": bem("line"),
  111. "style": lineStyle.value
  112. }, null)]);
  113. };
  114. }
  115. });
  116. export {
  117. stdin_default as default
  118. };