|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { Minus, Plus } from 'lucide-react'; |
| 4 | + |
| 5 | +import * as CounterPrimitive from '@/components/counter'; |
| 6 | + |
| 7 | +export interface CounterProps { |
| 8 | + start?: number; |
| 9 | + max?: number; |
| 10 | + decrementAriaLabel?: string; |
| 11 | + incrementAriaLabel?: string; |
| 12 | +} |
| 13 | + |
| 14 | +/** |
| 15 | + * This component supports various CSS variables for theming. Here's a comprehensive list, along |
| 16 | + * with their default values: |
| 17 | + * |
| 18 | + * ```css |
| 19 | + * :root { |
| 20 | + * --counter-focus: hsl(var(--primary)); |
| 21 | + * --counter-font-family: var(--font-family-body); |
| 22 | + * --counter-background: hsl(var(--background)); |
| 23 | + * --counter-background-hover: color-mix(in oklab, hsl(var(--contrast-100)) 50%, transparent); |
| 24 | + * --counter-border: hsl(var(--contrast-100)); |
| 25 | + * --counter-text: hsl(var(--foreground)); |
| 26 | + * --counter-icon-hover: hsl(var(--foreground)); |
| 27 | + * --counter-icon: hsl(var(--contrast-300)); |
| 28 | + * } |
| 29 | + * ``` |
| 30 | + */ |
| 31 | +export function Counter({ |
| 32 | + start = 0, |
| 33 | + max = 10, |
| 34 | + decrementAriaLabel = 'Decrease count', |
| 35 | + incrementAriaLabel = 'Increase count', |
| 36 | +}: CounterProps) { |
| 37 | + return ( |
| 38 | + <CounterPrimitive.Root max={max} start={start}> |
| 39 | + <CounterPrimitive.Decrease aria-label={decrementAriaLabel}> |
| 40 | + <Minus |
| 41 | + absoluteStrokeWidth |
| 42 | + className="text-[var(--counter-icon,hsl(var(--contrast-300)))] transition-colors duration-300 group-data-[state=enabled]:group-hover:text-[var(--counter-icon-hover,hsl(var(--foreground)))]" |
| 43 | + size={18} |
| 44 | + strokeWidth={1.5} |
| 45 | + /> |
| 46 | + </CounterPrimitive.Decrease> |
| 47 | + <CounterPrimitive.Input readOnly /> |
| 48 | + <CounterPrimitive.Increase aria-label={incrementAriaLabel}> |
| 49 | + <Plus |
| 50 | + absoluteStrokeWidth |
| 51 | + className="text-[var(--counter-icon,hsl(var(--contrast-300)))] transition-colors duration-300 group-data-[state=enabled]:group-hover:text-[var(--counter-icon-hover,hsl(var(--foreground)))]" |
| 52 | + size={18} |
| 53 | + strokeWidth={1.5} |
| 54 | + /> |
| 55 | + </CounterPrimitive.Increase> |
| 56 | + </CounterPrimitive.Root> |
| 57 | + ); |
| 58 | +} |
0 commit comments