@cartbase/storefront 0.16.0 → 0.18.0

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 (110) hide show
  1. package/LICENSE +21 -21
  2. package/package.json +258 -255
  3. package/src/api/auth.ts +108 -108
  4. package/src/api/carts.ts +523 -523
  5. package/src/api/categories.ts +184 -184
  6. package/src/api/checkout.ts +526 -526
  7. package/src/api/collections.ts +130 -130
  8. package/src/api/consent.ts +75 -75
  9. package/src/api/content.ts +125 -125
  10. package/src/api/customers.ts +303 -303
  11. package/src/api/gift-cards.ts +112 -112
  12. package/src/api/http.ts +180 -130
  13. package/src/api/index.ts +30 -30
  14. package/src/api/menus.ts +77 -77
  15. package/src/api/metaobjects.ts +136 -136
  16. package/src/api/orders.ts +290 -290
  17. package/src/api/products.ts +43 -1
  18. package/src/api/redirects.ts +37 -37
  19. package/src/api/regions.ts +200 -200
  20. package/src/api/reviews.ts +259 -259
  21. package/src/api/search.ts +163 -163
  22. package/src/api/store.ts +35 -35
  23. package/src/api/types.ts +91 -91
  24. package/src/cart-drawer/context.tsx +277 -164
  25. package/src/cart-drawer/cross-sell-carousel.tsx +211 -211
  26. package/src/cart-drawer/cross-sell-sidebar.tsx +158 -158
  27. package/src/cart-drawer/free-gift.tsx +1 -1
  28. package/src/cart-drawer/gift-wrap.tsx +82 -82
  29. package/src/cart-drawer/index.ts +71 -68
  30. package/src/cart-drawer/item/index.tsx +162 -162
  31. package/src/cart-drawer/item/quantity.tsx +8 -14
  32. package/src/cart-drawer/item/upsell.tsx +110 -110
  33. package/src/cart-drawer/labels.ts +123 -123
  34. package/src/cart-drawer/mutation-queue.ts +78 -0
  35. package/src/cart-drawer/notes.tsx +131 -131
  36. package/src/cart-drawer/sticky-footer.tsx +73 -73
  37. package/src/cart-drawer/summary-breakdown.tsx +197 -197
  38. package/src/checkout/address-error-copy.ts +117 -117
  39. package/src/checkout/boxnow-locker-selector.tsx +410 -410
  40. package/src/checkout/compare-addresses.ts +40 -40
  41. package/src/checkout/discount-section.tsx +218 -218
  42. package/src/checkout/error-copy-codes.ts +63 -63
  43. package/src/checkout/geocode.ts +154 -154
  44. package/src/checkout/gift-card-section.tsx +224 -224
  45. package/src/checkout/index.ts +72 -72
  46. package/src/checkout/labels.ts +495 -495
  47. package/src/checkout/payment-button.tsx +372 -372
  48. package/src/checkout/payment-error-copy.ts +154 -154
  49. package/src/checkout/promotion-error-copy.ts +91 -91
  50. package/src/checkout/use-checkout-orchestration.ts +1592 -1592
  51. package/src/common/country-flag.tsx +52 -52
  52. package/src/common/country-select.tsx +11 -11
  53. package/src/common/index.ts +20 -20
  54. package/src/common/market-select.tsx +57 -57
  55. package/src/index.ts +12 -12
  56. package/src/lib/country-name.ts +59 -59
  57. package/src/lib/get-product-price.ts +133 -133
  58. package/src/lib/media-image.tsx +39 -0
  59. package/src/lib/payment-constants.ts +53 -53
  60. package/src/lib/platform.ts +13 -13
  61. package/src/lib/price.tsx +39 -39
  62. package/src/lib/store-api-error.ts +36 -36
  63. package/src/lib/variant-caption.ts +32 -32
  64. package/src/locales/bg.ts +467 -467
  65. package/src/locales/context.ts +37 -37
  66. package/src/locales/en.ts +26 -26
  67. package/src/locales/es.ts +466 -466
  68. package/src/locales/index.ts +19 -19
  69. package/src/locales/provider.tsx +59 -59
  70. package/src/locales/types.ts +77 -77
  71. package/src/order/index.ts +62 -62
  72. package/src/order/labels.ts +79 -79
  73. package/src/order/order-item.tsx +1 -1
  74. package/src/order/order-totals.tsx +250 -250
  75. package/src/primitives/select-field.tsx +93 -93
  76. package/src/products/image-gallery.tsx +43 -43
  77. package/src/products/index.ts +68 -59
  78. package/src/products/option-select.tsx +67 -67
  79. package/src/products/product-actions-wrapper.tsx +63 -62
  80. package/src/products/product-actions.tsx +151 -150
  81. package/src/products/product-price.tsx +69 -69
  82. package/src/products/product-promises.tsx +61 -61
  83. package/src/products/product-specs.tsx +65 -65
  84. package/src/products/product-tabs.tsx +123 -123
  85. package/src/products/product-template.tsx +163 -162
  86. package/src/products/purchase-options.tsx +130 -130
  87. package/src/products/sets.ts +110 -0
  88. package/src/products/thumbnail.tsx +1 -1
  89. package/src/products/use-product-actions.ts +199 -164
  90. package/src/products/variant-matching.ts +71 -71
  91. package/src/products/variant-url.ts +74 -74
  92. package/src/reviews-ui/index.ts +73 -73
  93. package/src/store/category-template.tsx +136 -136
  94. package/src/store/index.ts +40 -40
  95. package/src/tracking/chatgpt-pixel.tsx +99 -99
  96. package/src/tracking/consent-init.tsx +62 -62
  97. package/src/tracking/events.ts +348 -348
  98. package/src/tracking/ga4.tsx +93 -93
  99. package/src/tracking/google-ads.ts +84 -84
  100. package/src/tracking/gtm.tsx +60 -60
  101. package/src/tracking/inline-script.ts +49 -49
  102. package/src/tracking/oaiq.ts +206 -206
  103. package/src/tracking/tiktok-pixel.tsx +91 -91
  104. package/src/tracking/track-init.tsx +56 -56
  105. package/src/tracking/track-order-purchase.tsx +122 -122
  106. package/src/tracking/ttq.ts +180 -180
  107. package/src/tracking/use-tracking-config.ts +54 -54
  108. package/theme/index.css +25 -25
  109. package/theme/theme.css +150 -150
  110. package/theme/tokens.css +106 -106
@@ -1,93 +1,93 @@
1
- "use client"
2
-
3
- import * as React from "react"
4
-
5
- import { cn } from "../lib/utils"
6
-
7
- /**
8
- * SelectField — floating-label native select primitive.
9
- *
10
- * Matches `Field`'s visual treatment — the label floats into the top-left
11
- * when a value is selected. Uses a plain native `<select>` for simplicity
12
- * and native mobile keyboard support. If a fancier dropdown is needed
13
- * (searchable, multi-select, rich options), use the shadcn `Select`
14
- * primitives directly from `@cartbase/storefront/primitives/ui/select`.
15
- *
16
- * Extracted from mindpages-storefront
17
- * src/modules/checkout/templates/checkout-client/index.tsx lines 207-270.
18
- *
19
- * @example
20
- * <SelectField label="Country" name="country" value={country} onChange={...}>
21
- * <option value="bg">Bulgaria</option>
22
- * <option value="de">Germany</option>
23
- * </SelectField>
24
- */
25
-
26
- export type SelectFieldProps = React.SelectHTMLAttributes<HTMLSelectElement> & {
27
- label: string
28
- children: React.ReactNode
29
- className?: string
30
- /**
31
- * A mark shown inside the control, before the value: a flag, a currency
32
- * symbol. Decorative and click-through, so the whole field still opens the
33
- * select. The value and the floating label make room for it.
34
- */
35
- leading?: React.ReactNode
36
- }
37
-
38
- export const SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(
39
- function SelectField(
40
- { label, required, disabled, children, className, value, leading, ...props },
41
- ref
42
- ) {
43
- const hasValue = value !== undefined && value !== null && value !== ""
44
-
45
- return (
46
- <div className={cn("relative", className)}>
47
- <select
48
- ref={ref}
49
- required={required}
50
- disabled={disabled}
51
- value={value}
52
- className={cn(
53
- "w-full h-[44px] pt-[14px] pb-[2px] pr-9 text-sm rounded-lg border transition-colors duration-150 appearance-none outline-none",
54
- leading ? "pl-10" : "px-3",
55
- "focus:border-primary focus:bg-primary/5",
56
- disabled
57
- ? "bg-muted border-border text-muted-foreground cursor-not-allowed"
58
- : "bg-card border-border text-foreground hover:border-muted-foreground"
59
- )}
60
- {...props}
61
- >
62
- {children}
63
- </select>
64
- {leading && (
65
- <span className="absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none flex items-center">
66
- {leading}
67
- </span>
68
- )}
69
- <span
70
- className={cn(
71
- "absolute pointer-events-none top-[14px] text-sm leading-4 origin-top-left",
72
- leading ? "left-10" : "left-3",
73
- "transition-transform transition-colors duration-150 ease-out",
74
- hasValue ? "text-muted-foreground" : "text-muted-foreground",
75
- hasValue ? "-translate-y-2 scale-[0.77]" : "translate-y-0 scale-100"
76
- )}
77
- >
78
- {label}
79
- </span>
80
- <svg
81
- className="absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground pointer-events-none"
82
- fill="none"
83
- viewBox="0 0 24 24"
84
- stroke="currentColor"
85
- strokeWidth={1.5}
86
- aria-hidden="true"
87
- >
88
- <path strokeLinecap="round" strokeLinejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
89
- </svg>
90
- </div>
91
- )
92
- }
93
- )
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "../lib/utils"
6
+
7
+ /**
8
+ * SelectField — floating-label native select primitive.
9
+ *
10
+ * Matches `Field`'s visual treatment — the label floats into the top-left
11
+ * when a value is selected. Uses a plain native `<select>` for simplicity
12
+ * and native mobile keyboard support. If a fancier dropdown is needed
13
+ * (searchable, multi-select, rich options), use the shadcn `Select`
14
+ * primitives directly from `@cartbase/storefront/primitives/ui/select`.
15
+ *
16
+ * Extracted from mindpages-storefront
17
+ * src/modules/checkout/templates/checkout-client/index.tsx lines 207-270.
18
+ *
19
+ * @example
20
+ * <SelectField label="Country" name="country" value={country} onChange={...}>
21
+ * <option value="bg">Bulgaria</option>
22
+ * <option value="de">Germany</option>
23
+ * </SelectField>
24
+ */
25
+
26
+ export type SelectFieldProps = React.SelectHTMLAttributes<HTMLSelectElement> & {
27
+ label: string
28
+ children: React.ReactNode
29
+ className?: string
30
+ /**
31
+ * A mark shown inside the control, before the value: a flag, a currency
32
+ * symbol. Decorative and click-through, so the whole field still opens the
33
+ * select. The value and the floating label make room for it.
34
+ */
35
+ leading?: React.ReactNode
36
+ }
37
+
38
+ export const SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(
39
+ function SelectField(
40
+ { label, required, disabled, children, className, value, leading, ...props },
41
+ ref
42
+ ) {
43
+ const hasValue = value !== undefined && value !== null && value !== ""
44
+
45
+ return (
46
+ <div className={cn("relative", className)}>
47
+ <select
48
+ ref={ref}
49
+ required={required}
50
+ disabled={disabled}
51
+ value={value}
52
+ className={cn(
53
+ "w-full h-[44px] pt-[14px] pb-[2px] pr-9 text-sm rounded-lg border transition-colors duration-150 appearance-none outline-none",
54
+ leading ? "pl-10" : "px-3",
55
+ "focus:border-primary focus:bg-primary/5",
56
+ disabled
57
+ ? "bg-muted border-border text-muted-foreground cursor-not-allowed"
58
+ : "bg-card border-border text-foreground hover:border-muted-foreground"
59
+ )}
60
+ {...props}
61
+ >
62
+ {children}
63
+ </select>
64
+ {leading && (
65
+ <span className="absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none flex items-center">
66
+ {leading}
67
+ </span>
68
+ )}
69
+ <span
70
+ className={cn(
71
+ "absolute pointer-events-none top-[14px] text-sm leading-4 origin-top-left",
72
+ leading ? "left-10" : "left-3",
73
+ "transition-transform transition-colors duration-150 ease-out",
74
+ hasValue ? "text-muted-foreground" : "text-muted-foreground",
75
+ hasValue ? "-translate-y-2 scale-[0.77]" : "translate-y-0 scale-100"
76
+ )}
77
+ >
78
+ {label}
79
+ </span>
80
+ <svg
81
+ className="absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground pointer-events-none"
82
+ fill="none"
83
+ viewBox="0 0 24 24"
84
+ stroke="currentColor"
85
+ strokeWidth={1.5}
86
+ aria-hidden="true"
87
+ >
88
+ <path strokeLinecap="round" strokeLinejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
89
+ </svg>
90
+ </div>
91
+ )
92
+ }
93
+ )
@@ -1,43 +1,43 @@
1
- /**
2
- * PDP image gallery — ported from
3
- * `@1click/ui/src/products/image-gallery.tsx` (v2.3.1). Data seam:
4
- * `HttpTypes.StoreProductImage[]` → Cartbase `StoreProductImage[]`
5
- * (`@cartbase/storefront/api/products`; images arrive rank-ordered from the
6
- * API). Server-safe.
7
- */
8
- import Image from "next/image"
9
- import type { StoreProductImage } from "../api/products"
10
-
11
- type ImageGalleryProps = {
12
- images: StoreProductImage[]
13
- }
14
-
15
- const ImageGallery = ({ images }: ImageGalleryProps) => {
16
- return (
17
- <div className="flex items-start relative">
18
- <div className="flex flex-col flex-1 sm:mx-16 gap-y-4">
19
- {images.map((image, index) => (
20
- <div
21
- key={image.id}
22
- className="relative aspect-[29/34] w-full overflow-hidden bg-muted rounded-lg"
23
- id={image.id}
24
- >
25
- {!!image.url && (
26
- <Image
27
- src={image.url}
28
- priority={index <= 2}
29
- className="absolute inset-0 rounded-lg"
30
- alt={`Product image ${index + 1}`}
31
- fill
32
- sizes="(max-width: 576px) 280px, (max-width: 768px) 360px, (max-width: 992px) 480px, 800px"
33
- style={{ objectFit: "cover" }}
34
- />
35
- )}
36
- </div>
37
- ))}
38
- </div>
39
- </div>
40
- )
41
- }
42
-
43
- export { ImageGallery, type ImageGalleryProps }
1
+ /**
2
+ * PDP image gallery — ported from
3
+ * `@1click/ui/src/products/image-gallery.tsx` (v2.3.1). Data seam:
4
+ * `HttpTypes.StoreProductImage[]` → Cartbase `StoreProductImage[]`
5
+ * (`@cartbase/storefront/api/products`; images arrive rank-ordered from the
6
+ * API). Server-safe.
7
+ */
8
+ import { StoreImage as Image } from "../lib/media-image"
9
+ import type { StoreProductImage } from "../api/products"
10
+
11
+ type ImageGalleryProps = {
12
+ images: StoreProductImage[]
13
+ }
14
+
15
+ const ImageGallery = ({ images }: ImageGalleryProps) => {
16
+ return (
17
+ <div className="flex items-start relative">
18
+ <div className="flex flex-col flex-1 sm:mx-16 gap-y-4">
19
+ {images.map((image, index) => (
20
+ <div
21
+ key={image.id}
22
+ className="relative aspect-[29/34] w-full overflow-hidden bg-muted rounded-lg"
23
+ id={image.id}
24
+ >
25
+ {!!image.url && (
26
+ <Image
27
+ src={image.url}
28
+ priority={index <= 2}
29
+ className="absolute inset-0 rounded-lg"
30
+ alt={`Product image ${index + 1}`}
31
+ fill
32
+ sizes="(max-width: 576px) 280px, (max-width: 768px) 360px, (max-width: 992px) 480px, 800px"
33
+ style={{ objectFit: "cover" }}
34
+ />
35
+ )}
36
+ </div>
37
+ ))}
38
+ </div>
39
+ </div>
40
+ )
41
+ }
42
+
43
+ export { ImageGallery, type ImageGalleryProps }
@@ -1,59 +1,68 @@
1
- /**
2
- * @cartbase/storefront — products family barrel. Prefer subpath imports
3
- * (`@cartbase/storefront/products/product-actions`) in apps; the barrel exists
4
- * for convenience and for the extra pure module (variant-matching).
5
- */
6
- export { ProductLabelsProvider, useProductLabels } from "./context"
7
- export { defaultProductLabels, type ProductLabels } from "./labels"
8
-
9
- export {
10
- optionsAsKeymap,
11
- optionsMatch,
12
- findMatchingVariant,
13
- type OptionChoices,
14
- type VariantOptionLike,
15
- } from "./variant-matching"
16
-
17
- export { Thumbnail, type ThumbnailProps } from "./thumbnail"
18
- export { PreviewPrice } from "./preview-price"
19
- export { ProductPrice } from "./product-price"
20
- export { OptionSelect, type OptionSelectProps } from "./option-select"
21
- // subscriptions-core step 4 — one-time vs plan purchase options.
22
- export {
23
- PurchaseOptions,
24
- previewPlanPrice,
25
- cadenceLabel,
26
- type PurchaseOptionsLabels,
27
- } from "./purchase-options"
28
- export { ImageGallery, type ImageGalleryProps } from "./image-gallery"
29
- // The product page contract: the address is the state, the default is the
30
- // merchant's, a switch is a browser event (variant-url + use-product-actions).
31
- export {
32
- VARIANT_PARAM,
33
- variantParamValue,
34
- findVariantByParam,
35
- defaultVariant,
36
- variantHref,
37
- } from "./variant-url"
38
- export {
39
- useProductActions,
40
- type UseProductActionsInput,
41
- type ProductActionsState,
42
- } from "./use-product-actions"
43
- export {
44
- ProductActions,
45
- type ProductActionsProps,
46
- type AddToCartInput,
47
- } from "./product-actions"
48
- export { MobileActions, type MobileActionsProps } from "./mobile-actions"
49
- export { ProductTabs, type ProductSection } from "./product-tabs"
50
- export { ProductSpecs, hasProductSpecs } from "./product-specs"
51
- export { ProductPromises, type ProductPromise } from "./product-promises"
52
- export { ProductInfo, type ProductInfoProps } from "./product-info"
53
- export { ProductPreview, type ProductPreviewProps } from "./product-preview"
54
- export { RelatedProducts, type RelatedProductsProps } from "./related-products"
55
- export {
56
- ProductActionsWrapper,
57
- type ProductActionsWrapperProps,
58
- } from "./product-actions-wrapper"
59
- export { ProductTemplate, type ProductTemplateProps } from "./product-template"
1
+ /**
2
+ * @cartbase/storefront — products family barrel. Prefer subpath imports
3
+ * (`@cartbase/storefront/products/product-actions`) in apps; the barrel exists
4
+ * for convenience and for the extra pure module (variant-matching).
5
+ */
6
+ export { ProductLabelsProvider, useProductLabels } from "./context"
7
+ export { defaultProductLabels, type ProductLabels } from "./labels"
8
+
9
+ export {
10
+ optionsAsKeymap,
11
+ optionsMatch,
12
+ findMatchingVariant,
13
+ type OptionChoices,
14
+ type VariantOptionLike,
15
+ } from "./variant-matching"
16
+
17
+ export { Thumbnail, type ThumbnailProps } from "./thumbnail"
18
+ export { PreviewPrice } from "./preview-price"
19
+ export { ProductPrice } from "./product-price"
20
+ export { OptionSelect, type OptionSelectProps } from "./option-select"
21
+ // subscriptions-core step 4 — one-time vs plan purchase options.
22
+ export {
23
+ PurchaseOptions,
24
+ previewPlanPrice,
25
+ cadenceLabel,
26
+ type PurchaseOptionsLabels,
27
+ } from "./purchase-options"
28
+ export { ImageGallery, type ImageGalleryProps } from "./image-gallery"
29
+ // The product page contract: the address is the state, the default is the
30
+ // merchant's, a switch is a browser event (variant-url + use-product-actions).
31
+ export {
32
+ VARIANT_PARAM,
33
+ variantParamValue,
34
+ findVariantByParam,
35
+ defaultVariant,
36
+ variantHref,
37
+ } from "./variant-url"
38
+ // Sets: what a set holds and which sets hold a product (kit links).
39
+ export {
40
+ SET_FIELDS,
41
+ linkOwner,
42
+ setContents,
43
+ setContentsByVariant,
44
+ setsContaining,
45
+ type SetPart,
46
+ } from "./sets"
47
+ export {
48
+ useProductActions,
49
+ type UseProductActionsInput,
50
+ type ProductActionsState,
51
+ } from "./use-product-actions"
52
+ export {
53
+ ProductActions,
54
+ type ProductActionsProps,
55
+ type AddToCartInput,
56
+ } from "./product-actions"
57
+ export { MobileActions, type MobileActionsProps } from "./mobile-actions"
58
+ export { ProductTabs, type ProductSection } from "./product-tabs"
59
+ export { ProductSpecs, hasProductSpecs } from "./product-specs"
60
+ export { ProductPromises, type ProductPromise } from "./product-promises"
61
+ export { ProductInfo, type ProductInfoProps } from "./product-info"
62
+ export { ProductPreview, type ProductPreviewProps } from "./product-preview"
63
+ export { RelatedProducts, type RelatedProductsProps } from "./related-products"
64
+ export {
65
+ ProductActionsWrapper,
66
+ type ProductActionsWrapperProps,
67
+ } from "./product-actions-wrapper"
68
+ export { ProductTemplate, type ProductTemplateProps } from "./product-template"
@@ -1,67 +1,67 @@
1
- "use client"
2
-
3
- /**
4
- * Option selector — ported from
5
- * `@1click/ui/src/products/option-select.tsx` (v2.3.1). Data seam:
6
- * `HttpTypes.StoreProductOption` → Cartbase `StoreProductOption`
7
- * (`@cartbase/storefront/api/products`; `values` is present on
8
- * `product.options[]`, which is what this component receives).
9
- */
10
- import React from "react"
11
- import type { StoreProductOption } from "../api/products"
12
- import { cn } from "../lib/utils"
13
- import { useProductLabels } from "./context"
14
-
15
- type OptionSelectProps = {
16
- option: StoreProductOption
17
- current: string | undefined
18
- updateOption: (optionId: string, value: string) => void
19
- title: string
20
- disabled: boolean
21
- "data-testid"?: string
22
- }
23
-
24
- const OptionSelect: React.FC<OptionSelectProps> = ({
25
- option,
26
- current,
27
- updateOption,
28
- title,
29
- "data-testid": dataTestId,
30
- disabled,
31
- }) => {
32
- const labels = useProductLabels()
33
- const filteredOptions = (option.values ?? []).map((v) => v.value)
34
-
35
- return (
36
- <div className="flex flex-col gap-y-3">
37
- <span className="text-sm text-foreground">
38
- {labels.selectOption} {title}
39
- </span>
40
- <div
41
- className="flex flex-wrap justify-between gap-2"
42
- data-testid={dataTestId}
43
- >
44
- {filteredOptions.map((v) => (
45
- <button
46
- onClick={() => updateOption(option.id, v!)}
47
- key={v}
48
- className={cn(
49
- "border border-border bg-muted text-sm h-10 rounded-lg p-2 flex-1",
50
- {
51
- "border-primary": v === current,
52
- "hover:shadow-sm transition-shadow ease-in-out duration-150":
53
- v !== current,
54
- }
55
- )}
56
- disabled={disabled}
57
- data-testid="option-button"
58
- >
59
- {v}
60
- </button>
61
- ))}
62
- </div>
63
- </div>
64
- )
65
- }
66
-
67
- export { OptionSelect, type OptionSelectProps }
1
+ "use client"
2
+
3
+ /**
4
+ * Option selector — ported from
5
+ * `@1click/ui/src/products/option-select.tsx` (v2.3.1). Data seam:
6
+ * `HttpTypes.StoreProductOption` → Cartbase `StoreProductOption`
7
+ * (`@cartbase/storefront/api/products`; `values` is present on
8
+ * `product.options[]`, which is what this component receives).
9
+ */
10
+ import React from "react"
11
+ import type { StoreProductOption } from "../api/products"
12
+ import { cn } from "../lib/utils"
13
+ import { useProductLabels } from "./context"
14
+
15
+ type OptionSelectProps = {
16
+ option: StoreProductOption
17
+ current: string | undefined
18
+ updateOption: (optionId: string, value: string) => void
19
+ title: string
20
+ disabled: boolean
21
+ "data-testid"?: string
22
+ }
23
+
24
+ const OptionSelect: React.FC<OptionSelectProps> = ({
25
+ option,
26
+ current,
27
+ updateOption,
28
+ title,
29
+ "data-testid": dataTestId,
30
+ disabled,
31
+ }) => {
32
+ const labels = useProductLabels()
33
+ const filteredOptions = (option.values ?? []).map((v) => v.value)
34
+
35
+ return (
36
+ <div className="flex flex-col gap-y-3">
37
+ <span className="text-sm text-foreground">
38
+ {labels.selectOption} {title}
39
+ </span>
40
+ <div
41
+ className="flex flex-wrap justify-between gap-2"
42
+ data-testid={dataTestId}
43
+ >
44
+ {filteredOptions.map((v) => (
45
+ <button
46
+ onClick={() => updateOption(option.id, v!)}
47
+ key={v}
48
+ className={cn(
49
+ "border border-border bg-muted text-sm h-10 rounded-lg p-2 flex-1",
50
+ {
51
+ "border-primary": v === current,
52
+ "hover:shadow-sm transition-shadow ease-in-out duration-150":
53
+ v !== current,
54
+ }
55
+ )}
56
+ disabled={disabled}
57
+ data-testid="option-button"
58
+ >
59
+ {v}
60
+ </button>
61
+ ))}
62
+ </div>
63
+ </div>
64
+ )
65
+ }
66
+
67
+ export { OptionSelect, type OptionSelectProps }