@wix/headless-stores 0.0.83 → 0.0.85

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.
@@ -874,6 +874,80 @@ export declare const Action: {
874
874
  /** Pre-order action button */
875
875
  readonly PreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
876
876
  };
877
+ /**
878
+ * Props for ProductVariantStock component
879
+ */
880
+ export interface ProductVariantStockProps {
881
+ /** Whether to render as a child component */
882
+ asChild?: boolean;
883
+ /** Custom render function when using asChild */
884
+ children?: AsChildChildren<{
885
+ status: 'in-stock' | 'limited-stock' | 'out-of-stock' | 'pre-order';
886
+ label: string;
887
+ }>;
888
+ /** CSS classes to apply to the default element */
889
+ className?: string;
890
+ /** Custom labels for different stock states */
891
+ labels?: {
892
+ /** Label for in stock state */
893
+ inStock?: string;
894
+ /** Label for limited stock state (when quantity is low) */
895
+ limitedStock?: string;
896
+ /** Label for out of stock state */
897
+ outOfStock?: string;
898
+ /** Label for pre-order state */
899
+ preOrder?: string;
900
+ };
901
+ }
902
+ /**
903
+ * Displays the selected variant stock status with customizable rendering and labels,
904
+ * including pre-order support. Similar to Product.Stock but for the selected variant.
905
+ *
906
+ * @component
907
+ * @example
908
+ * ```tsx
909
+ * // Default usage
910
+ * <Product.ProductVariant.Stock
911
+ * className="stock-indicator"
912
+ * labels={{
913
+ * inStock: 'In Stock',
914
+ * limitedStock: 'Limited Stock',
915
+ * outOfStock: 'Out of Stock',
916
+ * preOrder: 'Available for Pre-order'
917
+ * }}
918
+ * />
919
+ *
920
+ * // asChild with primitive
921
+ * <Product.ProductVariant.Stock asChild>
922
+ * <div className="variant-stock-status" />
923
+ * </Product.ProductVariant.Stock>
924
+ *
925
+ * // asChild with react component
926
+ * <Product.ProductVariant.Stock
927
+ * labels={{
928
+ * inStock: 'Available',
929
+ * limitedStock: 'Low Stock',
930
+ * outOfStock: 'Sold Out',
931
+ * preOrder: 'Pre-order Now'
932
+ * }}
933
+ * asChild
934
+ * >
935
+ * {React.forwardRef(({status, label, ...props}, ref) => (
936
+ * <div
937
+ * ref={ref}
938
+ * {...props}
939
+ * className="flex items-center gap-2 data-[state='in-stock']:text-green-600 data-[state='limited-stock']:text-yellow-600 data-[state='out-of-stock']:text-red-600 data-[state='pre-order']:text-blue-600"
940
+ * >
941
+ * <div className="w-3 h-3 rounded-full data-[state='in-stock']:bg-green-500 data-[state='limited-stock']:bg-yellow-500 data-[state='out-of-stock']:bg-red-500 data-[state='pre-order']:bg-blue-500" />
942
+ * <span className="text-sm font-medium">
943
+ * {label}
944
+ * </span>
945
+ * </div>
946
+ * ))}
947
+ * </Product.ProductVariant.Stock>
948
+ * ```
949
+ */
950
+ export declare const ProductVariantStock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
877
951
  /**
878
952
  * Props for ProductVariantSKU component
879
953
  */
@@ -952,9 +1026,11 @@ export interface ProductVariantWeightProps {
952
1026
  export declare const ProductVariantWeight: React.ForwardRefExoticComponent<ProductVariantWeightProps & React.RefAttributes<HTMLElement>>;
953
1027
  /**
954
1028
  * ProductVariant namespace containing product variant components
955
- * following the compound component pattern: Product.ProductVariant.SKU, Product.ProductVariant.Weight
1029
+ * following the compound component pattern: Product.ProductVariant.Stock, Product.ProductVariant.SKU, Product.ProductVariant.Weight
956
1030
  */
957
1031
  export declare const ProductVariant: {
1032
+ /** Product variant stock component */
1033
+ readonly Stock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
958
1034
  /** Product variant SKU component */
959
1035
  readonly SKU: React.ForwardRefExoticComponent<ProductVariantSKUProps & React.RefAttributes<HTMLElement>>;
960
1036
  /** Product variant weight component */
@@ -51,6 +51,7 @@ var TestIds;
51
51
  TestIds["productVariant"] = "product-variant";
52
52
  TestIds["productVariantSku"] = "product-variant-sku";
53
53
  TestIds["productVariantWeight"] = "product-variant-weight";
54
+ TestIds["productVariantStock"] = "product-variant-stock";
54
55
  TestIds["productModifiers"] = "product-modifiers";
55
56
  TestIds["productModifierOptions"] = "product-modifier-options";
56
57
  TestIds["productModifierOption"] = "product-modifier-option";
@@ -949,6 +950,113 @@ export const Action = {
949
950
  /** Pre-order action button */
950
951
  PreOrder: ProductActionPreOrder,
951
952
  };
953
+ /**
954
+ * Helper function to determine stock status and label based on availability and pre-order settings
955
+ */
956
+ function getStockStatusMessage(inStock, isPreOrderEnabled, availabilityStatus, labels) {
957
+ // Pre-order takes precedence
958
+ if (isPreOrderEnabled) {
959
+ return {
960
+ status: 'pre-order',
961
+ label: labels.preOrder,
962
+ };
963
+ }
964
+ // Handle stock status based on availability
965
+ if (inStock) {
966
+ switch (availabilityStatus) {
967
+ case InventoryAvailabilityStatus.IN_STOCK:
968
+ return {
969
+ status: 'in-stock',
970
+ label: labels.inStock,
971
+ };
972
+ case InventoryAvailabilityStatus.PARTIALLY_OUT_OF_STOCK:
973
+ return {
974
+ status: 'limited-stock',
975
+ label: labels.limitedStock,
976
+ };
977
+ default:
978
+ return {
979
+ status: 'in-stock',
980
+ label: labels.inStock,
981
+ };
982
+ }
983
+ }
984
+ return {
985
+ status: 'out-of-stock',
986
+ label: labels.outOfStock,
987
+ };
988
+ }
989
+ /**
990
+ * Displays the selected variant stock status with customizable rendering and labels,
991
+ * including pre-order support. Similar to Product.Stock but for the selected variant.
992
+ *
993
+ * @component
994
+ * @example
995
+ * ```tsx
996
+ * // Default usage
997
+ * <Product.ProductVariant.Stock
998
+ * className="stock-indicator"
999
+ * labels={{
1000
+ * inStock: 'In Stock',
1001
+ * limitedStock: 'Limited Stock',
1002
+ * outOfStock: 'Out of Stock',
1003
+ * preOrder: 'Available for Pre-order'
1004
+ * }}
1005
+ * />
1006
+ *
1007
+ * // asChild with primitive
1008
+ * <Product.ProductVariant.Stock asChild>
1009
+ * <div className="variant-stock-status" />
1010
+ * </Product.ProductVariant.Stock>
1011
+ *
1012
+ * // asChild with react component
1013
+ * <Product.ProductVariant.Stock
1014
+ * labels={{
1015
+ * inStock: 'Available',
1016
+ * limitedStock: 'Low Stock',
1017
+ * outOfStock: 'Sold Out',
1018
+ * preOrder: 'Pre-order Now'
1019
+ * }}
1020
+ * asChild
1021
+ * >
1022
+ * {React.forwardRef(({status, label, ...props}, ref) => (
1023
+ * <div
1024
+ * ref={ref}
1025
+ * {...props}
1026
+ * className="flex items-center gap-2 data-[state='in-stock']:text-green-600 data-[state='limited-stock']:text-yellow-600 data-[state='out-of-stock']:text-red-600 data-[state='pre-order']:text-blue-600"
1027
+ * >
1028
+ * <div className="w-3 h-3 rounded-full data-[state='in-stock']:bg-green-500 data-[state='limited-stock']:bg-yellow-500 data-[state='out-of-stock']:bg-red-500 data-[state='pre-order']:bg-blue-500" />
1029
+ * <span className="text-sm font-medium">
1030
+ * {label}
1031
+ * </span>
1032
+ * </div>
1033
+ * ))}
1034
+ * </Product.ProductVariant.Stock>
1035
+ * ```
1036
+ */
1037
+ export const ProductVariantStock = React.forwardRef((props, ref) => {
1038
+ const { asChild, children, className, labels } = props;
1039
+ return (_jsx(ProductVariantSelector.Stock, { children: ({ inStock, isPreOrderEnabled, availabilityStatus, currentVariantId, }) => {
1040
+ // Only render if we have a current variant selected
1041
+ if (!currentVariantId && !availabilityStatus) {
1042
+ return null;
1043
+ }
1044
+ // Default labels
1045
+ const defaultLabels = {
1046
+ inStock: 'In Stock',
1047
+ limitedStock: 'Limited Stock',
1048
+ outOfStock: 'Out of Stock',
1049
+ preOrder: 'Available for Pre-order',
1050
+ };
1051
+ const finalLabels = { ...defaultLabels, ...labels };
1052
+ // Get status and label using the helper function
1053
+ const { status, label } = getStockStatusMessage(inStock, isPreOrderEnabled, availabilityStatus, finalLabels);
1054
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productVariantStock, "data-state": status, customElement: children, customElementProps: {
1055
+ status,
1056
+ label,
1057
+ }, content: label, children: _jsx("span", { children: label }) }));
1058
+ } }));
1059
+ });
952
1060
  /**
953
1061
  * Displays the selected variant SKU with customizable rendering following the documented API.
954
1062
  *
@@ -1019,9 +1127,11 @@ export const ProductVariantWeight = React.forwardRef((props, ref) => {
1019
1127
  });
1020
1128
  /**
1021
1129
  * ProductVariant namespace containing product variant components
1022
- * following the compound component pattern: Product.ProductVariant.SKU, Product.ProductVariant.Weight
1130
+ * following the compound component pattern: Product.ProductVariant.Stock, Product.ProductVariant.SKU, Product.ProductVariant.Weight
1023
1131
  */
1024
1132
  export const ProductVariant = {
1133
+ /** Product variant stock component */
1134
+ Stock: ProductVariantStock,
1025
1135
  /** Product variant SKU component */
1026
1136
  SKU: ProductVariantSKU,
1027
1137
  /** Product variant weight component */
@@ -54,7 +54,9 @@ export const Root = React.forwardRef((props, ref) => {
54
54
  pagingMetadata: {
55
55
  count: products?.length || 0,
56
56
  },
57
- aggregations: {}, // Empty aggregation data
57
+ aggregations: {
58
+ results: [],
59
+ }, // Empty aggregation data
58
60
  customizations: [],
59
61
  };
60
62
  return (_jsx(CoreProductList.Root, { productsListConfig: serviceConfig, children: _jsx(RootContent, { children: children, className: className, ref: ref }) }));
@@ -874,6 +874,80 @@ export declare const Action: {
874
874
  /** Pre-order action button */
875
875
  readonly PreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
876
876
  };
877
+ /**
878
+ * Props for ProductVariantStock component
879
+ */
880
+ export interface ProductVariantStockProps {
881
+ /** Whether to render as a child component */
882
+ asChild?: boolean;
883
+ /** Custom render function when using asChild */
884
+ children?: AsChildChildren<{
885
+ status: 'in-stock' | 'limited-stock' | 'out-of-stock' | 'pre-order';
886
+ label: string;
887
+ }>;
888
+ /** CSS classes to apply to the default element */
889
+ className?: string;
890
+ /** Custom labels for different stock states */
891
+ labels?: {
892
+ /** Label for in stock state */
893
+ inStock?: string;
894
+ /** Label for limited stock state (when quantity is low) */
895
+ limitedStock?: string;
896
+ /** Label for out of stock state */
897
+ outOfStock?: string;
898
+ /** Label for pre-order state */
899
+ preOrder?: string;
900
+ };
901
+ }
902
+ /**
903
+ * Displays the selected variant stock status with customizable rendering and labels,
904
+ * including pre-order support. Similar to Product.Stock but for the selected variant.
905
+ *
906
+ * @component
907
+ * @example
908
+ * ```tsx
909
+ * // Default usage
910
+ * <Product.ProductVariant.Stock
911
+ * className="stock-indicator"
912
+ * labels={{
913
+ * inStock: 'In Stock',
914
+ * limitedStock: 'Limited Stock',
915
+ * outOfStock: 'Out of Stock',
916
+ * preOrder: 'Available for Pre-order'
917
+ * }}
918
+ * />
919
+ *
920
+ * // asChild with primitive
921
+ * <Product.ProductVariant.Stock asChild>
922
+ * <div className="variant-stock-status" />
923
+ * </Product.ProductVariant.Stock>
924
+ *
925
+ * // asChild with react component
926
+ * <Product.ProductVariant.Stock
927
+ * labels={{
928
+ * inStock: 'Available',
929
+ * limitedStock: 'Low Stock',
930
+ * outOfStock: 'Sold Out',
931
+ * preOrder: 'Pre-order Now'
932
+ * }}
933
+ * asChild
934
+ * >
935
+ * {React.forwardRef(({status, label, ...props}, ref) => (
936
+ * <div
937
+ * ref={ref}
938
+ * {...props}
939
+ * className="flex items-center gap-2 data-[state='in-stock']:text-green-600 data-[state='limited-stock']:text-yellow-600 data-[state='out-of-stock']:text-red-600 data-[state='pre-order']:text-blue-600"
940
+ * >
941
+ * <div className="w-3 h-3 rounded-full data-[state='in-stock']:bg-green-500 data-[state='limited-stock']:bg-yellow-500 data-[state='out-of-stock']:bg-red-500 data-[state='pre-order']:bg-blue-500" />
942
+ * <span className="text-sm font-medium">
943
+ * {label}
944
+ * </span>
945
+ * </div>
946
+ * ))}
947
+ * </Product.ProductVariant.Stock>
948
+ * ```
949
+ */
950
+ export declare const ProductVariantStock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
877
951
  /**
878
952
  * Props for ProductVariantSKU component
879
953
  */
@@ -952,9 +1026,11 @@ export interface ProductVariantWeightProps {
952
1026
  export declare const ProductVariantWeight: React.ForwardRefExoticComponent<ProductVariantWeightProps & React.RefAttributes<HTMLElement>>;
953
1027
  /**
954
1028
  * ProductVariant namespace containing product variant components
955
- * following the compound component pattern: Product.ProductVariant.SKU, Product.ProductVariant.Weight
1029
+ * following the compound component pattern: Product.ProductVariant.Stock, Product.ProductVariant.SKU, Product.ProductVariant.Weight
956
1030
  */
957
1031
  export declare const ProductVariant: {
1032
+ /** Product variant stock component */
1033
+ readonly Stock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
958
1034
  /** Product variant SKU component */
959
1035
  readonly SKU: React.ForwardRefExoticComponent<ProductVariantSKUProps & React.RefAttributes<HTMLElement>>;
960
1036
  /** Product variant weight component */
@@ -51,6 +51,7 @@ var TestIds;
51
51
  TestIds["productVariant"] = "product-variant";
52
52
  TestIds["productVariantSku"] = "product-variant-sku";
53
53
  TestIds["productVariantWeight"] = "product-variant-weight";
54
+ TestIds["productVariantStock"] = "product-variant-stock";
54
55
  TestIds["productModifiers"] = "product-modifiers";
55
56
  TestIds["productModifierOptions"] = "product-modifier-options";
56
57
  TestIds["productModifierOption"] = "product-modifier-option";
@@ -949,6 +950,113 @@ export const Action = {
949
950
  /** Pre-order action button */
950
951
  PreOrder: ProductActionPreOrder,
951
952
  };
953
+ /**
954
+ * Helper function to determine stock status and label based on availability and pre-order settings
955
+ */
956
+ function getStockStatusMessage(inStock, isPreOrderEnabled, availabilityStatus, labels) {
957
+ // Pre-order takes precedence
958
+ if (isPreOrderEnabled) {
959
+ return {
960
+ status: 'pre-order',
961
+ label: labels.preOrder,
962
+ };
963
+ }
964
+ // Handle stock status based on availability
965
+ if (inStock) {
966
+ switch (availabilityStatus) {
967
+ case InventoryAvailabilityStatus.IN_STOCK:
968
+ return {
969
+ status: 'in-stock',
970
+ label: labels.inStock,
971
+ };
972
+ case InventoryAvailabilityStatus.PARTIALLY_OUT_OF_STOCK:
973
+ return {
974
+ status: 'limited-stock',
975
+ label: labels.limitedStock,
976
+ };
977
+ default:
978
+ return {
979
+ status: 'in-stock',
980
+ label: labels.inStock,
981
+ };
982
+ }
983
+ }
984
+ return {
985
+ status: 'out-of-stock',
986
+ label: labels.outOfStock,
987
+ };
988
+ }
989
+ /**
990
+ * Displays the selected variant stock status with customizable rendering and labels,
991
+ * including pre-order support. Similar to Product.Stock but for the selected variant.
992
+ *
993
+ * @component
994
+ * @example
995
+ * ```tsx
996
+ * // Default usage
997
+ * <Product.ProductVariant.Stock
998
+ * className="stock-indicator"
999
+ * labels={{
1000
+ * inStock: 'In Stock',
1001
+ * limitedStock: 'Limited Stock',
1002
+ * outOfStock: 'Out of Stock',
1003
+ * preOrder: 'Available for Pre-order'
1004
+ * }}
1005
+ * />
1006
+ *
1007
+ * // asChild with primitive
1008
+ * <Product.ProductVariant.Stock asChild>
1009
+ * <div className="variant-stock-status" />
1010
+ * </Product.ProductVariant.Stock>
1011
+ *
1012
+ * // asChild with react component
1013
+ * <Product.ProductVariant.Stock
1014
+ * labels={{
1015
+ * inStock: 'Available',
1016
+ * limitedStock: 'Low Stock',
1017
+ * outOfStock: 'Sold Out',
1018
+ * preOrder: 'Pre-order Now'
1019
+ * }}
1020
+ * asChild
1021
+ * >
1022
+ * {React.forwardRef(({status, label, ...props}, ref) => (
1023
+ * <div
1024
+ * ref={ref}
1025
+ * {...props}
1026
+ * className="flex items-center gap-2 data-[state='in-stock']:text-green-600 data-[state='limited-stock']:text-yellow-600 data-[state='out-of-stock']:text-red-600 data-[state='pre-order']:text-blue-600"
1027
+ * >
1028
+ * <div className="w-3 h-3 rounded-full data-[state='in-stock']:bg-green-500 data-[state='limited-stock']:bg-yellow-500 data-[state='out-of-stock']:bg-red-500 data-[state='pre-order']:bg-blue-500" />
1029
+ * <span className="text-sm font-medium">
1030
+ * {label}
1031
+ * </span>
1032
+ * </div>
1033
+ * ))}
1034
+ * </Product.ProductVariant.Stock>
1035
+ * ```
1036
+ */
1037
+ export const ProductVariantStock = React.forwardRef((props, ref) => {
1038
+ const { asChild, children, className, labels } = props;
1039
+ return (_jsx(ProductVariantSelector.Stock, { children: ({ inStock, isPreOrderEnabled, availabilityStatus, currentVariantId, }) => {
1040
+ // Only render if we have a current variant selected
1041
+ if (!currentVariantId && !availabilityStatus) {
1042
+ return null;
1043
+ }
1044
+ // Default labels
1045
+ const defaultLabels = {
1046
+ inStock: 'In Stock',
1047
+ limitedStock: 'Limited Stock',
1048
+ outOfStock: 'Out of Stock',
1049
+ preOrder: 'Available for Pre-order',
1050
+ };
1051
+ const finalLabels = { ...defaultLabels, ...labels };
1052
+ // Get status and label using the helper function
1053
+ const { status, label } = getStockStatusMessage(inStock, isPreOrderEnabled, availabilityStatus, finalLabels);
1054
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productVariantStock, "data-state": status, customElement: children, customElementProps: {
1055
+ status,
1056
+ label,
1057
+ }, content: label, children: _jsx("span", { children: label }) }));
1058
+ } }));
1059
+ });
952
1060
  /**
953
1061
  * Displays the selected variant SKU with customizable rendering following the documented API.
954
1062
  *
@@ -1019,9 +1127,11 @@ export const ProductVariantWeight = React.forwardRef((props, ref) => {
1019
1127
  });
1020
1128
  /**
1021
1129
  * ProductVariant namespace containing product variant components
1022
- * following the compound component pattern: Product.ProductVariant.SKU, Product.ProductVariant.Weight
1130
+ * following the compound component pattern: Product.ProductVariant.Stock, Product.ProductVariant.SKU, Product.ProductVariant.Weight
1023
1131
  */
1024
1132
  export const ProductVariant = {
1133
+ /** Product variant stock component */
1134
+ Stock: ProductVariantStock,
1025
1135
  /** Product variant SKU component */
1026
1136
  SKU: ProductVariantSKU,
1027
1137
  /** Product variant weight component */
@@ -54,7 +54,9 @@ export const Root = React.forwardRef((props, ref) => {
54
54
  pagingMetadata: {
55
55
  count: products?.length || 0,
56
56
  },
57
- aggregations: {}, // Empty aggregation data
57
+ aggregations: {
58
+ results: [],
59
+ }, // Empty aggregation data
58
60
  customizations: [],
59
61
  };
60
62
  return (_jsx(CoreProductList.Root, { productsListConfig: serviceConfig, children: _jsx(RootContent, { children: children, className: className, ref: ref }) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.83",
3
+ "version": "0.0.85",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
@@ -63,7 +63,7 @@
63
63
  "@wix/ecom": "^1.0.1278",
64
64
  "@wix/essentials": "^0.1.24",
65
65
  "@wix/headless-components": "0.0.12",
66
- "@wix/headless-ecom": "0.0.26",
66
+ "@wix/headless-ecom": "0.0.27",
67
67
  "@wix/headless-media": "0.0.11",
68
68
  "@wix/headless-utils": "0.0.3",
69
69
  "@wix/redirects": "^1.0.83",