2021-04-12 09:49:02 -07:00
|
|
|
interface InputProps {
|
|
|
|
type: string
|
|
|
|
value: any
|
|
|
|
onChange: (e) => void
|
|
|
|
className?: string
|
|
|
|
disabled?: boolean
|
|
|
|
[x: string]: any
|
|
|
|
}
|
|
|
|
|
2021-04-13 16:41:04 -07:00
|
|
|
const Group = ({ children, className }) => {
|
|
|
|
return (
|
|
|
|
<div className={`flex border border-th-fgd-4 rounded ${className}`}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-04-12 09:49:02 -07:00
|
|
|
const Input = ({
|
|
|
|
type,
|
|
|
|
value,
|
|
|
|
onChange,
|
|
|
|
className,
|
|
|
|
disabled,
|
2021-04-12 13:01:55 -07:00
|
|
|
prefix,
|
|
|
|
suffix,
|
2021-04-12 09:49:02 -07:00
|
|
|
...props
|
|
|
|
}: InputProps) => {
|
|
|
|
return (
|
2021-04-12 13:01:55 -07:00
|
|
|
<div
|
2021-04-16 04:50:56 -07:00
|
|
|
className={`flex items-center h-10 rounded ${
|
2021-04-12 13:01:55 -07:00
|
|
|
disabled ? 'bg-th-bkg-3' : 'bg-th-bkg-1'
|
|
|
|
} ${className}`}
|
|
|
|
>
|
|
|
|
{prefix ? (
|
2021-04-16 04:50:56 -07:00
|
|
|
<div className="flex items-center justify-end border-r border-th-fgd-4 bg-th-bkg-2 p-2 h-full text-sm rounded rounded-r-none w-14 text-right">
|
2021-04-12 13:01:55 -07:00
|
|
|
{prefix}
|
|
|
|
</div>
|
|
|
|
) : null}
|
2021-04-13 16:41:04 -07:00
|
|
|
<div className="flex items-center h-full border border-transparent hover:border-th-primary">
|
2021-04-12 13:01:55 -07:00
|
|
|
<input
|
|
|
|
type={type}
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
2021-04-16 07:08:33 -07:00
|
|
|
className={`bg-transparent tracking-wider w-full focus:outline-none ${
|
2021-04-15 14:36:55 -07:00
|
|
|
disabled ? 'opacity-20 cursor-not-allowed' : ''
|
2021-04-16 07:08:33 -07:00
|
|
|
} ${type === 'number' ? 'text-right mr-1' : ''} ${
|
2021-04-15 14:36:55 -07:00
|
|
|
value.toString().length > 9 ? 'text-xs' : ''
|
|
|
|
}`}
|
2021-04-12 13:01:55 -07:00
|
|
|
disabled={disabled}
|
|
|
|
{...props}
|
|
|
|
/>
|
2021-04-13 16:41:04 -07:00
|
|
|
{suffix ? (
|
2021-04-15 14:36:55 -07:00
|
|
|
<span className="text-xs pl-0.5 pr-1 bg-transparent text-th-fgd-4">
|
2021-04-13 16:41:04 -07:00
|
|
|
{suffix}
|
|
|
|
</span>
|
|
|
|
) : null}
|
2021-04-12 13:01:55 -07:00
|
|
|
</div>
|
2021-04-12 09:49:02 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
Input.Group = Group
|
|
|
|
|
|
|
|
export default Input
|