UNPKG

2.93 kBJavaScriptView Raw
1var __defProp = Object.defineProperty;
2var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3var __getOwnPropNames = Object.getOwnPropertyNames;
4var __hasOwnProp = Object.prototype.hasOwnProperty;
5var __export = (target, all) => {
6 for (var name2 in all)
7 __defProp(target, name2, { get: all[name2], enumerable: true });
8};
9var __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};
17var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18var stdin_exports = {};
19__export(stdin_exports, {
20 default: () => stdin_default
21});
22module.exports = __toCommonJS(stdin_exports);
23var import_vue = require("vue");
24var import_utils = require("../utils");
25var import_swipe = require("../swipe");
26var import_use_expose = require("../composables/use-expose");
27const [name, bem] = (0, import_utils.createNamespace)("tabs");
28var stdin_default = (0, import_vue.defineComponent)({
29 name,
30 props: {
31 count: (0, import_utils.makeRequiredProp)(Number),
32 inited: Boolean,
33 animated: Boolean,
34 duration: (0, import_utils.makeRequiredProp)(import_utils.numericProp),
35 swipeable: Boolean,
36 lazyRender: Boolean,
37 currentIndex: (0, import_utils.makeRequiredProp)(Number)
38 },
39 emits: ["change"],
40 setup(props, {
41 emit,
42 slots
43 }) {
44 const swipeRef = (0, import_vue.ref)();
45 const onChange = (index) => emit("change", index);
46 const renderChildren = () => {
47 var _a;
48 const Content = (_a = slots.default) == null ? void 0 : _a.call(slots);
49 if (props.animated || props.swipeable) {
50 return (0, import_vue.createVNode)(import_swipe.Swipe, {
51 "ref": swipeRef,
52 "loop": false,
53 "class": bem("track"),
54 "duration": +props.duration * 1e3,
55 "touchable": props.swipeable,
56 "lazyRender": props.lazyRender,
57 "showIndicators": false,
58 "onChange": onChange
59 }, {
60 default: () => [Content]
61 });
62 }
63 return Content;
64 };
65 const swipeToCurrentTab = (index) => {
66 const swipe = swipeRef.value;
67 if (swipe && swipe.state.active !== index) {
68 swipe.swipeTo(index, {
69 immediate: !props.inited
70 });
71 }
72 };
73 (0, import_vue.watch)(() => props.currentIndex, swipeToCurrentTab);
74 (0, import_vue.onMounted)(() => {
75 swipeToCurrentTab(props.currentIndex);
76 });
77 (0, import_use_expose.useExpose)({
78 swipeRef
79 });
80 return () => (0, import_vue.createVNode)("div", {
81 "class": bem("content", {
82 animated: props.animated || props.swipeable
83 })
84 }, [renderChildren()]);
85 }
86});