UNPKG

4.17 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 navBarProps: () => navBarProps
22});
23module.exports = __toCommonJS(stdin_exports);
24var import_vue = require("vue");
25var import_utils = require("../utils");
26var import_use_placeholder = require("../composables/use-placeholder");
27var import_icon = require("../icon");
28const [name, bem] = (0, import_utils.createNamespace)("nav-bar");
29const navBarProps = {
30 title: String,
31 fixed: Boolean,
32 zIndex: import_utils.numericProp,
33 border: import_utils.truthProp,
34 leftText: String,
35 rightText: String,
36 leftDisabled: Boolean,
37 rightDisabled: Boolean,
38 leftArrow: Boolean,
39 placeholder: Boolean,
40 safeAreaInsetTop: Boolean,
41 clickable: import_utils.truthProp
42};
43var stdin_default = (0, import_vue.defineComponent)({
44 name,
45 props: navBarProps,
46 emits: ["clickLeft", "clickRight"],
47 setup(props, {
48 emit,
49 slots
50 }) {
51 const navBarRef = (0, import_vue.ref)();
52 const renderPlaceholder = (0, import_use_placeholder.usePlaceholder)(navBarRef, bem);
53 const onClickLeft = (event) => {
54 if (!props.leftDisabled) {
55 emit("clickLeft", event);
56 }
57 };
58 const onClickRight = (event) => {
59 if (!props.rightDisabled) {
60 emit("clickRight", event);
61 }
62 };
63 const renderLeft = () => {
64 if (slots.left) {
65 return slots.left();
66 }
67 return [props.leftArrow && (0, import_vue.createVNode)(import_icon.Icon, {
68 "class": bem("arrow"),
69 "name": "arrow-left"
70 }, null), props.leftText && (0, import_vue.createVNode)("span", {
71 "class": bem("text")
72 }, [props.leftText])];
73 };
74 const renderRight = () => {
75 if (slots.right) {
76 return slots.right();
77 }
78 return (0, import_vue.createVNode)("span", {
79 "class": bem("text")
80 }, [props.rightText]);
81 };
82 const renderNavBar = () => {
83 const {
84 title,
85 fixed,
86 border,
87 zIndex
88 } = props;
89 const style = (0, import_utils.getZIndexStyle)(zIndex);
90 const hasLeft = props.leftArrow || props.leftText || slots.left;
91 const hasRight = props.rightText || slots.right;
92 return (0, import_vue.createVNode)("div", {
93 "ref": navBarRef,
94 "style": style,
95 "class": [bem({
96 fixed
97 }), {
98 [import_utils.BORDER_BOTTOM]: border,
99 "van-safe-area-top": props.safeAreaInsetTop
100 }]
101 }, [(0, import_vue.createVNode)("div", {
102 "class": bem("content")
103 }, [hasLeft && (0, import_vue.createVNode)("div", {
104 "class": [bem("left", {
105 disabled: props.leftDisabled
106 }), props.clickable && !props.leftDisabled ? import_utils.HAPTICS_FEEDBACK : ""],
107 "onClick": onClickLeft
108 }, [renderLeft()]), (0, import_vue.createVNode)("div", {
109 "class": [bem("title"), "van-ellipsis"]
110 }, [slots.title ? slots.title() : title]), hasRight && (0, import_vue.createVNode)("div", {
111 "class": [bem("right", {
112 disabled: props.rightDisabled
113 }), props.clickable && !props.rightDisabled ? import_utils.HAPTICS_FEEDBACK : ""],
114 "onClick": onClickRight
115 }, [renderRight()])])]);
116 };
117 return () => {
118 if (props.fixed && props.placeholder) {
119 return renderPlaceholder(renderNavBar);
120 }
121 return renderNavBar();
122 };
123 }
124});