@shopify/hydrogen-react 0.0.0-next-781568d → 0.0.0-next-60821c3

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.
Files changed (53) hide show
  1. package/dist/browser-dev/CartLineProvider.mjs.map +1 -1
  2. package/dist/browser-dev/CartLineQuantity.mjs +12 -0
  3. package/dist/browser-dev/CartLineQuantity.mjs.map +1 -0
  4. package/dist/browser-dev/CartLineQuantityAdjustButton.mjs +48 -0
  5. package/dist/browser-dev/CartLineQuantityAdjustButton.mjs.map +1 -0
  6. package/dist/browser-dev/index.mjs +4 -0
  7. package/dist/browser-dev/index.mjs.map +1 -1
  8. package/dist/browser-prod/CartLineProvider.mjs.map +1 -1
  9. package/dist/browser-prod/CartLineQuantity.mjs +12 -0
  10. package/dist/browser-prod/CartLineQuantity.mjs.map +1 -0
  11. package/dist/browser-prod/CartLineQuantityAdjustButton.mjs +48 -0
  12. package/dist/browser-prod/CartLineQuantityAdjustButton.mjs.map +1 -0
  13. package/dist/browser-prod/index.mjs +4 -0
  14. package/dist/browser-prod/index.mjs.map +1 -1
  15. package/dist/node-dev/CartLineProvider.js.map +1 -1
  16. package/dist/node-dev/CartLineProvider.mjs.map +1 -1
  17. package/dist/node-dev/CartLineQuantity.js +12 -0
  18. package/dist/node-dev/CartLineQuantity.js.map +1 -0
  19. package/dist/node-dev/CartLineQuantity.mjs +12 -0
  20. package/dist/node-dev/CartLineQuantity.mjs.map +1 -0
  21. package/dist/node-dev/CartLineQuantityAdjustButton.js +48 -0
  22. package/dist/node-dev/CartLineQuantityAdjustButton.js.map +1 -0
  23. package/dist/node-dev/CartLineQuantityAdjustButton.mjs +48 -0
  24. package/dist/node-dev/CartLineQuantityAdjustButton.mjs.map +1 -0
  25. package/dist/node-dev/index.js +4 -0
  26. package/dist/node-dev/index.js.map +1 -1
  27. package/dist/node-dev/index.mjs +4 -0
  28. package/dist/node-dev/index.mjs.map +1 -1
  29. package/dist/node-prod/CartLineProvider.js.map +1 -1
  30. package/dist/node-prod/CartLineProvider.mjs.map +1 -1
  31. package/dist/node-prod/CartLineQuantity.js +12 -0
  32. package/dist/node-prod/CartLineQuantity.js.map +1 -0
  33. package/dist/node-prod/CartLineQuantity.mjs +12 -0
  34. package/dist/node-prod/CartLineQuantity.mjs.map +1 -0
  35. package/dist/node-prod/CartLineQuantityAdjustButton.js +48 -0
  36. package/dist/node-prod/CartLineQuantityAdjustButton.js.map +1 -0
  37. package/dist/node-prod/CartLineQuantityAdjustButton.mjs +48 -0
  38. package/dist/node-prod/CartLineQuantityAdjustButton.mjs.map +1 -0
  39. package/dist/node-prod/index.js +4 -0
  40. package/dist/node-prod/index.js.map +1 -1
  41. package/dist/node-prod/index.mjs +4 -0
  42. package/dist/node-prod/index.mjs.map +1 -1
  43. package/dist/types/CartLineProvider.d.ts +9 -3
  44. package/dist/types/CartLineQuantity.d.ts +13 -0
  45. package/dist/types/CartLineQuantityAdjustButton.d.ts +13 -0
  46. package/dist/types/index.d.cts +2 -0
  47. package/dist/types/index.d.ts +2 -0
  48. package/dist/types/storefront-api-response.types.d.ts +1 -1
  49. package/dist/umd/hydrogen-react.dev.js +47 -0
  50. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  51. package/dist/umd/hydrogen-react.prod.js +16 -16
  52. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  53. package/package.json +1 -1
@@ -0,0 +1,48 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useCallback } from "react";
3
+ import { useCart } from "./CartProvider.mjs";
4
+ import { useCartLine } from "./CartLineProvider.mjs";
5
+ import { BaseButton } from "./BaseButton.mjs";
6
+ function CartLineQuantityAdjustButton(props) {
7
+ const { status, linesRemove, linesUpdate } = useCart();
8
+ const cartLine = useCartLine();
9
+ const { children, adjust, onClick, ...passthroughProps } = props;
10
+ const handleAdjust = useCallback(() => {
11
+ if (adjust === "remove") {
12
+ linesRemove([(cartLine == null ? void 0 : cartLine.id) ?? ""]);
13
+ return;
14
+ }
15
+ const quantity = adjust === "decrease" ? ((cartLine == null ? void 0 : cartLine.quantity) ?? 0) - 1 : ((cartLine == null ? void 0 : cartLine.quantity) ?? 0) + 1;
16
+ if (quantity <= 0) {
17
+ linesRemove([(cartLine == null ? void 0 : cartLine.id) ?? ""]);
18
+ return;
19
+ }
20
+ const lineUpdate = {
21
+ id: (cartLine == null ? void 0 : cartLine.id) ?? "",
22
+ quantity,
23
+ attributes: (cartLine == null ? void 0 : cartLine.attributes) ?? []
24
+ };
25
+ linesUpdate([lineUpdate]);
26
+ }, [
27
+ adjust,
28
+ cartLine == null ? void 0 : cartLine.attributes,
29
+ cartLine == null ? void 0 : cartLine.id,
30
+ cartLine == null ? void 0 : cartLine.quantity,
31
+ linesRemove,
32
+ linesUpdate
33
+ ]);
34
+ return /* @__PURE__ */ jsx(
35
+ BaseButton,
36
+ {
37
+ onClick,
38
+ defaultOnClick: handleAdjust,
39
+ disabled: typeof passthroughProps.disabled !== "undefined" ? passthroughProps.disabled : status !== "idle",
40
+ ...passthroughProps,
41
+ children
42
+ }
43
+ );
44
+ }
45
+ export {
46
+ CartLineQuantityAdjustButton
47
+ };
48
+ //# sourceMappingURL=CartLineQuantityAdjustButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CartLineQuantityAdjustButton.mjs","sources":["../../src/CartLineQuantityAdjustButton.tsx"],"sourcesContent":["import {useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useCartLine} from './CartLineProvider.js';\nimport {BaseButton, type BaseButtonProps} from './BaseButton.js';\nimport type {CartLineUpdateInput} from './storefront-api-types.js';\n\ninterface CartLineQuantityAdjustButtonBaseProps {\n /** The adjustment for a cart line's quantity. Valid values: `increase` (default), `decrease`, or `remove`. */\n adjust?: 'increase' | 'decrease' | 'remove';\n}\n\ntype CartLineQuantityAdjustButtonProps<\n AsType extends React.ElementType = 'button'\n> = BaseButtonProps<AsType> & CartLineQuantityAdjustButtonBaseProps;\n\n/**\n * The `<CartLineQuantityAdjustButton />` component renders a button that adjusts the cart line's quantity when pressed.\n *\n * It must be a descendent of `<CartLineProvider/>` and `<CartProvider/>`.\n */\nexport function CartLineQuantityAdjustButton<\n AsType extends React.ElementType = 'button'\n>(props: CartLineQuantityAdjustButtonProps<AsType>): JSX.Element {\n const {status, linesRemove, linesUpdate} = useCart();\n const cartLine = useCartLine();\n const {children, adjust, onClick, ...passthroughProps} = props;\n\n const handleAdjust = useCallback(() => {\n if (adjust === 'remove') {\n linesRemove([cartLine?.id ?? '']);\n return;\n }\n\n const quantity =\n adjust === 'decrease'\n ? (cartLine?.quantity ?? 0) - 1\n : (cartLine?.quantity ?? 0) + 1;\n\n if (quantity <= 0) {\n linesRemove([cartLine?.id ?? '']);\n return;\n }\n\n const lineUpdate = {\n id: cartLine?.id ?? '',\n quantity,\n attributes: (cartLine?.attributes ??\n []) as CartLineUpdateInput['attributes'],\n } satisfies CartLineUpdateInput;\n\n linesUpdate([lineUpdate]);\n }, [\n adjust,\n cartLine?.attributes,\n cartLine?.id,\n cartLine?.quantity,\n linesRemove,\n linesUpdate,\n ]);\n\n return (\n <BaseButton\n onClick={onClick}\n defaultOnClick={handleAdjust}\n disabled={\n typeof passthroughProps.disabled !== 'undefined'\n ? passthroughProps.disabled\n : status !== 'idle'\n }\n {...passthroughProps}\n >\n {children}\n </BaseButton>\n );\n}\n"],"names":[],"mappings":";;;;;AAoBO,SAAS,6BAEd,OAA+D;AAC/D,QAAM,EAAC,QAAQ,aAAa,gBAAe,QAAQ;AACnD,QAAM,WAAW;AACjB,QAAM,EAAC,UAAU,QAAQ,SAAS,GAAG,iBAAoB,IAAA;AAEnD,QAAA,eAAe,YAAY,MAAM;AACrC,QAAI,WAAW,UAAU;AACvB,kBAAY,EAAC,qCAAU,OAAM,EAAE,CAAC;AAChC;AAAA,IACF;AAEM,UAAA,WACJ,WAAW,eACN,qCAAU,aAAY,KAAK,MAC3B,qCAAU,aAAY,KAAK;AAElC,QAAI,YAAY,GAAG;AACjB,kBAAY,EAAC,qCAAU,OAAM,EAAE,CAAC;AAChC;AAAA,IACF;AAEA,UAAM,aAAa;AAAA,MACjB,KAAI,qCAAU,OAAM;AAAA,MACpB;AAAA,MACA,aAAa,qCAAU,eACrB,CAAC;AAAA,IAAA;AAGO,gBAAA,CAAC,UAAU,CAAC;AAAA,EAAA,GACvB;AAAA,IACD;AAAA,IACA,qCAAU;AAAA,IACV,qCAAU;AAAA,IACV,qCAAU;AAAA,IACV;AAAA,IACA;AAAA,EAAA,CACD;AAGC,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,gBAAgB;AAAA,MAChB,UACE,OAAO,iBAAiB,aAAa,cACjC,iBAAiB,WACjB,WAAW;AAAA,MAEhB,GAAG;AAAA,MAEH;AAAA,IAAA;AAAA,EAAA;AAGP;"}
@@ -8,6 +8,8 @@ const CartCheckoutButton = require("./CartCheckoutButton.js");
8
8
  const CartCost = require("./CartCost.js");
9
9
  const CartLinePrice = require("./CartLinePrice.js");
10
10
  const CartLineProvider = require("./CartLineProvider.js");
11
+ const CartLineQuantity = require("./CartLineQuantity.js");
12
+ const CartLineQuantityAdjustButton = require("./CartLineQuantityAdjustButton.js");
11
13
  const CartProvider = require("./CartProvider.js");
12
14
  const codegen_helpers = require("./codegen.helpers.js");
13
15
  const cookiesUtils = require("./cookies-utils.js");
@@ -38,6 +40,8 @@ exports.CartCost = CartCost.CartCost;
38
40
  exports.CartLinePrice = CartLinePrice.CartLinePrice;
39
41
  exports.CartLineProvider = CartLineProvider.CartLineProvider;
40
42
  exports.useCartLine = CartLineProvider.useCartLine;
43
+ exports.CartLineQuantity = CartLineQuantity.CartLineQuantity;
44
+ exports.CartLineQuantityAdjustButton = CartLineQuantityAdjustButton.CartLineQuantityAdjustButton;
41
45
  exports.CartProvider = CartProvider.CartProvider;
42
46
  exports.useCart = CartProvider.useCart;
43
47
  exports.storefrontApiCustomScalars = codegen_helpers.storefrontApiCustomScalars;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -6,6 +6,8 @@ import { CartCheckoutButton } from "./CartCheckoutButton.mjs";
6
6
  import { CartCost } from "./CartCost.mjs";
7
7
  import { CartLinePrice } from "./CartLinePrice.mjs";
8
8
  import { CartLineProvider, useCartLine } from "./CartLineProvider.mjs";
9
+ import { CartLineQuantity } from "./CartLineQuantity.mjs";
10
+ import { CartLineQuantityAdjustButton } from "./CartLineQuantityAdjustButton.mjs";
9
11
  import { CartProvider, useCart } from "./CartProvider.mjs";
10
12
  import { storefrontApiCustomScalars } from "./codegen.helpers.mjs";
11
13
  import { getShopifyCookies } from "./cookies-utils.mjs";
@@ -33,6 +35,8 @@ export {
33
35
  CartCost,
34
36
  CartLinePrice,
35
37
  CartLineProvider,
38
+ CartLineQuantity,
39
+ CartLineQuantityAdjustButton,
36
40
  CartProvider,
37
41
  ExternalVideo,
38
42
  Image,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,15 +1,21 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { CartLine } from './storefront-api-types.js';
3
- export declare const CartLineContext: import("react").Context<CartLine | null>;
3
+ import type { PartialDeep } from 'type-fest';
4
+ type CartLinePartialDeep = PartialDeep<CartLine, {
5
+ recurseIntoArrays: true;
6
+ }>;
7
+ export declare const CartLineContext: import("react").Context<import("type-fest/source/partial-deep.js").PartialObjectDeep<CartLine, {
8
+ recurseIntoArrays: true;
9
+ }> | null>;
4
10
  /**
5
11
  * The `useCartLine` hook provides access to the [CartLine object](https://shopify.dev/api/storefront/unstable/objects/cartline) from the Storefront API. It must be a descendent of a `CartProvider` component.
6
12
  */
7
- export declare function useCartLine(): CartLine;
13
+ export declare function useCartLine(): CartLinePartialDeep;
8
14
  type CartLineProviderProps = {
9
15
  /** Any `ReactNode` elements. */
10
16
  children: ReactNode;
11
17
  /** A cart line object. */
12
- line: CartLine;
18
+ line: CartLinePartialDeep;
13
19
  };
14
20
  /**
15
21
  * The `CartLineProvider` component creates a context for using a cart line.
@@ -0,0 +1,13 @@
1
+ import type { ComponentPropsWithoutRef, ElementType } from 'react';
2
+ interface CartLineQuantityBaseProps<ComponentGeneric extends ElementType = 'span'> {
3
+ /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `span`. */
4
+ as?: ComponentGeneric;
5
+ }
6
+ export type CartLineQuantityProps<ComponentGeneric extends ElementType> = CartLineQuantityBaseProps<ComponentGeneric> & Omit<ComponentPropsWithoutRef<ComponentGeneric>, keyof CartLineQuantityBaseProps<ComponentGeneric>>;
7
+ /**
8
+ * The `<CartLineQuantity/>` component renders a `span` (or another element / component that can be customized by the `as` prop) with the cart line's quantity.
9
+ *
10
+ * It must be a descendent of a `<CartLineProvider/>` component, and uses the `useCartLine()` hook internally.
11
+ */
12
+ export declare function CartLineQuantity<ComponentGeneric extends ElementType = 'span'>(props: CartLineQuantityProps<ComponentGeneric>): JSX.Element;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { type BaseButtonProps } from './BaseButton.js';
2
+ interface CartLineQuantityAdjustButtonBaseProps {
3
+ /** The adjustment for a cart line's quantity. Valid values: `increase` (default), `decrease`, or `remove`. */
4
+ adjust?: 'increase' | 'decrease' | 'remove';
5
+ }
6
+ type CartLineQuantityAdjustButtonProps<AsType extends React.ElementType = 'button'> = BaseButtonProps<AsType> & CartLineQuantityAdjustButtonBaseProps;
7
+ /**
8
+ * The `<CartLineQuantityAdjustButton />` component renders a button that adjusts the cart line's quantity when pressed.
9
+ *
10
+ * It must be a descendent of `<CartLineProvider/>` and `<CartProvider/>`.
11
+ */
12
+ export declare function CartLineQuantityAdjustButton<AsType extends React.ElementType = 'button'>(props: CartLineQuantityAdjustButtonProps<AsType>): JSX.Element;
13
+ export {};
@@ -8,6 +8,8 @@ export { CartCheckoutButton } from './CartCheckoutButton.js';
8
8
  export { CartCost } from './CartCost.js';
9
9
  export { CartLinePrice } from './CartLinePrice.js';
10
10
  export { CartLineProvider, useCartLine } from './CartLineProvider.js';
11
+ export { CartLineQuantity } from './CartLineQuantity.js';
12
+ export { CartLineQuantityAdjustButton } from './CartLineQuantityAdjustButton.js';
11
13
  export { CartProvider, useCart } from './CartProvider.js';
12
14
  export { storefrontApiCustomScalars } from './codegen.helpers.js';
13
15
  export { getShopifyCookies } from './cookies-utils.js';
@@ -8,6 +8,8 @@ export { CartCheckoutButton } from './CartCheckoutButton.js';
8
8
  export { CartCost } from './CartCost.js';
9
9
  export { CartLinePrice } from './CartLinePrice.js';
10
10
  export { CartLineProvider, useCartLine } from './CartLineProvider.js';
11
+ export { CartLineQuantity } from './CartLineQuantity.js';
12
+ export { CartLineQuantityAdjustButton } from './CartLineQuantityAdjustButton.js';
11
13
  export { CartProvider, useCart } from './CartProvider.js';
12
14
  export { storefrontApiCustomScalars } from './codegen.helpers.js';
13
15
  export { getShopifyCookies } from './cookies-utils.js';
@@ -9,7 +9,7 @@ type StorefrontApiExtensions = {
9
9
  * Shows error codes common to Shopify. Additional error codes may also be shown.
10
10
  * https://shopify.dev/api/storefront#status_and_error_codes
11
11
  */
12
- code?: 'THROTTLED' | 'ACCESS_DENIED' | 'SHOP_INACTIVE' | 'INTERNAL_SERVER_ERROR' | string;
12
+ code?: 'THROTTLED' | 'ACCESS_DENIED' | 'SHOP_INACTIVE' | 'INTERNAL_SERVER_ERROR' | (string & {});
13
13
  };
14
14
  /**
15
15
  * The Storefront API can return a 200 OK response code when the query succeeds, and will populate the `data` property. The generic you pass in through type parameters will be the shape of the `data` object if successful. If you prefer a "deeply-partial" version of that generic object, consider using `StorefrontApiResponseOkPartial` instead.
@@ -3004,6 +3004,51 @@
3004
3004
  }) {
3005
3005
  return /* @__PURE__ */ React.createElement(CartLineContext.Provider, { value: line }, children);
3006
3006
  }
3007
+ function CartLineQuantity(props) {
3008
+ const cartLine = useCartLine();
3009
+ const { as, ...passthroughProps } = props;
3010
+ const Wrapper = as ? as : "span";
3011
+ return /* @__PURE__ */ React.createElement(Wrapper, { ...passthroughProps }, cartLine.quantity);
3012
+ }
3013
+ function CartLineQuantityAdjustButton(props) {
3014
+ const { status, linesRemove, linesUpdate } = useCart();
3015
+ const cartLine = useCartLine();
3016
+ const { children, adjust, onClick, ...passthroughProps } = props;
3017
+ const handleAdjust = React.useCallback(() => {
3018
+ if (adjust === "remove") {
3019
+ linesRemove([(cartLine == null ? void 0 : cartLine.id) ?? ""]);
3020
+ return;
3021
+ }
3022
+ const quantity = adjust === "decrease" ? ((cartLine == null ? void 0 : cartLine.quantity) ?? 0) - 1 : ((cartLine == null ? void 0 : cartLine.quantity) ?? 0) + 1;
3023
+ if (quantity <= 0) {
3024
+ linesRemove([(cartLine == null ? void 0 : cartLine.id) ?? ""]);
3025
+ return;
3026
+ }
3027
+ const lineUpdate = {
3028
+ id: (cartLine == null ? void 0 : cartLine.id) ?? "",
3029
+ quantity,
3030
+ attributes: (cartLine == null ? void 0 : cartLine.attributes) ?? []
3031
+ };
3032
+ linesUpdate([lineUpdate]);
3033
+ }, [
3034
+ adjust,
3035
+ cartLine == null ? void 0 : cartLine.attributes,
3036
+ cartLine == null ? void 0 : cartLine.id,
3037
+ cartLine == null ? void 0 : cartLine.quantity,
3038
+ linesRemove,
3039
+ linesUpdate
3040
+ ]);
3041
+ return /* @__PURE__ */ React.createElement(
3042
+ BaseButton,
3043
+ {
3044
+ onClick,
3045
+ defaultOnClick: handleAdjust,
3046
+ disabled: typeof passthroughProps.disabled !== "undefined" ? passthroughProps.disabled : status !== "idle",
3047
+ ...passthroughProps
3048
+ },
3049
+ children
3050
+ );
3051
+ }
3007
3052
  const storefrontApiCustomScalars = {
3008
3053
  // Keep in sync with the definitions in the app/nextjs/codegen.ts!
3009
3054
  DateTime: "string",
@@ -3819,6 +3864,8 @@
3819
3864
  exports2.CartCost = CartCost;
3820
3865
  exports2.CartLinePrice = CartLinePrice;
3821
3866
  exports2.CartLineProvider = CartLineProvider;
3867
+ exports2.CartLineQuantity = CartLineQuantity;
3868
+ exports2.CartLineQuantityAdjustButton = CartLineQuantityAdjustButton;
3822
3869
  exports2.CartProvider = CartProvider;
3823
3870
  exports2.ExternalVideo = ExternalVideo;
3824
3871
  exports2.Image = Image;