@otfdashkit/ui 0.1.2 → 0.1.3
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/dist/index.js +775 -539
- package/dist/index.mjs +639 -408
- package/package.json +1 -1
- package/src/index.ts +5 -0
- package/src/primitives/cart-line-item.tsx +81 -0
- package/src/primitives/empty-cart.tsx +52 -0
- package/src/primitives/price-tag.tsx +62 -0
- package/src/primitives/quantity-stepper.tsx +92 -0
- package/src/primitives/variant-picker.tsx +74 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otfdashkit/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "OTF UI — production-quality React component library. 98 primitives + blocks + layouts + charts on Radix + Tailwind v4. Cross-platform parity API with @otfdashkit/ui-native.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"otfdashkit",
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './primitives/button'
|
|
|
13
13
|
export * from './primitives/calendar'
|
|
14
14
|
export * from './primitives/card'
|
|
15
15
|
export * from './primitives/carousel'
|
|
16
|
+
export * from './primitives/cart-line-item'
|
|
16
17
|
export * from './primitives/chart'
|
|
17
18
|
export * from './primitives/checkbox'
|
|
18
19
|
export * from './primitives/code-block'
|
|
@@ -23,6 +24,7 @@ export * from './primitives/context-menu'
|
|
|
23
24
|
export * from './primitives/dialog'
|
|
24
25
|
export * from './primitives/drawer'
|
|
25
26
|
export * from './primitives/dropdown-menu'
|
|
27
|
+
export * from './primitives/empty-cart'
|
|
26
28
|
// export * from './primitives/form' // conflicts with forms/form.tsx (Form, FormField, etc.)
|
|
27
29
|
export * from './primitives/hover-card'
|
|
28
30
|
export * from './primitives/input-otp'
|
|
@@ -34,8 +36,10 @@ export * from './primitives/menubar'
|
|
|
34
36
|
export * from './primitives/navigation-menu'
|
|
35
37
|
export * from './primitives/pagination'
|
|
36
38
|
export * from './primitives/popover'
|
|
39
|
+
export * from './primitives/price-tag'
|
|
37
40
|
export * from './primitives/progress'
|
|
38
41
|
export * from './primitives/qr-code'
|
|
42
|
+
export * from './primitives/quantity-stepper'
|
|
39
43
|
export * from './primitives/radio'
|
|
40
44
|
export * from './primitives/rating'
|
|
41
45
|
export * from './primitives/resizable'
|
|
@@ -55,6 +59,7 @@ export * from './primitives/texture-card'
|
|
|
55
59
|
export * from './primitives/toggle-group'
|
|
56
60
|
export * from './primitives/toggle'
|
|
57
61
|
export * from './primitives/tooltip'
|
|
62
|
+
export * from './primitives/variant-picker'
|
|
58
63
|
|
|
59
64
|
// components
|
|
60
65
|
export * from './components/banner'
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { X } from 'lucide-react'
|
|
3
|
+
import { cn } from '../utils/cn'
|
|
4
|
+
import { Button } from './button'
|
|
5
|
+
import { PriceTag } from './price-tag'
|
|
6
|
+
import { QuantityStepper } from './quantity-stepper'
|
|
7
|
+
|
|
8
|
+
export type CartLineItemProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
|
|
9
|
+
/** Product thumbnail URL. */
|
|
10
|
+
image?: string
|
|
11
|
+
title: string
|
|
12
|
+
/** Variant summary line, e.g. "Whole bean · 250g". */
|
|
13
|
+
variant?: string
|
|
14
|
+
/** Unit price in minor units (cents). */
|
|
15
|
+
price: number
|
|
16
|
+
/** Optional compare-at unit price in minor units. */
|
|
17
|
+
compareAt?: number
|
|
18
|
+
currency?: string
|
|
19
|
+
quantity: number
|
|
20
|
+
onQuantityChange?: (qty: number) => void
|
|
21
|
+
onRemove?: () => void
|
|
22
|
+
minQuantity?: number
|
|
23
|
+
maxQuantity?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Cart row: thumbnail · title · variant · price · quantity stepper · remove. */
|
|
27
|
+
export const CartLineItem = React.forwardRef<HTMLDivElement, CartLineItemProps>(
|
|
28
|
+
(
|
|
29
|
+
{
|
|
30
|
+
image,
|
|
31
|
+
title,
|
|
32
|
+
variant,
|
|
33
|
+
price,
|
|
34
|
+
compareAt,
|
|
35
|
+
currency = 'USD',
|
|
36
|
+
quantity,
|
|
37
|
+
onQuantityChange,
|
|
38
|
+
onRemove,
|
|
39
|
+
minQuantity = 1,
|
|
40
|
+
maxQuantity = 99,
|
|
41
|
+
className,
|
|
42
|
+
...props
|
|
43
|
+
},
|
|
44
|
+
ref,
|
|
45
|
+
) => {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
ref={ref}
|
|
49
|
+
className={cn('flex items-center gap-4 rounded-lg border border-border bg-card p-3', className)}
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
{image && <img src={image} alt="" className="h-16 w-16 flex-none rounded-md object-cover" />}
|
|
53
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
54
|
+
<span className="truncate font-medium text-card-foreground">{title}</span>
|
|
55
|
+
{variant && <span className="truncate text-sm text-muted-foreground">{variant}</span>}
|
|
56
|
+
<PriceTag amount={price} compareAt={compareAt} currency={currency} size="sm" />
|
|
57
|
+
</div>
|
|
58
|
+
<QuantityStepper
|
|
59
|
+
value={quantity}
|
|
60
|
+
min={minQuantity}
|
|
61
|
+
max={maxQuantity}
|
|
62
|
+
onValueChange={onQuantityChange}
|
|
63
|
+
size="sm"
|
|
64
|
+
/>
|
|
65
|
+
{onRemove && (
|
|
66
|
+
<Button
|
|
67
|
+
type="button"
|
|
68
|
+
variant="ghost"
|
|
69
|
+
size="icon"
|
|
70
|
+
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
|
71
|
+
onClick={onRemove}
|
|
72
|
+
aria-label={`Remove ${title}`}
|
|
73
|
+
>
|
|
74
|
+
<X className="h-4 w-4" />
|
|
75
|
+
</Button>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
)
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
CartLineItem.displayName = 'CartLineItem'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { ShoppingCart } from 'lucide-react'
|
|
3
|
+
import { cn } from '../utils/cn'
|
|
4
|
+
import { Button } from './button'
|
|
5
|
+
|
|
6
|
+
export type EmptyCartProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
7
|
+
title?: string
|
|
8
|
+
description?: string
|
|
9
|
+
/** CTA label — renders a button only when `onAction` is also provided. */
|
|
10
|
+
actionLabel?: string
|
|
11
|
+
onAction?: () => void
|
|
12
|
+
/** Override the default cart icon. */
|
|
13
|
+
icon?: React.ReactNode
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Bespoke empty-cart state: soft icon chip, message, and a continue-shopping CTA. */
|
|
17
|
+
export const EmptyCart = React.forwardRef<HTMLDivElement, EmptyCartProps>(
|
|
18
|
+
(
|
|
19
|
+
{
|
|
20
|
+
title = 'Your cart is empty',
|
|
21
|
+
description = 'Browse the catalog and add something you love.',
|
|
22
|
+
actionLabel = 'Continue shopping',
|
|
23
|
+
onAction,
|
|
24
|
+
icon,
|
|
25
|
+
className,
|
|
26
|
+
...props
|
|
27
|
+
},
|
|
28
|
+
ref,
|
|
29
|
+
) => {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
ref={ref}
|
|
33
|
+
className={cn('flex flex-col items-center justify-center gap-4 px-6 py-12 text-center', className)}
|
|
34
|
+
{...props}
|
|
35
|
+
>
|
|
36
|
+
<div className="flex h-14 w-14 items-center justify-center rounded-full bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]">
|
|
37
|
+
{icon ?? <ShoppingCart className="h-6 w-6" strokeWidth={1.5} />}
|
|
38
|
+
</div>
|
|
39
|
+
<div className="flex flex-col gap-1">
|
|
40
|
+
<span className="text-base font-semibold text-foreground">{title}</span>
|
|
41
|
+
{description && <span className="max-w-xs text-sm text-muted-foreground">{description}</span>}
|
|
42
|
+
</div>
|
|
43
|
+
{actionLabel && onAction && (
|
|
44
|
+
<Button onClick={onAction} className="mt-1">
|
|
45
|
+
{actionLabel}
|
|
46
|
+
</Button>
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
},
|
|
51
|
+
)
|
|
52
|
+
EmptyCart.displayName = 'EmptyCart'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { cn } from '../utils/cn'
|
|
3
|
+
|
|
4
|
+
const SIZE = {
|
|
5
|
+
sm: { price: 'text-sm', compare: 'text-xs' },
|
|
6
|
+
md: { price: 'text-lg', compare: 'text-sm' },
|
|
7
|
+
lg: { price: 'text-2xl', compare: 'text-base' },
|
|
8
|
+
} as const
|
|
9
|
+
|
|
10
|
+
export type PriceTagProps = React.HTMLAttributes<HTMLSpanElement> & {
|
|
11
|
+
/** Price in minor units (e.g. cents). */
|
|
12
|
+
amount: number
|
|
13
|
+
/** Original/compare-at price in minor units — renders struck-through when greater than `amount`. */
|
|
14
|
+
compareAt?: number
|
|
15
|
+
/** ISO 4217 currency code. Default 'USD'. */
|
|
16
|
+
currency?: string
|
|
17
|
+
/** BCP-47 locale for formatting. Default 'en-US'. */
|
|
18
|
+
locale?: string
|
|
19
|
+
/** Size scale. Default 'md'. */
|
|
20
|
+
size?: keyof typeof SIZE
|
|
21
|
+
/** Show the "−N%" discount pill when on sale. Default true. */
|
|
22
|
+
showDiscount?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatMoney(minor: number, currency: string, locale: string) {
|
|
26
|
+
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(minor / 100)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Formatted currency price with an optional compare-at strikethrough and discount pill.
|
|
31
|
+
* Amounts are minor units (cents) so there's no float drift.
|
|
32
|
+
*/
|
|
33
|
+
export const PriceTag = React.forwardRef<HTMLSpanElement, PriceTagProps>(
|
|
34
|
+
(
|
|
35
|
+
{ amount, compareAt, currency = 'USD', locale = 'en-US', size = 'md', showDiscount = true, className, ...props },
|
|
36
|
+
ref,
|
|
37
|
+
) => {
|
|
38
|
+
const onSale = compareAt !== undefined && compareAt > amount
|
|
39
|
+
const pct = onSale ? Math.round((1 - amount / compareAt) * 100) : 0
|
|
40
|
+
const s = SIZE[size]
|
|
41
|
+
return (
|
|
42
|
+
<span ref={ref} className={cn('inline-flex items-baseline gap-2 font-sans tabular-nums', className)} {...props}>
|
|
43
|
+
<span className={cn('font-semibold tracking-tight text-foreground', s.price)}>
|
|
44
|
+
{formatMoney(amount, currency, locale)}
|
|
45
|
+
</span>
|
|
46
|
+
{onSale && (
|
|
47
|
+
<>
|
|
48
|
+
<span className={cn('text-muted-foreground line-through', s.compare)}>
|
|
49
|
+
{formatMoney(compareAt, currency, locale)}
|
|
50
|
+
</span>
|
|
51
|
+
{showDiscount && (
|
|
52
|
+
<span className="rounded-full bg-destructive/10 px-2 py-0.5 text-xs font-semibold text-destructive">
|
|
53
|
+
−{pct}%
|
|
54
|
+
</span>
|
|
55
|
+
)}
|
|
56
|
+
</>
|
|
57
|
+
)}
|
|
58
|
+
</span>
|
|
59
|
+
)
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
PriceTag.displayName = 'PriceTag'
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Minus, Plus } from 'lucide-react'
|
|
3
|
+
import { cn } from '../utils/cn'
|
|
4
|
+
import { Button } from './button'
|
|
5
|
+
|
|
6
|
+
export type QuantityStepperProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
|
|
7
|
+
/** Controlled quantity. */
|
|
8
|
+
value?: number
|
|
9
|
+
/** Uncontrolled initial quantity. Default 1. */
|
|
10
|
+
defaultValue?: number
|
|
11
|
+
/** Fires with the clamped next quantity. */
|
|
12
|
+
onValueChange?: (value: number) => void
|
|
13
|
+
/** Minimum (decrement disables here). Default 1. */
|
|
14
|
+
min?: number
|
|
15
|
+
/** Maximum (increment disables here). Default 99. */
|
|
16
|
+
max?: number
|
|
17
|
+
/** Increment/decrement step. Default 1. */
|
|
18
|
+
step?: number
|
|
19
|
+
/** Control size. Default 'md'. */
|
|
20
|
+
size?: 'sm' | 'md'
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
'aria-label'?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Increment / decrement quantity control with min/max clamping. */
|
|
26
|
+
export const QuantityStepper = React.forwardRef<HTMLDivElement, QuantityStepperProps>(
|
|
27
|
+
(
|
|
28
|
+
{
|
|
29
|
+
value: valueProp,
|
|
30
|
+
defaultValue = 1,
|
|
31
|
+
onValueChange,
|
|
32
|
+
min = 1,
|
|
33
|
+
max = 99,
|
|
34
|
+
step = 1,
|
|
35
|
+
size = 'md',
|
|
36
|
+
disabled = false,
|
|
37
|
+
className,
|
|
38
|
+
'aria-label': ariaLabel = 'Quantity',
|
|
39
|
+
...props
|
|
40
|
+
},
|
|
41
|
+
ref,
|
|
42
|
+
) => {
|
|
43
|
+
const isControlled = valueProp !== undefined
|
|
44
|
+
const [internal, setInternal] = React.useState(defaultValue)
|
|
45
|
+
const value = isControlled ? (valueProp as number) : internal
|
|
46
|
+
const commit = (next: number) => {
|
|
47
|
+
const clamped = Math.max(min, Math.min(max, next))
|
|
48
|
+
if (!isControlled) setInternal(clamped)
|
|
49
|
+
onValueChange?.(clamped)
|
|
50
|
+
}
|
|
51
|
+
const dim = size === 'sm' ? 'h-7 w-7' : 'h-9 w-9'
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
ref={ref}
|
|
55
|
+
role="group"
|
|
56
|
+
aria-label={ariaLabel}
|
|
57
|
+
className={cn('inline-flex items-center rounded-md border border-input', className)}
|
|
58
|
+
{...props}
|
|
59
|
+
>
|
|
60
|
+
<Button
|
|
61
|
+
type="button"
|
|
62
|
+
variant="ghost"
|
|
63
|
+
size="icon"
|
|
64
|
+
className={cn('rounded-r-none', dim)}
|
|
65
|
+
disabled={disabled || value <= min}
|
|
66
|
+
onClick={() => commit(value - step)}
|
|
67
|
+
aria-label="Decrease quantity"
|
|
68
|
+
>
|
|
69
|
+
<Minus className="h-4 w-4" />
|
|
70
|
+
</Button>
|
|
71
|
+
<span
|
|
72
|
+
aria-live="polite"
|
|
73
|
+
className={cn('select-none text-center text-sm font-medium tabular-nums', size === 'sm' ? 'min-w-7' : 'min-w-8')}
|
|
74
|
+
>
|
|
75
|
+
{value}
|
|
76
|
+
</span>
|
|
77
|
+
<Button
|
|
78
|
+
type="button"
|
|
79
|
+
variant="ghost"
|
|
80
|
+
size="icon"
|
|
81
|
+
className={cn('rounded-l-none', dim)}
|
|
82
|
+
disabled={disabled || value >= max}
|
|
83
|
+
onClick={() => commit(value + step)}
|
|
84
|
+
aria-label="Increase quantity"
|
|
85
|
+
>
|
|
86
|
+
<Plus className="h-4 w-4" />
|
|
87
|
+
</Button>
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
)
|
|
92
|
+
QuantityStepper.displayName = 'QuantityStepper'
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { cn } from '../utils/cn'
|
|
3
|
+
|
|
4
|
+
export type VariantOption = {
|
|
5
|
+
value: string
|
|
6
|
+
label: string
|
|
7
|
+
/** Optional color swatch — a CSS color from your product data (not a design token). */
|
|
8
|
+
swatch?: string
|
|
9
|
+
disabled?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type VariantPickerProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
|
|
13
|
+
/** Group label, e.g. "Grind" or "Size". */
|
|
14
|
+
label?: string
|
|
15
|
+
options: VariantOption[]
|
|
16
|
+
/** Controlled selected value. */
|
|
17
|
+
value?: string
|
|
18
|
+
/** Uncontrolled initial value. */
|
|
19
|
+
defaultValue?: string
|
|
20
|
+
onValueChange?: (value: string) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Single-select product-option picker (grind, size, color) with selected + out-of-stock states. */
|
|
24
|
+
export const VariantPicker = React.forwardRef<HTMLDivElement, VariantPickerProps>(
|
|
25
|
+
({ label, options, value: valueProp, defaultValue, onValueChange, className, ...props }, ref) => {
|
|
26
|
+
const isControlled = valueProp !== undefined
|
|
27
|
+
const [internal, setInternal] = React.useState(defaultValue)
|
|
28
|
+
const value = isControlled ? valueProp : internal
|
|
29
|
+
const select = (v: string) => {
|
|
30
|
+
if (!isControlled) setInternal(v)
|
|
31
|
+
onValueChange?.(v)
|
|
32
|
+
}
|
|
33
|
+
return (
|
|
34
|
+
<div ref={ref} role="radiogroup" aria-label={label} className={cn('flex flex-col gap-2', className)} {...props}>
|
|
35
|
+
{label && (
|
|
36
|
+
<span className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">{label}</span>
|
|
37
|
+
)}
|
|
38
|
+
<div className="flex flex-wrap gap-2">
|
|
39
|
+
{options.map((opt) => {
|
|
40
|
+
const selected = value === opt.value
|
|
41
|
+
return (
|
|
42
|
+
<button
|
|
43
|
+
key={opt.value}
|
|
44
|
+
type="button"
|
|
45
|
+
role="radio"
|
|
46
|
+
aria-checked={selected}
|
|
47
|
+
disabled={opt.disabled}
|
|
48
|
+
onClick={() => select(opt.value)}
|
|
49
|
+
className={cn(
|
|
50
|
+
'inline-flex items-center gap-2 rounded-md border px-3 py-1.5 text-sm font-medium transition-colors',
|
|
51
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
|
|
52
|
+
selected
|
|
53
|
+
? 'border-primary bg-primary/10 text-[hsl(var(--primary))]'
|
|
54
|
+
: 'border-border hover:bg-accent hover:text-accent-foreground',
|
|
55
|
+
opt.disabled && 'cursor-not-allowed text-muted-foreground line-through opacity-50',
|
|
56
|
+
)}
|
|
57
|
+
>
|
|
58
|
+
{opt.swatch && (
|
|
59
|
+
<span
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
className="h-4 w-4 rounded-full border border-border"
|
|
62
|
+
style={{ backgroundColor: opt.swatch }}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
65
|
+
{opt.label}
|
|
66
|
+
</button>
|
|
67
|
+
)
|
|
68
|
+
})}
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
},
|
|
73
|
+
)
|
|
74
|
+
VariantPicker.displayName = 'VariantPicker'
|