hongluan-ui
Version:
Hongluan Component Library for Vue 3
158 lines (155 loc) • 5.87 kB
JavaScript
import { defineComponent, inject, watch, computed, openBlock, createElementBlock, Fragment, unref, createVNode, withCtx, createCommentVNode, createElementVNode, normalizeClass, renderSlot, toDisplayString, createBlock, resolveDynamicComponent, renderList, mergeProps, createTextVNode } from 'vue';
import { omit } from 'lodash-unified';
import { HlButton } from '../../button/index.mjs';
import { HlIcon } from '../../icon/index.mjs';
import '../../system-icon/index.mjs';
import '../../../hooks/index.mjs';
import { tourStepProps, tourStepEmits } from './step.mjs';
import { tourKey } from './helper.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import SystemClose from '../../system-icon/src/close.mjs';
const __default__ = defineComponent({
name: "TourStep"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: tourStepProps,
emits: tourStepEmits,
setup(__props, { emit }) {
const props = __props;
const { t } = useLocale();
const {
currentStep,
current,
total,
showClose,
mergedType,
slots: tourSlots,
updateModelValue,
onClose: tourOnClose,
onFinish: tourOnFinish,
onChange
} = inject(tourKey);
watch(props, (val) => {
currentStep.value = val;
}, {
immediate: true
});
const mergedShowClose = computed(() => {
var _a;
return (_a = props.showClose) != null ? _a : showClose.value;
});
const filterButtonProps = (btnProps) => {
if (!btnProps)
return;
return omit(btnProps, ["children", "onClick"]);
};
const onPrev = () => {
var _a, _b;
current.value -= 1;
if ((_a = props.prevButtonProps) == null ? void 0 : _a.onClick) {
(_b = props.prevButtonProps) == null ? void 0 : _b.onClick();
}
onChange();
};
const onNext = () => {
var _a;
if (current.value >= total.value - 1) {
onFinish();
} else {
current.value += 1;
}
if ((_a = props.prevButtonProps) == null ? void 0 : _a.onClick) {
props.prevButtonProps.onClick();
}
onChange();
};
const onFinish = () => {
onClose();
tourOnFinish();
};
const onClose = () => {
updateModelValue(false);
tourOnClose();
emit("close");
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock(Fragment, null, [
unref(mergedShowClose) ? (openBlock(), createElementBlock("button", {
key: 0,
"aria-label": "Close",
class: "tour-closebtn",
type: "button",
onClick: onClose
}, [
createVNode(unref(HlIcon), { class: "tour-close" }, {
default: withCtx(() => [
createVNode(unref(SystemClose))
]),
_: 1
})
])) : createCommentVNode("v-if", true),
createElementVNode("header", {
class: normalizeClass(["tour-header", { "show-close": unref(showClose) }])
}, [
renderSlot(_ctx.$slots, "header", {}, () => [
createElementVNode("span", {
role: "heading",
class: "tour-title"
}, toDisplayString(_ctx.title), 1)
])
], 2),
createElementVNode("div", { class: "tour-body" }, [
renderSlot(_ctx.$slots, "default", {}, () => [
createElementVNode("span", null, toDisplayString(_ctx.description), 1)
])
]),
createElementVNode("footer", { class: "tour-footer" }, [
createElementVNode("div", { class: "tour-indicators" }, [
unref(tourSlots).indicators ? (openBlock(), createBlock(resolveDynamicComponent(unref(tourSlots).indicators), {
key: 0,
current: unref(current),
total: unref(total)
}, null, 8, ["current", "total"])) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(total), (item, index) => {
return openBlock(), createElementBlock("span", {
key: item,
class: normalizeClass(["tour-indicator", index === unref(current) ? "is-active" : ""])
}, null, 2);
}), 128))
]),
createElementVNode("div", { class: "tour-buttons" }, [
unref(current) > 0 ? (openBlock(), createBlock(unref(HlButton), mergeProps({
key: 0,
size: "sm",
class: "m-r-md",
type: unref(mergedType)
}, filterButtonProps(_ctx.prevButtonProps), { onClick: onPrev }), {
default: withCtx(() => {
var _a, _b;
return [
createTextVNode(toDisplayString((_b = (_a = _ctx.prevButtonProps) == null ? void 0 : _a.children) != null ? _b : unref(t)("hl.tour.previous")), 1)
];
}),
_: 1
}, 16, ["type"])) : createCommentVNode("v-if", true),
unref(current) <= unref(total) - 1 ? (openBlock(), createBlock(unref(HlButton), mergeProps({
key: 1,
size: "sm",
type: unref(mergedType) === "primary" ? "default" : "primary"
}, filterButtonProps(_ctx.nextButtonProps), { onClick: onNext }), {
default: withCtx(() => {
var _a, _b;
return [
createTextVNode(toDisplayString((_b = (_a = _ctx.nextButtonProps) == null ? void 0 : _a.children) != null ? _b : unref(current) === unref(total) - 1 ? unref(t)("hl.tour.finish") : unref(t)("hl.tour.next")), 1)
];
}),
_: 1
}, 16, ["type"])) : createCommentVNode("v-if", true)
])
])
], 64);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=step2.mjs.map