Step.mjs 3.3 KB

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