added password visibility toggle

This commit is contained in:
medentem
2024-10-02 15:54:53 -05:00
parent 06d2c393ce
commit 4b532fc7f8
4 changed files with 30 additions and 6 deletions
+13 -1
View File
@@ -4,6 +4,8 @@ import type {
} from "@components/Form/DynamicForm.js";
import { Generator } from "@components/UI/Generator.js";
import type { ChangeEventHandler, MouseEventHandler } from "react";
import { useState } from "react";
import { Eye, EyeOff } from "lucide-react";
import { Controller, type FieldValues } from "react-hook-form";
export interface PasswordGeneratorProps<T> extends BaseFormBuilderProps<T> {
@@ -21,13 +23,23 @@ export function PasswordGenerator<T extends FieldValues>({
field,
disabled,
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) {
const [passwordShown, setPasswordShown] = useState(false);
const togglePasswordVisiblity = () => {
setPasswordShown(passwordShown ? false : true);
};
return (
<Controller
name={field.name}
control={control}
render={({ field: { value, ...rest } }) => (
<Generator
hide={field.hide}
type={field.hide && !passwordShown ? "password" : "text"}
action={field.hide ? {
icon: passwordShown ? EyeOff : Eye,
onClick: togglePasswordVisiblity
} : undefined}
devicePSKBitCount={field.devicePSKBitCount}
bits={field.bits}
inputChange={field.inputChange}