@wix/headless-stores 0.0.84 → 0.0.86
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.
- package/cjs/dist/react/Product.d.ts +89 -5
- package/cjs/dist/react/Product.js +115 -5
- package/dist/react/Product.d.ts +89 -5
- package/dist/react/Product.js +115 -5
- package/package.json +1 -1
|
@@ -24,6 +24,14 @@ interface ModifiersContextValue {
|
|
|
24
24
|
* Hook to access modifiers context
|
|
25
25
|
*/
|
|
26
26
|
export declare function useModifiersContext(): ModifiersContextValue;
|
|
27
|
+
/**
|
|
28
|
+
* Basic stock status type for product availability states
|
|
29
|
+
*/
|
|
30
|
+
export type BasicStockStatus = 'in-stock' | 'limited-stock' | 'out-of-stock';
|
|
31
|
+
/**
|
|
32
|
+
* Extended stock status type including pre-order capability
|
|
33
|
+
*/
|
|
34
|
+
export type StockStatus = BasicStockStatus | 'can-pre-order';
|
|
27
35
|
/**
|
|
28
36
|
* Props for the Product root component following the documented API
|
|
29
37
|
*/
|
|
@@ -328,7 +336,7 @@ export interface StockProps {
|
|
|
328
336
|
asChild?: boolean;
|
|
329
337
|
/** Custom render function when using asChild */
|
|
330
338
|
children?: AsChildChildren<{
|
|
331
|
-
status:
|
|
339
|
+
status: BasicStockStatus;
|
|
332
340
|
label: string;
|
|
333
341
|
}>;
|
|
334
342
|
/** CSS classes to apply to the default element */
|
|
@@ -675,7 +683,7 @@ export interface ProductQuantitySubComponentProps {
|
|
|
675
683
|
}
|
|
676
684
|
/**
|
|
677
685
|
* Product quantity selector component that integrates with the selected variant.
|
|
678
|
-
* Provides quantity controls with stock validation and pre-order support.
|
|
686
|
+
* Provides quantity controls with stock validation and can-pre-order support.
|
|
679
687
|
* Uses a compound component pattern with Root, Decrement, Input, Increment, and Raw sub-components.
|
|
680
688
|
*
|
|
681
689
|
* @component
|
|
@@ -737,7 +745,7 @@ export interface ProductQuantitySubComponentProps {
|
|
|
737
745
|
export declare const ProductQuantity: React.ForwardRefExoticComponent<ProductQuantityProps & React.RefAttributes<HTMLDivElement>>;
|
|
738
746
|
/**
|
|
739
747
|
* Product Quantity Decrement component.
|
|
740
|
-
* Automatically handles disabled state based on stock and pre-order settings.
|
|
748
|
+
* Automatically handles disabled state based on stock and can-pre-order settings.
|
|
741
749
|
* Must be used within Product.Quantity.Root.
|
|
742
750
|
*
|
|
743
751
|
* @component
|
|
@@ -859,7 +867,7 @@ export declare const ProductActionAddToCart: React.ForwardRefExoticComponent<Pro
|
|
|
859
867
|
export declare const ProductActionBuyNow: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
860
868
|
/**
|
|
861
869
|
* Pre-Order action button component following the documented API.
|
|
862
|
-
* Handles pre-order functionality when products are not in stock.
|
|
870
|
+
* Handles can-pre-order functionality when products are not in stock.
|
|
863
871
|
*/
|
|
864
872
|
export declare const ProductActionPreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
865
873
|
/**
|
|
@@ -874,6 +882,80 @@ export declare const Action: {
|
|
|
874
882
|
/** Pre-order action button */
|
|
875
883
|
readonly PreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
876
884
|
};
|
|
885
|
+
/**
|
|
886
|
+
* Props for ProductVariantStock component
|
|
887
|
+
*/
|
|
888
|
+
export interface ProductVariantStockProps {
|
|
889
|
+
/** Whether to render as a child component */
|
|
890
|
+
asChild?: boolean;
|
|
891
|
+
/** Custom render function when using asChild */
|
|
892
|
+
children?: AsChildChildren<{
|
|
893
|
+
status: StockStatus;
|
|
894
|
+
label: string;
|
|
895
|
+
}>;
|
|
896
|
+
/** CSS classes to apply to the default element */
|
|
897
|
+
className?: string;
|
|
898
|
+
/** Custom labels for different stock states */
|
|
899
|
+
labels?: {
|
|
900
|
+
/** Label for in stock state */
|
|
901
|
+
inStock?: string;
|
|
902
|
+
/** Label for limited stock state (when quantity is low) */
|
|
903
|
+
limitedStock?: string;
|
|
904
|
+
/** Label for out of stock state */
|
|
905
|
+
outOfStock?: string;
|
|
906
|
+
/** Label for can-pre-order state */
|
|
907
|
+
preOrder?: string;
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Displays the selected variant stock status with customizable rendering and labels,
|
|
912
|
+
* including can-pre-order support. Similar to Product.Stock but for the selected variant.
|
|
913
|
+
*
|
|
914
|
+
* @component
|
|
915
|
+
* @example
|
|
916
|
+
* ```tsx
|
|
917
|
+
* // Default usage
|
|
918
|
+
* <Product.ProductVariant.Stock
|
|
919
|
+
* className="stock-indicator"
|
|
920
|
+
* labels={{
|
|
921
|
+
* inStock: 'In Stock',
|
|
922
|
+
* limitedStock: 'Limited Stock',
|
|
923
|
+
* outOfStock: 'Out of Stock',
|
|
924
|
+
* preOrder: 'Available for Pre-order'
|
|
925
|
+
* }}
|
|
926
|
+
* />
|
|
927
|
+
*
|
|
928
|
+
* // asChild with primitive
|
|
929
|
+
* <Product.ProductVariant.Stock asChild>
|
|
930
|
+
* <div className="variant-stock-status" />
|
|
931
|
+
* </Product.ProductVariant.Stock>
|
|
932
|
+
*
|
|
933
|
+
* // asChild with react component
|
|
934
|
+
* <Product.ProductVariant.Stock
|
|
935
|
+
* labels={{
|
|
936
|
+
* inStock: 'Available',
|
|
937
|
+
* limitedStock: 'Low Stock',
|
|
938
|
+
* outOfStock: 'Sold Out',
|
|
939
|
+
* preOrder: 'Pre-order Now'
|
|
940
|
+
* }}
|
|
941
|
+
* asChild
|
|
942
|
+
* >
|
|
943
|
+
* {React.forwardRef(({status, label, ...props}, ref) => (
|
|
944
|
+
* <div
|
|
945
|
+
* ref={ref}
|
|
946
|
+
* {...props}
|
|
947
|
+
* 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='can-pre-order']:text-blue-600"
|
|
948
|
+
* >
|
|
949
|
+
* <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='can-pre-order']:bg-blue-500" />
|
|
950
|
+
* <span className="text-sm font-medium">
|
|
951
|
+
* {label}
|
|
952
|
+
* </span>
|
|
953
|
+
* </div>
|
|
954
|
+
* ))}
|
|
955
|
+
* </Product.ProductVariant.Stock>
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
export declare const ProductVariantStock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
|
|
877
959
|
/**
|
|
878
960
|
* Props for ProductVariantSKU component
|
|
879
961
|
*/
|
|
@@ -952,9 +1034,11 @@ export interface ProductVariantWeightProps {
|
|
|
952
1034
|
export declare const ProductVariantWeight: React.ForwardRefExoticComponent<ProductVariantWeightProps & React.RefAttributes<HTMLElement>>;
|
|
953
1035
|
/**
|
|
954
1036
|
* ProductVariant namespace containing product variant components
|
|
955
|
-
* following the compound component pattern: Product.ProductVariant.SKU, Product.ProductVariant.Weight
|
|
1037
|
+
* following the compound component pattern: Product.ProductVariant.Stock, Product.ProductVariant.SKU, Product.ProductVariant.Weight
|
|
956
1038
|
*/
|
|
957
1039
|
export declare const ProductVariant: {
|
|
1040
|
+
/** Product variant stock component */
|
|
1041
|
+
readonly Stock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
|
|
958
1042
|
/** Product variant SKU component */
|
|
959
1043
|
readonly SKU: React.ForwardRefExoticComponent<ProductVariantSKUProps & React.RefAttributes<HTMLElement>>;
|
|
960
1044
|
/** 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";
|
|
@@ -58,7 +59,7 @@ var TestIds;
|
|
|
58
59
|
TestIds["productAddToCart"] = "product-add-to-cart";
|
|
59
60
|
TestIds["productActionAddToCart"] = "product-action-add-to-cart";
|
|
60
61
|
TestIds["productActionBuyNow"] = "product-action-buy-now";
|
|
61
|
-
TestIds["productActionPreOrder"] = "product-action-pre-order";
|
|
62
|
+
TestIds["productActionPreOrder"] = "product-action-can-pre-order";
|
|
62
63
|
TestIds["productQuantity"] = "product-quantity";
|
|
63
64
|
TestIds["productQuantityDecrement"] = "product-quantity-decrement";
|
|
64
65
|
TestIds["productQuantityInput"] = "product-quantity-input";
|
|
@@ -691,7 +692,7 @@ export const ProductMediaGallery = React.forwardRef((props, ref) => {
|
|
|
691
692
|
export { ProductMediaGallery as MediaGallery };
|
|
692
693
|
/**
|
|
693
694
|
* Product quantity selector component that integrates with the selected variant.
|
|
694
|
-
* Provides quantity controls with stock validation and pre-order support.
|
|
695
|
+
* Provides quantity controls with stock validation and can-pre-order support.
|
|
695
696
|
* Uses a compound component pattern with Root, Decrement, Input, Increment, and Raw sub-components.
|
|
696
697
|
*
|
|
697
698
|
* @component
|
|
@@ -768,7 +769,7 @@ export const ProductQuantity = React.forwardRef((props, ref) => {
|
|
|
768
769
|
});
|
|
769
770
|
/**
|
|
770
771
|
* Product Quantity Decrement component.
|
|
771
|
-
* Automatically handles disabled state based on stock and pre-order settings.
|
|
772
|
+
* Automatically handles disabled state based on stock and can-pre-order settings.
|
|
772
773
|
* Must be used within Product.Quantity.Root.
|
|
773
774
|
*
|
|
774
775
|
* @component
|
|
@@ -916,7 +917,7 @@ export const ProductActionBuyNow = React.forwardRef((props, ref) => {
|
|
|
916
917
|
});
|
|
917
918
|
/**
|
|
918
919
|
* Pre-Order action button component following the documented API.
|
|
919
|
-
* Handles pre-order functionality when products are not in stock.
|
|
920
|
+
* Handles can-pre-order functionality when products are not in stock.
|
|
920
921
|
*/
|
|
921
922
|
export const ProductActionPreOrder = React.forwardRef((props, ref) => {
|
|
922
923
|
const { asChild, children, className, label, loadingState } = props;
|
|
@@ -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 can-pre-order settings
|
|
955
|
+
*/
|
|
956
|
+
function getStockStatusMessage(inStock, isPreOrderEnabled, availabilityStatus, labels) {
|
|
957
|
+
// Pre-order takes precedence
|
|
958
|
+
if (isPreOrderEnabled && !inStock) {
|
|
959
|
+
return {
|
|
960
|
+
status: 'can-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 can-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='can-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='can-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 */
|
package/dist/react/Product.d.ts
CHANGED
|
@@ -24,6 +24,14 @@ interface ModifiersContextValue {
|
|
|
24
24
|
* Hook to access modifiers context
|
|
25
25
|
*/
|
|
26
26
|
export declare function useModifiersContext(): ModifiersContextValue;
|
|
27
|
+
/**
|
|
28
|
+
* Basic stock status type for product availability states
|
|
29
|
+
*/
|
|
30
|
+
export type BasicStockStatus = 'in-stock' | 'limited-stock' | 'out-of-stock';
|
|
31
|
+
/**
|
|
32
|
+
* Extended stock status type including pre-order capability
|
|
33
|
+
*/
|
|
34
|
+
export type StockStatus = BasicStockStatus | 'can-pre-order';
|
|
27
35
|
/**
|
|
28
36
|
* Props for the Product root component following the documented API
|
|
29
37
|
*/
|
|
@@ -328,7 +336,7 @@ export interface StockProps {
|
|
|
328
336
|
asChild?: boolean;
|
|
329
337
|
/** Custom render function when using asChild */
|
|
330
338
|
children?: AsChildChildren<{
|
|
331
|
-
status:
|
|
339
|
+
status: BasicStockStatus;
|
|
332
340
|
label: string;
|
|
333
341
|
}>;
|
|
334
342
|
/** CSS classes to apply to the default element */
|
|
@@ -675,7 +683,7 @@ export interface ProductQuantitySubComponentProps {
|
|
|
675
683
|
}
|
|
676
684
|
/**
|
|
677
685
|
* Product quantity selector component that integrates with the selected variant.
|
|
678
|
-
* Provides quantity controls with stock validation and pre-order support.
|
|
686
|
+
* Provides quantity controls with stock validation and can-pre-order support.
|
|
679
687
|
* Uses a compound component pattern with Root, Decrement, Input, Increment, and Raw sub-components.
|
|
680
688
|
*
|
|
681
689
|
* @component
|
|
@@ -737,7 +745,7 @@ export interface ProductQuantitySubComponentProps {
|
|
|
737
745
|
export declare const ProductQuantity: React.ForwardRefExoticComponent<ProductQuantityProps & React.RefAttributes<HTMLDivElement>>;
|
|
738
746
|
/**
|
|
739
747
|
* Product Quantity Decrement component.
|
|
740
|
-
* Automatically handles disabled state based on stock and pre-order settings.
|
|
748
|
+
* Automatically handles disabled state based on stock and can-pre-order settings.
|
|
741
749
|
* Must be used within Product.Quantity.Root.
|
|
742
750
|
*
|
|
743
751
|
* @component
|
|
@@ -859,7 +867,7 @@ export declare const ProductActionAddToCart: React.ForwardRefExoticComponent<Pro
|
|
|
859
867
|
export declare const ProductActionBuyNow: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
860
868
|
/**
|
|
861
869
|
* Pre-Order action button component following the documented API.
|
|
862
|
-
* Handles pre-order functionality when products are not in stock.
|
|
870
|
+
* Handles can-pre-order functionality when products are not in stock.
|
|
863
871
|
*/
|
|
864
872
|
export declare const ProductActionPreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
865
873
|
/**
|
|
@@ -874,6 +882,80 @@ export declare const Action: {
|
|
|
874
882
|
/** Pre-order action button */
|
|
875
883
|
readonly PreOrder: React.ForwardRefExoticComponent<ProductActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
876
884
|
};
|
|
885
|
+
/**
|
|
886
|
+
* Props for ProductVariantStock component
|
|
887
|
+
*/
|
|
888
|
+
export interface ProductVariantStockProps {
|
|
889
|
+
/** Whether to render as a child component */
|
|
890
|
+
asChild?: boolean;
|
|
891
|
+
/** Custom render function when using asChild */
|
|
892
|
+
children?: AsChildChildren<{
|
|
893
|
+
status: StockStatus;
|
|
894
|
+
label: string;
|
|
895
|
+
}>;
|
|
896
|
+
/** CSS classes to apply to the default element */
|
|
897
|
+
className?: string;
|
|
898
|
+
/** Custom labels for different stock states */
|
|
899
|
+
labels?: {
|
|
900
|
+
/** Label for in stock state */
|
|
901
|
+
inStock?: string;
|
|
902
|
+
/** Label for limited stock state (when quantity is low) */
|
|
903
|
+
limitedStock?: string;
|
|
904
|
+
/** Label for out of stock state */
|
|
905
|
+
outOfStock?: string;
|
|
906
|
+
/** Label for can-pre-order state */
|
|
907
|
+
preOrder?: string;
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Displays the selected variant stock status with customizable rendering and labels,
|
|
912
|
+
* including can-pre-order support. Similar to Product.Stock but for the selected variant.
|
|
913
|
+
*
|
|
914
|
+
* @component
|
|
915
|
+
* @example
|
|
916
|
+
* ```tsx
|
|
917
|
+
* // Default usage
|
|
918
|
+
* <Product.ProductVariant.Stock
|
|
919
|
+
* className="stock-indicator"
|
|
920
|
+
* labels={{
|
|
921
|
+
* inStock: 'In Stock',
|
|
922
|
+
* limitedStock: 'Limited Stock',
|
|
923
|
+
* outOfStock: 'Out of Stock',
|
|
924
|
+
* preOrder: 'Available for Pre-order'
|
|
925
|
+
* }}
|
|
926
|
+
* />
|
|
927
|
+
*
|
|
928
|
+
* // asChild with primitive
|
|
929
|
+
* <Product.ProductVariant.Stock asChild>
|
|
930
|
+
* <div className="variant-stock-status" />
|
|
931
|
+
* </Product.ProductVariant.Stock>
|
|
932
|
+
*
|
|
933
|
+
* // asChild with react component
|
|
934
|
+
* <Product.ProductVariant.Stock
|
|
935
|
+
* labels={{
|
|
936
|
+
* inStock: 'Available',
|
|
937
|
+
* limitedStock: 'Low Stock',
|
|
938
|
+
* outOfStock: 'Sold Out',
|
|
939
|
+
* preOrder: 'Pre-order Now'
|
|
940
|
+
* }}
|
|
941
|
+
* asChild
|
|
942
|
+
* >
|
|
943
|
+
* {React.forwardRef(({status, label, ...props}, ref) => (
|
|
944
|
+
* <div
|
|
945
|
+
* ref={ref}
|
|
946
|
+
* {...props}
|
|
947
|
+
* 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='can-pre-order']:text-blue-600"
|
|
948
|
+
* >
|
|
949
|
+
* <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='can-pre-order']:bg-blue-500" />
|
|
950
|
+
* <span className="text-sm font-medium">
|
|
951
|
+
* {label}
|
|
952
|
+
* </span>
|
|
953
|
+
* </div>
|
|
954
|
+
* ))}
|
|
955
|
+
* </Product.ProductVariant.Stock>
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
export declare const ProductVariantStock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
|
|
877
959
|
/**
|
|
878
960
|
* Props for ProductVariantSKU component
|
|
879
961
|
*/
|
|
@@ -952,9 +1034,11 @@ export interface ProductVariantWeightProps {
|
|
|
952
1034
|
export declare const ProductVariantWeight: React.ForwardRefExoticComponent<ProductVariantWeightProps & React.RefAttributes<HTMLElement>>;
|
|
953
1035
|
/**
|
|
954
1036
|
* ProductVariant namespace containing product variant components
|
|
955
|
-
* following the compound component pattern: Product.ProductVariant.SKU, Product.ProductVariant.Weight
|
|
1037
|
+
* following the compound component pattern: Product.ProductVariant.Stock, Product.ProductVariant.SKU, Product.ProductVariant.Weight
|
|
956
1038
|
*/
|
|
957
1039
|
export declare const ProductVariant: {
|
|
1040
|
+
/** Product variant stock component */
|
|
1041
|
+
readonly Stock: React.ForwardRefExoticComponent<ProductVariantStockProps & React.RefAttributes<HTMLElement>>;
|
|
958
1042
|
/** Product variant SKU component */
|
|
959
1043
|
readonly SKU: React.ForwardRefExoticComponent<ProductVariantSKUProps & React.RefAttributes<HTMLElement>>;
|
|
960
1044
|
/** Product variant weight component */
|
package/dist/react/Product.js
CHANGED
|
@@ -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";
|
|
@@ -58,7 +59,7 @@ var TestIds;
|
|
|
58
59
|
TestIds["productAddToCart"] = "product-add-to-cart";
|
|
59
60
|
TestIds["productActionAddToCart"] = "product-action-add-to-cart";
|
|
60
61
|
TestIds["productActionBuyNow"] = "product-action-buy-now";
|
|
61
|
-
TestIds["productActionPreOrder"] = "product-action-pre-order";
|
|
62
|
+
TestIds["productActionPreOrder"] = "product-action-can-pre-order";
|
|
62
63
|
TestIds["productQuantity"] = "product-quantity";
|
|
63
64
|
TestIds["productQuantityDecrement"] = "product-quantity-decrement";
|
|
64
65
|
TestIds["productQuantityInput"] = "product-quantity-input";
|
|
@@ -691,7 +692,7 @@ export const ProductMediaGallery = React.forwardRef((props, ref) => {
|
|
|
691
692
|
export { ProductMediaGallery as MediaGallery };
|
|
692
693
|
/**
|
|
693
694
|
* Product quantity selector component that integrates with the selected variant.
|
|
694
|
-
* Provides quantity controls with stock validation and pre-order support.
|
|
695
|
+
* Provides quantity controls with stock validation and can-pre-order support.
|
|
695
696
|
* Uses a compound component pattern with Root, Decrement, Input, Increment, and Raw sub-components.
|
|
696
697
|
*
|
|
697
698
|
* @component
|
|
@@ -768,7 +769,7 @@ export const ProductQuantity = React.forwardRef((props, ref) => {
|
|
|
768
769
|
});
|
|
769
770
|
/**
|
|
770
771
|
* Product Quantity Decrement component.
|
|
771
|
-
* Automatically handles disabled state based on stock and pre-order settings.
|
|
772
|
+
* Automatically handles disabled state based on stock and can-pre-order settings.
|
|
772
773
|
* Must be used within Product.Quantity.Root.
|
|
773
774
|
*
|
|
774
775
|
* @component
|
|
@@ -916,7 +917,7 @@ export const ProductActionBuyNow = React.forwardRef((props, ref) => {
|
|
|
916
917
|
});
|
|
917
918
|
/**
|
|
918
919
|
* Pre-Order action button component following the documented API.
|
|
919
|
-
* Handles pre-order functionality when products are not in stock.
|
|
920
|
+
* Handles can-pre-order functionality when products are not in stock.
|
|
920
921
|
*/
|
|
921
922
|
export const ProductActionPreOrder = React.forwardRef((props, ref) => {
|
|
922
923
|
const { asChild, children, className, label, loadingState } = props;
|
|
@@ -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 can-pre-order settings
|
|
955
|
+
*/
|
|
956
|
+
function getStockStatusMessage(inStock, isPreOrderEnabled, availabilityStatus, labels) {
|
|
957
|
+
// Pre-order takes precedence
|
|
958
|
+
if (isPreOrderEnabled && !inStock) {
|
|
959
|
+
return {
|
|
960
|
+
status: 'can-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 can-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='can-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='can-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 */
|