@otfdashkit/ui 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otfdashkit/ui",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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'
@@ -162,7 +167,8 @@ export * from './text'
162
167
  export * from './backgrounds'
163
168
  export * from './headers'
164
169
  export * from './motion'
165
- // export * from './data' // conflicts with components/data-grid (DataGrid)
170
+ // './data' is not star-exported: its DataGrid name collides with components/data-grid.
171
+ export { DataGrid as AdvancedDataGrid, type DataGridProps as AdvancedDataGridProps } from './data/DataGrid'
166
172
  export * from './data/DataList'
167
173
  export * from './data/EventCalendar'
168
174
  export * from './data/GridList'
@@ -1,131 +1,2 @@
1
- import React from 'react'
2
- import { Slot } from '@radix-ui/react-slot'
3
- import { cva, type VariantProps } from 'class-variance-authority'
4
- import { cn } from '../utils/cn'
5
-
6
- const buttonVariants = cva(
7
- [
8
- 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium font-sans',
9
- 'transition-colors duration-[var(--duration-fast,100ms)]',
10
- 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
11
- 'disabled:pointer-events-none disabled:opacity-50',
12
- 'select-none',
13
- ].join(' '),
14
- {
15
- variants: {
16
- variant: {
17
- default:
18
- 'bg-primary text-primary-foreground hover:bg-primary/90 active:bg-primary/80',
19
- secondary:
20
- 'bg-secondary text-secondary-foreground hover:bg-secondary/80 active:bg-secondary/70',
21
- outline:
22
- 'border border-border bg-transparent hover:bg-accent hover:text-accent-foreground active:bg-accent/70',
23
- ghost:
24
- 'hover:bg-accent hover:text-accent-foreground active:bg-accent/70',
25
- destructive:
26
- 'bg-destructive text-destructive-foreground hover:bg-destructive/90 active:bg-destructive/80',
27
- link:
28
- 'text-primary underline-offset-4 hover:underline',
29
- /** Gradient stack — premium variant */
30
- gradient: [
31
- 'bg-gradient-to-b from-primary to-[hsl(var(--primary)/0.8)]',
32
- 'text-primary-foreground',
33
- 'shadow-[0_1px_0_0_rgba(255,255,255,0.1)_inset,0_-1px_0_0_rgba(0,0,0,0.25)_inset]',
34
- 'hover:from-[hsl(var(--primary)/0.9)] hover:to-[hsl(var(--primary)/0.7)]',
35
- 'active:from-[hsl(var(--primary)/0.8)] active:to-[hsl(var(--primary)/0.6)]',
36
- ].join(' '),
37
- /** Texture — nested ring surface as a button */
38
- texture: [
39
- 'relative border border-border/40',
40
- 'bg-gradient-to-b from-card to-[hsl(var(--card)/0.9)]',
41
- 'text-foreground',
42
- 'shadow-[0_0_0_1px_hsl(var(--border)/0.2)_inset]',
43
- 'hover:border-border/60 hover:bg-accent',
44
- 'active:shadow-none',
45
- ].join(' '),
46
- /** Shimmer — animated conic gradient sweep with a hover highlight.
47
- * Loud + premium; reserve for primary CTAs and pricing pages, not
48
- * for in-product UI (gets tiring fast). Cross-platform parity with
49
- * @otfdashkit/ui-native via the same `shimmer` variant key. */
50
- shimmer: [
51
- 'relative isolate overflow-hidden',
52
- 'bg-primary text-primary-foreground',
53
- 'shadow-[0_1px_0_rgba(255,255,255,0.18)_inset,0_-1px_0_rgba(0,0,0,0.25)_inset]',
54
- 'hover:bg-primary/95',
55
- // Continuous conic-gradient sweep behind the surface.
56
- 'before:absolute before:inset-[-1px] before:rounded-[inherit] before:-z-10',
57
- 'before:bg-[conic-gradient(from_0deg,transparent_0deg,transparent_70deg,rgba(255,255,255,0.55)_90deg,transparent_110deg,transparent_360deg)]',
58
- 'before:animate-[shimmer-rotate_2.6s_linear_infinite]',
59
- // Diagonal gloss that sweeps on hover.
60
- 'after:absolute after:inset-0 after:rounded-[inherit] after:pointer-events-none',
61
- 'after:bg-[linear-gradient(115deg,transparent_30%,rgba(255,255,255,0.22)_50%,transparent_70%)]',
62
- 'after:translate-x-[-120%] hover:after:translate-x-[120%] after:transition-transform after:duration-[900ms] after:ease-out',
63
- ].join(' '),
64
- },
65
- size: {
66
- sm: 'h-8 px-3 text-xs rounded-md',
67
- default: 'h-9 px-4 py-2',
68
- lg: 'h-11 px-6 text-base',
69
- xl: 'h-12 px-8 text-base',
70
- icon: 'h-9 w-9 p-0',
71
- 'icon-sm': 'h-7 w-7 p-0 text-xs',
72
- },
73
- },
74
- defaultVariants: { variant: 'default', size: 'default' },
75
- }
76
- )
77
-
78
- export interface ButtonProps
79
- extends React.ButtonHTMLAttributes<HTMLButtonElement>,
80
- VariantProps<typeof buttonVariants> {
81
- asChild?: boolean
82
- }
83
-
84
- export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
85
- ({ className, variant, size, asChild = false, ...props }, ref) => {
86
- const Comp = asChild ? Slot : 'button'
87
- return (
88
- <Comp
89
- data-slot="button"
90
- className={cn(buttonVariants({ variant, size }), className)}
91
- ref={ref}
92
- {...props}
93
- />
94
- )
95
- }
96
- )
97
- Button.displayName = 'Button'
98
-
99
- export interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
100
- icon: React.ReactNode
101
- label: string
102
- size?: 'sm' | 'default' | 'lg'
103
- variant?: VariantProps<typeof buttonVariants>['variant']
104
- asChild?: boolean
105
- }
106
-
107
- export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
108
- ({ icon, label, size = 'default', variant = 'ghost', className, asChild = false, ...props }, ref) => {
109
- const Comp = asChild ? Slot : 'button'
110
- const sizeClass = size === 'sm' ? 'h-7 w-7' : size === 'lg' ? 'h-10 w-10' : 'h-9 w-9'
111
- return (
112
- <Comp
113
- ref={ref}
114
- aria-label={label}
115
- data-slot="icon-button"
116
- className={cn(
117
- buttonVariants({ variant }),
118
- sizeClass,
119
- 'p-0 shrink-0',
120
- className
121
- )}
122
- {...props}
123
- >
124
- {icon}
125
- </Comp>
126
- )
127
- }
128
- )
129
- IconButton.displayName = 'IconButton'
130
-
131
- export { buttonVariants }
1
+ // Single source of truth lives in ../button; this path stays so existing imports keep working.
2
+ export * from '../button'
@@ -14,12 +14,42 @@ const buttonVariants = cva(
14
14
  ghost: 'hover:bg-accent hover:text-accent-foreground',
15
15
  destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
16
16
  link: 'text-primary underline-offset-4 hover:underline',
17
+ gradient: [
18
+ 'bg-gradient-to-b from-primary to-[hsl(var(--primary)/0.8)]',
19
+ 'text-primary-foreground',
20
+ 'shadow-[0_1px_0_0_rgba(255,255,255,0.1)_inset,0_-1px_0_0_rgba(0,0,0,0.25)_inset]',
21
+ 'hover:from-[hsl(var(--primary)/0.9)] hover:to-[hsl(var(--primary)/0.7)]',
22
+ 'active:from-[hsl(var(--primary)/0.8)] active:to-[hsl(var(--primary)/0.6)]',
23
+ ].join(' '),
24
+ texture: [
25
+ 'relative border border-border/40',
26
+ 'bg-gradient-to-b from-card to-[hsl(var(--card)/0.9)]',
27
+ 'text-foreground',
28
+ 'shadow-[0_0_0_1px_hsl(var(--border)/0.2)_inset]',
29
+ 'hover:border-border/60 hover:bg-accent',
30
+ 'active:shadow-none',
31
+ ].join(' '),
32
+ // Loud by design: keep for primary CTAs. The sweep keyframe ships in themes/base.css.
33
+ shimmer: [
34
+ 'relative isolate overflow-hidden',
35
+ 'bg-primary text-primary-foreground',
36
+ 'shadow-[0_1px_0_rgba(255,255,255,0.18)_inset,0_-1px_0_rgba(0,0,0,0.25)_inset]',
37
+ 'hover:bg-primary/95',
38
+ 'before:absolute before:inset-[-1px] before:rounded-[inherit] before:-z-10',
39
+ 'before:bg-[conic-gradient(from_0deg,transparent_0deg,transparent_70deg,rgba(255,255,255,0.55)_90deg,transparent_110deg,transparent_360deg)]',
40
+ 'before:animate-[shimmer-rotate_2.6s_linear_infinite] motion-reduce:before:animate-none',
41
+ 'after:absolute after:inset-0 after:rounded-[inherit] after:pointer-events-none',
42
+ 'after:bg-[linear-gradient(115deg,transparent_30%,rgba(255,255,255,0.22)_50%,transparent_70%)]',
43
+ 'after:translate-x-[-120%] hover:after:translate-x-[120%] after:transition-transform after:duration-[900ms] after:ease-out',
44
+ ].join(' '),
17
45
  },
18
46
  size: {
19
47
  sm: 'h-8 px-3 text-xs',
20
48
  default: 'h-9 px-4 py-2',
21
49
  lg: 'h-11 px-6 text-base',
50
+ xl: 'h-12 px-8 text-base',
22
51
  icon: 'h-9 w-9',
52
+ 'icon-sm': 'h-7 w-7 p-0 text-xs',
23
53
  },
24
54
  },
25
55
  defaultVariants: { variant: 'default', size: 'default' },
@@ -40,4 +70,26 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
40
70
  )
41
71
  Button.displayName = 'Button'
42
72
 
73
+ export interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
74
+ icon: React.ReactNode
75
+ /** Accessible name; an icon-only button has no visible text. */
76
+ label: string
77
+ size?: 'sm' | 'default' | 'lg'
78
+ variant?: VariantProps<typeof buttonVariants>['variant']
79
+ asChild?: boolean
80
+ }
81
+
82
+ export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
83
+ ({ icon, label, size = 'default', variant = 'ghost', className, asChild = false, ...props }, ref) => {
84
+ const Comp = asChild ? Slot : 'button'
85
+ const sizeClass = size === 'sm' ? 'h-7 w-7' : size === 'lg' ? 'h-10 w-10' : 'h-9 w-9'
86
+ return (
87
+ <Comp ref={ref} aria-label={label} className={cn(buttonVariants({ variant }), sizeClass, 'p-0 shrink-0', className)} {...props}>
88
+ {icon}
89
+ </Comp>
90
+ )
91
+ }
92
+ )
93
+ IconButton.displayName = 'IconButton'
94
+
43
95
  export { buttonVariants }
@@ -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'