1 | var __defProp = Object.defineProperty;
|
2 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
4 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5 | var __export = (target, all) => {
|
6 | for (var name2 in all)
|
7 | __defProp(target, name2, { get: all[name2], enumerable: true });
|
8 | };
|
9 | var __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 | };
|
17 | var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18 | var stdin_exports = {};
|
19 | __export(stdin_exports, {
|
20 | default: () => stdin_default,
|
21 | tabProps: () => tabProps
|
22 | });
|
23 | module.exports = __toCommonJS(stdin_exports);
|
24 | var import_vue = require("vue");
|
25 | var import_shared = require("@vue/shared");
|
26 | var import_utils = require("../utils");
|
27 | var import_Tabs = require("../tabs/Tabs");
|
28 | var import_use = require("@vant/use");
|
29 | var import_use_id = require("../composables/use-id");
|
30 | var import_use_expose = require("../composables/use-expose");
|
31 | var import_use_route = require("../composables/use-route");
|
32 | var import_use_tab_status = require("../composables/use-tab-status");
|
33 | var import_TabTitle = require("./TabTitle");
|
34 | var import_swipe_item = require("../swipe-item");
|
35 | const [name, bem] = (0, import_utils.createNamespace)("tab");
|
36 | const tabProps = (0, import_utils.extend)({}, import_use_route.routeProps, {
|
37 | dot: Boolean,
|
38 | name: import_utils.numericProp,
|
39 | badge: import_utils.numericProp,
|
40 | title: String,
|
41 | disabled: Boolean,
|
42 | titleClass: import_utils.unknownProp,
|
43 | titleStyle: [String, Object],
|
44 | showZeroBadge: import_utils.truthProp
|
45 | });
|
46 | var stdin_default = (0, import_vue.defineComponent)({
|
47 | name,
|
48 | props: tabProps,
|
49 | setup(props, {
|
50 | slots
|
51 | }) {
|
52 | const id = (0, import_use_id.useId)();
|
53 | const inited = (0, import_vue.ref)(false);
|
54 | const instance = (0, import_vue.getCurrentInstance)();
|
55 | const {
|
56 | parent,
|
57 | index
|
58 | } = (0, import_use.useParent)(import_Tabs.TABS_KEY);
|
59 | if (!parent) {
|
60 | if (process.env.NODE_ENV !== "production") {
|
61 | console.error("[Vant] <Tab> must be a child component of <Tabs>.");
|
62 | }
|
63 | return;
|
64 | }
|
65 | const getName = () => {
|
66 | var _a;
|
67 | return (_a = props.name) != null ? _a : index.value;
|
68 | };
|
69 | const init = () => {
|
70 | inited.value = true;
|
71 | if (parent.props.lazyRender) {
|
72 | (0, import_vue.nextTick)(() => {
|
73 | parent.onRendered(getName(), props.title);
|
74 | });
|
75 | }
|
76 | };
|
77 | const active = (0, import_vue.computed)(() => {
|
78 | const isActive = getName() === parent.currentName.value;
|
79 | if (isActive && !inited.value) {
|
80 | init();
|
81 | }
|
82 | return isActive;
|
83 | });
|
84 | const parsedClass = (0, import_vue.ref)("");
|
85 | const parsedStyle = (0, import_vue.ref)("");
|
86 | (0, import_vue.watchEffect)(() => {
|
87 | const {
|
88 | titleClass,
|
89 | titleStyle
|
90 | } = props;
|
91 | parsedClass.value = titleClass ? (0, import_shared.normalizeClass)(titleClass) : "";
|
92 | parsedStyle.value = titleStyle && typeof titleStyle !== "string" ? (0, import_shared.stringifyStyle)((0, import_shared.normalizeStyle)(titleStyle)) : titleStyle;
|
93 | });
|
94 | const renderTitle = (onClickTab) => (0, import_vue.createVNode)(import_TabTitle.TabTitle, (0, import_vue.mergeProps)({
|
95 | "key": id,
|
96 | "id": `${parent.id}-${index.value}`,
|
97 | "ref": parent.setTitleRefs(index.value),
|
98 | "style": parsedStyle.value,
|
99 | "class": parsedClass.value,
|
100 | "isActive": active.value,
|
101 | "controls": id,
|
102 | "scrollable": parent.scrollable.value,
|
103 | "activeColor": parent.props.titleActiveColor,
|
104 | "inactiveColor": parent.props.titleInactiveColor,
|
105 | "onClick": (event) => onClickTab(instance.proxy, index.value, event)
|
106 | }, (0, import_utils.pick)(parent.props, ["type", "color", "shrink"]), (0, import_utils.pick)(props, ["dot", "badge", "title", "disabled", "showZeroBadge"])), {
|
107 | title: slots.title
|
108 | });
|
109 | const hasInactiveClass = (0, import_vue.ref)(!active.value);
|
110 | (0, import_vue.watch)(active, (val) => {
|
111 | if (val) {
|
112 | hasInactiveClass.value = false;
|
113 | } else {
|
114 | (0, import_use.doubleRaf)(() => {
|
115 | hasInactiveClass.value = true;
|
116 | });
|
117 | }
|
118 | });
|
119 | (0, import_vue.watch)(() => props.title, () => {
|
120 | parent.setLine();
|
121 | parent.scrollIntoView();
|
122 | });
|
123 | (0, import_vue.provide)(import_use_tab_status.TAB_STATUS_KEY, active);
|
124 | (0, import_use_expose.useExpose)({
|
125 | id,
|
126 | renderTitle
|
127 | });
|
128 | return () => {
|
129 | var _a;
|
130 | const label = `${parent.id}-${index.value}`;
|
131 | const {
|
132 | animated,
|
133 | swipeable,
|
134 | scrollspy,
|
135 | lazyRender
|
136 | } = parent.props;
|
137 | if (!slots.default && !animated) {
|
138 | return;
|
139 | }
|
140 | const show = scrollspy || active.value;
|
141 | if (animated || swipeable) {
|
142 | return (0, import_vue.createVNode)(import_swipe_item.SwipeItem, {
|
143 | "id": id,
|
144 | "role": "tabpanel",
|
145 | "class": bem("panel-wrapper", {
|
146 | inactive: hasInactiveClass.value
|
147 | }),
|
148 | "tabindex": active.value ? 0 : -1,
|
149 | "aria-hidden": !active.value,
|
150 | "aria-labelledby": label,
|
151 | "data-allow-mismatch": "attribute"
|
152 | }, {
|
153 | default: () => {
|
154 | var _a2;
|
155 | return [(0, import_vue.createVNode)("div", {
|
156 | "class": bem("panel")
|
157 | }, [(_a2 = slots.default) == null ? void 0 : _a2.call(slots)])];
|
158 | }
|
159 | });
|
160 | }
|
161 | const shouldRender = inited.value || scrollspy || !lazyRender;
|
162 | const Content = shouldRender ? (_a = slots.default) == null ? void 0 : _a.call(slots) : null;
|
163 | return (0, import_vue.withDirectives)((0, import_vue.createVNode)("div", {
|
164 | "id": id,
|
165 | "role": "tabpanel",
|
166 | "class": bem("panel"),
|
167 | "tabindex": show ? 0 : -1,
|
168 | "aria-labelledby": label,
|
169 | "data-allow-mismatch": "attribute"
|
170 | }, [Content]), [[import_vue.vShow, show]]);
|
171 | };
|
172 | }
|
173 | });
|