2022-02-22 15:30:54 -08:00
|
|
|
import { forwardRef, ReactNode } from 'react'
|
2022-02-07 02:28:36 -08:00
|
|
|
|
2021-04-12 09:49:02 -07:00
|
|
|
interface InputProps {
|
|
|
|
type: string
|
|
|
|
value: any
|
|
|
|
onChange: (e) => void
|
|
|
|
className?: string
|
|
|
|
disabled?: boolean
|
2021-09-13 14:14:59 -07:00
|
|
|
prefixClassname?: string
|
2021-05-18 09:27:09 -07:00
|
|
|
error?: boolean
|
2021-04-12 09:49:02 -07:00
|
|
|
[x: string]: any
|
|
|
|
}
|
|
|
|
|
2022-04-05 21:18:02 -07:00
|
|
|
const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
|
|
|
|
const {
|
2022-02-07 02:28:36 -08:00
|
|
|
type,
|
|
|
|
value,
|
|
|
|
onChange,
|
|
|
|
className,
|
|
|
|
error,
|
|
|
|
wrapperClassName = 'w-full',
|
|
|
|
disabled,
|
|
|
|
prefix,
|
|
|
|
prefixClassName,
|
|
|
|
suffix,
|
2022-04-05 21:18:02 -07:00
|
|
|
} = props
|
|
|
|
return (
|
|
|
|
<div className={`relative flex ${wrapperClassName}`}>
|
|
|
|
{prefix ? (
|
|
|
|
<div
|
|
|
|
className={`absolute left-2 top-1/2 -translate-y-1/2 transform ${prefixClassName}`}
|
|
|
|
>
|
|
|
|
{prefix}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<input
|
|
|
|
className={`${className} h-10 w-full flex-1 rounded-md border bg-th-bkg-1 px-2 pb-px
|
2022-03-09 12:53:11 -08:00
|
|
|
text-th-fgd-1 ${
|
2022-02-20 03:38:40 -08:00
|
|
|
error ? 'border-th-red' : 'border-th-bkg-4'
|
|
|
|
} default-transition hover:border-th-fgd-4
|
|
|
|
focus:border-th-fgd-4 focus:outline-none
|
2021-04-24 19:10:28 -07:00
|
|
|
${
|
|
|
|
disabled
|
2022-03-09 12:53:11 -08:00
|
|
|
? 'cursor-not-allowed bg-th-bkg-3 text-th-fgd-3 hover:border-th-fgd-4'
|
2021-04-24 19:10:28 -07:00
|
|
|
: ''
|
|
|
|
}
|
2022-02-25 08:41:15 -08:00
|
|
|
${prefix ? 'pl-7' : ''}
|
|
|
|
${suffix ? 'pr-11' : ''}`}
|
2022-04-05 21:18:02 -07:00
|
|
|
disabled={disabled}
|
|
|
|
ref={ref}
|
|
|
|
{...props}
|
|
|
|
type={type}
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
{suffix ? (
|
|
|
|
<span className="absolute right-0 flex h-full items-center bg-transparent pr-2 text-xs text-th-fgd-4">
|
|
|
|
{suffix}
|
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
2021-04-12 09:49:02 -07:00
|
|
|
|
|
|
|
export default Input
|
2022-02-22 15:30:54 -08:00
|
|
|
|
|
|
|
interface LabelProps {
|
|
|
|
children: ReactNode
|
|
|
|
className?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Label = ({ children, className }: LabelProps) => (
|
2022-03-09 12:53:11 -08:00
|
|
|
<label className={`mb-1.5 block text-th-fgd-2 ${className}`}>
|
2022-02-22 15:30:54 -08:00
|
|
|
{children}
|
|
|
|
</label>
|
|
|
|
)
|