2022-05-19 17:42:03 +00:00
|
|
|
import clsx from 'clsx'
|
2022-05-26 22:22:44 +00:00
|
|
|
import { ReactNode } from 'react'
|
2022-05-19 17:42:03 +00:00
|
|
|
|
2022-05-26 21:41:24 +00:00
|
|
|
import React from 'react'
|
2022-05-19 17:42:03 +00:00
|
|
|
import { Col } from './layout/col'
|
|
|
|
import { Spacer } from './layout/spacer'
|
2022-10-10 02:37:24 +00:00
|
|
|
import { Input } from './input'
|
2022-05-19 17:42:03 +00:00
|
|
|
|
|
|
|
export function NumberInput(props: {
|
|
|
|
numberString: string
|
|
|
|
onChange: (newNumberString: string) => void
|
|
|
|
error: string | undefined
|
|
|
|
disabled?: boolean
|
2022-07-22 05:57:56 +00:00
|
|
|
placeholder?: string
|
2022-05-19 17:42:03 +00:00
|
|
|
className?: string
|
|
|
|
inputClassName?: string
|
|
|
|
// Needed to focus the amount input
|
|
|
|
inputRef?: React.MutableRefObject<any>
|
2022-05-26 22:22:44 +00:00
|
|
|
children?: ReactNode
|
2022-05-19 17:42:03 +00:00
|
|
|
}) {
|
|
|
|
const {
|
|
|
|
numberString,
|
|
|
|
onChange,
|
|
|
|
error,
|
|
|
|
disabled,
|
2022-07-22 05:57:56 +00:00
|
|
|
placeholder,
|
2022-05-19 17:42:03 +00:00
|
|
|
className,
|
|
|
|
inputClassName,
|
|
|
|
inputRef,
|
|
|
|
children,
|
|
|
|
} = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col className={className}>
|
|
|
|
<label className="input-group">
|
2022-10-10 02:37:24 +00:00
|
|
|
<Input
|
2022-05-19 17:42:03 +00:00
|
|
|
className={clsx(
|
2022-10-10 02:37:24 +00:00
|
|
|
'max-w-[200px] !text-lg',
|
2022-05-19 17:42:03 +00:00
|
|
|
error && 'input-error',
|
|
|
|
inputClassName
|
|
|
|
)}
|
|
|
|
ref={inputRef}
|
|
|
|
type="number"
|
2022-07-22 05:57:56 +00:00
|
|
|
pattern="[0-9]*"
|
|
|
|
inputMode="numeric"
|
|
|
|
placeholder={placeholder ?? '0'}
|
2022-05-19 17:42:03 +00:00
|
|
|
maxLength={9}
|
|
|
|
value={numberString}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={(e) => onChange(e.target.value.substring(0, 9))}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
<div className="mb-2 mr-auto self-center whitespace-nowrap text-xs font-medium tracking-wide text-red-500">
|
|
|
|
{error}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{children}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|