-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,74 @@ | ||
"use client"; | ||
import { AiOutlineLoading3Quarters } from "react-icons/ai"; | ||
import { forwardRef } from "react"; | ||
|
||
import { cn, variantInput } from "@/lib/utils"; | ||
import styles from "@/styles/component/form.module.css"; | ||
|
||
const Input = forwardRef<HTMLInputElement, IInput>( | ||
({ | ||
label, | ||
labelSide = "top", | ||
error, | ||
type = "text", | ||
className, | ||
isLoading = false, | ||
isRequired = false, | ||
onChange, | ||
inputClassName, | ||
logo, | ||
disabled, | ||
variant = "solid", | ||
...props | ||
}) => { | ||
return ( | ||
<div className={`${className} relative`}> | ||
<label | ||
className={cn("flex", { | ||
"items-center gap-2": labelSide === "left", | ||
"flex-col": labelSide === "top", | ||
})} | ||
> | ||
{label && ( | ||
<span | ||
className={cn(styles.inputLabel, { | ||
"!text-red-500": error, | ||
"w-[80px]": labelSide === "left", | ||
})} | ||
> | ||
{label} {isRequired && <span className="text-red-500">*</span>} | ||
</span> | ||
)} | ||
<span className="flex relative w-full"> | ||
<span | ||
className={cn(styles.inputLogo, { | ||
"!text-red-500": error, | ||
})} | ||
> | ||
{logo && logo} | ||
</span> | ||
<input | ||
type={type} | ||
{...props} | ||
onChange={onChange} | ||
className={cn(`${variantInput[variant]} ${styles.inputDefault}`, { | ||
inputClassName, | ||
"opacity-50 cursor-not-allowed": disabled, | ||
export default function Input({ | ||
label, | ||
labelSide = "top", | ||
error, | ||
type = "text", | ||
className, | ||
isLoading = false, | ||
isRequired = false, | ||
inputClassName, | ||
logo, | ||
variant = "solid", | ||
...props | ||
}: IInput) { | ||
return ( | ||
<div className={`${className} relative`}> | ||
<label | ||
className={cn("flex", { | ||
"items-center gap-2": labelSide === "left", | ||
"flex-col": labelSide === "top", | ||
})} | ||
> | ||
{label && ( | ||
<span | ||
className={cn(styles.inputLabel, { | ||
"!text-red-500": error, | ||
"w-[80px]": labelSide === "left", | ||
})} | ||
> | ||
{label} {isRequired && <span className="text-red-500">*</span>} | ||
</span> | ||
)} | ||
<span className="flex relative w-full"> | ||
<span | ||
className={cn(styles.inputLogo, { | ||
"!text-red-500": error, | ||
})} | ||
> | ||
{logo && logo} | ||
</span> | ||
<input | ||
type={type} | ||
{...props} | ||
className={cn( | ||
``, | ||
variantInput[variant], | ||
styles.inputDefault, | ||
inputClassName, | ||
{ | ||
"!pl-8": logo, | ||
"border !border-red-500": error, | ||
})} | ||
disabled={disabled} | ||
/> | ||
{isLoading && ( | ||
<span className={styles.inputLoading}> | ||
<AiOutlineLoading3Quarters /> | ||
</span> | ||
}, | ||
)} | ||
</span> | ||
</label> | ||
{error && ( | ||
<span role="alert" className={styles.inputError}> | ||
{error} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
Input.displayName = "Input"; | ||
export default Input; | ||
/> | ||
{isLoading && ( | ||
<span className={styles.inputLoading}> | ||
<AiOutlineLoading3Quarters /> | ||
</span> | ||
)} | ||
</span> | ||
</label> | ||
{error && ( | ||
<span role="alert" className={styles.inputError}> | ||
{error} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters