import * as React from "react" import { cn } from "@/lib/utils" import { useStore } from "@/lib/states" export interface InputProps extends React.InputHTMLAttributes {} const Input = React.forwardRef( ({ className, type, ...props }, ref) => { const updateAppState = useStore((state) => state.updateAppState) const handleOnFocus = () => { updateAppState({ disableShortCuts: true }) } const handleOnBlur = () => { updateAppState({ disableShortCuts: false }) } return ( ) } ) Input.displayName = "Input" export interface NumberInputProps extends InputProps { numberValue: number allowFloat: boolean onNumberValueChange: (value: number) => void } const NumberInput = React.forwardRef( ( { numberValue, allowFloat, onNumberValueChange, className, ...rest }, ref ) => { const [value, setValue] = React.useState(numberValue.toString()) React.useEffect(() => { if (value !== numberValue.toString() + ".") { setValue(numberValue.toString()) } }, [numberValue]) const onInput = (evt: React.FormEvent) => { const target = evt.target as HTMLInputElement let val = target.value if (allowFloat) { val = val.replace(/[^0-9.]/g, "").replace(/(\..*?)\..*/g, "$1") if (val.length === 0) { onNumberValueChange(0) return } // val = parseFloat(val).toFixed(2) onNumberValueChange(parseFloat(val)) } else { val = val.replace(/\D/g, "") if (val.length === 0) { onNumberValueChange(0) return } onNumberValueChange(parseInt(val, 10)) } setValue(val) } return ( ) } ) export { Input, NumberInput }