@wix/headless-stores 0.0.68 → 0.0.70

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.
@@ -641,3 +641,49 @@ export declare const ProductMediaGallery: React.ForwardRefExoticComponent<Produc
641
641
  * Alias for ProductMediaGallery to match the documented API
642
642
  */
643
643
  export { ProductMediaGallery as MediaGallery };
644
+ /**
645
+ * Props for Product Action components following the documented API
646
+ */
647
+ export interface ProductActionProps {
648
+ /** Whether to render as a child component */
649
+ asChild?: boolean;
650
+ /** Text label for the button */
651
+ label: string;
652
+ /** Custom render function when using asChild */
653
+ children?: AsChildChildren<{
654
+ disabled: boolean;
655
+ isLoading: boolean;
656
+ onClick: () => Promise<void>;
657
+ }>;
658
+ /** CSS classes to apply to the button */
659
+ className?: string;
660
+ /** Content to display when loading */
661
+ loadingState?: string | React.ReactNode;
662
+ }
663
+ /**
664
+ * Add to cart action button component following the documented API.
665
+ * Automatically integrates with the selected variant and handles loading states.
666
+ */
667
+ export declare const ProductActionAddToCart: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
668
+ /**
669
+ * Buy Now action button component following the documented API.
670
+ * Bypasses the cart and redirects directly to checkout.
671
+ */
672
+ export declare const ProductActionBuyNow: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
673
+ /**
674
+ * Pre-Order action button component following the documented API.
675
+ * Handles pre-order functionality when products are not in stock.
676
+ */
677
+ export declare const ProductActionPreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
678
+ /**
679
+ * Actions namespace containing all product action components
680
+ * following the documented API: Product.Action.AddToCart, Product.Action.BuyNow, Product.Action.PreOrder
681
+ */
682
+ export declare const Action: {
683
+ /** Add to cart action button */
684
+ readonly AddToCart: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
685
+ /** Buy now action button */
686
+ readonly BuyNow: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
687
+ /** Pre-order action button */
688
+ readonly PreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
689
+ };
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { InventoryAvailabilityStatus } from '@wix/auto_sdk_stores_products-v-3';
3
3
  import React from 'react';
4
+ import { Commerce } from '@wix/headless-ecom/react';
4
5
  import { AsChildSlot } from '@wix/headless-utils/react';
5
6
  import { MediaGallery } from '@wix/headless-media/react';
6
7
  import * as CoreProduct from './core/Product.js';
@@ -49,6 +50,10 @@ var TestIds;
49
50
  TestIds["productModifierOptions"] = "product-modifier-options";
50
51
  TestIds["productModifierOption"] = "product-modifier-option";
51
52
  TestIds["productMediaGallery"] = "product-media-gallery";
53
+ TestIds["productAddToCart"] = "product-add-to-cart";
54
+ TestIds["productActionAddToCart"] = "product-action-add-to-cart";
55
+ TestIds["productActionBuyNow"] = "product-action-buy-now";
56
+ TestIds["productActionPreOrder"] = "product-action-pre-order";
52
57
  })(TestIds || (TestIds = {}));
53
58
  /**
54
59
  * Root component that provides all necessary service contexts for a complete product experience.
@@ -674,3 +679,82 @@ export const ProductMediaGallery = React.forwardRef((props, ref) => {
674
679
  * Alias for ProductMediaGallery to match the documented API
675
680
  */
676
681
  export { ProductMediaGallery as MediaGallery };
682
+ /**
683
+ * Add to cart action button component following the documented API.
684
+ * Automatically integrates with the selected variant and handles loading states.
685
+ */
686
+ export const ProductActionAddToCart = React.forwardRef((props, ref) => {
687
+ const { asChild, children, className, label, loadingState } = props;
688
+ return (_jsx(SelectedVariant.Actions, { children: ({ lineItems, canAddToCart, isLoading, addToCart, isPreOrderEnabled, }) => {
689
+ if (isPreOrderEnabled) {
690
+ return null;
691
+ }
692
+ const onClick = addToCart;
693
+ const disabled = !canAddToCart || isLoading;
694
+ if (asChild && children) {
695
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productActionAddToCart, "data-in-progress": isLoading, customElement: children, customElementProps: {
696
+ disabled,
697
+ isLoading,
698
+ onClick,
699
+ } }));
700
+ }
701
+ return (_jsx(Commerce.Actions.AddToCart, { ref: ref, label: label, lineItems: lineItems, className: className, disabled: disabled, loadingState: loadingState, "data-testid": TestIds.productActionAddToCart, "data-in-progress": isLoading }));
702
+ } }));
703
+ });
704
+ /**
705
+ * Buy Now action button component following the documented API.
706
+ * Bypasses the cart and redirects directly to checkout.
707
+ */
708
+ export const ProductActionBuyNow = React.forwardRef((props, ref) => {
709
+ const { asChild, children, className, label, loadingState } = props;
710
+ return (_jsx(SelectedVariant.Actions, { children: ({ lineItems, canAddToCart, isLoading, buyNow, inStock, isPreOrderEnabled, }) => {
711
+ if (!inStock || isPreOrderEnabled) {
712
+ return null;
713
+ }
714
+ const onClick = buyNow;
715
+ const disabled = !canAddToCart || isLoading;
716
+ if (asChild && children) {
717
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productActionBuyNow, "data-in-progress": isLoading, customElement: children, customElementProps: {
718
+ disabled,
719
+ isLoading,
720
+ onClick,
721
+ } }));
722
+ }
723
+ return (_jsx(Commerce.Actions.BuyNow, { ref: ref, label: label, lineItems: lineItems, className: className, disabled: disabled, loadingState: loadingState, "data-testid": TestIds.productActionBuyNow, "data-in-progress": isLoading }));
724
+ } }));
725
+ });
726
+ /**
727
+ * Pre-Order action button component following the documented API.
728
+ * Handles pre-order functionality when products are not in stock.
729
+ */
730
+ export const ProductActionPreOrder = React.forwardRef((props, ref) => {
731
+ const { asChild, children, className, label, loadingState } = props;
732
+ return (_jsx(SelectedVariant.Actions, { children: ({ lineItems, isLoading, addToCart, isPreOrderEnabled }) => {
733
+ if (!isPreOrderEnabled) {
734
+ return null;
735
+ }
736
+ const canPreOrder = !isLoading;
737
+ const onClick = addToCart;
738
+ const disabled = !canPreOrder;
739
+ if (asChild && children) {
740
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productActionPreOrder, "data-in-progress": isLoading, customElement: children, customElementProps: {
741
+ disabled,
742
+ isLoading,
743
+ onClick,
744
+ } }));
745
+ }
746
+ return (_jsx(Commerce.Actions.AddToCart, { ref: ref, label: label, lineItems: lineItems, className: className, disabled: disabled, loadingState: loadingState, "data-testid": TestIds.productActionPreOrder, "data-in-progress": isLoading }));
747
+ } }));
748
+ });
749
+ /**
750
+ * Actions namespace containing all product action components
751
+ * following the documented API: Product.Action.AddToCart, Product.Action.BuyNow, Product.Action.PreOrder
752
+ */
753
+ export const Action = {
754
+ /** Add to cart action button */
755
+ AddToCart: ProductActionAddToCart,
756
+ /** Buy now action button */
757
+ BuyNow: ProductActionBuyNow,
758
+ /** Pre-order action button */
759
+ PreOrder: ProductActionPreOrder,
760
+ };
@@ -1,4 +1,5 @@
1
1
  import { SelectedVariantServiceConfig } from '../../services/selected-variant-service.js';
2
+ import { type LineItem } from '@wix/headless-ecom/services';
2
3
  export interface RootProps {
3
4
  children: React.ReactNode;
4
5
  selectedVariantServiceConfig?: SelectedVariantServiceConfig;
@@ -177,6 +178,8 @@ export interface ActionsRenderProps {
177
178
  addToCart: () => Promise<void>;
178
179
  /** Function to buy now (clear cart, add product, proceed to checkout) */
179
180
  buyNow: () => Promise<void>;
181
+ /** Line items */
182
+ lineItems: LineItem[];
180
183
  /** Whether add to cart is available */
181
184
  canAddToCart: boolean;
182
185
  /** Whether add to cart is currently loading */
@@ -245,6 +245,7 @@ export function Actions(props) {
245
245
  return variantService.createLineItems(quantity, modifiersData);
246
246
  };
247
247
  const commonProps = {
248
+ lineItems: getLineItems(),
248
249
  addToCart,
249
250
  canAddToCart,
250
251
  isLoading,
@@ -641,3 +641,49 @@ export declare const ProductMediaGallery: React.ForwardRefExoticComponent<Produc
641
641
  * Alias for ProductMediaGallery to match the documented API
642
642
  */
643
643
  export { ProductMediaGallery as MediaGallery };
644
+ /**
645
+ * Props for Product Action components following the documented API
646
+ */
647
+ export interface ProductActionProps {
648
+ /** Whether to render as a child component */
649
+ asChild?: boolean;
650
+ /** Text label for the button */
651
+ label: string;
652
+ /** Custom render function when using asChild */
653
+ children?: AsChildChildren<{
654
+ disabled: boolean;
655
+ isLoading: boolean;
656
+ onClick: () => Promise<void>;
657
+ }>;
658
+ /** CSS classes to apply to the button */
659
+ className?: string;
660
+ /** Content to display when loading */
661
+ loadingState?: string | React.ReactNode;
662
+ }
663
+ /**
664
+ * Add to cart action button component following the documented API.
665
+ * Automatically integrates with the selected variant and handles loading states.
666
+ */
667
+ export declare const ProductActionAddToCart: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
668
+ /**
669
+ * Buy Now action button component following the documented API.
670
+ * Bypasses the cart and redirects directly to checkout.
671
+ */
672
+ export declare const ProductActionBuyNow: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
673
+ /**
674
+ * Pre-Order action button component following the documented API.
675
+ * Handles pre-order functionality when products are not in stock.
676
+ */
677
+ export declare const ProductActionPreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
678
+ /**
679
+ * Actions namespace containing all product action components
680
+ * following the documented API: Product.Action.AddToCart, Product.Action.BuyNow, Product.Action.PreOrder
681
+ */
682
+ export declare const Action: {
683
+ /** Add to cart action button */
684
+ readonly AddToCart: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
685
+ /** Buy now action button */
686
+ readonly BuyNow: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
687
+ /** Pre-order action button */
688
+ readonly PreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
689
+ };
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { InventoryAvailabilityStatus } from '@wix/auto_sdk_stores_products-v-3';
3
3
  import React from 'react';
4
+ import { Commerce } from '@wix/headless-ecom/react';
4
5
  import { AsChildSlot } from '@wix/headless-utils/react';
5
6
  import { MediaGallery } from '@wix/headless-media/react';
6
7
  import * as CoreProduct from './core/Product.js';
@@ -49,6 +50,10 @@ var TestIds;
49
50
  TestIds["productModifierOptions"] = "product-modifier-options";
50
51
  TestIds["productModifierOption"] = "product-modifier-option";
51
52
  TestIds["productMediaGallery"] = "product-media-gallery";
53
+ TestIds["productAddToCart"] = "product-add-to-cart";
54
+ TestIds["productActionAddToCart"] = "product-action-add-to-cart";
55
+ TestIds["productActionBuyNow"] = "product-action-buy-now";
56
+ TestIds["productActionPreOrder"] = "product-action-pre-order";
52
57
  })(TestIds || (TestIds = {}));
53
58
  /**
54
59
  * Root component that provides all necessary service contexts for a complete product experience.
@@ -674,3 +679,82 @@ export const ProductMediaGallery = React.forwardRef((props, ref) => {
674
679
  * Alias for ProductMediaGallery to match the documented API
675
680
  */
676
681
  export { ProductMediaGallery as MediaGallery };
682
+ /**
683
+ * Add to cart action button component following the documented API.
684
+ * Automatically integrates with the selected variant and handles loading states.
685
+ */
686
+ export const ProductActionAddToCart = React.forwardRef((props, ref) => {
687
+ const { asChild, children, className, label, loadingState } = props;
688
+ return (_jsx(SelectedVariant.Actions, { children: ({ lineItems, canAddToCart, isLoading, addToCart, isPreOrderEnabled, }) => {
689
+ if (isPreOrderEnabled) {
690
+ return null;
691
+ }
692
+ const onClick = addToCart;
693
+ const disabled = !canAddToCart || isLoading;
694
+ if (asChild && children) {
695
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productActionAddToCart, "data-in-progress": isLoading, customElement: children, customElementProps: {
696
+ disabled,
697
+ isLoading,
698
+ onClick,
699
+ } }));
700
+ }
701
+ return (_jsx(Commerce.Actions.AddToCart, { ref: ref, label: label, lineItems: lineItems, className: className, disabled: disabled, loadingState: loadingState, "data-testid": TestIds.productActionAddToCart, "data-in-progress": isLoading }));
702
+ } }));
703
+ });
704
+ /**
705
+ * Buy Now action button component following the documented API.
706
+ * Bypasses the cart and redirects directly to checkout.
707
+ */
708
+ export const ProductActionBuyNow = React.forwardRef((props, ref) => {
709
+ const { asChild, children, className, label, loadingState } = props;
710
+ return (_jsx(SelectedVariant.Actions, { children: ({ lineItems, canAddToCart, isLoading, buyNow, inStock, isPreOrderEnabled, }) => {
711
+ if (!inStock || isPreOrderEnabled) {
712
+ return null;
713
+ }
714
+ const onClick = buyNow;
715
+ const disabled = !canAddToCart || isLoading;
716
+ if (asChild && children) {
717
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productActionBuyNow, "data-in-progress": isLoading, customElement: children, customElementProps: {
718
+ disabled,
719
+ isLoading,
720
+ onClick,
721
+ } }));
722
+ }
723
+ return (_jsx(Commerce.Actions.BuyNow, { ref: ref, label: label, lineItems: lineItems, className: className, disabled: disabled, loadingState: loadingState, "data-testid": TestIds.productActionBuyNow, "data-in-progress": isLoading }));
724
+ } }));
725
+ });
726
+ /**
727
+ * Pre-Order action button component following the documented API.
728
+ * Handles pre-order functionality when products are not in stock.
729
+ */
730
+ export const ProductActionPreOrder = React.forwardRef((props, ref) => {
731
+ const { asChild, children, className, label, loadingState } = props;
732
+ return (_jsx(SelectedVariant.Actions, { children: ({ lineItems, isLoading, addToCart, isPreOrderEnabled }) => {
733
+ if (!isPreOrderEnabled) {
734
+ return null;
735
+ }
736
+ const canPreOrder = !isLoading;
737
+ const onClick = addToCart;
738
+ const disabled = !canPreOrder;
739
+ if (asChild && children) {
740
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productActionPreOrder, "data-in-progress": isLoading, customElement: children, customElementProps: {
741
+ disabled,
742
+ isLoading,
743
+ onClick,
744
+ } }));
745
+ }
746
+ return (_jsx(Commerce.Actions.AddToCart, { ref: ref, label: label, lineItems: lineItems, className: className, disabled: disabled, loadingState: loadingState, "data-testid": TestIds.productActionPreOrder, "data-in-progress": isLoading }));
747
+ } }));
748
+ });
749
+ /**
750
+ * Actions namespace containing all product action components
751
+ * following the documented API: Product.Action.AddToCart, Product.Action.BuyNow, Product.Action.PreOrder
752
+ */
753
+ export const Action = {
754
+ /** Add to cart action button */
755
+ AddToCart: ProductActionAddToCart,
756
+ /** Buy now action button */
757
+ BuyNow: ProductActionBuyNow,
758
+ /** Pre-order action button */
759
+ PreOrder: ProductActionPreOrder,
760
+ };
@@ -1,4 +1,5 @@
1
1
  import { SelectedVariantServiceConfig } from '../../services/selected-variant-service.js';
2
+ import { type LineItem } from '@wix/headless-ecom/services';
2
3
  export interface RootProps {
3
4
  children: React.ReactNode;
4
5
  selectedVariantServiceConfig?: SelectedVariantServiceConfig;
@@ -177,6 +178,8 @@ export interface ActionsRenderProps {
177
178
  addToCart: () => Promise<void>;
178
179
  /** Function to buy now (clear cart, add product, proceed to checkout) */
179
180
  buyNow: () => Promise<void>;
181
+ /** Line items */
182
+ lineItems: LineItem[];
180
183
  /** Whether add to cart is available */
181
184
  canAddToCart: boolean;
182
185
  /** Whether add to cart is currently loading */
@@ -245,6 +245,7 @@ export function Actions(props) {
245
245
  return variantService.createLineItems(quantity, modifiersData);
246
246
  };
247
247
  const commonProps = {
248
+ lineItems: getLineItems(),
248
249
  addToCart,
249
250
  canAddToCart,
250
251
  isLoading,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.68",
3
+ "version": "0.0.70",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
@@ -62,8 +62,8 @@
62
62
  "@wix/auto_sdk_stores_read-only-variants-v-3": "^1.0.23",
63
63
  "@wix/ecom": "^1.0.1278",
64
64
  "@wix/essentials": "^0.1.24",
65
- "@wix/headless-components": "0.0.6",
66
- "@wix/headless-ecom": "0.0.20",
65
+ "@wix/headless-components": "0.0.7",
66
+ "@wix/headless-ecom": "0.0.21",
67
67
  "@wix/headless-media": "0.0.11",
68
68
  "@wix/headless-utils": "0.0.3",
69
69
  "@wix/redirects": "^1.0.83",