feat(inputs): ✨ Add number input
This commit is contained in:
@ -13,14 +13,14 @@ export const SmartNumberInput = ({
|
||||
onValueChange,
|
||||
...props
|
||||
}: {
|
||||
initialValue: number
|
||||
onValueChange: (value: number) => void
|
||||
initialValue?: number
|
||||
onValueChange: (value?: number) => void
|
||||
} & NumberInputProps) => {
|
||||
const [value, setValue] = useState(initialValue.toString())
|
||||
const [value, setValue] = useState(initialValue?.toString() ?? '')
|
||||
|
||||
useEffect(() => {
|
||||
if (value.endsWith('.') || value.endsWith(',')) return
|
||||
if (value === '') onValueChange(0)
|
||||
if (value === '') onValueChange(undefined)
|
||||
const newValue = parseFloat(value)
|
||||
if (isNaN(newValue)) return
|
||||
onValueChange(newValue)
|
||||
|
@ -17,14 +17,14 @@ export const TypingEmulation = ({
|
||||
onUpdate({ ...typingEmulation, enabled: !typingEmulation.enabled })
|
||||
}
|
||||
|
||||
const handleSpeedChange = (speed: number) => {
|
||||
const handleSpeedChange = (speed?: number) => {
|
||||
if (!typingEmulation) return
|
||||
onUpdate({ ...typingEmulation, speed })
|
||||
onUpdate({ ...typingEmulation, speed: speed ?? 0 })
|
||||
}
|
||||
|
||||
const handleMaxDelayChange = (maxDelay: number) => {
|
||||
const handleMaxDelayChange = (maxDelay?: number) => {
|
||||
if (!typingEmulation) return
|
||||
onUpdate({ ...typingEmulation, maxDelay: maxDelay })
|
||||
onUpdate({ ...typingEmulation, maxDelay: maxDelay ?? 0 })
|
||||
}
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user