manifold/web/components/bucket-input.tsx
Marshall Polaris 47f10301c8
Change lodash stuff so that it can be tree-shaken out of build (#233)
* Set common package.json sideEffects: false

* Configure SWC to modularize lodash imports

* Import specific lodash functions instead of _

* Add an eslint rule to avoid full lodash import
2022-05-22 01:36:05 -07:00

43 lines
949 B
TypeScript

import { useState } from 'react'
import { NumericContract } from 'common/contract'
import { getMappedBucket } from 'common/calculate-dpm'
import { NumberInput } from './number-input'
export function BucketInput(props: {
contract: NumericContract
isSubmitting?: boolean
onBucketChange: (value?: number, bucket?: string) => void
}) {
const { contract, isSubmitting, onBucketChange } = props
const [numberString, setNumberString] = useState('')
const onChange = (s: string) => {
setNumberString(s)
const value = parseFloat(s)
if (!isFinite(value)) {
onBucketChange(undefined, undefined)
return
}
const bucket = getMappedBucket(value, contract)
onBucketChange(value, bucket)
}
return (
<NumberInput
inputClassName="w-full max-w-none"
onChange={onChange}
error={undefined}
disabled={isSubmitting}
numberString={numberString}
label="Value"
/>
)
}