2022-01-30 21:51:30 +00:00
|
|
|
import { Row } from './layout/row'
|
|
|
|
|
|
|
|
export function ProbabilitySelector(props: {
|
|
|
|
probabilityInt: number
|
|
|
|
setProbabilityInt: (p: number) => void
|
|
|
|
isSubmitting?: boolean
|
2022-04-28 14:47:18 +00:00
|
|
|
minProb?: number
|
|
|
|
maxProb?: number
|
2022-01-30 21:51:30 +00:00
|
|
|
}) {
|
2022-04-28 14:47:18 +00:00
|
|
|
const { probabilityInt, setProbabilityInt, isSubmitting, minProb, maxProb } =
|
|
|
|
props
|
2022-01-30 21:51:30 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Row className="items-center gap-2">
|
|
|
|
<label className="input-group input-group-lg w-fit text-lg">
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
value={probabilityInt}
|
|
|
|
className="input input-bordered input-md text-lg"
|
|
|
|
disabled={isSubmitting}
|
2022-04-28 14:47:18 +00:00
|
|
|
min={minProb ?? 1}
|
|
|
|
max={maxProb ?? 99}
|
2022-01-30 21:51:30 +00:00
|
|
|
onChange={(e) =>
|
|
|
|
setProbabilityInt(parseInt(e.target.value.substring(0, 2)))
|
|
|
|
}
|
2022-04-28 14:47:18 +00:00
|
|
|
onBlur={() =>
|
|
|
|
setProbabilityInt(
|
|
|
|
maxProb && probabilityInt > maxProb
|
|
|
|
? maxProb
|
|
|
|
: minProb && probabilityInt < minProb
|
|
|
|
? minProb
|
|
|
|
: probabilityInt
|
|
|
|
)
|
|
|
|
}
|
2022-01-30 21:51:30 +00:00
|
|
|
/>
|
|
|
|
<span>%</span>
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="range"
|
|
|
|
className="range range-primary"
|
2022-04-28 14:47:18 +00:00
|
|
|
min={minProb ?? 1}
|
|
|
|
max={maxProb ?? 99}
|
2022-01-30 21:51:30 +00:00
|
|
|
value={probabilityInt}
|
|
|
|
onChange={(e) => setProbabilityInt(parseInt(e.target.value))}
|
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|