Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add password visibility button to authentication pages #572

Merged
merged 14 commits into from
Nov 24, 2023
11 changes: 8 additions & 3 deletions components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { forwardRef, InputHTMLAttributes } from "react";
import { forwardRef, InputHTMLAttributes, ReactNode } from "react";

interface Props extends InputHTMLAttributes<HTMLInputElement> {
text: string;
autocomplete?: string;
fgColor: string;
bgColor: string;
enabled?: boolean;
right?: ReactNode;
}

export default forwardRef<HTMLInputElement, Props>(function Input(
Expand All @@ -20,6 +21,7 @@ export default forwardRef<HTMLInputElement, Props>(function Input(
bgColor,
onChange,
enabled,
right,
...rest
},
ref
Expand All @@ -43,20 +45,23 @@ export default forwardRef<HTMLInputElement, Props>(function Input(
>
{text}
</label>
<div className="mt-2">
<div
className={`text-iregular mt-2 flex items-center ${textColor} ${backColor} appearance-none rounded-full border border-gray-300 px-3 py-2 pl-6 placeholder-gray-400 shadow-sm sm:text-sm`}
>
<input
id={id}
name={name}
type={type}
autoComplete={autocomplete}
value={value}
required
className={`text-iregular ${textColor} ${backColor} block w-full appearance-none rounded-full border border-gray-300 px-3 py-2 pl-6 placeholder-gray-400 shadow-sm focus:outline-none sm:text-sm`}
className="w-full bg-transparent outline-none"
onChange={onChange}
disabled={enabled == false}
ref={ref}
{...rest}
/>
{right}
</div>
</div>
);
Expand Down
55 changes: 55 additions & 0 deletions components/PasswordInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { forwardRef, InputHTMLAttributes, useState } from "react";

import Input from "@components/Input";

import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons";

interface Props extends InputHTMLAttributes<HTMLInputElement> {
text?: string;
autocomplete?: string;
fgColor: string;
bgColor: string;
enabled?: boolean;
}

export default forwardRef<HTMLInputElement, Props>(function PasswordInput(
{
text = "PASSWORD",
id = "password",
name = "password",
type = "password",
autocomplete = "current-password",
fgColor,
bgColor,
...rest
},
ref
) {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);

const togglePasswordVisibility = () => {
setIsPasswordVisible(!isPasswordVisible);
};

return (
<Input
{...rest}
text={text}
id={id}
name={name}
type={isPasswordVisible ? "text" : "password"}
fgColor="white"
bgColor="primary"
autoComplete="current-password"
right={
<FontAwesomeIcon
className="mx-2 cursor-pointer"
onClick={togglePasswordVisibility}
icon={isPasswordVisible ? faEyeSlash : faEye}
/>
}
ref={ref}
/>
);
});
19 changes: 9 additions & 10 deletions layout/Login/components/LoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -35,16 +36,14 @@ export default function LoginForm() {
autoComplete="email"
ref={emailRef}
/>
<Input
text="YOUR PASSWORD"
id="password"
name="password"
type="password"
fgColor="white"
bgColor="primary"
autoComplete="current-password"
ref={passwordRef}
/>
<div>
<PasswordInput
text="YOUR PASSWORD"
fgColor="white"
bgColor="primary"
ref={passwordRef}
/>
</div>
<Text
padding="6"
text="Forgot your password?"
Expand Down
12 changes: 3 additions & 9 deletions layout/ResetPassword/components/ResetPasswordForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Button from "@components/Button";
import ImageButton from "@components/ImageButton";

import Form from "@components/Form";
import Input from "@components/Input";
import PasswordInput from "@components/PasswordInput";

export default function ResetPasswordForm() {
const router = useRouter();
Expand Down Expand Up @@ -51,22 +51,16 @@ export default function ResetPasswordForm() {
<>
{success === null && (
<Form onSubmit={onSubmit}>
<Input
<PasswordInput
text="PASSWORD"
id="password"
name="password"
type="password"
autoComplete="current-password"
fgColor="white"
bgColor="primary"
ref={passwordRef}
/>
<Input
<PasswordInput
text="CONFIRM PASSWORD"
id="confirm"
name="confirm"
type="password"
autoComplete="current-password"
fgColor="white"
bgColor="primary"
ref={passwordConfirmationRef}
Expand Down
19 changes: 3 additions & 16 deletions layout/SignUp/components/SignUpForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAuth } from "@context/Auth";
import Button from "@components/Button";
import Form from "@components/Form";
import Input from "@components/Input";
import PasswordInput from "@components/PasswordInput";

import BarebonesQRScanner from "@components/QRScanner/BarebonesQRScanner";

Expand Down Expand Up @@ -92,25 +93,11 @@ export default function SignUpForm() {
bgColor="primary"
onChange={(e) => updateNickname(e.currentTarget.value)}
/>
<Input
text="PASSWORD"
id="password"
name="password"
type="password"
autoComplete="current-password"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePassword(e.currentTarget.value)}
/>
<Input
<PasswordInput text="PASSWORD" fgColor="white" bgColor="primary" />
Darguima marked this conversation as resolved.
Show resolved Hide resolved
<PasswordInput
text="CONFIRM PASSWORD"
id="password"
Darguima marked this conversation as resolved.
Show resolved Hide resolved
name="password"
type="password"
autoComplete="current-password"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePasswordConfirmation(e.currentTarget.value)}
/>
<Button
text={scanning ? "STOP SCANNING" : "SCAN QR"}
Expand Down
19 changes: 3 additions & 16 deletions pages/register/[uuid].js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -68,25 +69,11 @@ function Register() {
bgColor="primary"
onChange={(e) => updateNickname(e.currentTarget.value)}
/>
<Input
text="PASSWORD"
id="password"
name="password"
type="password"
autoComplete="current-password"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePassword(e.currentTarget.value)}
/>
<Input
<PasswordInput text="PASSWORD" fgColor="white" bgColor="primary" />
Darguima marked this conversation as resolved.
Show resolved Hide resolved
<PasswordInput
text="CONFIRM PASSWORD"
id="password"
name="password"
type="password"
autoComplete="current-password"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePasswordConfirmation(e.currentTarget.value)}
/>
<Button
type="submit"
Expand Down
Loading