Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout / cart improvements #104

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/commerce/components/add-to-cart-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const AddToCartWidget: React.FC<{
</Button>
<div className={cn(
'grow-0 shrink-0 flex items-center cursor-default xs:px-2',
priSmaller ? 'text-xs' : 'text-sm',
priSmaller || ghost ? 'text-xs' : 'text-sm',
digitClx
)}>
{item.quantity}{ghost ? '' : ' in Bag'}
Expand Down
5 changes: 1 addition & 4 deletions packages/commerce/components/buy/carousel-buy-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ const CarouselBuyCard: React.FC<{
if (peek.role === 'single-family') {

const sort = (): 'none' | 'asc' | 'desc' => {
if (!uiSpec.singleFamily?.options) {
return 'none'
}
const options = uiSpec.singleFamily.options
const options = uiSpec.singleFamily?.options ?? {}
const showSlider = 'showSlider' in options ? options.showSlider! : true
return ('sort' in options) ?
options.sort!
Expand Down
24 changes: 12 additions & 12 deletions packages/commerce/components/cart/cart-panel/cart-line-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ const CartLineItem: React.FC<{
const promoPrice = showPromoCode ? cmmc.itemPromoPrice(item) : undefined

return (
<div className={cn('flex flex-col justify-start items-start text-sm font-sans', className)}>
<div
className={
'flex flex-row justify-between items-center gap-1 ' +
(itemClicked && !selected ? 'cursor-pointer ' : 'cursor-default ')
}
onClick={() => {itemClicked && itemClicked(item)}}
>
{/* 1px gap between image and border for better emphasis w small images */}
<div className={selected ? 'border-foreground p-[1px] border rounded-sm' : 'p-[2px]'}>
<div
className={cn(
'flex flex-col justify-start items-start text-sm font-sans',
'border border-background rounded-sm p-1',
selected ? 'border-foreground' : '',
(itemClicked && !selected ? 'cursor-pointer hover:!border-muted-4' : 'cursor-default '),
className
)}
onClick={() => {itemClicked && itemClicked(item)}}
>
<div className='flex flex-row justify-between items-center gap-1' >
{item.img ? (
<Image def={item.img} constrainTo={{w: imgSizePx, h: imgSizePx}} />
) : ( // placeholder so things align
<div style={{height: imgSizePx, width: imgSizePx}} className='bg-level-3'/>
)}
</div>
<div className='grow leading-tight ml-1'>{renderTitle(item.title)}</div>
</div>
<div className='flex flex-row items-center justify-between w-full'>
<div className='flex flex-row items-center'>
<AddToCartWidget variant='minimal' item={item} buttonClx='!h-8 md:!h-6' />
<AddToCartWidget variant='minimal' item={item} />
{item.quantity > 1 && (<span className='pl-2.5'>{'@' + formatCurrencyValue(item.price)}</span>)}
</div>
<div className='flex flex-row gap-1 items-center justify-end'>
Expand Down
6 changes: 4 additions & 2 deletions packages/commerce/components/cart/cart-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ const CartPanel: React.FC<PropsWithChildren & {
/>
))}
</>)}
<div className={totalClx}>
{showPromoCode && (
<Suspense>
<PromoCode/>
</Suspense>
)}
{(showShipping || showPromoCode) && (
<div className='flex flex-col gap-1 py-2 border-t'>
<div className={'flex flex-col gap-0.5 pb-1.5 text-sm ' + (!showPromoCode ? 'border-t pt-1.5' : '')} >
<p className='flex justify-between'>
<span className='text-muted-1'>Subtotal</span>
<span className='font-semibold'>{cmmc.cartTotal === 0 ? '0' : formatCurrencyValue(cmmc.cartTotal)}</span>
Expand All @@ -122,10 +123,11 @@ const CartPanel: React.FC<PropsWithChildren & {
)}
</div>
)}
<p className={cn('border-t py-2 flex justify-between', totalClx)}>
<p className={cn('border-t py-2 flex justify-between')}>
TOTAL
<span className='font-semibold'>{formatCurrencyValue(showPromoCode ? cmmc.promoAppliedCartTotal : cmmc.cartTotal)}</span>
</p>
</div>
</>))

const scrolling = (): boolean => (cmmc.cartItems.length > scrollAfter)
Expand Down
6 changes: 3 additions & 3 deletions packages/commerce/components/cart/cart-panel/promo-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const PromoCode = observer(() => {
}

return (
<div className='flex flex-col gap-2 border-t py-2'>
<div className='flex flex-col gap-2 border-t py-1'>
<Form {...form}>
<form onSubmit={form.handleSubmit(applyPromoCode)}>
<div className='flex gap-2 items-center'>
Expand All @@ -78,15 +78,15 @@ const PromoCode = observer(() => {
render={({ field }) => (
<FormItem className='w-full'>
<FormControl>
<Input {...field} placeholder='Discount or invite code' onInput={removePromoCode}/>
<Input {...field} className='h-9' placeholder='Discount or invite code' onInput={removePromoCode}/>
</FormControl>
</FormItem>
)}
/>
{codeAccepted ? (
<Check/>
) : (
<Button variant='outline' className='!w-fit !min-w-0 font-inter'>Apply</Button>
<Button variant='outline' className='!w-fit !min-w-0 font-inter text-muted text-sm'>Apply</Button>
)}
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion packages/commerce/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hanzo/commerce",
"version": "7.1.5",
"version": "7.1.20",
"description": "e-commerce framework.",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hanzo/ui",
"version": "3.8.21",
"version": "3.8.24",
"description": "Library that contains shared UI primitives, support for a common design system, and other boilerplate support.",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down Expand Up @@ -66,6 +66,7 @@
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-toggle": "^1.0.3",
"@radix-ui/react-toggle-group": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.6",
"@splinetool/react-spline": "^2.2.6",
"@splinetool/runtime": "^1.0.75",
"@tailwindcss/container-queries": "^0.1.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/primitives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export {
TabsContent
} from './tabs'

export * from './tooltip'


export { default as ActionButton } from './action-button'
export { default as ApplyTypography, type TypographySize} from './apply-typography'
export { default as AspectRatio } from './aspect-ratio'
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/primitives/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
className={cn(
'flex h-10 w-full rounded-md border border-muted-3 bg-inherit px-3 py-2 text-sm ring-offset-background ' +
'file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-2 ' +
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ' +
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 ' +
'first-letter:disabled:cursor-not-allowed disabled:opacity-50',
className
)}
Expand Down
30 changes: 30 additions & 0 deletions packages/ui/primitives/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client'

import * as React from 'react'
import * as TooltipPrimitive from '@radix-ui/react-tooltip'

import { cn } from '../util'

const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
'z-floating overflow-hidden rounded-sm border bg-level-1 px-2 py-1.5 text-sm text-muted shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className
)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading