import { useState, useEffect } from 'react' export function QuantityInput({ value, onSave }: { value: number; onSave: (qty: number) => void }) { const [local, setLocal] = useState(String(value)) useEffect(() => setLocal(String(value)), [value]) const commit = () => { const qty = Math.max(1, Math.min(999, Number(local) || 1)) setLocal(String(qty)) if (qty !== value) onSave(qty) } return (
setLocal(e.target.value.replace(/\D/g, ''))} onBlur={commit} onKeyDown={e => { if (e.key === 'Enter') { commit(); (e.target as HTMLInputElement).blur() } }} style={{ width: 24, border: 'none', outline: 'none', background: 'transparent', fontSize: 12, textAlign: 'right', fontFamily: 'inherit', color: 'var(--text-secondary)', padding: 0 }} /> x
) }