From 2f3f7261a0f898e33ebd825166f9a12e5b3e52e9 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Sat, 13 Apr 2024 21:14:17 +0200 Subject: [PATCH] Some new inputfield types --- .../Components/Inputs/DescriptionInput.tsx | 38 ++++++++++++++ .../src/Components/Inputs/PasswordInput.tsx | 44 ++++++++++++++++ .../Components/Inputs/ProjectNameInput.tsx | 48 ++++++++++++++++++ .../src/Components/Inputs/UsernameInput.tsx | 50 +++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 frontend/src/Components/Inputs/DescriptionInput.tsx create mode 100644 frontend/src/Components/Inputs/PasswordInput.tsx create mode 100644 frontend/src/Components/Inputs/ProjectNameInput.tsx create mode 100644 frontend/src/Components/Inputs/UsernameInput.tsx diff --git a/frontend/src/Components/Inputs/DescriptionInput.tsx b/frontend/src/Components/Inputs/DescriptionInput.tsx new file mode 100644 index 0000000..43e046c --- /dev/null +++ b/frontend/src/Components/Inputs/DescriptionInput.tsx @@ -0,0 +1,38 @@ +import { projDescHighLimit, projDescLowLimit } from "../../Data/constants"; + +export default function DescriptionInput(props: { + desc: string; + placeholder: string; + onChange: (e: React.ChangeEvent) => void; +}): JSX.Element { + return ( + <> + +
+ {props.desc.length > projDescHighLimit && ( +

+ Description must be under 100 characters +

+ )} + {props.desc.length <= projDescHighLimit && + props.desc.length > projDescLowLimit && ( +

+ Valid project description! +

+ )} +
+ + ); +} diff --git a/frontend/src/Components/Inputs/PasswordInput.tsx b/frontend/src/Components/Inputs/PasswordInput.tsx new file mode 100644 index 0000000..9f67e98 --- /dev/null +++ b/frontend/src/Components/Inputs/PasswordInput.tsx @@ -0,0 +1,44 @@ +import { passwordLength } from "../../Data/constants"; +import { lowercase } from "../../Data/regex"; + +export default function PasswordInput(props: { + password: string; + onChange: (e: React.ChangeEvent) => void; +}): JSX.Element { + const password = props.password; + return ( + <> + +
+ {password.length === passwordLength && + lowercase.test(props.password) && ( +

+ Valid password! +

+ )} + {password.length !== passwordLength && ( +

+ Password must be 6 characters +

+ )} + {!lowercase.test(password) && password !== "" && ( +

+ No number, uppercase or special
characters allowed +

+ )} +
+ + ); +} diff --git a/frontend/src/Components/Inputs/ProjectNameInput.tsx b/frontend/src/Components/Inputs/ProjectNameInput.tsx new file mode 100644 index 0000000..af7ce9f --- /dev/null +++ b/frontend/src/Components/Inputs/ProjectNameInput.tsx @@ -0,0 +1,48 @@ +import { projNameHighLimit, projNameLowLimit } from "../../Data/constants"; +import { alphanumeric } from "../../Data/regex"; + +export default function ProjectNameInput(props: { + name: string; + onChange: (e: React.ChangeEvent) => void; +}): JSX.Element { + const name = props.name; + return ( + <> + = projNameLowLimit && + name.length <= projNameHighLimit && + alphanumeric.test(name) + ? "border-2 border-green-500 dark:border-green-500 focus-visible:border-green-500 outline-none rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight" + : "border-2 border-red-600 dark:border-red-600 focus:border-red-600 outline-none rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight" + } + spellCheck="false" + id="New name" + type="text" + placeholder="Project name" + value={name} + onChange={props.onChange} + /> +
+ {!alphanumeric.test(name) && name !== "" && ( +

+ No special characters allowed +

+ )} + {(name.length < projNameLowLimit || + name.length > projNameHighLimit) && ( +

+ Project name must be 10-99 characters +

+ )} + {alphanumeric.test(props.name) && + name.length >= projNameHighLimit && + name.length <= projNameHighLimit && ( +

+ Valid project name! +

+ )} +
+ + ); +} diff --git a/frontend/src/Components/Inputs/UsernameInput.tsx b/frontend/src/Components/Inputs/UsernameInput.tsx new file mode 100644 index 0000000..8f653ba --- /dev/null +++ b/frontend/src/Components/Inputs/UsernameInput.tsx @@ -0,0 +1,50 @@ +import { usernameLowLimit, usernameUpLimit } from "../../Data/constants"; +import { alphanumeric } from "../../Data/regex"; + +export default function UsernameInput(props: { + username: string; + onChange: (e: React.ChangeEvent) => void; +}): JSX.Element { + const username = props.username; + return ( + <> + = usernameLowLimit && + username.length <= usernameUpLimit && + alphanumeric.test(props.username) + ? "border-2 border-green-500 dark:border-green-500 focus-visible:border-green-500 outline-none rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight" + : "border-2 border-red-600 dark:border-red-600 focus:border-red-600 outline-none rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight" + } + spellCheck="false" + id="New username" + type="text" + placeholder="Username" + value={username} + onChange={props.onChange} + /> +
+ {alphanumeric.test(username) && + username.length >= usernameLowLimit && + username.length <= usernameUpLimit && ( +

+ Valid username! +

+ )} + {!alphanumeric.test(username) && username !== "" && ( +

+ No special characters allowed +

+ )} + {!( + username.length >= usernameLowLimit && + username.length <= usernameUpLimit + ) && ( +

+ Username must be 5-10 characters +

+ )} +
+ + ); +}