ckgl/node_modules/vant/lib/step/Step.js
2024-12-21 13:52:42 +08:00

137 lines
4.3 KiB
JavaScript

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_utils = require("../utils");
var import_Steps = require("../steps/Steps");
var import_use = require("@vant/use");
var import_icon = require("../icon");
const [name, bem] = (0, import_utils.createNamespace)("step");
var stdin_default = (0, import_vue.defineComponent)({
name,
setup(props, {
slots
}) {
const {
parent,
index
} = (0, import_use.useParent)(import_Steps.STEPS_KEY);
if (!parent) {
if (process.env.NODE_ENV !== "production") {
console.error("[Vant] <Step> must be a child component of <Steps>.");
}
return;
}
const parentProps = parent.props;
const getStatus = () => {
const active = +parentProps.active;
if (index.value < active) {
return "finish";
}
return index.value === active ? "process" : "waiting";
};
const isActive = () => getStatus() === "process";
const lineStyle = (0, import_vue.computed)(() => ({
background: getStatus() === "finish" ? parentProps.activeColor : parentProps.inactiveColor
}));
const titleStyle = (0, import_vue.computed)(() => {
if (isActive()) {
return {
color: parentProps.activeColor
};
}
if (getStatus() === "waiting") {
return {
color: parentProps.inactiveColor
};
}
});
const onClickStep = () => parent.onClickStep(index.value);
const renderCircle = () => {
const {
iconPrefix,
finishIcon,
activeIcon,
activeColor,
inactiveIcon
} = parentProps;
if (isActive()) {
if (slots["active-icon"]) {
return slots["active-icon"]();
}
return (0, import_vue.createVNode)(import_icon.Icon, {
"class": bem("icon", "active"),
"name": activeIcon,
"color": activeColor,
"classPrefix": iconPrefix
}, null);
}
if (getStatus() === "finish" && (finishIcon || slots["finish-icon"])) {
if (slots["finish-icon"]) {
return slots["finish-icon"]();
}
return (0, import_vue.createVNode)(import_icon.Icon, {
"class": bem("icon", "finish"),
"name": finishIcon,
"color": activeColor,
"classPrefix": iconPrefix
}, null);
}
if (slots["inactive-icon"]) {
return slots["inactive-icon"]();
}
if (inactiveIcon) {
return (0, import_vue.createVNode)(import_icon.Icon, {
"class": bem("icon"),
"name": inactiveIcon,
"classPrefix": iconPrefix
}, null);
}
return (0, import_vue.createVNode)("i", {
"class": bem("circle"),
"style": lineStyle.value
}, null);
};
return () => {
var _a;
const status = getStatus();
return (0, import_vue.createVNode)("div", {
"class": [import_utils.BORDER, bem([parentProps.direction, {
[status]: status
}])]
}, [(0, import_vue.createVNode)("div", {
"class": bem("title", {
active: isActive()
}),
"style": titleStyle.value,
"onClick": onClickStep
}, [(_a = slots.default) == null ? void 0 : _a.call(slots)]), (0, import_vue.createVNode)("div", {
"class": bem("circle-container"),
"onClick": onClickStep
}, [renderCircle()]), (0, import_vue.createVNode)("div", {
"class": bem("line"),
"style": lineStyle.value
}, null)]);
};
}
});