import clsx from 'clsx' import { Col } from './layout/col' import { Spacer } from './layout/spacer' export function ProbabilityInput(props: { prob: number | undefined onChange: (newProb: number | undefined) => void error: string | undefined setError: (error: string | undefined) => void disabled?: boolean className?: string inputClassName?: string }) { const { prob, onChange, error, disabled, className, inputClassName } = props const onProbChange = (str: string) => { let prob = parseInt(str.replace(/\D/g, '')) const isInvalid = !str || isNaN(prob) if (prob.toString().length > 2) prob = +prob.toString().slice(0, 2) onChange(isInvalid ? undefined : prob) } return ( {error && (
{error}
)} ) }