@shopify/hydrogen-react 0.0.0-next-81b4528 → 0.0.0-next-a09da91

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,70 @@
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 BaseButton = require("./BaseButton.js");
7
+ const jsxRuntime = require("react/jsx-runtime");
8
+ function AddToCartButton(props) {
9
+ var _a;
10
+ const [addingItem, setAddingItem] = react.useState(false);
11
+ const {
12
+ variantId: explicitVariantId,
13
+ quantity = 1,
14
+ attributes,
15
+ sellingPlanId,
16
+ onClick,
17
+ children,
18
+ accessibleAddingToCartLabel,
19
+ ...passthroughProps
20
+ } = props;
21
+ const {
22
+ status,
23
+ linesAdd
24
+ } = CartProvider.useCart();
25
+ const {
26
+ selectedVariant
27
+ } = ProductProvider.useProduct();
28
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
29
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
30
+ react.useEffect(() => {
31
+ if (addingItem && status === "idle") {
32
+ setAddingItem(false);
33
+ }
34
+ }, [status, addingItem]);
35
+ const handleAddItem = react.useCallback(() => {
36
+ setAddingItem(true);
37
+ linesAdd([{
38
+ quantity,
39
+ merchandiseId: variantId || "",
40
+ attributes,
41
+ sellingPlanId
42
+ }]);
43
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
44
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
45
+ children: [/* @__PURE__ */ jsxRuntime.jsx(BaseButton.BaseButton, {
46
+ ...passthroughProps,
47
+ disabled,
48
+ onClick,
49
+ defaultOnClick: handleAddItem,
50
+ children
51
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsxRuntime.jsx("p", {
52
+ style: {
53
+ position: "absolute",
54
+ width: "1px",
55
+ height: "1px",
56
+ padding: "0",
57
+ margin: "-1px",
58
+ overflow: "hidden",
59
+ clip: "rect(0, 0, 0, 0)",
60
+ whiteSpace: "nowrap",
61
+ borderWidth: "0"
62
+ },
63
+ role: "alert",
64
+ "aria-live": "assertive",
65
+ children: addingItem ? accessibleAddingToCartLabel : null
66
+ }) : null]
67
+ });
68
+ }
69
+ exports.AddToCartButton = AddToCartButton;
70
+ //# sourceMappingURL=AddToCartButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.js","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {BaseButton, BaseButtonProps} from './BaseButton.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"],"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","BaseButton","position","width","height","padding","margin","overflow","clip","whiteSpace","borderWidth"],"mappings":";;;;;;;AA0BO,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,IAACC,uBAAD;AAAA,MAAA,GACMd;AAAAA,MACJ;AAAA,MACA;AAAA,MACA,gBAAgBS;AAAAA,MAJlB;AAAA,IAAA,CADF,GASGV,8BACCc,2BAAA,IAAA,KAAA;AAAA,MACE,OAAO;AAAA,QACLE,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,UAeGlC,aAAaU,8BAA8B;AAAA,IAf9C,CAAA,IAiBE,IA3BN;AAAA,EAAA,CADF;AA+BD;;"}
@@ -0,0 +1,70 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { useCart } from "./CartProvider.mjs";
3
+ import { useProduct } from "./ProductProvider.mjs";
4
+ import { BaseButton } from "./BaseButton.mjs";
5
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
6
+ function AddToCartButton(props) {
7
+ var _a;
8
+ const [addingItem, setAddingItem] = useState(false);
9
+ const {
10
+ variantId: explicitVariantId,
11
+ quantity = 1,
12
+ attributes,
13
+ sellingPlanId,
14
+ onClick,
15
+ children,
16
+ accessibleAddingToCartLabel,
17
+ ...passthroughProps
18
+ } = props;
19
+ const {
20
+ status,
21
+ linesAdd
22
+ } = useCart();
23
+ const {
24
+ selectedVariant
25
+ } = useProduct();
26
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
27
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
28
+ useEffect(() => {
29
+ if (addingItem && status === "idle") {
30
+ setAddingItem(false);
31
+ }
32
+ }, [status, addingItem]);
33
+ const handleAddItem = useCallback(() => {
34
+ setAddingItem(true);
35
+ linesAdd([{
36
+ quantity,
37
+ merchandiseId: variantId || "",
38
+ attributes,
39
+ sellingPlanId
40
+ }]);
41
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
42
+ return /* @__PURE__ */ jsxs(Fragment, {
43
+ children: [/* @__PURE__ */ jsx(BaseButton, {
44
+ ...passthroughProps,
45
+ disabled,
46
+ onClick,
47
+ defaultOnClick: handleAddItem,
48
+ children
49
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsx("p", {
50
+ style: {
51
+ position: "absolute",
52
+ width: "1px",
53
+ height: "1px",
54
+ padding: "0",
55
+ margin: "-1px",
56
+ overflow: "hidden",
57
+ clip: "rect(0, 0, 0, 0)",
58
+ whiteSpace: "nowrap",
59
+ borderWidth: "0"
60
+ },
61
+ role: "alert",
62
+ "aria-live": "assertive",
63
+ children: addingItem ? accessibleAddingToCartLabel : null
64
+ }) : null]
65
+ });
66
+ }
67
+ export {
68
+ AddToCartButton
69
+ };
70
+ //# sourceMappingURL=AddToCartButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {BaseButton, BaseButtonProps} from './BaseButton.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"],"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"],"mappings":";;;;;AA0BO,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;"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const react = require("react");
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ function BaseButton(props) {
6
+ const {
7
+ as,
8
+ onClick,
9
+ defaultOnClick,
10
+ children,
11
+ buttonRef,
12
+ ...passthroughProps
13
+ } = props;
14
+ const handleOnClick = react.useCallback((event) => {
15
+ if (onClick) {
16
+ const clickShouldContinue = onClick(event);
17
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
18
+ return;
19
+ }
20
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
21
+ }, [defaultOnClick, onClick]);
22
+ const Component = as || "button";
23
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, {
24
+ ref: buttonRef,
25
+ onClick: handleOnClick,
26
+ ...passthroughProps,
27
+ children
28
+ });
29
+ }
30
+ exports.BaseButton = BaseButton;
31
+ //# sourceMappingURL=BaseButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseButton.js","sources":["../../src/BaseButton.tsx"],"sourcesContent":["import {ReactNode, Ref, useCallback} from 'react';\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":["BaseButton","props","as","onClick","defaultOnClick","children","buttonRef","passthroughProps","handleOnClick","useCallback","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;;;AA0BO,SAASA,WACdC,OACA;AACM,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDN,IAAAA;AAEEO,QAAAA,gBAAgBC,kBACpB,CAACC,UAA4D;AAC3D,QAAIP,SAAS;AACLQ,YAAAA,sBAAsBR,QAAQO,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDR,qDAAiBM;AAAAA,EAAH,GAEhB,CAACN,gBAAgBD,OAAjB,CAd+B;AAiBjC,QAAMU,YAAYX,MAAM;AAExB,wCACG,WAAD;AAAA,IAAW,KAAKI;AAAAA,IAAW,SAASE;AAAAA,IAApC,GAAuDD;AAAAA,IAAvD;AAAA,EAAA,CADF;AAKD;;"}
@@ -0,0 +1,31 @@
1
+ import { useCallback } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ function BaseButton(props) {
4
+ const {
5
+ as,
6
+ onClick,
7
+ defaultOnClick,
8
+ children,
9
+ buttonRef,
10
+ ...passthroughProps
11
+ } = props;
12
+ const handleOnClick = useCallback((event) => {
13
+ if (onClick) {
14
+ const clickShouldContinue = onClick(event);
15
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
16
+ return;
17
+ }
18
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
19
+ }, [defaultOnClick, onClick]);
20
+ const Component = as || "button";
21
+ return /* @__PURE__ */ jsx(Component, {
22
+ ref: buttonRef,
23
+ onClick: handleOnClick,
24
+ ...passthroughProps,
25
+ children
26
+ });
27
+ }
28
+ export {
29
+ BaseButton
30
+ };
31
+ //# sourceMappingURL=BaseButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseButton.mjs","sources":["../../src/BaseButton.tsx"],"sourcesContent":["import {ReactNode, Ref, useCallback} from 'react';\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":["BaseButton","props","as","onClick","defaultOnClick","children","buttonRef","passthroughProps","handleOnClick","useCallback","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;AA0BO,SAASA,WACdC,OACA;AACM,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDN,IAAAA;AAEEO,QAAAA,gBAAgBC,YACpB,CAACC,UAA4D;AAC3D,QAAIP,SAAS;AACLQ,YAAAA,sBAAsBR,QAAQO,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDR,qDAAiBM;AAAAA,EAAH,GAEhB,CAACN,gBAAgBD,OAAjB,CAd+B;AAiBjC,QAAMU,YAAYX,MAAM;AAExB,6BACG,WAAD;AAAA,IAAW,KAAKI;AAAAA,IAAW,SAASE;AAAAA,IAApC,GAAuDD;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,70 @@
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 BaseButton = require("./BaseButton.js");
7
+ const jsxRuntime = require("react/jsx-runtime");
8
+ function AddToCartButton(props) {
9
+ var _a;
10
+ const [addingItem, setAddingItem] = react.useState(false);
11
+ const {
12
+ variantId: explicitVariantId,
13
+ quantity = 1,
14
+ attributes,
15
+ sellingPlanId,
16
+ onClick,
17
+ children,
18
+ accessibleAddingToCartLabel,
19
+ ...passthroughProps
20
+ } = props;
21
+ const {
22
+ status,
23
+ linesAdd
24
+ } = CartProvider.useCart();
25
+ const {
26
+ selectedVariant
27
+ } = ProductProvider.useProduct();
28
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
29
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
30
+ react.useEffect(() => {
31
+ if (addingItem && status === "idle") {
32
+ setAddingItem(false);
33
+ }
34
+ }, [status, addingItem]);
35
+ const handleAddItem = react.useCallback(() => {
36
+ setAddingItem(true);
37
+ linesAdd([{
38
+ quantity,
39
+ merchandiseId: variantId || "",
40
+ attributes,
41
+ sellingPlanId
42
+ }]);
43
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
44
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
45
+ children: [/* @__PURE__ */ jsxRuntime.jsx(BaseButton.BaseButton, {
46
+ ...passthroughProps,
47
+ disabled,
48
+ onClick,
49
+ defaultOnClick: handleAddItem,
50
+ children
51
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsxRuntime.jsx("p", {
52
+ style: {
53
+ position: "absolute",
54
+ width: "1px",
55
+ height: "1px",
56
+ padding: "0",
57
+ margin: "-1px",
58
+ overflow: "hidden",
59
+ clip: "rect(0, 0, 0, 0)",
60
+ whiteSpace: "nowrap",
61
+ borderWidth: "0"
62
+ },
63
+ role: "alert",
64
+ "aria-live": "assertive",
65
+ children: addingItem ? accessibleAddingToCartLabel : null
66
+ }) : null]
67
+ });
68
+ }
69
+ exports.AddToCartButton = AddToCartButton;
70
+ //# sourceMappingURL=AddToCartButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.js","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {BaseButton, BaseButtonProps} from './BaseButton.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"],"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","BaseButton","position","width","height","padding","margin","overflow","clip","whiteSpace","borderWidth"],"mappings":";;;;;;;AA0BO,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,IAACC,uBAAD;AAAA,MAAA,GACMd;AAAAA,MACJ;AAAA,MACA;AAAA,MACA,gBAAgBS;AAAAA,MAJlB;AAAA,IAAA,CADF,GASGV,8BACCc,2BAAA,IAAA,KAAA;AAAA,MACE,OAAO;AAAA,QACLE,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,UAeGlC,aAAaU,8BAA8B;AAAA,IAf9C,CAAA,IAiBE,IA3BN;AAAA,EAAA,CADF;AA+BD;;"}
@@ -0,0 +1,70 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { useCart } from "./CartProvider.mjs";
3
+ import { useProduct } from "./ProductProvider.mjs";
4
+ import { BaseButton } from "./BaseButton.mjs";
5
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
6
+ function AddToCartButton(props) {
7
+ var _a;
8
+ const [addingItem, setAddingItem] = useState(false);
9
+ const {
10
+ variantId: explicitVariantId,
11
+ quantity = 1,
12
+ attributes,
13
+ sellingPlanId,
14
+ onClick,
15
+ children,
16
+ accessibleAddingToCartLabel,
17
+ ...passthroughProps
18
+ } = props;
19
+ const {
20
+ status,
21
+ linesAdd
22
+ } = useCart();
23
+ const {
24
+ selectedVariant
25
+ } = useProduct();
26
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
27
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
28
+ useEffect(() => {
29
+ if (addingItem && status === "idle") {
30
+ setAddingItem(false);
31
+ }
32
+ }, [status, addingItem]);
33
+ const handleAddItem = useCallback(() => {
34
+ setAddingItem(true);
35
+ linesAdd([{
36
+ quantity,
37
+ merchandiseId: variantId || "",
38
+ attributes,
39
+ sellingPlanId
40
+ }]);
41
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
42
+ return /* @__PURE__ */ jsxs(Fragment, {
43
+ children: [/* @__PURE__ */ jsx(BaseButton, {
44
+ ...passthroughProps,
45
+ disabled,
46
+ onClick,
47
+ defaultOnClick: handleAddItem,
48
+ children
49
+ }), accessibleAddingToCartLabel ? /* @__PURE__ */ jsx("p", {
50
+ style: {
51
+ position: "absolute",
52
+ width: "1px",
53
+ height: "1px",
54
+ padding: "0",
55
+ margin: "-1px",
56
+ overflow: "hidden",
57
+ clip: "rect(0, 0, 0, 0)",
58
+ whiteSpace: "nowrap",
59
+ borderWidth: "0"
60
+ },
61
+ role: "alert",
62
+ "aria-live": "assertive",
63
+ children: addingItem ? accessibleAddingToCartLabel : null
64
+ }) : null]
65
+ });
66
+ }
67
+ export {
68
+ AddToCartButton
69
+ };
70
+ //# sourceMappingURL=AddToCartButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\n\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {BaseButton, BaseButtonProps} from './BaseButton.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"],"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"],"mappings":";;;;;AA0BO,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;"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const react = require("react");
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ function BaseButton(props) {
6
+ const {
7
+ as,
8
+ onClick,
9
+ defaultOnClick,
10
+ children,
11
+ buttonRef,
12
+ ...passthroughProps
13
+ } = props;
14
+ const handleOnClick = react.useCallback((event) => {
15
+ if (onClick) {
16
+ const clickShouldContinue = onClick(event);
17
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
18
+ return;
19
+ }
20
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
21
+ }, [defaultOnClick, onClick]);
22
+ const Component = as || "button";
23
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, {
24
+ ref: buttonRef,
25
+ onClick: handleOnClick,
26
+ ...passthroughProps,
27
+ children
28
+ });
29
+ }
30
+ exports.BaseButton = BaseButton;
31
+ //# sourceMappingURL=BaseButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseButton.js","sources":["../../src/BaseButton.tsx"],"sourcesContent":["import {ReactNode, Ref, useCallback} from 'react';\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":["BaseButton","props","as","onClick","defaultOnClick","children","buttonRef","passthroughProps","handleOnClick","useCallback","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;;;AA0BO,SAASA,WACdC,OACA;AACM,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDN,IAAAA;AAEEO,QAAAA,gBAAgBC,kBACpB,CAACC,UAA4D;AAC3D,QAAIP,SAAS;AACLQ,YAAAA,sBAAsBR,QAAQO,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDR,qDAAiBM;AAAAA,EAAH,GAEhB,CAACN,gBAAgBD,OAAjB,CAd+B;AAiBjC,QAAMU,YAAYX,MAAM;AAExB,wCACG,WAAD;AAAA,IAAW,KAAKI;AAAAA,IAAW,SAASE;AAAAA,IAApC,GAAuDD;AAAAA,IAAvD;AAAA,EAAA,CADF;AAKD;;"}
@@ -0,0 +1,31 @@
1
+ import { useCallback } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ function BaseButton(props) {
4
+ const {
5
+ as,
6
+ onClick,
7
+ defaultOnClick,
8
+ children,
9
+ buttonRef,
10
+ ...passthroughProps
11
+ } = props;
12
+ const handleOnClick = useCallback((event) => {
13
+ if (onClick) {
14
+ const clickShouldContinue = onClick(event);
15
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
16
+ return;
17
+ }
18
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
19
+ }, [defaultOnClick, onClick]);
20
+ const Component = as || "button";
21
+ return /* @__PURE__ */ jsx(Component, {
22
+ ref: buttonRef,
23
+ onClick: handleOnClick,
24
+ ...passthroughProps,
25
+ children
26
+ });
27
+ }
28
+ export {
29
+ BaseButton
30
+ };
31
+ //# sourceMappingURL=BaseButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseButton.mjs","sources":["../../src/BaseButton.tsx"],"sourcesContent":["import {ReactNode, Ref, useCallback} from 'react';\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":["BaseButton","props","as","onClick","defaultOnClick","children","buttonRef","passthroughProps","handleOnClick","useCallback","event","clickShouldContinue","defaultPrevented","Component"],"mappings":";;AA0BO,SAASA,WACdC,OACA;AACM,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,EACDN,IAAAA;AAEEO,QAAAA,gBAAgBC,YACpB,CAACC,UAA4D;AAC3D,QAAIP,SAAS;AACLQ,YAAAA,sBAAsBR,QAAQO,KAAD;AACnC,UACG,OAAOC,wBAAwB,aAC9BA,wBAAwB,UAC1BD,+BAAOE;AAEP;AAAA,IACH;AAEDR,qDAAiBM;AAAAA,EAAH,GAEhB,CAACN,gBAAgBD,OAAjB,CAd+B;AAiBjC,QAAMU,YAAYX,MAAM;AAExB,6BACG,WAAD;AAAA,IAAW,KAAKI;AAAAA,IAAW,SAASE;AAAAA,IAApC,GAAuDD;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,22 @@
1
+ import { BaseButtonProps } from './BaseButton.js';
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 {};
@@ -0,0 +1,15 @@
1
+ import { ReactNode, Ref } from 'react';
2
+ export interface CustomBaseButtonProps<AsType> {
3
+ /** 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. */
4
+ as?: AsType;
5
+ /** Any ReactNode elements. */
6
+ children: ReactNode;
7
+ /** Click event handler. Default behaviour triggers unless prevented */
8
+ onClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
9
+ /** A default onClick behavior */
10
+ defaultOnClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
11
+ /** A ref to the underlying button */
12
+ buttonRef?: Ref<HTMLButtonElement>;
13
+ }
14
+ export declare type BaseButtonProps<AsType extends React.ElementType> = CustomBaseButtonProps<AsType> & Omit<React.ComponentPropsWithoutRef<AsType>, keyof CustomBaseButtonProps<AsType>>;
15
+ export declare function BaseButton<AsType extends React.ElementType = 'button'>(props: BaseButtonProps<AsType>): JSX.Element;
@@ -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';