(
parseFloat(props.value as string) || props.value
);
useEffect(() => {
setVO(props.value);
}, [props.value]);
const handleInput = (v: number | string) => {
setVO(v);
return v;
};
const handleChange = (newV: number | string) => {
props.onInput && props.onInput(newV);
};
const handleBlur = () => {
props.onBlur && props.onBlur(0);
};
const clamp = (v: number, min: number, max: number): number =>
Math.min(Math.max(v, min), max);
return (
{props.label && }
{typeof vO === "string" ? (
{
const target = e.target as HTMLInputElement;
handleInput(String(target.value));
}}
/>
) : (
{
const target = e.target as HTMLInputElement;
handleChange(handleInput(parseFloat(target.value) as number));
}}
handleBlur={handleBlur}
handleIncrease={() => {
const newVO = clamp(
(vO as number) + (props.step || 1),
props.min || -Infinity,
props.max || +Infinity
);
setVO(newVO);
props.onInput && props.onInput(newVO);
}}
handleDecrease={() => {
const newVO = clamp(
(vO as number) - (props.step || 1),
props.min || -Infinity,
props.max || +Infinity
);
setVO(newVO);
props.onInput && props.onInput(newVO);
}}
/>
)}
{props.showCopyButton && }
);
}