@shopify/hydrogen-react 2022.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -0
- package/dist/dev/ExternalVideo.cjs +39 -0
- package/dist/dev/ExternalVideo.cjs.map +1 -0
- package/dist/dev/ExternalVideo.js +39 -0
- package/dist/dev/ExternalVideo.js.map +1 -0
- package/dist/dev/Image.cjs +104 -0
- package/dist/dev/Image.cjs.map +1 -0
- package/dist/dev/Image.js +104 -0
- package/dist/dev/Image.js.map +1 -0
- package/dist/dev/MediaFile.cjs +57 -0
- package/dist/dev/MediaFile.cjs.map +1 -0
- package/dist/dev/MediaFile.js +57 -0
- package/dist/dev/MediaFile.js.map +1 -0
- package/dist/dev/Metafield.cjs +295 -0
- package/dist/dev/Metafield.cjs.map +1 -0
- package/dist/dev/Metafield.js +295 -0
- package/dist/dev/Metafield.js.map +1 -0
- package/dist/dev/ModelViewer.cjs +145 -0
- package/dist/dev/ModelViewer.cjs.map +1 -0
- package/dist/dev/ModelViewer.js +145 -0
- package/dist/dev/ModelViewer.js.map +1 -0
- package/dist/dev/Money.cjs +40 -0
- package/dist/dev/Money.cjs.map +1 -0
- package/dist/dev/Money.js +40 -0
- package/dist/dev/Money.js.map +1 -0
- package/dist/dev/ProductPrice.cjs +61 -0
- package/dist/dev/ProductPrice.cjs.map +1 -0
- package/dist/dev/ProductPrice.js +61 -0
- package/dist/dev/ProductPrice.js.map +1 -0
- package/dist/dev/ProductProvider.cjs +161 -0
- package/dist/dev/ProductProvider.cjs.map +1 -0
- package/dist/dev/ProductProvider.js +161 -0
- package/dist/dev/ProductProvider.js.map +1 -0
- package/dist/dev/ShopPayButton.cjs +64 -0
- package/dist/dev/ShopPayButton.cjs.map +1 -0
- package/dist/dev/ShopPayButton.js +64 -0
- package/dist/dev/ShopPayButton.js.map +1 -0
- package/dist/dev/ShopifyProvider.cjs +46 -0
- package/dist/dev/ShopifyProvider.cjs.map +1 -0
- package/dist/dev/ShopifyProvider.js +46 -0
- package/dist/dev/ShopifyProvider.js.map +1 -0
- package/dist/dev/Video.cjs +44 -0
- package/dist/dev/Video.cjs.map +1 -0
- package/dist/dev/Video.js +44 -0
- package/dist/dev/Video.js.map +1 -0
- package/dist/dev/flatten-connection.cjs +23 -0
- package/dist/dev/flatten-connection.cjs.map +1 -0
- package/dist/dev/flatten-connection.js +23 -0
- package/dist/dev/flatten-connection.js.map +1 -0
- package/dist/dev/image-size.cjs +80 -0
- package/dist/dev/image-size.cjs.map +1 -0
- package/dist/dev/image-size.js +80 -0
- package/dist/dev/image-size.js.map +1 -0
- package/dist/dev/index.cjs +35 -0
- package/dist/dev/index.cjs.map +1 -0
- package/dist/dev/index.js +35 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/dev/load-script.cjs +52 -0
- package/dist/dev/load-script.cjs.map +1 -0
- package/dist/dev/load-script.js +52 -0
- package/dist/dev/load-script.js.map +1 -0
- package/dist/dev/storefront-api-constants.cjs +5 -0
- package/dist/dev/storefront-api-constants.cjs.map +1 -0
- package/dist/dev/storefront-api-constants.js +5 -0
- package/dist/dev/storefront-api-constants.js.map +1 -0
- package/dist/dev/storefront-client.cjs +72 -0
- package/dist/dev/storefront-client.cjs.map +1 -0
- package/dist/dev/storefront-client.js +72 -0
- package/dist/dev/storefront-client.js.map +1 -0
- package/dist/dev/useMoney.cjs +72 -0
- package/dist/dev/useMoney.cjs.map +1 -0
- package/dist/dev/useMoney.js +72 -0
- package/dist/dev/useMoney.js.map +1 -0
- package/dist/prod/ExternalVideo.cjs +39 -0
- package/dist/prod/ExternalVideo.cjs.map +1 -0
- package/dist/prod/ExternalVideo.js +39 -0
- package/dist/prod/ExternalVideo.js.map +1 -0
- package/dist/prod/Image.cjs +99 -0
- package/dist/prod/Image.cjs.map +1 -0
- package/dist/prod/Image.js +99 -0
- package/dist/prod/Image.js.map +1 -0
- package/dist/prod/MediaFile.cjs +59 -0
- package/dist/prod/MediaFile.cjs.map +1 -0
- package/dist/prod/MediaFile.js +59 -0
- package/dist/prod/MediaFile.js.map +1 -0
- package/dist/prod/Metafield.cjs +288 -0
- package/dist/prod/Metafield.cjs.map +1 -0
- package/dist/prod/Metafield.js +288 -0
- package/dist/prod/Metafield.js.map +1 -0
- package/dist/prod/ModelViewer.cjs +143 -0
- package/dist/prod/ModelViewer.cjs.map +1 -0
- package/dist/prod/ModelViewer.js +143 -0
- package/dist/prod/ModelViewer.js.map +1 -0
- package/dist/prod/Money.cjs +40 -0
- package/dist/prod/Money.cjs.map +1 -0
- package/dist/prod/Money.js +40 -0
- package/dist/prod/Money.js.map +1 -0
- package/dist/prod/ProductPrice.cjs +61 -0
- package/dist/prod/ProductPrice.cjs.map +1 -0
- package/dist/prod/ProductPrice.js +61 -0
- package/dist/prod/ProductPrice.js.map +1 -0
- package/dist/prod/ProductProvider.cjs +161 -0
- package/dist/prod/ProductProvider.cjs.map +1 -0
- package/dist/prod/ProductProvider.js +161 -0
- package/dist/prod/ProductProvider.js.map +1 -0
- package/dist/prod/ShopPayButton.cjs +64 -0
- package/dist/prod/ShopPayButton.cjs.map +1 -0
- package/dist/prod/ShopPayButton.js +64 -0
- package/dist/prod/ShopPayButton.js.map +1 -0
- package/dist/prod/ShopifyProvider.cjs +46 -0
- package/dist/prod/ShopifyProvider.cjs.map +1 -0
- package/dist/prod/ShopifyProvider.js +46 -0
- package/dist/prod/ShopifyProvider.js.map +1 -0
- package/dist/prod/Video.cjs +44 -0
- package/dist/prod/Video.cjs.map +1 -0
- package/dist/prod/Video.js +44 -0
- package/dist/prod/Video.js.map +1 -0
- package/dist/prod/flatten-connection.cjs +18 -0
- package/dist/prod/flatten-connection.cjs.map +1 -0
- package/dist/prod/flatten-connection.js +18 -0
- package/dist/prod/flatten-connection.js.map +1 -0
- package/dist/prod/image-size.cjs +80 -0
- package/dist/prod/image-size.cjs.map +1 -0
- package/dist/prod/image-size.js +80 -0
- package/dist/prod/image-size.js.map +1 -0
- package/dist/prod/index.cjs +35 -0
- package/dist/prod/index.cjs.map +1 -0
- package/dist/prod/index.js +35 -0
- package/dist/prod/index.js.map +1 -0
- package/dist/prod/load-script.cjs +52 -0
- package/dist/prod/load-script.cjs.map +1 -0
- package/dist/prod/load-script.js +52 -0
- package/dist/prod/load-script.js.map +1 -0
- package/dist/prod/storefront-api-constants.cjs +5 -0
- package/dist/prod/storefront-api-constants.cjs.map +1 -0
- package/dist/prod/storefront-api-constants.js +5 -0
- package/dist/prod/storefront-api-constants.js.map +1 -0
- package/dist/prod/storefront-client.cjs +57 -0
- package/dist/prod/storefront-client.cjs.map +1 -0
- package/dist/prod/storefront-client.js +57 -0
- package/dist/prod/storefront-client.js.map +1 -0
- package/dist/prod/useMoney.cjs +72 -0
- package/dist/prod/useMoney.cjs.map +1 -0
- package/dist/prod/useMoney.js +72 -0
- package/dist/prod/useMoney.js.map +1 -0
- package/dist/types/ExternalVideo.d.ts +67 -0
- package/dist/types/Image.d.ts +54 -0
- package/dist/types/MediaFile.d.ts +31 -0
- package/dist/types/Metafield.d.ts +58 -0
- package/dist/types/ModelViewer.d.ts +57 -0
- package/dist/types/Money.d.ts +29 -0
- package/dist/types/ProductPrice.d.ts +22 -0
- package/dist/types/ProductProvider.d.ts +74 -0
- package/dist/types/ShopPayButton.d.ts +42 -0
- package/dist/types/ShopifyProvider.d.ts +42 -0
- package/dist/types/Video.d.ts +20 -0
- package/dist/types/flatten-connection.d.ts +17 -0
- package/dist/types/image-size.d.ts +36 -0
- package/dist/types/index.d.cts +15 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/load-script.d.ts +11 -0
- package/dist/types/storefront-api-constants.d.ts +1 -0
- package/dist/types/storefront-api-response.types.d.ts +68 -0
- package/dist/types/storefront-api-types.d.ts +6537 -0
- package/dist/types/storefront-client.d.ts +63 -0
- package/dist/types/useMoney.d.ts +55 -0
- package/dist/umd/hydrogen-react.dev.js +1472 -0
- package/dist/umd/hydrogen-react.dev.js.map +1 -0
- package/dist/umd/hydrogen-react.prod.js +3 -0
- package/dist/umd/hydrogen-react.prod.js.map +1 -0
- package/package.json +106 -0
- package/storefront.schema.json +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const ShopifyProvider = require("./ShopifyProvider.cjs");
|
|
5
|
+
function useMoney(money) {
|
|
6
|
+
const {
|
|
7
|
+
locale
|
|
8
|
+
} = ShopifyProvider.useShop();
|
|
9
|
+
if (!locale) {
|
|
10
|
+
throw new Error(`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`);
|
|
11
|
+
}
|
|
12
|
+
const amount = parseFloat(money.amount);
|
|
13
|
+
const options = react.useMemo(() => ({
|
|
14
|
+
style: "currency",
|
|
15
|
+
currency: money.currencyCode
|
|
16
|
+
}), [money.currencyCode]);
|
|
17
|
+
const defaultFormatter = useLazyFormatter(locale, options);
|
|
18
|
+
const nameFormatter = useLazyFormatter(locale, {
|
|
19
|
+
...options,
|
|
20
|
+
currencyDisplay: "name"
|
|
21
|
+
});
|
|
22
|
+
const narrowSymbolFormatter = useLazyFormatter(locale, {
|
|
23
|
+
...options,
|
|
24
|
+
currencyDisplay: "narrowSymbol"
|
|
25
|
+
});
|
|
26
|
+
const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
|
|
27
|
+
...options,
|
|
28
|
+
minimumFractionDigits: 0,
|
|
29
|
+
maximumFractionDigits: 0
|
|
30
|
+
});
|
|
31
|
+
const withoutCurrencyFormatter = useLazyFormatter(locale);
|
|
32
|
+
const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
|
|
33
|
+
minimumFractionDigits: 0,
|
|
34
|
+
maximumFractionDigits: 0
|
|
35
|
+
});
|
|
36
|
+
const isPartCurrency = (part) => part.type === "currency";
|
|
37
|
+
const lazyFormatters = react.useMemo(() => ({
|
|
38
|
+
original: () => money,
|
|
39
|
+
currencyCode: () => money.currencyCode,
|
|
40
|
+
localizedString: () => defaultFormatter().format(amount),
|
|
41
|
+
parts: () => defaultFormatter().formatToParts(amount),
|
|
42
|
+
withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
|
|
43
|
+
withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
|
|
44
|
+
currencyName: () => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return (_b = (_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
|
|
47
|
+
},
|
|
48
|
+
currencySymbol: () => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return (_b = (_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
|
|
51
|
+
},
|
|
52
|
+
currencyNarrowSymbol: () => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return (_b = (_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : "";
|
|
55
|
+
},
|
|
56
|
+
amount: () => defaultFormatter().formatToParts(amount).filter((part) => ["decimal", "fraction", "group", "integer", "literal"].includes(part.type)).map((part) => part.value).join("")
|
|
57
|
+
}), [money, amount, nameFormatter, defaultFormatter, narrowSymbolFormatter, withoutCurrencyFormatter, withoutTrailingZerosFormatter, withoutTrailingZerosOrCurrencyFormatter]);
|
|
58
|
+
return react.useMemo(() => new Proxy(lazyFormatters, {
|
|
59
|
+
get: (target, key) => {
|
|
60
|
+
var _a;
|
|
61
|
+
return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
|
|
62
|
+
}
|
|
63
|
+
}), [lazyFormatters]);
|
|
64
|
+
}
|
|
65
|
+
function useLazyFormatter(locale, options) {
|
|
66
|
+
return react.useMemo(() => {
|
|
67
|
+
let memoized;
|
|
68
|
+
return () => memoized != null ? memoized : memoized = new Intl.NumberFormat(locale, options);
|
|
69
|
+
}, [locale, options]);
|
|
70
|
+
}
|
|
71
|
+
exports.useMoney = useMoney;
|
|
72
|
+
//# sourceMappingURL=useMoney.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMoney.cjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {locale} = useShop();\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const options = useMemo(\n () => ({\n style: 'currency',\n currency: money.currencyCode,\n }),\n [money.currencyCode]\n );\n\n const defaultFormatter = useLazyFormatter(locale, options);\n\n const nameFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n });\n\n const narrowSymbolFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n });\n\n const withoutTrailingZerosFormatter = useLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const withoutCurrencyFormatter = useLazyFormatter(locale);\n\n const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const isPartCurrency = (part: Intl.NumberFormatPart) =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type\n )\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ]\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters]\n );\n}\n\nfunction useLazyFormatter(locale: string, options?: Intl.NumberFormatOptions) {\n return useMemo(() => {\n let memoized: Intl.NumberFormat;\n return () => (memoized ??= new Intl.NumberFormat(locale, options));\n }, [locale, options]);\n}\n"],"names":["useMoney","money","locale","useShop","Error","amount","parseFloat","options","useMemo","style","currency","currencyCode","defaultFormatter","useLazyFormatter","nameFormatter","currencyDisplay","narrowSymbolFormatter","withoutTrailingZerosFormatter","minimumFractionDigits","maximumFractionDigits","withoutCurrencyFormatter","withoutTrailingZerosOrCurrencyFormatter","isPartCurrency","part","type","lazyFormatters","original","localizedString","format","parts","formatToParts","withoutTrailingZeros","withoutTrailingZerosAndCurrency","currencyName","find","value","currencySymbol","currencyNarrowSymbol","filter","includes","map","join","Proxy","get","target","key","Reflect","call","memoized","Intl","NumberFormat"],"mappings":"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"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useShop } from "./ShopifyProvider.js";
|
|
3
|
+
function useMoney(money) {
|
|
4
|
+
const {
|
|
5
|
+
locale
|
|
6
|
+
} = useShop();
|
|
7
|
+
if (!locale) {
|
|
8
|
+
throw new Error(`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`);
|
|
9
|
+
}
|
|
10
|
+
const amount = parseFloat(money.amount);
|
|
11
|
+
const options = useMemo(() => ({
|
|
12
|
+
style: "currency",
|
|
13
|
+
currency: money.currencyCode
|
|
14
|
+
}), [money.currencyCode]);
|
|
15
|
+
const defaultFormatter = useLazyFormatter(locale, options);
|
|
16
|
+
const nameFormatter = useLazyFormatter(locale, {
|
|
17
|
+
...options,
|
|
18
|
+
currencyDisplay: "name"
|
|
19
|
+
});
|
|
20
|
+
const narrowSymbolFormatter = useLazyFormatter(locale, {
|
|
21
|
+
...options,
|
|
22
|
+
currencyDisplay: "narrowSymbol"
|
|
23
|
+
});
|
|
24
|
+
const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
|
|
25
|
+
...options,
|
|
26
|
+
minimumFractionDigits: 0,
|
|
27
|
+
maximumFractionDigits: 0
|
|
28
|
+
});
|
|
29
|
+
const withoutCurrencyFormatter = useLazyFormatter(locale);
|
|
30
|
+
const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
|
|
31
|
+
minimumFractionDigits: 0,
|
|
32
|
+
maximumFractionDigits: 0
|
|
33
|
+
});
|
|
34
|
+
const isPartCurrency = (part) => part.type === "currency";
|
|
35
|
+
const lazyFormatters = useMemo(() => ({
|
|
36
|
+
original: () => money,
|
|
37
|
+
currencyCode: () => money.currencyCode,
|
|
38
|
+
localizedString: () => defaultFormatter().format(amount),
|
|
39
|
+
parts: () => defaultFormatter().formatToParts(amount),
|
|
40
|
+
withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
|
|
41
|
+
withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
|
|
42
|
+
currencyName: () => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
return (_b = (_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
|
|
45
|
+
},
|
|
46
|
+
currencySymbol: () => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return (_b = (_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
|
|
49
|
+
},
|
|
50
|
+
currencyNarrowSymbol: () => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
return (_b = (_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : "";
|
|
53
|
+
},
|
|
54
|
+
amount: () => defaultFormatter().formatToParts(amount).filter((part) => ["decimal", "fraction", "group", "integer", "literal"].includes(part.type)).map((part) => part.value).join("")
|
|
55
|
+
}), [money, amount, nameFormatter, defaultFormatter, narrowSymbolFormatter, withoutCurrencyFormatter, withoutTrailingZerosFormatter, withoutTrailingZerosOrCurrencyFormatter]);
|
|
56
|
+
return useMemo(() => new Proxy(lazyFormatters, {
|
|
57
|
+
get: (target, key) => {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
|
|
60
|
+
}
|
|
61
|
+
}), [lazyFormatters]);
|
|
62
|
+
}
|
|
63
|
+
function useLazyFormatter(locale, options) {
|
|
64
|
+
return useMemo(() => {
|
|
65
|
+
let memoized;
|
|
66
|
+
return () => memoized != null ? memoized : memoized = new Intl.NumberFormat(locale, options);
|
|
67
|
+
}, [locale, options]);
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
useMoney
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=useMoney.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMoney.js","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {locale} = useShop();\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const options = useMemo(\n () => ({\n style: 'currency',\n currency: money.currencyCode,\n }),\n [money.currencyCode]\n );\n\n const defaultFormatter = useLazyFormatter(locale, options);\n\n const nameFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n });\n\n const narrowSymbolFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n });\n\n const withoutTrailingZerosFormatter = useLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const withoutCurrencyFormatter = useLazyFormatter(locale);\n\n const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const isPartCurrency = (part: Intl.NumberFormatPart) =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type\n )\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ]\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters]\n );\n}\n\nfunction useLazyFormatter(locale: string, options?: Intl.NumberFormatOptions) {\n return useMemo(() => {\n let memoized: Intl.NumberFormat;\n return () => (memoized ??= new Intl.NumberFormat(locale, options));\n }, [locale, options]);\n}\n"],"names":["useMoney","money","locale","useShop","Error","amount","parseFloat","options","useMemo","style","currency","currencyCode","defaultFormatter","useLazyFormatter","nameFormatter","currencyDisplay","narrowSymbolFormatter","withoutTrailingZerosFormatter","minimumFractionDigits","maximumFractionDigits","withoutCurrencyFormatter","withoutTrailingZerosOrCurrencyFormatter","isPartCurrency","part","type","lazyFormatters","original","localizedString","format","parts","formatToParts","withoutTrailingZeros","withoutTrailingZerosAndCurrency","currencyName","find","value","currencySymbol","currencyNarrowSymbol","filter","includes","map","join","Proxy","get","target","key","Reflect","call","memoized","Intl","NumberFormat"],"mappings":"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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ExternalVideo as ExternalVideoType } from './storefront-api-types.js';
|
|
2
|
+
import type { PartialDeep } from 'type-fest';
|
|
3
|
+
interface BaseProps {
|
|
4
|
+
/**
|
|
5
|
+
* An object with fields that correspond to the Storefront API's [ExternalVideo object](https://shopify.dev/api/storefront/reference/products/externalvideo).
|
|
6
|
+
*/
|
|
7
|
+
data: PartialDeep<ExternalVideoType, {
|
|
8
|
+
recurseIntoArrays: true;
|
|
9
|
+
}>;
|
|
10
|
+
/** An object containing the options available for either
|
|
11
|
+
* [YouTube](https://developers.google.com/youtube/player_parameters#Parameters) or
|
|
12
|
+
* [Vimeo](https://vimeo.zendesk.com/hc/en-us/articles/360001494447-Using-Player-Parameters).
|
|
13
|
+
*/
|
|
14
|
+
options?: YouTube | Vimeo;
|
|
15
|
+
}
|
|
16
|
+
declare type PropsWeControl = 'src';
|
|
17
|
+
export declare type ExternalVideoProps = Omit<JSX.IntrinsicElements['iframe'], PropsWeControl> & BaseProps;
|
|
18
|
+
/**
|
|
19
|
+
* The `ExternalVideo` component renders an embedded video for the Storefront
|
|
20
|
+
* API's [ExternalVideo object](https://shopify.dev/api/storefront/reference/products/externalvideo).
|
|
21
|
+
*/
|
|
22
|
+
export declare function ExternalVideo(props: ExternalVideoProps): JSX.Element;
|
|
23
|
+
interface YouTube {
|
|
24
|
+
autoplay?: 0 | 1;
|
|
25
|
+
cc_lang_pref?: string;
|
|
26
|
+
cc_load_policy?: 1;
|
|
27
|
+
color?: 'red' | 'white';
|
|
28
|
+
controls?: 0 | 1;
|
|
29
|
+
disablekb?: 0 | 1;
|
|
30
|
+
enablejsapi?: 0 | 1;
|
|
31
|
+
end?: number;
|
|
32
|
+
fs?: 0 | 1;
|
|
33
|
+
hl?: string;
|
|
34
|
+
iv_load_policy?: 1 | 3;
|
|
35
|
+
list?: string;
|
|
36
|
+
list_type?: 'playlist' | 'user_uploads';
|
|
37
|
+
loop?: 0 | 1;
|
|
38
|
+
modest_branding?: 1;
|
|
39
|
+
origin?: string;
|
|
40
|
+
playlist?: string;
|
|
41
|
+
plays_inline?: 0 | 1;
|
|
42
|
+
rel?: 0 | 1;
|
|
43
|
+
start?: number;
|
|
44
|
+
widget_referrer?: string;
|
|
45
|
+
}
|
|
46
|
+
declare type VimeoBoolean = 0 | 1 | boolean;
|
|
47
|
+
interface Vimeo {
|
|
48
|
+
autopause?: VimeoBoolean;
|
|
49
|
+
autoplay?: VimeoBoolean;
|
|
50
|
+
background?: VimeoBoolean;
|
|
51
|
+
byline?: VimeoBoolean;
|
|
52
|
+
color?: string;
|
|
53
|
+
controls?: VimeoBoolean;
|
|
54
|
+
dnt?: VimeoBoolean;
|
|
55
|
+
loop?: VimeoBoolean;
|
|
56
|
+
muted?: VimeoBoolean;
|
|
57
|
+
pip?: VimeoBoolean;
|
|
58
|
+
playsinline?: VimeoBoolean;
|
|
59
|
+
portrait?: VimeoBoolean;
|
|
60
|
+
quality?: '240p' | '360p' | '540p' | '720p' | '1080p' | '2k' | '4k';
|
|
61
|
+
speed?: VimeoBoolean;
|
|
62
|
+
'#t'?: string;
|
|
63
|
+
texttrack?: string;
|
|
64
|
+
title?: VimeoBoolean;
|
|
65
|
+
transparent?: VimeoBoolean;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Image as ImageType } from './storefront-api-types.js';
|
|
3
|
+
import type { PartialDeep, Simplify } from 'type-fest';
|
|
4
|
+
declare type HtmlImageProps = React.ImgHTMLAttributes<HTMLImageElement>;
|
|
5
|
+
export declare type ShopifyLoaderOptions = {
|
|
6
|
+
crop?: 'top' | 'bottom' | 'left' | 'right' | 'center';
|
|
7
|
+
scale?: 2 | 3;
|
|
8
|
+
width?: HtmlImageProps['width'] | ImageType['width'];
|
|
9
|
+
height?: HtmlImageProps['height'] | ImageType['height'];
|
|
10
|
+
};
|
|
11
|
+
export declare type ShopifyLoaderParams = Simplify<ShopifyLoaderOptions & {
|
|
12
|
+
src: ImageType['url'];
|
|
13
|
+
}>;
|
|
14
|
+
export declare type ShopifyImageProps = Omit<HtmlImageProps, 'src'> & {
|
|
15
|
+
/** An object with fields that correspond to the Storefront API's
|
|
16
|
+
* [Image object](https://shopify.dev/api/storefront/reference/common-objects/image).
|
|
17
|
+
* The `data` prop is required.
|
|
18
|
+
*/
|
|
19
|
+
data: PartialDeep<ImageType, {
|
|
20
|
+
recurseIntoArrays: true;
|
|
21
|
+
}>;
|
|
22
|
+
/** A custom function that generates the image URL. Parameters passed in
|
|
23
|
+
* are `ShopifyLoaderParams`
|
|
24
|
+
*/
|
|
25
|
+
loader?: (params: ShopifyLoaderParams) => string;
|
|
26
|
+
/** An object of `loader` function options. For example, if the `loader` function
|
|
27
|
+
* requires a `scale` option, then the value can be a property of the
|
|
28
|
+
* `loaderOptions` object (for example, `{scale: 2}`). The object shape is `ShopifyLoaderOptions`.
|
|
29
|
+
*/
|
|
30
|
+
loaderOptions?: ShopifyLoaderOptions;
|
|
31
|
+
/**
|
|
32
|
+
* `src` isn't used, and should instead be passed as part of the `data` object
|
|
33
|
+
*/
|
|
34
|
+
src?: never;
|
|
35
|
+
/**
|
|
36
|
+
* An array of pixel widths to overwrite the default generated srcset. For example, `[300, 600, 800]`.
|
|
37
|
+
*/
|
|
38
|
+
widths?: (HtmlImageProps['width'] | ImageType['width'])[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The `Image` component renders an image for the Storefront API's
|
|
42
|
+
* [Image object](https://shopify.dev/api/storefront/reference/common-objects/image) by using the `data` prop. You can [customize this component](https://shopify.dev/api/hydrogen/components#customizing-hydrogen-components) using passthrough props.
|
|
43
|
+
*
|
|
44
|
+
* An image's width and height are determined using the following priority list:
|
|
45
|
+
* 1. The width and height values for the `loaderOptions` prop
|
|
46
|
+
* 2. The width and height values for bare props
|
|
47
|
+
* 3. The width and height values for the `data` prop
|
|
48
|
+
*
|
|
49
|
+
* If only one of `width` or `height` are defined, then the other will attempt to be calculated based on the image's aspect ratio,
|
|
50
|
+
* provided that both `data.width` and `data.height` are available. If `data.width` and `data.height` aren't available, then the aspect ratio cannot be determined and the missing
|
|
51
|
+
* value will remain as `null`
|
|
52
|
+
*/
|
|
53
|
+
export declare function Image({ data, width, height, loading, loader, loaderOptions, widths, decoding, ...rest }: ShopifyImageProps): JSX.Element | null;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ShopifyImageProps } from './Image.js';
|
|
3
|
+
import { Video } from './Video.js';
|
|
4
|
+
import { ExternalVideo } from './ExternalVideo.js';
|
|
5
|
+
import { ModelViewer } from './ModelViewer.js';
|
|
6
|
+
import type { MediaEdge as MediaEdgeType } from './storefront-api-types.js';
|
|
7
|
+
import type { PartialDeep } from 'type-fest';
|
|
8
|
+
interface MediaFileProps {
|
|
9
|
+
/** An object with fields that correspond to the Storefront API's [Media object](https://shopify.dev/api/storefront/reference/products/media). */
|
|
10
|
+
data: PartialDeep<MediaEdgeType['node'], {
|
|
11
|
+
recurseIntoArrays: true;
|
|
12
|
+
}>;
|
|
13
|
+
/** The options for the `Image`, `Video`, or `ExternalVideo` components. */
|
|
14
|
+
mediaOptions?: {
|
|
15
|
+
/** Props that will only apply when an `<Image />` is rendered */
|
|
16
|
+
image: Omit<ShopifyImageProps, 'data'>;
|
|
17
|
+
/** Props that will only apply when a `<Video />` is rendered */
|
|
18
|
+
video: Omit<React.ComponentProps<typeof Video>, 'data'>;
|
|
19
|
+
/** Props that will only apply when an `<ExternalVideo />` is rendered */
|
|
20
|
+
externalVideo: Omit<React.ComponentProps<typeof ExternalVideo>['options'], 'data'>;
|
|
21
|
+
/** Props that will only apply when a `<ModelViewer />` is rendered */
|
|
22
|
+
modelViewer: Omit<typeof ModelViewer, 'data'>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `MediaFile` component renders the media for the Storefront API's
|
|
27
|
+
* [Media object](https://shopify.dev/api/storefront/reference/products/media). It renders an `Image`, a
|
|
28
|
+
* `Video`, an `ExternalVideo`, or a `ModelViewer` depending on the `__typename` of the `data` prop.
|
|
29
|
+
*/
|
|
30
|
+
export declare function MediaFile({ data, mediaOptions, ...passthroughProps }: MediaFileProps): JSX.Element | null;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type ElementType, type ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
import type { Metafield as MetafieldType } from './storefront-api-types.js';
|
|
3
|
+
import type { PartialDeep, JsonValue } from 'type-fest';
|
|
4
|
+
interface BaseProps<ComponentGeneric extends ElementType> {
|
|
5
|
+
/** An object with fields that correspond to the Storefront API's [Metafield object](https://shopify.dev/api/storefront/reference/common-objects/metafield). */
|
|
6
|
+
data: PartialDeep<MetafieldType, {
|
|
7
|
+
recurseIntoArrays: true;
|
|
8
|
+
}> | null;
|
|
9
|
+
/** An HTML tag or React component to be rendered as the base element wrapper. The default value varies depending on [metafield.type](https://shopify.dev/apps/metafields/types). */
|
|
10
|
+
as?: ComponentGeneric;
|
|
11
|
+
}
|
|
12
|
+
export declare type MetafieldProps<ComponentGeneric extends ElementType> = ComponentPropsWithoutRef<ComponentGeneric> & BaseProps<ComponentGeneric>;
|
|
13
|
+
/**
|
|
14
|
+
* The `Metafield` component renders the value of a Storefront
|
|
15
|
+
* API's [Metafield object](https://shopify.dev/api/storefront/reference/common-objects/metafield).
|
|
16
|
+
* Relies on the `locale` property of the `useShop()` hook, so it must be a desendent of `<ShopifyProvider/>`
|
|
17
|
+
*
|
|
18
|
+
* Renders a smart default of the Metafield's `value`. For more information, refer to the [Default output](#default-output) section.
|
|
19
|
+
*/
|
|
20
|
+
export declare function Metafield<ComponentGeneric extends ElementType>(props: MetafieldProps<ComponentGeneric>): JSX.Element | null;
|
|
21
|
+
/**
|
|
22
|
+
* The `parseMetafield` utility transforms a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/Metafield)
|
|
23
|
+
* into a new object whose `values` have been parsed according to the metafield `type`.
|
|
24
|
+
* If the metafield is `null`, then it returns `null` back.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseMetafield(
|
|
27
|
+
/** A [Metafield](https://shopify.dev/api/storefront/reference/common-objects/Metafield) or null */
|
|
28
|
+
metafield: PartialDeep<MetafieldType, {
|
|
29
|
+
recurseIntoArrays: true;
|
|
30
|
+
}> | null): PartialDeep<ParsedMetafield, {
|
|
31
|
+
recurseIntoArrays: true;
|
|
32
|
+
}> | null;
|
|
33
|
+
/**
|
|
34
|
+
* The `parseMetafieldValue` function parses a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `type`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseMetafieldValue(metafield: PartialDeep<MetafieldType, {
|
|
37
|
+
recurseIntoArrays: true;
|
|
38
|
+
}> | null): ParsedMetafield['value'];
|
|
39
|
+
/**
|
|
40
|
+
* Parses a JSON string while preventing prototype injection attacks.
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseJSON(json: string): any;
|
|
43
|
+
export declare function getMeasurementAsString(measurement: Measurement, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
44
|
+
declare type ParsedMetafield = Omit<PartialDeep<MetafieldType, {
|
|
45
|
+
recurseIntoArrays: true;
|
|
46
|
+
}>, 'value'> & {
|
|
47
|
+
value?: string | number | boolean | JsonValue | Date | Rating | Measurement;
|
|
48
|
+
};
|
|
49
|
+
export interface Rating {
|
|
50
|
+
value: number;
|
|
51
|
+
scale_min: number;
|
|
52
|
+
scale_max: number;
|
|
53
|
+
}
|
|
54
|
+
interface Measurement {
|
|
55
|
+
unit: string;
|
|
56
|
+
value: number;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Model3d } from './storefront-api-types.js';
|
|
2
|
+
import type { PartialDeep } from 'type-fest';
|
|
3
|
+
import type { ModelViewerElement } from '@google/model-viewer/lib/model-viewer.js';
|
|
4
|
+
declare type PropsWeControl = 'src';
|
|
5
|
+
declare global {
|
|
6
|
+
namespace JSX {
|
|
7
|
+
interface IntrinsicElements {
|
|
8
|
+
'model-viewer': PartialDeep<ModelViewerElement, {
|
|
9
|
+
recurseIntoArrays: true;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare type ModelViewerProps = Omit<PartialDeep<JSX.IntrinsicElements['model-viewer'], {
|
|
15
|
+
recurseIntoArrays: true;
|
|
16
|
+
}>, PropsWeControl> & {
|
|
17
|
+
/** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/latest/objects/model3d). */
|
|
18
|
+
data: PartialDeep<Model3d, {
|
|
19
|
+
recurseIntoArrays: true;
|
|
20
|
+
}>;
|
|
21
|
+
/** The callback to invoke when the 'error' event is triggered. Refer to [error in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-error). */
|
|
22
|
+
onError?: (event: Event) => void;
|
|
23
|
+
/** The callback to invoke when the `load` event is triggered. Refer to [load in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-load). */
|
|
24
|
+
onLoad?: (event: Event) => void;
|
|
25
|
+
/** The callback to invoke when the 'preload' event is triggered. Refer to [preload in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-preload). */
|
|
26
|
+
onPreload?: (event: Event) => void;
|
|
27
|
+
/** The callback to invoke when the 'model-visibility' event is triggered. Refer to [model-visibility in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-modelVisibility). */
|
|
28
|
+
onModelVisibility?: (event: Event) => void;
|
|
29
|
+
/** The callback to invoke when the 'progress' event is triggered. Refer to [progress in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-progress). */
|
|
30
|
+
onProgress?: (event: Event) => void;
|
|
31
|
+
/** The callback to invoke when the 'ar-status' event is triggered. Refer to [ar-status in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arStatus). */
|
|
32
|
+
onArStatus?: (event: Event) => void;
|
|
33
|
+
/** The callback to invoke when the 'ar-tracking' event is triggered. Refer to [ar-tracking in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arTracking). */
|
|
34
|
+
onArTracking?: (event: Event) => void;
|
|
35
|
+
/** The callback to invoke when the 'quick-look-button-tapped' event is triggered. Refer to [quick-look-button-tapped in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-quickLookButtonTapped). */
|
|
36
|
+
onQuickLookButtonTapped?: (event: Event) => void;
|
|
37
|
+
/** The callback to invoke when the 'camera-change' event is triggered. Refer to [camera-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-events-cameraChange). */
|
|
38
|
+
onCameraChange?: (event: Event) => void;
|
|
39
|
+
/** The callback to invoke when the 'environment-change' event is triggered. Refer to [environment-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-lightingandenv-events-environmentChange). */
|
|
40
|
+
onEnvironmentChange?: (event: Event) => void;
|
|
41
|
+
/** The callback to invoke when the 'play' event is triggered. Refer to [play in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-play). */
|
|
42
|
+
onPlay?: (event: Event) => void;
|
|
43
|
+
/** The callback to invoke when the 'pause' event is triggered. Refer to [pause in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-pause). */
|
|
44
|
+
onPause?: (event: Event) => void;
|
|
45
|
+
/** The callback to invoke when the 'scene-graph-ready' event is triggered. Refer to [scene-graph-ready in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-scenegraph-events-sceneGraphReady). */
|
|
46
|
+
onSceneGraphReady?: (event: Event) => void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The `ModelViewer` component renders a 3D model (with the `model-viewer` custom element) for
|
|
50
|
+
* the Storefront API's [Model3d object](https://shopify.dev/api/storefront/reference/products/model3d).
|
|
51
|
+
*
|
|
52
|
+
* The `model-viewer` custom element is lazily downloaded through a dynamically-injected `<script type="module">` tag when the `<ModelViewer />` component is rendered
|
|
53
|
+
*
|
|
54
|
+
* ModelViewer is using version `1.21.1` of the `@google/model-viewer` library.
|
|
55
|
+
*/
|
|
56
|
+
export declare function ModelViewer(props: ModelViewerProps): JSX.Element | null;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import type { MoneyV2, UnitPriceMeasurement } from './storefront-api-types.js';
|
|
3
|
+
import type { PartialDeep } from 'type-fest';
|
|
4
|
+
interface CustomProps<ComponentGeneric extends React.ElementType> {
|
|
5
|
+
/** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */
|
|
6
|
+
as?: ComponentGeneric;
|
|
7
|
+
/** An object with fields that correspond to the Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2). */
|
|
8
|
+
data: PartialDeep<MoneyV2, {
|
|
9
|
+
recurseIntoArrays: true;
|
|
10
|
+
}>;
|
|
11
|
+
/** Whether to remove the currency symbol from the output. */
|
|
12
|
+
withoutCurrency?: boolean;
|
|
13
|
+
/** Whether to remove trailing zeros (fractional money) from the output. */
|
|
14
|
+
withoutTrailingZeros?: boolean;
|
|
15
|
+
/** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/latest/objects/unitpricemeasurement). */
|
|
16
|
+
measurement?: PartialDeep<UnitPriceMeasurement, {
|
|
17
|
+
recurseIntoArrays: true;
|
|
18
|
+
}>;
|
|
19
|
+
/** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */
|
|
20
|
+
measurementSeparator?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export declare type MoneyProps<ComponentGeneric extends React.ElementType> = CustomProps<ComponentGeneric> & Omit<React.ComponentPropsWithoutRef<ComponentGeneric>, keyof CustomProps<ComponentGeneric>>;
|
|
23
|
+
/**
|
|
24
|
+
* The `Money` component renders a string of the Storefront API's
|
|
25
|
+
* [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) according to the
|
|
26
|
+
* `locale` in the `ShopifyProvider` component.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Money<ComponentGeneric extends React.ElementType>({ data, as, withoutCurrency, withoutTrailingZeros, measurement, measurementSeparator, ...passthroughProps }: MoneyProps<ComponentGeneric>): JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Product } from './storefront-api-types.js';
|
|
3
|
+
import { type MoneyProps } from './Money.js';
|
|
4
|
+
import type { PartialDeep } from 'type-fest';
|
|
5
|
+
interface ProductPriceProps {
|
|
6
|
+
/** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
7
|
+
data: PartialDeep<Product, {
|
|
8
|
+
recurseIntoArrays: true;
|
|
9
|
+
}>;
|
|
10
|
+
/** The type of price. Valid values: `regular` (default) or `compareAt`. */
|
|
11
|
+
priceType?: 'regular' | 'compareAt';
|
|
12
|
+
/** The type of value. Valid values: `min` (default), `max` or `unit`. */
|
|
13
|
+
valueType?: 'max' | 'min' | 'unit';
|
|
14
|
+
/** The ID of the variant. */
|
|
15
|
+
variantId?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The `ProductPrice` component renders a `Money` component with the product
|
|
19
|
+
* [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ProductPrice<ComponentGeneric extends React.ElementType>(props: ProductPriceProps & Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>): JSX.Element | null;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { SelectedOption as SelectedOptionType, Product, ProductVariant as ProductVariantType, ProductVariantConnection, SellingPlan as SellingPlanType, SellingPlanAllocation as SellingPlanAllocationType, SellingPlanGroup as SellingPlanGroupType, SellingPlanGroupConnection } from './storefront-api-types.js';
|
|
2
|
+
import type { PartialDeep } from 'type-fest';
|
|
3
|
+
declare type InitialVariantId = ProductVariantType['id'] | null;
|
|
4
|
+
interface ProductProviderProps {
|
|
5
|
+
/** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
6
|
+
data: PartialDeep<Product, {
|
|
7
|
+
recurseIntoArrays: true;
|
|
8
|
+
}>;
|
|
9
|
+
/** A `ReactNode` element. */
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* The initially selected variant.
|
|
13
|
+
* The following logic applies to `initialVariantId`:
|
|
14
|
+
* 1. If `initialVariantId` is provided, then it's used even if it's out of stock.
|
|
15
|
+
* 2. If `initialVariantId` is provided but is `null`, then no variant is used.
|
|
16
|
+
* 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.
|
|
17
|
+
* 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.
|
|
18
|
+
*/
|
|
19
|
+
initialVariantId?: InitialVariantId;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `<ProductProvider />` is a context provider that enables use of the `useProduct()` hook.
|
|
23
|
+
*
|
|
24
|
+
* It helps manage selected options and variants for a product.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ProductProvider({ children, data: product, initialVariantId: explicitVariantId, }: ProductProviderProps): JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* Provides access to the context value provided by `<ProductProvider />`. Must be a descendent of `<ProductProvider />`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useProduct(): ProductHookValue;
|
|
31
|
+
export interface OptionWithValues {
|
|
32
|
+
name: SelectedOptionType['name'];
|
|
33
|
+
values: SelectedOptionType['value'][];
|
|
34
|
+
}
|
|
35
|
+
declare type ProductHookValue = PartialDeep<{
|
|
36
|
+
/** An array of the variant `nodes` from the `VariantConnection`. */
|
|
37
|
+
variants: ProductVariantType[];
|
|
38
|
+
variantsConnection?: ProductVariantConnection;
|
|
39
|
+
/** An array of the product's options and values. */
|
|
40
|
+
options: OptionWithValues[];
|
|
41
|
+
/** The selected variant. */
|
|
42
|
+
selectedVariant?: ProductVariantType | null;
|
|
43
|
+
selectedOptions: SelectedOptions;
|
|
44
|
+
/** The selected selling plan. */
|
|
45
|
+
selectedSellingPlan?: SellingPlanType;
|
|
46
|
+
/** The selected selling plan allocation. */
|
|
47
|
+
selectedSellingPlanAllocation?: SellingPlanAllocationType;
|
|
48
|
+
/** The selling plan groups. */
|
|
49
|
+
sellingPlanGroups?: (Omit<SellingPlanGroupType, 'sellingPlans'> & {
|
|
50
|
+
sellingPlans: SellingPlanType[];
|
|
51
|
+
})[];
|
|
52
|
+
sellingPlanGroupsConnection?: SellingPlanGroupConnection;
|
|
53
|
+
}, {
|
|
54
|
+
recurseIntoArrays: true;
|
|
55
|
+
}> & {
|
|
56
|
+
/** A callback to set the selected variant to the variant passed as an argument. */
|
|
57
|
+
setSelectedVariant: (variant: PartialDeep<ProductVariantType, {
|
|
58
|
+
recurseIntoArrays: true;
|
|
59
|
+
}> | null) => void;
|
|
60
|
+
/** A callback to set the selected option. */
|
|
61
|
+
setSelectedOption: (name: SelectedOptionType['name'], value: SelectedOptionType['value']) => void;
|
|
62
|
+
/** A callback to set multiple selected options at once. */
|
|
63
|
+
setSelectedOptions: (options: SelectedOptions) => void;
|
|
64
|
+
/** A callback to set the selected selling plan to the one passed as an argument. */
|
|
65
|
+
setSelectedSellingPlan: (sellingPlan: PartialDeep<SellingPlanType, {
|
|
66
|
+
recurseIntoArrays: true;
|
|
67
|
+
}>) => void;
|
|
68
|
+
/** A callback that returns a boolean indicating if the option is in stock. */
|
|
69
|
+
isOptionInStock: (name: SelectedOptionType['name'], value: SelectedOptionType['value']) => boolean;
|
|
70
|
+
};
|
|
71
|
+
export declare type SelectedOptions = {
|
|
72
|
+
[key: string]: string;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare type ShopPayButtonProps = {
|
|
2
|
+
/** A string of classes to apply to the `div` that wraps the Shop Pay button. */
|
|
3
|
+
className?: string;
|
|
4
|
+
/** A string that's applied to the [CSS custom property (variable)](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) `--shop-pay-button-width` for the [Buy with Shop Pay component](https://shopify.dev/custom-storefronts/tools/web-components#buy-with-shop-pay-component). */
|
|
5
|
+
width?: string;
|
|
6
|
+
} & ({
|
|
7
|
+
/** An array of IDs of the variants to purchase with Shop Pay. This will only ever have a quantity of 1 for each variant. If you want to use other quantities, then use 'variantIdsAndQuantities'. */
|
|
8
|
+
variantIds: string[];
|
|
9
|
+
/** An array of variant IDs and quantities to purchase with Shop Pay. */
|
|
10
|
+
variantIdsAndQuantities?: never;
|
|
11
|
+
} | {
|
|
12
|
+
/** An array of IDs of the variants to purchase with Shop Pay. This will only ever have a quantity of 1 for each variant. If you want to use other quantities, then use 'variantIdsAndQuantities'. */
|
|
13
|
+
variantIds?: never;
|
|
14
|
+
/** An array of variant IDs and quantities to purchase with Shop Pay. */
|
|
15
|
+
variantIdsAndQuantities: Array<{
|
|
16
|
+
id: string;
|
|
17
|
+
quantity: number;
|
|
18
|
+
}>;
|
|
19
|
+
});
|
|
20
|
+
declare global {
|
|
21
|
+
namespace JSX {
|
|
22
|
+
interface IntrinsicElements {
|
|
23
|
+
'shop-pay-button': {
|
|
24
|
+
variants: string;
|
|
25
|
+
'store-url': string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The `ShopPayButton` component renders a button that redirects to the Shop Pay checkout.
|
|
32
|
+
* It renders a [`<shop-pay-button>`](https://shopify.dev/custom-storefronts/tools/web-components) custom element, for which it will lazy-load the source code automatically.
|
|
33
|
+
* It relies on the `<ShopProvider>` context provider.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ShopPayButton({ variantIds, className, variantIdsAndQuantities, width, }: ShopPayButtonProps): JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* Takes a string in the format of "gid://shopify/ProductVariant/41007289630776" and returns a string of the ID part at the end: "41007289630776"
|
|
38
|
+
*/
|
|
39
|
+
export declare function getIdFromGid(id?: string): string | undefined;
|
|
40
|
+
export declare const MissingPropsErrorMessage = "You must pass in either \"variantIds\" or \"variantIdsAndQuantities\" to ShopPayButton";
|
|
41
|
+
export declare const DoublePropsErrorMessage = "You must provide either a variantIds or variantIdsAndQuantities prop, but not both in the ShopPayButton component";
|
|
42
|
+
export {};
|