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 | tabbarItemProps: () => tabbarItemProps
|
22 | });
|
23 | module.exports = __toCommonJS(stdin_exports);
|
24 | var import_vue = require("vue");
|
25 | var import_utils = require("../utils");
|
26 | var import_Tabbar = require("../tabbar/Tabbar");
|
27 | var import_use = require("@vant/use");
|
28 | var import_use_route = require("../composables/use-route");
|
29 | var import_icon = require("../icon");
|
30 | var import_badge = require("../badge");
|
31 | const [name, bem] = (0, import_utils.createNamespace)("tabbar-item");
|
32 | const tabbarItemProps = (0, import_utils.extend)({}, import_use_route.routeProps, {
|
33 | dot: Boolean,
|
34 | icon: String,
|
35 | name: import_utils.numericProp,
|
36 | badge: import_utils.numericProp,
|
37 | badgeProps: Object,
|
38 | iconPrefix: String
|
39 | });
|
40 | var stdin_default = (0, import_vue.defineComponent)({
|
41 | name,
|
42 | props: tabbarItemProps,
|
43 | emits: ["click"],
|
44 | setup(props, {
|
45 | emit,
|
46 | slots
|
47 | }) {
|
48 | const route = (0, import_use_route.useRoute)();
|
49 | const vm = (0, import_vue.getCurrentInstance)().proxy;
|
50 | const {
|
51 | parent,
|
52 | index
|
53 | } = (0, import_use.useParent)(import_Tabbar.TABBAR_KEY);
|
54 | if (!parent) {
|
55 | if (process.env.NODE_ENV !== "production") {
|
56 | console.error("[Vant] <TabbarItem> must be a child component of <Tabbar>.");
|
57 | }
|
58 | return;
|
59 | }
|
60 | const active = (0, import_vue.computed)(() => {
|
61 | var _a;
|
62 | const {
|
63 | route: route2,
|
64 | modelValue
|
65 | } = parent.props;
|
66 | if (route2 && "$route" in vm) {
|
67 | const {
|
68 | $route
|
69 | } = vm;
|
70 | const {
|
71 | to
|
72 | } = props;
|
73 | const config = (0, import_utils.isObject)(to) ? to : {
|
74 | path: to
|
75 | };
|
76 | return !!$route.matched.find((val) => {
|
77 | const pathMatched = "path" in config && config.path === val.path;
|
78 | const nameMatched = "name" in config && config.name === val.name;
|
79 | return pathMatched || nameMatched;
|
80 | });
|
81 | }
|
82 | return ((_a = props.name) != null ? _a : index.value) === modelValue;
|
83 | });
|
84 | const onClick = (event) => {
|
85 | var _a;
|
86 | if (!active.value) {
|
87 | parent.setActive((_a = props.name) != null ? _a : index.value, route);
|
88 | }
|
89 | emit("click", event);
|
90 | };
|
91 | const renderIcon = () => {
|
92 | if (slots.icon) {
|
93 | return slots.icon({
|
94 | active: active.value
|
95 | });
|
96 | }
|
97 | if (props.icon) {
|
98 | return (0, import_vue.createVNode)(import_icon.Icon, {
|
99 | "name": props.icon,
|
100 | "classPrefix": props.iconPrefix
|
101 | }, null);
|
102 | }
|
103 | };
|
104 | return () => {
|
105 | var _a;
|
106 | const {
|
107 | dot,
|
108 | badge
|
109 | } = props;
|
110 | const {
|
111 | activeColor,
|
112 | inactiveColor
|
113 | } = parent.props;
|
114 | const color = active.value ? activeColor : inactiveColor;
|
115 | return (0, import_vue.createVNode)("div", {
|
116 | "role": "tab",
|
117 | "class": bem({
|
118 | active: active.value
|
119 | }),
|
120 | "style": {
|
121 | color
|
122 | },
|
123 | "tabindex": 0,
|
124 | "aria-selected": active.value,
|
125 | "onClick": onClick
|
126 | }, [(0, import_vue.createVNode)(import_badge.Badge, (0, import_vue.mergeProps)({
|
127 | "dot": dot,
|
128 | "class": bem("icon"),
|
129 | "content": badge
|
130 | }, props.badgeProps), {
|
131 | default: renderIcon
|
132 | }), (0, import_vue.createVNode)("div", {
|
133 | "class": bem("text")
|
134 | }, [(_a = slots.default) == null ? void 0 : _a.call(slots, {
|
135 | active: active.value
|
136 | })])]);
|
137 | };
|
138 | }
|
139 | });
|