UNPKG

@shopify/hydrogen-react

Version:

React components, hooks, and utilities for creating custom Shopify storefronts

41 lines (40 loc) 1.47 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const useMoney = require("./useMoney.js"); const jsxRuntime = require("react/jsx-runtime"); function Money({ data, as, withoutCurrency, withoutTrailingZeros, measurement, measurementSeparator = "/", ...passthroughProps }) { if (!isMoney(data)) { throw new Error(`<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`); } const moneyObject = useMoney.useMoney(data); const Wrapper = as != null ? as : "div"; let output = moneyObject.localizedString; if (withoutCurrency || withoutTrailingZeros) { if (withoutCurrency && !withoutTrailingZeros) { output = moneyObject.amount; } else if (!withoutCurrency && withoutTrailingZeros) { output = moneyObject.withoutTrailingZeros; } else { output = moneyObject.withoutTrailingZerosAndCurrency; } } return /* @__PURE__ */ jsxRuntime.jsxs(Wrapper, { ...passthroughProps, children: [output, measurement && measurement.referenceUnit && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [measurementSeparator, measurement.referenceUnit] })] }); } function isMoney(maybeMoney) { return typeof maybeMoney.amount === "string" && !!maybeMoney.amount && typeof maybeMoney.currencyCode === "string" && !!maybeMoney.currencyCode; } exports.Money = Money; //# sourceMappingURL=Money.js.map