2024-03-05 16:56:17 +00:00
|
|
|
import * as React from "react"
|
|
|
|
|
|
|
|
import { cn } from "~/utils"
|
|
|
|
import { EyeOpenIcon, EyeNoneIcon } from "@radix-ui/react-icons"
|
|
|
|
|
|
|
|
export interface InputProps
|
2024-03-12 03:41:49 +00:00
|
|
|
extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
|
|
fullWidth: boolean,
|
|
|
|
leftIcon?: React.ReactNode
|
|
|
|
}
|
2024-03-05 16:56:17 +00:00
|
|
|
|
|
|
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
2024-03-12 03:41:49 +00:00
|
|
|
({ className, type, fullWidth, leftIcon, ...props }, ref) => {
|
2024-03-05 16:56:17 +00:00
|
|
|
const [showPassword, setShowPassword] = React.useState<boolean>(false)
|
|
|
|
const [mask, setMask] = React.useState<boolean>(false)
|
|
|
|
const toggleShowPassword = () => {
|
|
|
|
setShowPassword((show) => !show)
|
|
|
|
setMask((mask) => !mask)
|
|
|
|
}
|
|
|
|
return (
|
2024-03-12 03:41:49 +00:00
|
|
|
<div className={`relative ${fullWidth ? "w-full" : ""}`}>
|
|
|
|
{leftIcon && (
|
|
|
|
<div className="absolute left-4 top-1/2 -translate-y-1/2">
|
|
|
|
{leftIcon}
|
|
|
|
</div>
|
|
|
|
)}
|
2024-03-05 16:56:17 +00:00
|
|
|
<input
|
|
|
|
type={type && !mask ? type : "text"}
|
|
|
|
className={cn(
|
|
|
|
"flex h-14 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-input-placeholder focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
2024-03-12 03:41:49 +00:00
|
|
|
className,
|
|
|
|
leftIcon && "pl-10"
|
2024-03-05 16:56:17 +00:00
|
|
|
)}
|
|
|
|
ref={ref}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
{type === "password" ? <button
|
|
|
|
type="button"
|
|
|
|
className="absolute right-4 top-5 text-input"
|
|
|
|
onClick={toggleShowPassword}
|
|
|
|
onKeyDown={toggleShowPassword}
|
|
|
|
>
|
|
|
|
{showPassword ? <EyeOpenIcon /> : <EyeNoneIcon />}
|
|
|
|
</button> : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
Input.displayName = "Input"
|
|
|
|
|
|
|
|
export { Input }
|