-
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
1 parent
4864655
commit 080e81b
Showing
4 changed files
with
66 additions
and
39 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
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,61 +1,87 @@ | ||
import { motion } from "framer-motion" | ||
import { ChangeEvent, useState } from "react" | ||
import { AiFillEye, AiFillEyeInvisible } from "react-icons/ai" | ||
|
||
interface InputProps extends React.HTMLAttributes<HTMLInputElement> { | ||
type: 'email' | 'password' | 'number' | ||
type: "email" | "password" | "number" | ||
placeholder: string | ||
value: string | ||
onChange: (e: ChangeEvent<HTMLInputElement>) => void | ||
checked?: boolean | ||
size?: "sm" | "" | undefined | ||
inputError?: string | undefined | ||
} | ||
|
||
export function Input({ type, size, placeholder, ...props }: InputProps) { | ||
export function Input({ type, size, placeholder, inputError, ...props }: InputProps) { | ||
const [showPassword, setShowPassword] = useState(false) | ||
|
||
return ( | ||
<> | ||
{type === "password" | ||
? ( | ||
<div className="relative w-full"> | ||
<input | ||
className={`peer/input p-4 bg-primary-foreground text-secondary z-[9] ${size === "sm" ? "w-[100px] h-[40px]" : "w-full h-[55px]"} | ||
{type === "password" ? ( | ||
<div className="relative w-full"> | ||
<input | ||
className={`peer/input p-4 bg-primary-dark text-secondary z-[9] | ||
${inputError ? "border-danger border-[1px]" : ""} | ||
${size === "sm" ? "w-[100px] h-[40px]" : "w-full h-[55px]"} | ||
outline-none`} | ||
type={showPassword ? "text" : "password"} placeholder=" " | ||
{...props} | ||
/> | ||
<label className="absolute | ||
type={showPassword ? "text" : "password"} | ||
placeholder=" " | ||
{...props} | ||
/> | ||
<label | ||
className="absolute | ||
left-1 top-[50%] translate-y-[-120%] text-xs | ||
peer-placeholder-shown/input:left-4 peer-placeholder-shown/input:translate-y-[-50%] peer-placeholder-shown/input:text-md | ||
font-secondary text-secondary transition-all duration-300 | ||
pointer-events-none select-none">{placeholder}</label> | ||
{showPassword ? ( | ||
<AiFillEyeInvisible | ||
className="absolute right-4 top-[50%] translate-y-[-50%] w-8 h-8 text-secondary cursor-pointer z-[10]" | ||
onClick={() => setShowPassword(!showPassword)} | ||
/> | ||
) : ( | ||
<AiFillEye | ||
className="absolute right-4 w-8 h-8 top-[50%] translate-y-[-50%] text-secondary cursor-pointer z-[10]" | ||
onClick={() => setShowPassword(!showPassword)} | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<div className="relative w-full"> | ||
<input | ||
className={`peer/input p-4 bg-primary-foreground text-secondary z-[9] ${size === "sm" ? "w-[100px] h-[40px]" : "w-full h-[55px]"} | ||
outline-none`} | ||
type='email' placeholder=" " required | ||
{...props} | ||
pointer-events-none select-none"> | ||
{placeholder} | ||
</label> | ||
{showPassword ? ( | ||
<AiFillEyeInvisible | ||
className="absolute right-4 top-[50%] translate-y-[-50%] w-8 h-8 text-secondary cursor-pointer z-[10]" | ||
onClick={() => setShowPassword(!showPassword)} | ||
/> | ||
<label className="absolute | ||
) : ( | ||
<AiFillEye | ||
className="absolute right-4 w-8 h-8 top-[50%] translate-y-[-50%] text-secondary cursor-pointer z-[10]" | ||
onClick={() => setShowPassword(!showPassword)} | ||
/> | ||
)} | ||
<motion.p | ||
className="absolute font-secondary text-danger text-xs" | ||
initial={{ rotate: 0 }} | ||
animate={{ rotate: [0, -5, 5, 0] }}> | ||
{inputError} | ||
</motion.p> | ||
</div> | ||
) : ( | ||
<div className="relative w-full"> | ||
<input | ||
className={`peer/input p-4 bg-primary-dark text-secondary z-[9] | ||
${inputError ? "border-danger border-[1px]" : ""} | ||
${size === "sm" ? "w-[100px] h-[40px]" : "w-full h-[55px]"} | ||
outline-none`} | ||
type="email" | ||
placeholder=" " | ||
required | ||
{...props} | ||
/> | ||
<label | ||
className="absolute | ||
left-1 top-[50%] translate-y-[-120%] text-xs | ||
peer-placeholder-shown/input:left-4 peer-placeholder-shown/input:translate-y-[-50%] peer-placeholder-shown/input:text-md | ||
font-secondary text-secondary transition-all duration-300 | ||
pointer-events-none select-none">{placeholder}</label> | ||
</div> | ||
)} | ||
pointer-events-none select-none"> | ||
{placeholder} | ||
</label> | ||
<motion.p | ||
className="absolute font-secondary text-danger text-xs" | ||
initial={{ rotate: 0 }} | ||
animate={{ rotate: [0, -5, 5, 0] }}> | ||
{inputError} | ||
</motion.p> | ||
</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