import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Minus, Plus } from "lucide-react"; import { cn } from "@/lib/utils"; interface NumericInputProps { value: number; onChange: (value: number) => void; min?: number; max?: number; step?: number; showSteppers?: boolean; disabled?: boolean; placeholder?: string; className?: string; quickValues?: number[]; label?: string; } export function NumericInput({ value, onChange, min = 0, max, step = 1, showSteppers = true, disabled = false, placeholder = "0", className, quickValues, label }: NumericInputProps) { const [isFocused, setIsFocused] = useState(false); const handleDecrement = () => { const newValue = value - step; if (newValue >= min) { onChange(newValue); } }; const handleIncrement = () => { const newValue = value + step; if (!max || newValue <= max) { onChange(newValue); } }; const handleChange = (e: React.ChangeEvent) => { const newValue = parseFloat(e.target.value) || 0; if (newValue >= min && (!max || newValue <= max)) { onChange(newValue); } }; const handleQuickValue = (quickValue: number) => { onChange(quickValue); }; return (
{label && ( )}
{showSteppers && ( )}
setIsFocused(true)} onBlur={() => setIsFocused(false)} disabled={disabled} placeholder={placeholder} min={min} max={max} step={step} className={cn( "h-12 text-center text-lg font-semibold", "touch-manipulation", isFocused && "ring-2 ring-primary" )} />
{showSteppers && ( )}
{quickValues && quickValues.length > 0 && (
{quickValues.map((quickValue) => ( ))}
)}
); } // Currency input variant interface CurrencyInputProps extends Omit { currency?: string; showSteppers?: boolean; largeStep?: number; } export function CurrencyInput({ value, onChange, min = 0, max, step = 100, largeStep = 1000, disabled = false, placeholder = "0", className, currency = "₹", label, showSteppers = true }: CurrencyInputProps) { const quickValues = [1000, 5000, 10000, 25000, 50000, 100000]; return (
{label && ( )}
{showSteppers && ( )}
{currency} onChange(parseFloat(e.target.value) || 0)} disabled={disabled} placeholder={placeholder} min={min} max={max} step={step} className={cn( "h-12 pl-10 pr-4 text-center text-lg font-semibold", "touch-manipulation", className )} />
{showSteppers && ( )}
{quickValues.map((quickValue) => ( ))}
); }