@shopify/hydrogen-react 0.0.0-next-81b4528 → 0.0.0-next-182fb2f

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.
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const react = require("react");
4
+ const CartProvider = require("./CartProvider.js");
5
+ const ProductProvider = require("./ProductProvider.js");
6
+ const jsxRuntime = require("react/jsx-runtime");
7
+ function AddToCartButton(props) {
8
+ var _a;
9
+ const [addingItem, setAddingItem] = react.useState(false);
10
+ const {
11
+ variantId: explicitVariantId,
12
+ quantity = 1,
13
+ attributes,
14
+ sellingPlanId,
15
+ onClick,
16
+ children,
17
+ accessibleAddingToCartLabel,
18
+ ...passthroughProps
19
+ } = props;
20
+ const {
21
+ status,
22
+ linesAdd
23
+ } = CartProvider.useCart();
24
+ const {
25
+ selectedVariant
26
+ } = ProductProvider.useProduct();
27
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
28
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
29
+ react.useEffect(() => {
30
+ if (addingItem && status === "idle") {
31
+ setAddingItem(false);
32
+ }
33
+ }, [status, addingItem]);
34
+ const handleAddItem = react.useCallback(() => {
35
+ setAddingItem(true);
36
+ linesAdd([{
37
+ quantity,
38
+ merchandiseId: variantId || "",
39
+ attributes,
40
+ sellingPlanId
41
+ }]);
42
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
43
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
44
+ children: [/* @__PURE__ */ jsxRuntime.jsx(BaseButton, {
45
+ ...passthroughProps,
46
+ disabled,
47
+ onClick,
48
+ defaultOnClick: handleAddItem,
49
+ children
50
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsxRuntime.jsx("p", {
51
+ style: {
52
+ position: "absolute",
53
+ width: "1px",
54
+ height: "1px",
55
+ padding: "0",
56
+ margin: "-1px",
57
+ overflow: "hidden",
58
+ clip: "rect(0, 0, 0, 0)",
59
+ whiteSpace: "nowrap",
60
+ borderWidth: "0"
61
+ },
62
+ role: "alert",
63
+ "aria-live": "assertive",
64
+ children: addingItem ? accessibleAddingToCartLabel : null
65
+ }) : null]
66
+ });
67
+ }
68
+ function BaseButton(props) {
69
+ const {
70
+ as,
71
+ onClick,
72
+ defaultOnClick,
73
+ children,
74
+ buttonRef,
75
+ ...passthroughProps
76
+ } = props;
77
+ const handleOnClick = react.useCallback((event) => {
78
+ if (onClick) {
79
+ const clickShouldContinue = onClick(event);
80
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
81
+ return;
82
+ }
83
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
84
+ }, [defaultOnClick, onClick]);
85
+ const Component = as || "button";
86
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, {
87
+ ref: buttonRef,
88
+ onClick: handleOnClick,
89
+ ...passthroughProps,
90
+ children
91
+ });
92
+ }
93
+ exports.AddToCartButton = AddToCartButton;
94
+ exports.BaseButton = BaseButton;
95
+ //# sourceMappingURL=AddToCartButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.js","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, Ref, ReactNode, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\n\ninterface AddToCartButtonProps {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps & BaseButtonProps<AsType>\n) {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n passthroughProps.disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\nexport interface CustomBaseButtonProps<AsType> {\n /** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */\n as?: AsType;\n /** Any ReactNode elements. */\n children: ReactNode;\n /** Click event handler. Default behaviour triggers unless prevented */\n onClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A default onClick behavior */\n defaultOnClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A ref to the underlying button */\n buttonRef?: Ref<HTMLButtonElement>;\n}\n\nexport type BaseButtonProps<AsType extends React.ElementType> =\n CustomBaseButtonProps<AsType> &\n Omit<\n React.ComponentPropsWithoutRef<AsType>,\n keyof CustomBaseButtonProps<AsType>\n >;\n\nexport function BaseButton<AsType extends React.ElementType = 'button'>(\n props: BaseButtonProps<AsType>\n) {\n const {\n as,\n onClick,\n defaultOnClick,\n children,\n buttonRef,\n ...passthroughProps\n } = props;\n\n const handleOnClick = useCallback(\n (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n if (onClick) {\n const clickShouldContinue = onClick(event);\n if (\n (typeof clickShouldContinue === 'boolean' &&\n clickShouldContinue === false) ||\n event?.defaultPrevented\n )\n return;\n }\n\n defaultOnClick?.(event);\n },\n [defaultOnClick, onClick]\n );\n\n const Component = as || 'button';\n\n return (\n <Component ref={buttonRef} onClick={handleOnClick} {...passthroughProps}>\n {children}\n </Component>\n );\n}\n"],"names":["AddToCartButton","props","addingItem","setAddingItem","useState","variantId","explicitVariantId","quantity","attributes","sellingPlanId","onClick","children","accessibleAddingToCartLabel","passthroughProps","status","linesAdd","useCart","selectedVariant","useProduct","id","disabled","useEffect","handleAddItem","useCallback","merchandiseId","_Fragment","_jsx","position","width","height","padding","margin","overflow","clip","whiteSpace","borderWidth","BaseButton","as","defaultOnClick","buttonRef","handleOnClick","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;;;;;AAyBO,SAASA,gBACdC,OACA;;AACA,QAAM,CAACC,YAAYC,aAAb,IAA8BC,eAAkB,KAAV;AACtC,QAAA;AAAA,IACJC,WAAWC;AAAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDZ,IAAAA;AACE,QAAA;AAAA,IAACa;AAAAA,IAAQC;AAAAA,MAAYC,aAA3B,QAAA;AACM,QAAA;AAAA,IAACC;AAAAA,MAAmBC,gBAA1B,WAAA;AACMb,QAAAA,aAAYC,qDAAqBW,mDAAiBE,OAAtCb,YAA4C;AACxDc,QAAAA,WACJd,sBAAsB,QACtBD,cAAc,MACdY,oBAAoB,QACpBf,cACAW,iBAAiBO;AAEnBC,QAAAA,UAAU,MAAM;AACVnB,QAAAA,cAAcY,WAAW,QAAQ;AACnCX,oBAAc,KAAD;AAAA,IACd;AAAA,EAAA,GACA,CAACW,QAAQZ,UAAT,CAJM;AAMHoB,QAAAA,gBAAgBC,MAAAA,YAAY,MAAM;AACtCpB,kBAAc,IAAD;AACbY,aAAS,CACP;AAAA,MACER;AAAAA,MACAiB,eAAenB,aAAa;AAAA,MAC5BG;AAAAA,MACAC;AAAAA,IALK,CAAA,CAAD;AAAA,EAAA,GAQP,CAACM,UAAUR,UAAUF,WAAWG,YAAYC,aAA5C,CAV8B;AAYjC,yCACEgB,WAAAA,UAAA;AAAA,IAAA,UACE,CAAAC,2BAAA,IAAC,YAAD;AAAA,MAAA,GACMb;AAAAA,MACJ;AAAA,MACA;AAAA,MACA,gBAAgBS;AAAAA,MAJlB;AAAA,IAAA,CADF,GASGV,8BACCc,2BAAA,IAAA,KAAA;AAAA,MACE,OAAO;AAAA,QACLC,UAAU;AAAA,QACVC,OAAO;AAAA,QACPC,QAAQ;AAAA,QACRC,SAAS;AAAA,QACTC,QAAQ;AAAA,QACRC,UAAU;AAAA,QACVC,MAAM;AAAA,QACNC,YAAY;AAAA,QACZC,aAAa;AAAA,MATR;AAAA,MAWP,MAAK;AAAA,MACL,aAAU;AAAA,MAbZ,UAeGjC,aAAaU,8BAA8B;AAAA,IAf9C,CAAA,IAiBE,IA3BN;AAAA,EAAA,CADF;AA+BD;AA0BM,SAASwB,WACdnC,OACA;AACM,QAAA;AAAA,IACJoC;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,OACG1B;AAAAA,EACDZ,IAAAA;AAEEuC,QAAAA,gBAAgBjB,kBACpB,CAACkB,UAA4D;AAC3D,QAAI/B,SAAS;AACLgC,YAAAA,sBAAsBhC,QAAQ+B,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDL,qDAAiBG;AAAAA,EAAH,GAEhB,CAACH,gBAAgB5B,OAAjB,CAd+B;AAiBjC,QAAMkC,YAAYP,MAAM;AAExB,wCACG,WAAD;AAAA,IAAW,KAAKE;AAAAA,IAAW,SAASC;AAAAA,IAApC,GAAuD3B;AAAAA,IAAvD;AAAA,EAAA,CADF;AAKD;;;"}
@@ -0,0 +1,95 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { useCart } from "./CartProvider.mjs";
3
+ import { useProduct } from "./ProductProvider.mjs";
4
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
5
+ function AddToCartButton(props) {
6
+ var _a;
7
+ const [addingItem, setAddingItem] = useState(false);
8
+ const {
9
+ variantId: explicitVariantId,
10
+ quantity = 1,
11
+ attributes,
12
+ sellingPlanId,
13
+ onClick,
14
+ children,
15
+ accessibleAddingToCartLabel,
16
+ ...passthroughProps
17
+ } = props;
18
+ const {
19
+ status,
20
+ linesAdd
21
+ } = useCart();
22
+ const {
23
+ selectedVariant
24
+ } = useProduct();
25
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
26
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
27
+ useEffect(() => {
28
+ if (addingItem && status === "idle") {
29
+ setAddingItem(false);
30
+ }
31
+ }, [status, addingItem]);
32
+ const handleAddItem = useCallback(() => {
33
+ setAddingItem(true);
34
+ linesAdd([{
35
+ quantity,
36
+ merchandiseId: variantId || "",
37
+ attributes,
38
+ sellingPlanId
39
+ }]);
40
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
41
+ return /* @__PURE__ */ jsxs(Fragment, {
42
+ children: [/* @__PURE__ */ jsx(BaseButton, {
43
+ ...passthroughProps,
44
+ disabled,
45
+ onClick,
46
+ defaultOnClick: handleAddItem,
47
+ children
48
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsx("p", {
49
+ style: {
50
+ position: "absolute",
51
+ width: "1px",
52
+ height: "1px",
53
+ padding: "0",
54
+ margin: "-1px",
55
+ overflow: "hidden",
56
+ clip: "rect(0, 0, 0, 0)",
57
+ whiteSpace: "nowrap",
58
+ borderWidth: "0"
59
+ },
60
+ role: "alert",
61
+ "aria-live": "assertive",
62
+ children: addingItem ? accessibleAddingToCartLabel : null
63
+ }) : null]
64
+ });
65
+ }
66
+ function BaseButton(props) {
67
+ const {
68
+ as,
69
+ onClick,
70
+ defaultOnClick,
71
+ children,
72
+ buttonRef,
73
+ ...passthroughProps
74
+ } = props;
75
+ const handleOnClick = useCallback((event) => {
76
+ if (onClick) {
77
+ const clickShouldContinue = onClick(event);
78
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
79
+ return;
80
+ }
81
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
82
+ }, [defaultOnClick, onClick]);
83
+ const Component = as || "button";
84
+ return /* @__PURE__ */ jsx(Component, {
85
+ ref: buttonRef,
86
+ onClick: handleOnClick,
87
+ ...passthroughProps,
88
+ children
89
+ });
90
+ }
91
+ export {
92
+ AddToCartButton,
93
+ BaseButton
94
+ };
95
+ //# sourceMappingURL=AddToCartButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, Ref, ReactNode, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\n\ninterface AddToCartButtonProps {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps & BaseButtonProps<AsType>\n) {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n passthroughProps.disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\nexport interface CustomBaseButtonProps<AsType> {\n /** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */\n as?: AsType;\n /** Any ReactNode elements. */\n children: ReactNode;\n /** Click event handler. Default behaviour triggers unless prevented */\n onClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A default onClick behavior */\n defaultOnClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A ref to the underlying button */\n buttonRef?: Ref<HTMLButtonElement>;\n}\n\nexport type BaseButtonProps<AsType extends React.ElementType> =\n CustomBaseButtonProps<AsType> &\n Omit<\n React.ComponentPropsWithoutRef<AsType>,\n keyof CustomBaseButtonProps<AsType>\n >;\n\nexport function BaseButton<AsType extends React.ElementType = 'button'>(\n props: BaseButtonProps<AsType>\n) {\n const {\n as,\n onClick,\n defaultOnClick,\n children,\n buttonRef,\n ...passthroughProps\n } = props;\n\n const handleOnClick = useCallback(\n (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n if (onClick) {\n const clickShouldContinue = onClick(event);\n if (\n (typeof clickShouldContinue === 'boolean' &&\n clickShouldContinue === false) ||\n event?.defaultPrevented\n )\n return;\n }\n\n defaultOnClick?.(event);\n },\n [defaultOnClick, onClick]\n );\n\n const Component = as || 'button';\n\n return (\n <Component ref={buttonRef} onClick={handleOnClick} {...passthroughProps}>\n {children}\n </Component>\n );\n}\n"],"names":["AddToCartButton","props","addingItem","setAddingItem","useState","variantId","explicitVariantId","quantity","attributes","sellingPlanId","onClick","children","accessibleAddingToCartLabel","passthroughProps","status","linesAdd","useCart","selectedVariant","useProduct","id","disabled","useEffect","handleAddItem","useCallback","merchandiseId","_Fragment","_jsx","position","width","height","padding","margin","overflow","clip","whiteSpace","borderWidth","BaseButton","as","defaultOnClick","buttonRef","handleOnClick","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;;;AAyBO,SAASA,gBACdC,OACA;;AACA,QAAM,CAACC,YAAYC,aAAb,IAA8BC,SAAkB,KAAV;AACtC,QAAA;AAAA,IACJC,WAAWC;AAAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDZ,IAAAA;AACE,QAAA;AAAA,IAACa;AAAAA,IAAQC;AAAAA,MAAYC,QAA3B;AACM,QAAA;AAAA,IAACC;AAAAA,MAAmBC,WAA1B;AACMb,QAAAA,aAAYC,qDAAqBW,mDAAiBE,OAAtCb,YAA4C;AACxDc,QAAAA,WACJd,sBAAsB,QACtBD,cAAc,MACdY,oBAAoB,QACpBf,cACAW,iBAAiBO;AAEnBC,YAAU,MAAM;AACVnB,QAAAA,cAAcY,WAAW,QAAQ;AACnCX,oBAAc,KAAD;AAAA,IACd;AAAA,EAAA,GACA,CAACW,QAAQZ,UAAT,CAJM;AAMHoB,QAAAA,gBAAgBC,YAAY,MAAM;AACtCpB,kBAAc,IAAD;AACbY,aAAS,CACP;AAAA,MACER;AAAAA,MACAiB,eAAenB,aAAa;AAAA,MAC5BG;AAAAA,MACAC;AAAAA,IALK,CAAA,CAAD;AAAA,EAAA,GAQP,CAACM,UAAUR,UAAUF,WAAWG,YAAYC,aAA5C,CAV8B;AAYjC,8BACEgB,UAAA;AAAA,IAAA,UACE,CAAAC,oBAAC,YAAD;AAAA,MAAA,GACMb;AAAAA,MACJ;AAAA,MACA;AAAA,MACA,gBAAgBS;AAAAA,MAJlB;AAAA,IAAA,CADF,GASGV,8BACCc,oBAAA,KAAA;AAAA,MACE,OAAO;AAAA,QACLC,UAAU;AAAA,QACVC,OAAO;AAAA,QACPC,QAAQ;AAAA,QACRC,SAAS;AAAA,QACTC,QAAQ;AAAA,QACRC,UAAU;AAAA,QACVC,MAAM;AAAA,QACNC,YAAY;AAAA,QACZC,aAAa;AAAA,MATR;AAAA,MAWP,MAAK;AAAA,MACL,aAAU;AAAA,MAbZ,UAeGjC,aAAaU,8BAA8B;AAAA,IAf9C,CAAA,IAiBE,IA3BN;AAAA,EAAA,CADF;AA+BD;AA0BM,SAASwB,WACdnC,OACA;AACM,QAAA;AAAA,IACJoC;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,OACG1B;AAAAA,EACDZ,IAAAA;AAEEuC,QAAAA,gBAAgBjB,YACpB,CAACkB,UAA4D;AAC3D,QAAI/B,SAAS;AACLgC,YAAAA,sBAAsBhC,QAAQ+B,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDL,qDAAiBG;AAAAA,EAAH,GAEhB,CAACH,gBAAgB5B,OAAjB,CAd+B;AAiBjC,QAAMkC,YAAYP,MAAM;AAExB,6BACG,WAAD;AAAA,IAAW,KAAKE;AAAAA,IAAW,SAASC;AAAAA,IAApC,GAAuD3B;AAAAA,IAAvD;AAAA,EAAA,CADF;AAKD;"}
package/dist/dev/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const AddToCartButton = require("./AddToCartButton.js");
3
4
  const CartProvider = require("./CartProvider.js");
4
5
  const ExternalVideo = require("./ExternalVideo.js");
5
6
  const flattenConnection = require("./flatten-connection.js");
@@ -16,6 +17,7 @@ const ShopPayButton = require("./ShopPayButton.js");
16
17
  const storefrontClient = require("./storefront-client.js");
17
18
  const useMoney = require("./useMoney.js");
18
19
  const Video = require("./Video.js");
20
+ exports.AddToCartButton = AddToCartButton.AddToCartButton;
19
21
  exports.CartProvider = CartProvider.CartProvider;
20
22
  exports.useCart = CartProvider.useCart;
21
23
  exports.ExternalVideo = ExternalVideo.ExternalVideo;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
+ import { AddToCartButton } from "./AddToCartButton.mjs";
1
2
  import { CartProvider, useCart } from "./CartProvider.mjs";
2
3
  import { ExternalVideo } from "./ExternalVideo.mjs";
3
4
  import { flattenConnection } from "./flatten-connection.mjs";
@@ -15,6 +16,7 @@ import { createStorefrontClient } from "./storefront-client.mjs";
15
16
  import { useMoney } from "./useMoney.mjs";
16
17
  import { Video } from "./Video.mjs";
17
18
  export {
19
+ AddToCartButton,
18
20
  CartProvider,
19
21
  ExternalVideo,
20
22
  Image,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const react = require("react");
4
+ const CartProvider = require("./CartProvider.js");
5
+ const ProductProvider = require("./ProductProvider.js");
6
+ const jsxRuntime = require("react/jsx-runtime");
7
+ function AddToCartButton(props) {
8
+ var _a;
9
+ const [addingItem, setAddingItem] = react.useState(false);
10
+ const {
11
+ variantId: explicitVariantId,
12
+ quantity = 1,
13
+ attributes,
14
+ sellingPlanId,
15
+ onClick,
16
+ children,
17
+ accessibleAddingToCartLabel,
18
+ ...passthroughProps
19
+ } = props;
20
+ const {
21
+ status,
22
+ linesAdd
23
+ } = CartProvider.useCart();
24
+ const {
25
+ selectedVariant
26
+ } = ProductProvider.useProduct();
27
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
28
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
29
+ react.useEffect(() => {
30
+ if (addingItem && status === "idle") {
31
+ setAddingItem(false);
32
+ }
33
+ }, [status, addingItem]);
34
+ const handleAddItem = react.useCallback(() => {
35
+ setAddingItem(true);
36
+ linesAdd([{
37
+ quantity,
38
+ merchandiseId: variantId || "",
39
+ attributes,
40
+ sellingPlanId
41
+ }]);
42
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
43
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
44
+ children: [/* @__PURE__ */ jsxRuntime.jsx(BaseButton, {
45
+ ...passthroughProps,
46
+ disabled,
47
+ onClick,
48
+ defaultOnClick: handleAddItem,
49
+ children
50
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsxRuntime.jsx("p", {
51
+ style: {
52
+ position: "absolute",
53
+ width: "1px",
54
+ height: "1px",
55
+ padding: "0",
56
+ margin: "-1px",
57
+ overflow: "hidden",
58
+ clip: "rect(0, 0, 0, 0)",
59
+ whiteSpace: "nowrap",
60
+ borderWidth: "0"
61
+ },
62
+ role: "alert",
63
+ "aria-live": "assertive",
64
+ children: addingItem ? accessibleAddingToCartLabel : null
65
+ }) : null]
66
+ });
67
+ }
68
+ function BaseButton(props) {
69
+ const {
70
+ as,
71
+ onClick,
72
+ defaultOnClick,
73
+ children,
74
+ buttonRef,
75
+ ...passthroughProps
76
+ } = props;
77
+ const handleOnClick = react.useCallback((event) => {
78
+ if (onClick) {
79
+ const clickShouldContinue = onClick(event);
80
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
81
+ return;
82
+ }
83
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
84
+ }, [defaultOnClick, onClick]);
85
+ const Component = as || "button";
86
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, {
87
+ ref: buttonRef,
88
+ onClick: handleOnClick,
89
+ ...passthroughProps,
90
+ children
91
+ });
92
+ }
93
+ exports.AddToCartButton = AddToCartButton;
94
+ exports.BaseButton = BaseButton;
95
+ //# sourceMappingURL=AddToCartButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.js","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, Ref, ReactNode, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\n\ninterface AddToCartButtonProps {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps & BaseButtonProps<AsType>\n) {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n passthroughProps.disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\nexport interface CustomBaseButtonProps<AsType> {\n /** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */\n as?: AsType;\n /** Any ReactNode elements. */\n children: ReactNode;\n /** Click event handler. Default behaviour triggers unless prevented */\n onClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A default onClick behavior */\n defaultOnClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A ref to the underlying button */\n buttonRef?: Ref<HTMLButtonElement>;\n}\n\nexport type BaseButtonProps<AsType extends React.ElementType> =\n CustomBaseButtonProps<AsType> &\n Omit<\n React.ComponentPropsWithoutRef<AsType>,\n keyof CustomBaseButtonProps<AsType>\n >;\n\nexport function BaseButton<AsType extends React.ElementType = 'button'>(\n props: BaseButtonProps<AsType>\n) {\n const {\n as,\n onClick,\n defaultOnClick,\n children,\n buttonRef,\n ...passthroughProps\n } = props;\n\n const handleOnClick = useCallback(\n (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n if (onClick) {\n const clickShouldContinue = onClick(event);\n if (\n (typeof clickShouldContinue === 'boolean' &&\n clickShouldContinue === false) ||\n event?.defaultPrevented\n )\n return;\n }\n\n defaultOnClick?.(event);\n },\n [defaultOnClick, onClick]\n );\n\n const Component = as || 'button';\n\n return (\n <Component ref={buttonRef} onClick={handleOnClick} {...passthroughProps}>\n {children}\n </Component>\n );\n}\n"],"names":["AddToCartButton","props","addingItem","setAddingItem","useState","variantId","explicitVariantId","quantity","attributes","sellingPlanId","onClick","children","accessibleAddingToCartLabel","passthroughProps","status","linesAdd","useCart","selectedVariant","useProduct","id","disabled","useEffect","handleAddItem","useCallback","merchandiseId","_Fragment","_jsx","position","width","height","padding","margin","overflow","clip","whiteSpace","borderWidth","BaseButton","as","defaultOnClick","buttonRef","handleOnClick","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;;;;;AAyBO,SAASA,gBACdC,OACA;;AACA,QAAM,CAACC,YAAYC,aAAb,IAA8BC,eAAkB,KAAV;AACtC,QAAA;AAAA,IACJC,WAAWC;AAAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDZ,IAAAA;AACE,QAAA;AAAA,IAACa;AAAAA,IAAQC;AAAAA,MAAYC,aAA3B,QAAA;AACM,QAAA;AAAA,IAACC;AAAAA,MAAmBC,gBAA1B,WAAA;AACMb,QAAAA,aAAYC,qDAAqBW,mDAAiBE,OAAtCb,YAA4C;AACxDc,QAAAA,WACJd,sBAAsB,QACtBD,cAAc,MACdY,oBAAoB,QACpBf,cACAW,iBAAiBO;AAEnBC,QAAAA,UAAU,MAAM;AACVnB,QAAAA,cAAcY,WAAW,QAAQ;AACnCX,oBAAc,KAAD;AAAA,IACd;AAAA,EAAA,GACA,CAACW,QAAQZ,UAAT,CAJM;AAMHoB,QAAAA,gBAAgBC,MAAAA,YAAY,MAAM;AACtCpB,kBAAc,IAAD;AACbY,aAAS,CACP;AAAA,MACER;AAAAA,MACAiB,eAAenB,aAAa;AAAA,MAC5BG;AAAAA,MACAC;AAAAA,IALK,CAAA,CAAD;AAAA,EAAA,GAQP,CAACM,UAAUR,UAAUF,WAAWG,YAAYC,aAA5C,CAV8B;AAYjC,yCACEgB,WAAAA,UAAA;AAAA,IAAA,UACE,CAAAC,2BAAA,IAAC,YAAD;AAAA,MAAA,GACMb;AAAAA,MACJ;AAAA,MACA;AAAA,MACA,gBAAgBS;AAAAA,MAJlB;AAAA,IAAA,CADF,GASGV,8BACCc,2BAAA,IAAA,KAAA;AAAA,MACE,OAAO;AAAA,QACLC,UAAU;AAAA,QACVC,OAAO;AAAA,QACPC,QAAQ;AAAA,QACRC,SAAS;AAAA,QACTC,QAAQ;AAAA,QACRC,UAAU;AAAA,QACVC,MAAM;AAAA,QACNC,YAAY;AAAA,QACZC,aAAa;AAAA,MATR;AAAA,MAWP,MAAK;AAAA,MACL,aAAU;AAAA,MAbZ,UAeGjC,aAAaU,8BAA8B;AAAA,IAf9C,CAAA,IAiBE,IA3BN;AAAA,EAAA,CADF;AA+BD;AA0BM,SAASwB,WACdnC,OACA;AACM,QAAA;AAAA,IACJoC;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,OACG1B;AAAAA,EACDZ,IAAAA;AAEEuC,QAAAA,gBAAgBjB,kBACpB,CAACkB,UAA4D;AAC3D,QAAI/B,SAAS;AACLgC,YAAAA,sBAAsBhC,QAAQ+B,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDL,qDAAiBG;AAAAA,EAAH,GAEhB,CAACH,gBAAgB5B,OAAjB,CAd+B;AAiBjC,QAAMkC,YAAYP,MAAM;AAExB,wCACG,WAAD;AAAA,IAAW,KAAKE;AAAAA,IAAW,SAASC;AAAAA,IAApC,GAAuD3B;AAAAA,IAAvD;AAAA,EAAA,CADF;AAKD;;;"}
@@ -0,0 +1,95 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { useCart } from "./CartProvider.mjs";
3
+ import { useProduct } from "./ProductProvider.mjs";
4
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
5
+ function AddToCartButton(props) {
6
+ var _a;
7
+ const [addingItem, setAddingItem] = useState(false);
8
+ const {
9
+ variantId: explicitVariantId,
10
+ quantity = 1,
11
+ attributes,
12
+ sellingPlanId,
13
+ onClick,
14
+ children,
15
+ accessibleAddingToCartLabel,
16
+ ...passthroughProps
17
+ } = props;
18
+ const {
19
+ status,
20
+ linesAdd
21
+ } = useCart();
22
+ const {
23
+ selectedVariant
24
+ } = useProduct();
25
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
26
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
27
+ useEffect(() => {
28
+ if (addingItem && status === "idle") {
29
+ setAddingItem(false);
30
+ }
31
+ }, [status, addingItem]);
32
+ const handleAddItem = useCallback(() => {
33
+ setAddingItem(true);
34
+ linesAdd([{
35
+ quantity,
36
+ merchandiseId: variantId || "",
37
+ attributes,
38
+ sellingPlanId
39
+ }]);
40
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
41
+ return /* @__PURE__ */ jsxs(Fragment, {
42
+ children: [/* @__PURE__ */ jsx(BaseButton, {
43
+ ...passthroughProps,
44
+ disabled,
45
+ onClick,
46
+ defaultOnClick: handleAddItem,
47
+ children
48
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsx("p", {
49
+ style: {
50
+ position: "absolute",
51
+ width: "1px",
52
+ height: "1px",
53
+ padding: "0",
54
+ margin: "-1px",
55
+ overflow: "hidden",
56
+ clip: "rect(0, 0, 0, 0)",
57
+ whiteSpace: "nowrap",
58
+ borderWidth: "0"
59
+ },
60
+ role: "alert",
61
+ "aria-live": "assertive",
62
+ children: addingItem ? accessibleAddingToCartLabel : null
63
+ }) : null]
64
+ });
65
+ }
66
+ function BaseButton(props) {
67
+ const {
68
+ as,
69
+ onClick,
70
+ defaultOnClick,
71
+ children,
72
+ buttonRef,
73
+ ...passthroughProps
74
+ } = props;
75
+ const handleOnClick = useCallback((event) => {
76
+ if (onClick) {
77
+ const clickShouldContinue = onClick(event);
78
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
79
+ return;
80
+ }
81
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
82
+ }, [defaultOnClick, onClick]);
83
+ const Component = as || "button";
84
+ return /* @__PURE__ */ jsx(Component, {
85
+ ref: buttonRef,
86
+ onClick: handleOnClick,
87
+ ...passthroughProps,
88
+ children
89
+ });
90
+ }
91
+ export {
92
+ AddToCartButton,
93
+ BaseButton
94
+ };
95
+ //# sourceMappingURL=AddToCartButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, Ref, ReactNode, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\n\ninterface AddToCartButtonProps {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps & BaseButtonProps<AsType>\n) {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n passthroughProps.disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\nexport interface CustomBaseButtonProps<AsType> {\n /** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */\n as?: AsType;\n /** Any ReactNode elements. */\n children: ReactNode;\n /** Click event handler. Default behaviour triggers unless prevented */\n onClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A default onClick behavior */\n defaultOnClick?: (\n event?: React.MouseEvent<HTMLButtonElement, MouseEvent>\n ) => void | boolean;\n /** A ref to the underlying button */\n buttonRef?: Ref<HTMLButtonElement>;\n}\n\nexport type BaseButtonProps<AsType extends React.ElementType> =\n CustomBaseButtonProps<AsType> &\n Omit<\n React.ComponentPropsWithoutRef<AsType>,\n keyof CustomBaseButtonProps<AsType>\n >;\n\nexport function BaseButton<AsType extends React.ElementType = 'button'>(\n props: BaseButtonProps<AsType>\n) {\n const {\n as,\n onClick,\n defaultOnClick,\n children,\n buttonRef,\n ...passthroughProps\n } = props;\n\n const handleOnClick = useCallback(\n (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n if (onClick) {\n const clickShouldContinue = onClick(event);\n if (\n (typeof clickShouldContinue === 'boolean' &&\n clickShouldContinue === false) ||\n event?.defaultPrevented\n )\n return;\n }\n\n defaultOnClick?.(event);\n },\n [defaultOnClick, onClick]\n );\n\n const Component = as || 'button';\n\n return (\n <Component ref={buttonRef} onClick={handleOnClick} {...passthroughProps}>\n {children}\n </Component>\n );\n}\n"],"names":["AddToCartButton","props","addingItem","setAddingItem","useState","variantId","explicitVariantId","quantity","attributes","sellingPlanId","onClick","children","accessibleAddingToCartLabel","passthroughProps","status","linesAdd","useCart","selectedVariant","useProduct","id","disabled","useEffect","handleAddItem","useCallback","merchandiseId","_Fragment","_jsx","position","width","height","padding","margin","overflow","clip","whiteSpace","borderWidth","BaseButton","as","defaultOnClick","buttonRef","handleOnClick","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;;;AAyBO,SAASA,gBACdC,OACA;;AACA,QAAM,CAACC,YAAYC,aAAb,IAA8BC,SAAkB,KAAV;AACtC,QAAA;AAAA,IACJC,WAAWC;AAAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDZ,IAAAA;AACE,QAAA;AAAA,IAACa;AAAAA,IAAQC;AAAAA,MAAYC,QAA3B;AACM,QAAA;AAAA,IAACC;AAAAA,MAAmBC,WAA1B;AACMb,QAAAA,aAAYC,qDAAqBW,mDAAiBE,OAAtCb,YAA4C;AACxDc,QAAAA,WACJd,sBAAsB,QACtBD,cAAc,MACdY,oBAAoB,QACpBf,cACAW,iBAAiBO;AAEnBC,YAAU,MAAM;AACVnB,QAAAA,cAAcY,WAAW,QAAQ;AACnCX,oBAAc,KAAD;AAAA,IACd;AAAA,EAAA,GACA,CAACW,QAAQZ,UAAT,CAJM;AAMHoB,QAAAA,gBAAgBC,YAAY,MAAM;AACtCpB,kBAAc,IAAD;AACbY,aAAS,CACP;AAAA,MACER;AAAAA,MACAiB,eAAenB,aAAa;AAAA,MAC5BG;AAAAA,MACAC;AAAAA,IALK,CAAA,CAAD;AAAA,EAAA,GAQP,CAACM,UAAUR,UAAUF,WAAWG,YAAYC,aAA5C,CAV8B;AAYjC,8BACEgB,UAAA;AAAA,IAAA,UACE,CAAAC,oBAAC,YAAD;AAAA,MAAA,GACMb;AAAAA,MACJ;AAAA,MACA;AAAA,MACA,gBAAgBS;AAAAA,MAJlB;AAAA,IAAA,CADF,GASGV,8BACCc,oBAAA,KAAA;AAAA,MACE,OAAO;AAAA,QACLC,UAAU;AAAA,QACVC,OAAO;AAAA,QACPC,QAAQ;AAAA,QACRC,SAAS;AAAA,QACTC,QAAQ;AAAA,QACRC,UAAU;AAAA,QACVC,MAAM;AAAA,QACNC,YAAY;AAAA,QACZC,aAAa;AAAA,MATR;AAAA,MAWP,MAAK;AAAA,MACL,aAAU;AAAA,MAbZ,UAeGjC,aAAaU,8BAA8B;AAAA,IAf9C,CAAA,IAiBE,IA3BN;AAAA,EAAA,CADF;AA+BD;AA0BM,SAASwB,WACdnC,OACA;AACM,QAAA;AAAA,IACJoC;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,IACA3B;AAAAA,IACA4B;AAAAA,OACG1B;AAAAA,EACDZ,IAAAA;AAEEuC,QAAAA,gBAAgBjB,YACpB,CAACkB,UAA4D;AAC3D,QAAI/B,SAAS;AACLgC,YAAAA,sBAAsBhC,QAAQ+B,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDL,qDAAiBG;AAAAA,EAAH,GAEhB,CAACH,gBAAgB5B,OAAjB,CAd+B;AAiBjC,QAAMkC,YAAYP,MAAM;AAExB,6BACG,WAAD;AAAA,IAAW,KAAKE;AAAAA,IAAW,SAASC;AAAAA,IAApC,GAAuD3B;AAAAA,IAAvD;AAAA,EAAA,CADF;AAKD;"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const AddToCartButton = require("./AddToCartButton.js");
3
4
  const CartProvider = require("./CartProvider.js");
4
5
  const ExternalVideo = require("./ExternalVideo.js");
5
6
  const flattenConnection = require("./flatten-connection.js");
@@ -16,6 +17,7 @@ const ShopPayButton = require("./ShopPayButton.js");
16
17
  const storefrontClient = require("./storefront-client.js");
17
18
  const useMoney = require("./useMoney.js");
18
19
  const Video = require("./Video.js");
20
+ exports.AddToCartButton = AddToCartButton.AddToCartButton;
19
21
  exports.CartProvider = CartProvider.CartProvider;
20
22
  exports.useCart = CartProvider.useCart;
21
23
  exports.ExternalVideo = ExternalVideo.ExternalVideo;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
+ import { AddToCartButton } from "./AddToCartButton.mjs";
1
2
  import { CartProvider, useCart } from "./CartProvider.mjs";
2
3
  import { ExternalVideo } from "./ExternalVideo.mjs";
3
4
  import { flattenConnection } from "./flatten-connection.mjs";
@@ -15,6 +16,7 @@ import { createStorefrontClient } from "./storefront-client.mjs";
15
16
  import { useMoney } from "./useMoney.mjs";
16
17
  import { Video } from "./Video.mjs";
17
18
  export {
19
+ AddToCartButton,
18
20
  CartProvider,
19
21
  ExternalVideo,
20
22
  Image,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,36 @@
1
+ import { Ref, ReactNode } from 'react';
2
+ interface AddToCartButtonProps {
3
+ /** An array of cart line attributes that belong to the item being added to the cart. */
4
+ attributes?: {
5
+ key: string;
6
+ value: string;
7
+ }[];
8
+ /** The ID of the variant. */
9
+ variantId?: string | null;
10
+ /** The item quantity. */
11
+ quantity?: number;
12
+ /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */
13
+ accessibleAddingToCartLabel?: string;
14
+ /** The selling plan ID of the subscription variant */
15
+ sellingPlanId?: string;
16
+ }
17
+ /**
18
+ * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.
19
+ * It must be a descendent of the `CartProvider` component.
20
+ */
21
+ export declare function AddToCartButton<AsType extends React.ElementType = 'button'>(props: AddToCartButtonProps & BaseButtonProps<AsType>): JSX.Element;
22
+ export interface CustomBaseButtonProps<AsType> {
23
+ /** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */
24
+ as?: AsType;
25
+ /** Any ReactNode elements. */
26
+ children: ReactNode;
27
+ /** Click event handler. Default behaviour triggers unless prevented */
28
+ onClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
29
+ /** A default onClick behavior */
30
+ defaultOnClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
31
+ /** A ref to the underlying button */
32
+ buttonRef?: Ref<HTMLButtonElement>;
33
+ }
34
+ export declare type BaseButtonProps<AsType extends React.ElementType> = CustomBaseButtonProps<AsType> & Omit<React.ComponentPropsWithoutRef<AsType>, keyof CustomBaseButtonProps<AsType>>;
35
+ export declare function BaseButton<AsType extends React.ElementType = 'button'>(props: BaseButtonProps<AsType>): JSX.Element;
36
+ export {};
@@ -1,3 +1,4 @@
1
+ export { AddToCartButton } from './AddToCartButton.js';
1
2
  export type { CartState, CartStatus, Cart, CartWithActions, CartAction, } from './cart-types.js';
2
3
  export { CartProvider, useCart } from './CartProvider.js';
3
4
  export { ExternalVideo } from './ExternalVideo.js';
@@ -1,3 +1,4 @@
1
+ export { AddToCartButton } from './AddToCartButton.js';
1
2
  export type { CartState, CartStatus, Cart, CartWithActions, CartAction, } from './cart-types.js';
2
3
  export { CartProvider, useCart } from './CartProvider.js';
3
4
  export { ExternalVideo } from './ExternalVideo.js';