@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.
- package/components/add-to-cart-widget.tsx +7 -5
- package/components/cart-line-item.tsx +24 -15
- package/components/cart.tsx +5 -3
- package/components/facet-toggles-widget/facet-image.tsx +26 -13
- package/components/facet-toggles-widget/index.tsx +1 -1
- package/components/facets-widget.tsx +5 -2
- package/package.json +1 -1
|
@@ -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-
|
|
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-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<div className=''>{item.title}</div>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
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>
|
package/components/cart.tsx
CHANGED
|
@@ -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-
|
|
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-
|
|
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) => (
|
|
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
|
-
|
|
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
|
|
24
|
+
const isURL = typeof img === 'string'
|
|
18
25
|
if (isURL) {
|
|
19
26
|
return (
|
|
20
27
|
<Image
|
|
21
|
-
src={
|
|
22
|
-
alt={`Toggle ${
|
|
23
|
-
className={'block mr-1
|
|
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 (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
}
|