UNPKG

@react-vant-next/campaign

Version:

React Mobile UI Components based on Vant UI - Next Generation

79 lines (74 loc) 4.12 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var ui = require('@react-vant-next/ui'); var utils = require('@react-vant-next/utils'); var cls = require('clsx'); function isStringOrNumber(target) { return typeof target === "string" || typeof target === "number"; } const [bem] = utils.createNamespace("product-card"); const ProductCard = (p) => { const props = utils.mergeProps(p, { currency: "¥", decimal: true, }); const renderTitle = () => { if (props.title) { return (jsxRuntime.jsx("div", { className: cls(bem("title"), "rv-multi-ellipsis--l2"), children: props.title })); } return null; }; const renderThumbTag = () => { if (props.tag) { return (jsxRuntime.jsx("div", { className: cls(bem("tag")), children: isStringOrNumber(props.tag) ? (jsxRuntime.jsx(ui.Tag, { mark: true, type: "danger", children: props.tag })) : (props.tag) })); } return null; }; const renderThumbImage = () => { if (!props.thumb) return null; if (typeof props.thumb === "string") { return (jsxRuntime.jsx(ui.Image, { src: props.thumb, fit: "cover", width: "100%", height: "100%", lazyload: props.lazyload })); } return props.thumb; }; const renderThumb = () => { if (props.thumb) { return (jsxRuntime.jsxs("a", { href: props.thumbLink, className: cls(bem("thumb")), onClick: props.onClickThumb, children: [renderThumbImage(), renderThumbTag()] })); } return null; }; const renderDesc = () => { if (props.desc) { return jsxRuntime.jsx("div", { className: cls(bem("desc"), "rv-ellipsis"), children: props.desc }); } return null; }; const renderPriceText = () => { if (isStringOrNumber(props.price)) { const priceArr = props.price.toString().split("."); return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("span", { className: cls(bem("price-currency")), children: props.currency }), jsxRuntime.jsx("span", { className: cls(bem("price-integer")), children: priceArr[0] }), props.decimal && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [".", jsxRuntime.jsx("span", { className: cls(bem("price-decimal")), children: priceArr[1] || "00" })] }))] })); } return props.price; }; const renderOriginalPrice = () => { return (jsxRuntime.jsx("div", { className: cls(bem("origin-price")), children: isStringOrNumber(props.originPrice) ? `${props.currency} ${props.originPrice}` : props.originPrice })); }; const showNum = utils.isDef(props.num); const showPrice = utils.isDef(props.price); const showOriginPrice = utils.isDef(props.originPrice); const showBottom = showNum || showPrice || showOriginPrice || props.bottom; const Price = showPrice && (jsxRuntime.jsx("div", { className: cls(bem("price")), children: renderPriceText() })); const OriginPrice = showOriginPrice && renderOriginalPrice(); const Num = showNum && (jsxRuntime.jsx("div", { className: cls(bem("num")), children: isStringOrNumber(props.num) ? `x${props.num}` : props.num })); const Footer = props.footer && (jsxRuntime.jsx("div", { className: cls(bem("footer")), children: props.footer })); const Bottom = showBottom && (jsxRuntime.jsxs("div", { className: cls(bem("bottom")), children: [props.priceTop, Price, OriginPrice, Num, props.bottom] })); return (jsxRuntime.jsxs("div", { className: cls(bem(), props.className), style: props.style, onClick: props.onClick, children: [jsxRuntime.jsxs("div", { className: cls(bem("header")), children: [renderThumb(), jsxRuntime.jsxs("div", { className: cls(bem("content", { centered: props.centered })), children: [jsxRuntime.jsxs("div", { children: [renderTitle(), renderDesc(), props.tags] }), Bottom] })] }), Footer] })); }; exports.default = ProductCard; //# sourceMappingURL=ProductCard.js.map