-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInput.tsx
More file actions
53 lines (48 loc) · 1.23 KB
/
Input.tsx
File metadata and controls
53 lines (48 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { cva } from 'class-variance-authority';
import { InputHTMLAttributes, Ref } from 'react';
import { cn } from '../../lib';
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
ref?: Ref<HTMLInputElement>;
isError?: boolean;
helperText?: string;
}
const inputBorderVariants = cva(
'w-full h-[4.4rem] rounded-[4px] border box-border body4-r px-[0.8rem] py-[1.2rem] transition-colors ',
{
variants: {
isError: {
true: 'border-error focus-within:border-error',
false: 'border-gray200 focus-within:border-main400',
},
},
defaultVariants: {
isError: false,
},
}
);
const Input = ({
ref,
isError,
className,
helperText,
...props
}: InputProps) => {
return (
<div className="flex flex-col gap-[0.5rem]">
<div className={cn(inputBorderVariants({ isError }), className)}>
<input
ref={ref}
className="placeholder-font-gray-3 w-full focus:outline-none"
aria-invalid={isError}
{...props}
/>
</div>
{isError && helperText && (
<div className="flex items-center">
<p className="text-error body4-r">{helperText}</p>
</div>
)}
</div>
);
};
export default Input;