feat: create input for toggleable inputs like passwords/connectinstrings

This commit is contained in:
Marius
2024-06-08 11:55:05 +02:00
parent 936cf76a4c
commit d54c6e4ac9
12 changed files with 60 additions and 46 deletions

View File

@@ -0,0 +1,22 @@
import { useState } from "react";
import { EyeIcon, EyeOffIcon } from "lucide-react";
import { Input } from "../ui/input";
import { Button } from "../ui/button";
interface ToggleVisibilityInputProps {
value: string | undefined
}
export default function ToggleVisibilityInput({ value }: ToggleVisibilityInputProps) {
const [inputType, setInputType] = useState<'password' | 'text'>('password');
const togglePasswordVisibility = () => {
setInputType(prevType => (prevType === 'password' ? 'text' : 'password'));
};
return (
<div className="flex w-full items-center space-x-2">
<Input value={value} type={inputType} />
<Button onClick={togglePasswordVisibility}>{inputType === "password" ? <EyeIcon /> : <EyeOffIcon />}</Button>
</div>
)
}