mango-ui-v3/components/Input.tsx

68 lines
1.5 KiB
TypeScript
Raw Normal View History

interface InputProps {
type: string
value: any
onChange: (e) => void
className?: string
disabled?: boolean
2021-09-13 14:14:59 -07:00
prefixClassname?: string
error?: boolean
[x: string]: any
}
2021-04-24 19:10:28 -07:00
const Group = ({ children, className = '' }) => {
2021-04-18 03:34:37 -07:00
return <div className={`flex ${className}`}>{children}</div>
2021-04-13 16:41:04 -07:00
}
const Input = ({
type,
value,
onChange,
className,
error,
2021-04-18 03:34:37 -07:00
wrapperClassName = 'w-full',
disabled,
prefix,
2021-09-13 14:14:59 -07:00
prefixClassName,
suffix,
...props
}: InputProps) => {
return (
2021-04-18 03:34:37 -07:00
<div className={`flex relative ${wrapperClassName}`}>
{prefix ? (
2021-04-24 19:10:28 -07:00
<div
2021-09-26 06:20:51 -07:00
className={`absolute left-2 top-1/2 transform -translate-y-1/2 ${prefixClassName}`}
2021-04-24 19:10:28 -07:00
>
{prefix}
</div>
) : null}
<input
2021-04-18 03:34:37 -07:00
type={type}
value={value}
onChange={onChange}
2021-09-26 06:20:51 -07:00
className={`${className} bg-th-bkg-1 pb-px px-2 flex-1 rounded-md h-10 text-th-fgd-1 w-full
border ${
error ? 'border-th-red' : 'border-th-bkg-4'
} default-transition hover:border-th-primary
2021-04-24 19:10:28 -07:00
focus:border-th-primary focus:outline-none
${
disabled
? 'bg-th-bkg-3 cursor-not-allowed hover:border-th-fgd-4 text-th-fgd-3'
2021-04-24 19:10:28 -07:00
: ''
}
2021-09-26 06:20:51 -07:00
${prefix ? 'pl-7' : ''}`}
2021-04-18 03:34:37 -07:00
disabled={disabled}
{...props}
/>
{suffix ? (
<span className="absolute right-0 text-xs flex items-center pr-2 h-full bg-transparent text-th-fgd-4">
{suffix}
</span>
) : null}
</div>
)
}
Input.Group = Group
export default Input