From 4923c9c2b8c25b363b8b4796cea55fd5cd4928d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1rio=20Guimar=C3=A3es?= <49988070+Darguima@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:07:36 +0000 Subject: [PATCH] feat: add password visibility button to authentication pages (#572) * LoginForm Visibility Feature * Others Pages Password Visibility Feature * `register/[uuid].js` Password Visibility Feature * Ran Formatter * Created PasswordInput component * Add cursors-pointer style * Ran formatter * GH requested Changes * Fixed name/id props * Removing right Props from Input * Adding ids props and some fixes * removed type props * Revert "Removing right Props from Input" This reverts commit 3ac9ec63a7d2f864a31236bee4fdfa5ebc88a006. * InputBase Wrapper Component --- components/Input/index.tsx | 92 ++++++++++++------- components/PasswordInput/index.tsx | 45 +++++++++ layout/Login/components/LoginForm/index.tsx | 5 +- .../components/ResetPasswordForm/index.tsx | 10 +- layout/SignUp/components/SignUpForm/index.tsx | 13 +-- pages/register/[uuid].js | 15 ++- 6 files changed, 121 insertions(+), 59 deletions(-) create mode 100644 components/PasswordInput/index.tsx diff --git a/components/Input/index.tsx b/components/Input/index.tsx index 1074d261..ed3eade3 100644 --- a/components/Input/index.tsx +++ b/components/Input/index.tsx @@ -1,29 +1,26 @@ import { forwardRef, InputHTMLAttributes } from "react"; -interface Props extends InputHTMLAttributes { +export interface InputBaseProps + extends Pick, "id" | "children"> { text: string; - autocomplete?: string; fgColor: string; bgColor: string; enabled?: boolean; } -export default forwardRef(function Input( - { - text, - id, - name, - type, - value, - autocomplete, - fgColor, - bgColor, - onChange, - enabled, - ...rest - }, - ref -) { +export interface InputDefaultProps + extends InputBaseProps, + InputHTMLAttributes {} + +// A wrapper to the to standardize styles for the container +export function InputBase({ + text, + id, + fgColor, + bgColor, + enabled, + children, +}: InputBaseProps) { let textColor = `text-${fgColor}`; let backColor = `bg-${bgColor}`; @@ -43,21 +40,52 @@ export default forwardRef(function Input( > {text} -
- +
+ {children}
); +} + +export default forwardRef(function Input( + { + text, + id, + name, + type, + value, + autoComplete, + fgColor, + bgColor, + onChange, + enabled, + ...rest + }, + ref +) { + return ( + + + + ); }); diff --git a/components/PasswordInput/index.tsx b/components/PasswordInput/index.tsx new file mode 100644 index 00000000..82181a6b --- /dev/null +++ b/components/PasswordInput/index.tsx @@ -0,0 +1,45 @@ +import { forwardRef, useState } from "react"; + +import { InputBase, InputDefaultProps } from "@components/Input"; + +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons"; + +export default forwardRef( + function PasswordInput( + { text, id, name, type, fgColor, bgColor, enabled, ...rest }, + ref + ) { + const [isPasswordVisible, setIsPasswordVisible] = useState(false); + + const togglePasswordVisibility = () => { + setIsPasswordVisible(!isPasswordVisible); + }; + + return ( + + + + + ); + } +); diff --git a/layout/Login/components/LoginForm/index.tsx b/layout/Login/components/LoginForm/index.tsx index f4c8b174..5f2412a5 100644 --- a/layout/Login/components/LoginForm/index.tsx +++ b/layout/Login/components/LoginForm/index.tsx @@ -7,6 +7,7 @@ import Text from "@layout/moonstone/authentication/Text"; import Form from "@components/Form"; import Input from "@components/Input"; +import PasswordInput from "@components/PasswordInput"; export default function LoginForm() { const { errors, login, isLoading } = useAuth(); @@ -35,14 +36,12 @@ export default function LoginForm() { autoComplete="email" ref={emailRef} /> - {success === null && (
- - updateNickname(e.currentTarget.value)} /> - updatePassword(e.currentTarget.value)} /> - updatePasswordConfirmation(e.currentTarget.value)} diff --git a/pages/register/[uuid].js b/pages/register/[uuid].js index 8687c621..728191d7 100644 --- a/pages/register/[uuid].js +++ b/pages/register/[uuid].js @@ -9,6 +9,7 @@ import Card from "@components/Card"; import Return from "@components/Return"; import Form from "@components/Form"; import Input from "@components/Input"; +import PasswordInput from "@components/PasswordInput"; import Title from "@layout/moonstone/authentication/Title"; import Text from "@layout/moonstone/authentication/Text"; @@ -68,22 +69,18 @@ function Register() { bgColor="primary" onChange={(e) => updateNickname(e.currentTarget.value)} /> - updatePassword(e.currentTarget.value)} /> - updatePasswordConfirmation(e.currentTarget.value)}