import type { FC, SetStateAction } from 'react' import { RiArrowDownSLine, RiArrowUpSLine } from '@remixicon/react' import Input, { type InputProps } from '../input' import classNames from '@/utils/classnames' export type InputNumberProps = { unit?: string value: number onChange: (value: number) => void amount?: number size?: 'sm' | 'md' } & Omit export const InputNumber: FC = (props) => { const { unit, className, onChange, amount = 1, value, size = 'md', max, min, ...rest } = props const update = (input: SetStateAction) => { const current = typeof input === 'function' ? input(value) : input as number if (max && current >= (max as number)) return if (min && current <= (min as number)) return onChange(current) } const inc = () => update(val => val + amount) const dec = () => update(val => val - amount) return
{ const parsed = Number(e.target.value) if (Number.isNaN(parsed)) return onChange(parsed) }} /> {unit &&
{unit}
}
}