@hanzo/commerce 1.1.8 → 1.1.10

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.
@@ -13,6 +13,7 @@ const AddToCartWidget: React.FC<{
13
13
  ghost?: boolean
14
14
  disabled?: boolean
15
15
  className?: string
16
+ buttonClx?: string
16
17
  isMobile?: boolean
17
18
  wide?: boolean
18
19
  size?: ButtonSizes
@@ -21,11 +22,12 @@ const AddToCartWidget: React.FC<{
21
22
  ghost=false,
22
23
  disabled=false,
23
24
  className='',
25
+ buttonClx='',
24
26
  size='xs'
25
27
  }) => {
26
28
 
27
- const iconClx = ghost ? 'h-3 w-3 text-muted-3 hover:text-foreground' : 'h-5 w-5 mr-1'
28
- const digitClx = ghost ? 'px-1' : 'px-2 font-bold '
29
+ const iconClx = ghost ? 'h-4 w-4 md:h-3 md:w-3 text-muted-3 hover:text-foreground' : 'h-5 w-5 mr-1'
30
+ const digitClx = ghost ? 'px-2 md:px-0.5' : 'sm:px-2 font-bold '
29
31
 
30
32
  if (disabled) {
31
33
  return (
@@ -42,7 +44,7 @@ const AddToCartWidget: React.FC<{
42
44
  size={size}
43
45
  variant={ghost ? 'ghost' : 'secondary'}
44
46
  rounded={ghost ? 'full' : 'xl'}
45
- className='px-1 lg:min-w-0 lg:px-2 xs:grow xs:justify-end'
47
+ className={cn('px-1 lg:min-w-0 lg:px-2 xs:grow xs:justify-end', buttonClx)}
46
48
  key='left'
47
49
  onClick={item.decrement.bind(item)}
48
50
  >
@@ -58,7 +60,7 @@ const AddToCartWidget: React.FC<{
58
60
  size={size}
59
61
  variant={ghost ? 'ghost' : 'secondary'}
60
62
  rounded={ghost ? 'full' : 'xl'}
61
- className='px-1 lg:min-w-0 lg:px-2 xs:grow xs:justify-start'
63
+ className={cn('px-1 lg:min-w-0 lg:px-2 xs:grow xs:justify-start', buttonClx)}
62
64
  onClick={item.increment.bind(item)}
63
65
  key='right'
64
66
  >
@@ -71,7 +73,7 @@ const AddToCartWidget: React.FC<{
71
73
  size={size}
72
74
  variant='secondary'
73
75
  rounded='xl'
74
- className={className}
76
+ className={cn(buttonClx, className)}
75
77
  onClick={item.increment.bind(item)}
76
78
  >
77
79
  <Icons.plus className='h-5 w-5 mr-1' aria-hidden='true'/>
@@ -10,6 +10,14 @@ import { formatPrice } from '../util'
10
10
 
11
11
  const IMG_SIZE=40
12
12
 
13
+ const renderTitle = (t: string): React.ReactNode => {
14
+ const toks = t.split(', ')
15
+ if (toks.length === 2) {
16
+ return <><p>{toks[0]},</p><p className=''>{toks[1]}</p></>
17
+ }
18
+ return <p>{t}</p>
19
+ }
20
+
13
21
  const CartLineItem: React.FC<{
14
22
  item: LineItem
15
23
  className?: string
@@ -23,21 +31,22 @@ const CartLineItem: React.FC<{
23
31
  const imgSize = (isMobile) ? IMG_SIZE * 0.65 : IMG_SIZE
24
32
 
25
33
  return (
26
- <div className='flex flex-row justify-between items-center gap-2 sm:gap-4'>
27
- {!!item.img ? (
28
- <Image src={item.img} alt={item.title + ' image'} height={imgSize} width={imgSize} className='self-start'/>
29
- ) : (
30
- <div style={{height: imgSize, width: imgSize}}/ >
31
- )}
32
- <div className={cn('text-sm font-sans grow', className)} >
33
- <div className=''>{item.title}</div>
34
- <div className='flex flex-row items-center justify-between'>
35
- <div className='flex flex-row items-center'>
36
- <AddToCartWidget isMobile={isMobile} className='mr-2' item={item} ghost/>{item.quantity > 1 && '@' + formatPrice(item.price)}
37
- </div>
38
- <div className='flex flex-row items-center justify-end'>
39
- {formatPrice(item.price * item.quantity)}
40
- </div>
34
+ <div className={cn('flex flex-col justify-start items-start text-sm font-sans', className)}>
35
+ <div className='flex flex-row justify-between items-center gap-2'>
36
+ {!!item.img ? (
37
+ <Image src={item.img} alt={item.title + ' image'} height={imgSize} width={imgSize} className=''/>
38
+ ) : (
39
+ <div style={{height: imgSize, width: imgSize}}/ >
40
+ )}
41
+ <div className='grow leading-tight'>{renderTitle(item.title)}</div>
42
+ </div>
43
+ <div className='flex flex-row items-center justify-between w-full'>
44
+ <div className='flex flex-row items-center'>
45
+ <AddToCartWidget isMobile={isMobile} className='' item={item} size='xs' buttonClx='h-8 md:h-6' ghost/>
46
+ {item.quantity > 1 && (<span className='pl-2.5'>{'@' + formatPrice(item.price)}</span>)}
47
+ </div>
48
+ <div className='flex flex-row items-center justify-end'>
49
+ {formatPrice(item.price * item.quantity)}
41
50
  </div>
42
51
  </div>
43
52
  </div>
@@ -28,14 +28,16 @@ const Cart: React.FC<PropsWithChildren & {
28
28
  const auth = useAuth()
29
29
 
30
30
  return (
31
- <div className={cn('border p-6 rounded-lg', className)}>
31
+ <div className={cn('border p-4 rounded-lg', className)}>
32
32
  {children}
33
33
  <div className='mt-2'>
34
- {!!children && <div className='h-[1px] w-pr-80 mb-3 mx-auto bg-muted-3'/>}
34
+ {!!children && <div className='h-[1px] w-pr-80 mb-4 mx-auto bg-muted-3'/>}
35
35
  {cmmc.cartItems.length === 0 ? (
36
36
  <p className='text-center mt-4'>No items in cart</p>
37
37
  ) : (<>
38
- {cmmc.cartItems.map((item, i) => (<CartLineItem isMobile={isMobile} item={item} key={item.sku} className='mb-4 sm:mb-2'/>))}
38
+ {cmmc.cartItems.map((item, i) => (
39
+ <CartLineItem isMobile={isMobile} item={item} key={item.sku} className='mb-2 md:mb-3'/>
40
+ ))}
39
41
  <p className='mt-6 text-right border-t pt-1'>TOTAL: <span className='font-semibold'>{cmmc.cartTotal === 0 ? '0' : formatPrice(cmmc.cartTotal)}</span></p>
40
42
  </>)}
41
43
  </div>
@@ -11,29 +11,42 @@ const FacetImage: React.FC<{
11
11
  }> = ({
12
12
  facetValueDesc
13
13
  }) => {
14
- if (!facetValueDesc.img) {
14
+ const {
15
+ img,
16
+ imgAR: ar,
17
+ label
18
+ } = facetValueDesc
19
+
20
+
21
+ if (!img) {
15
22
  return null
16
23
  }
17
- const isURL = typeof facetValueDesc.img === 'string'
24
+ const isURL = typeof img === 'string'
18
25
  if (isURL) {
19
26
  return (
20
27
  <Image
21
- src={facetValueDesc.img as string}
22
- alt={`Toggle ${facetValueDesc.label}`}
23
- className={'block mr-1 aspect-square rounded border border-muted-2'}
24
- width={ICON_SIZE}
28
+ src={img as string}
29
+ alt={`Toggle ${label}`}
30
+ className={'block mr-1 rounded border border-muted-2 ' + (ar ? '' : 'aspect-square')}
31
+ width={ar ? ar * ICON_SIZE : ICON_SIZE}
25
32
  height={ICON_SIZE}
26
33
  />
27
34
  )
28
35
  }
36
+
37
+ // Otherwise, assume it's a ReactNode of an imported SVG
38
+
39
+ // If it's not square, center it in the appropriate dimension
29
40
  const svgStyle: any = { position: 'relative' }
30
- if (facetValueDesc.imgAR && facetValueDesc.imgAR < 1) {
31
- const w = ICON_SIZE * SVG_MULT
32
- svgStyle.top = (( 1 / facetValueDesc.imgAR - 1) * w) / 2
33
- }
34
- else if (facetValueDesc.imgAR && facetValueDesc.imgAR > 1) {
35
- const h = ICON_SIZE * SVG_MULT
36
- svgStyle.left = (((1 - facetValueDesc.imgAR) * h) / 2)
41
+ if (ar) {
42
+ if (ar < 1) {
43
+ const w = ICON_SIZE * SVG_MULT
44
+ svgStyle.top = (( 1 / ar - 1) * w) / 2
45
+ }
46
+ else if (ar > 1) {
47
+ const h = ICON_SIZE * SVG_MULT
48
+ svgStyle.left = (((1 - ar) * h) / 2)
49
+ }
37
50
  }
38
51
 
39
52
  return (
@@ -75,7 +75,7 @@ const FacetTogglesWidget: React.FC<{
75
75
  >
76
76
  <span className={cn('flex flex-row justify-center gap-1 h-4 items-center')} >
77
77
  <FacetImage facetValueDesc={fv} />
78
- <span className='whitespace-nowrap'>{fv.label}</span>
78
+ {(!isMobile || !fv.img) && (<span className='whitespace-nowrap'>{fv.label}</span>)}
79
79
  </span>
80
80
  </ToggleGroupItem>
81
81
  )
@@ -17,6 +17,7 @@ const FacetsWidget: React.FC<PropsWithChildren & {
17
17
  id?: string
18
18
  className?: string
19
19
  tabSize?: string
20
+ childrenAfter?: boolean
20
21
  }> = ({
21
22
  children,
22
23
  facets,
@@ -27,11 +28,13 @@ const FacetsWidget: React.FC<PropsWithChildren & {
27
28
  isMobile=false,
28
29
  className='',
29
30
  tabSize,
30
- id='FacetsWidget'
31
+ id='FacetsWidget',
32
+ childrenAfter=true
31
33
  }) => {
32
34
  const horiz = className.includes('flex-row')
33
35
  return (
34
36
  <div id={id} className={className} >
37
+ {!childrenAfter && children}
35
38
  {Object.keys(facets).map((key, i) => (
36
39
  <FacetTogglesWidget
37
40
  key={i}
@@ -44,7 +47,7 @@ const FacetsWidget: React.FC<PropsWithChildren & {
44
47
  tabSize={tabSize}
45
48
  />
46
49
  ))}
47
- {children}
50
+ {childrenAfter && children}
48
51
  </div>
49
52
  )
50
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/commerce",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Library with shopping cart components.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",