UNPKG

4.58 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 submitBarProps: () => submitBarProps
22});
23module.exports = __toCommonJS(stdin_exports);
24var import_vue = require("vue");
25var import_utils = require("../utils");
26var import_icon = require("../icon");
27var import_button = require("../button");
28var import_use_placeholder = require("../composables/use-placeholder");
29const [name, bem, t] = (0, import_utils.createNamespace)("submit-bar");
30const submitBarProps = {
31 tip: String,
32 label: String,
33 price: Number,
34 tipIcon: String,
35 loading: Boolean,
36 currency: (0, import_utils.makeStringProp)("\xA5"),
37 disabled: Boolean,
38 textAlign: String,
39 buttonText: String,
40 buttonType: (0, import_utils.makeStringProp)("danger"),
41 buttonColor: String,
42 suffixLabel: String,
43 placeholder: Boolean,
44 decimalLength: (0, import_utils.makeNumericProp)(2),
45 safeAreaInsetBottom: import_utils.truthProp
46};
47var stdin_default = (0, import_vue.defineComponent)({
48 name,
49 props: submitBarProps,
50 emits: ["submit"],
51 setup(props, {
52 emit,
53 slots
54 }) {
55 const root = (0, import_vue.ref)();
56 const renderPlaceholder = (0, import_use_placeholder.usePlaceholder)(root, bem);
57 const renderText = () => {
58 const {
59 price,
60 label,
61 currency,
62 textAlign,
63 suffixLabel,
64 decimalLength
65 } = props;
66 if (typeof price === "number") {
67 const pricePair = (price / 100).toFixed(+decimalLength).split(".");
68 const decimal = decimalLength ? `.${pricePair[1]}` : "";
69 return (0, import_vue.createVNode)("div", {
70 "class": bem("text"),
71 "style": {
72 textAlign
73 }
74 }, [(0, import_vue.createVNode)("span", null, [label || t("label")]), (0, import_vue.createVNode)("span", {
75 "class": bem("price")
76 }, [currency, (0, import_vue.createVNode)("span", {
77 "class": bem("price-integer")
78 }, [pricePair[0]]), decimal]), suffixLabel && (0, import_vue.createVNode)("span", {
79 "class": bem("suffix-label")
80 }, [suffixLabel])]);
81 }
82 };
83 const renderTip = () => {
84 var _a;
85 const {
86 tip,
87 tipIcon
88 } = props;
89 if (slots.tip || tip) {
90 return (0, import_vue.createVNode)("div", {
91 "class": bem("tip")
92 }, [tipIcon && (0, import_vue.createVNode)(import_icon.Icon, {
93 "class": bem("tip-icon"),
94 "name": tipIcon
95 }, null), tip && (0, import_vue.createVNode)("span", {
96 "class": bem("tip-text")
97 }, [tip]), (_a = slots.tip) == null ? void 0 : _a.call(slots)]);
98 }
99 };
100 const onClickButton = () => emit("submit");
101 const renderButton = () => {
102 if (slots.button) {
103 return slots.button();
104 }
105 return (0, import_vue.createVNode)(import_button.Button, {
106 "round": true,
107 "type": props.buttonType,
108 "text": props.buttonText,
109 "class": bem("button", props.buttonType),
110 "color": props.buttonColor,
111 "loading": props.loading,
112 "disabled": props.disabled,
113 "onClick": onClickButton
114 }, null);
115 };
116 const renderSubmitBar = () => {
117 var _a, _b;
118 return (0, import_vue.createVNode)("div", {
119 "ref": root,
120 "class": [bem(), {
121 "van-safe-area-bottom": props.safeAreaInsetBottom
122 }]
123 }, [(_a = slots.top) == null ? void 0 : _a.call(slots), renderTip(), (0, import_vue.createVNode)("div", {
124 "class": bem("bar")
125 }, [(_b = slots.default) == null ? void 0 : _b.call(slots), renderText(), renderButton()])]);
126 };
127 return () => {
128 if (props.placeholder) {
129 return renderPlaceholder(renderSubmitBar);
130 }
131 return renderSubmitBar();
132 };
133 }
134});