@hanzo/commerce 1.1.6 → 1.1.7

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.
@@ -12,12 +12,14 @@ const FacetTogglesWidget: React.FC<{
12
12
  mutator: StringMutator | StringArrayMutator
13
13
  multiple?: boolean
14
14
  className?: string
15
+ buttonClx?: string
15
16
  isMobile?: boolean
16
17
  tabSize?: string
17
18
  }> = ({
18
19
  facetValues,
19
20
  mutator,
20
21
  multiple='',
22
+ buttonClx='',
21
23
  className='',
22
24
  isMobile=false,
23
25
  tabSize
@@ -50,7 +52,7 @@ const FacetTogglesWidget: React.FC<{
50
52
  type={multiple ? 'multiple' : 'single'}
51
53
  value={val}
52
54
  variant='default'
53
- size={isMobile ? 'sm' : tabSize ? tabSize : 'default'}
55
+ size={tabSize ? tabSize : (isMobile ? 'sm' : 'default')}
54
56
  onValueChange={multiple ? handleChangeMultiple : handleChangeSingle}
55
57
  className={className}
56
58
  {...roundedToSpread}
@@ -69,6 +71,7 @@ const FacetTogglesWidget: React.FC<{
69
71
  disabled={(last && last === fv.value || fv.value === mutator.get())}
70
72
  aria-label={`Select ${fv.label}`}
71
73
  {...roundedToSpread}
74
+ className={buttonClx}
72
75
  >
73
76
  <span className={cn('flex flex-row justify-center gap-1 h-4 items-center')} >
74
77
  <FacetImage facetValueDesc={fv} />
@@ -9,8 +9,9 @@ import FacetTogglesWidget from './facet-toggles-widget'
9
9
 
10
10
  const FacetsWidget: React.FC<PropsWithChildren & {
11
11
  facets: FacetsDesc
12
- facetClassNames?: string[]
13
12
  mutators: StringMutator[] | StringArrayMutator[]
13
+ facetClx?: string[]
14
+ facetItemClx?: string
14
15
  multiple?: boolean
15
16
  isMobile?: boolean
16
17
  id?: string
@@ -21,7 +22,8 @@ const FacetsWidget: React.FC<PropsWithChildren & {
21
22
  facets,
22
23
  mutators,
23
24
  multiple=false,
24
- facetClassNames,
25
+ facetClx,
26
+ facetItemClx='',
25
27
  isMobile=false,
26
28
  className='',
27
29
  tabSize,
@@ -37,7 +39,8 @@ const FacetsWidget: React.FC<PropsWithChildren & {
37
39
  mutator={mutators[i]}
38
40
  isMobile={isMobile}
39
41
  facetValues={facets[parseInt(key)]}
40
- className={cn((horiz ? '' : 'mb-2'), (i !== 0 && !horiz) ? 'mt-2' : '', (facetClassNames?.[i]) ?? '')}
42
+ className={cn((horiz ? '' : 'mb-2'), (i !== 0 && !horiz) ? 'mt-2' : '', (facetClx?.[i]) ?? '')}
43
+ buttonClx={facetItemClx}
41
44
  tabSize={tabSize}
42
45
  />
43
46
  ))}
@@ -19,18 +19,20 @@ const ProductSelectionRadioGroup: React.FC<{
19
19
  itemClx='',
20
20
  showPrice=true
21
21
  }) => (
22
- <RadioGroup
23
- className={groupClx}
24
- onValueChange={onValueChange}
25
- value={selectedSku}
26
- >
27
- {products.map((prod) => (
28
- <div className={itemClx} key={prod.sku}>
29
- <RadioGroupItem value={prod.sku} id={prod.sku} />
30
- <Label htmlFor={prod.sku}>{prod.titleAsOption + (showPrice ? (', ' + formatPrice(prod.price)) : '')}</Label>
31
- </div>
32
- ))}
33
- </RadioGroup>
22
+ products.length > 1 && (
23
+ <RadioGroup
24
+ className={groupClx}
25
+ onValueChange={onValueChange}
26
+ value={selectedSku}
27
+ >
28
+ {products.map((prod) => (
29
+ <div className={itemClx} key={prod.sku}>
30
+ <RadioGroupItem value={prod.sku} id={prod.sku} />
31
+ <Label htmlFor={prod.sku}>{prod.titleAsOption + (showPrice ? (', ' + formatPrice(prod.price)) : '')}</Label>
32
+ </div>
33
+ ))}
34
+ </RadioGroup>
35
+ )
34
36
  )
35
37
 
36
38
  export default ProductSelectionRadioGroup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/commerce",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Library with shopping cart components.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -76,6 +76,7 @@ class StandaloneService
76
76
 
77
77
  makeObservable(this, {
78
78
  cartItems: computed,
79
+ cartQuantity: computed,
79
80
  cartTotal: computed,
80
81
  specifiedItems: computed,
81
82
  specifiedCategories: computed,
@@ -118,6 +119,13 @@ class StandaloneService
118
119
  )
119
120
  }
120
121
 
122
+ get cartQuantity(): number {
123
+ return this.cartItems.reduce(
124
+ (total, item) => (total + item.quantity),
125
+ 0
126
+ )
127
+ }
128
+
121
129
  setCurrentItem(skuToFind: string | undefined): boolean {
122
130
 
123
131
  if (skuToFind === undefined || skuToFind.length === 0) {
@@ -4,8 +4,13 @@ import type Category from './category'
4
4
 
5
5
  interface CommerceService extends ObsLineItemRef {
6
6
 
7
+ /** Items in cart */
7
8
  get cartItems(): LineItem[]
9
+ /** Total of all quantities of items in cart */
10
+ get cartQuantity(): number
11
+ /** Total of all prices X quantities of items in cart */
8
12
  get cartTotal(): number
13
+
9
14
  getCartCategorySubtotal(categoryId: string): number
10
15
 
11
16
  createOrder(email: string, paymentMethod: string): Promise<string | undefined>