From 1717c35e5996aa91b0344cb45a1924945f0afaf6 Mon Sep 17 00:00:00 2001 From: sksmagr23 Date: Tue, 18 Jun 2024 11:55:17 +0530 Subject: [PATCH] frontend: improved the button component The button component is modified to make it more user friendly ,and added default options for type and size props like reject, accept and button content accepted as children. fixes #120 --- frontend/src/Navbar.tsx | 69 +++++++++++++------------ frontend/src/library/button.tsx | 90 ++++++++++++++++++++++++++++----- frontend/src/library/modal.tsx | 14 ++--- frontend/src/pages/Error.tsx | 9 ++-- frontend/src/pages/Game.tsx | 10 ++-- frontend/src/pages/Home.tsx | 26 ++++------ frontend/src/pages/Login.tsx | 14 ++--- frontend/src/pages/SignUp.tsx | 14 ++--- 8 files changed, 155 insertions(+), 91 deletions(-) diff --git a/frontend/src/Navbar.tsx b/frontend/src/Navbar.tsx index 9085549..d357d5e 100644 --- a/frontend/src/Navbar.tsx +++ b/frontend/src/Navbar.tsx @@ -40,12 +40,13 @@ const Navbar: React.FC = () => { <>
) : ( @@ -53,12 +54,13 @@ const Navbar: React.FC = () => { {showLoginBtn && (
)} @@ -83,51 +85,54 @@ const Navbar: React.FC = () => { {auth.getUser()?.name} ) : ( <> )}
void; + variant?: 'accept' | 'reject' | ''; + size?: 'small' | 'medium' | 'large'; + children: React.ReactNode; }; const Button: React.FC = ({ - text, - textColor = 'text-white', - backgroundColor = 'bg-lime-500', - fontSize = 'text-lg', - rounded = 'rounded-2xl', - buttonSize = 'w-36 h-11', - px = 'px-3', - py = 'py-1', - borderColor = 'border-black', - hoverColor = 'hover:bg-lime-600', + textColor, + backgroundColor, + fontSize, + rounded, + buttonSize, + px, + py, + borderColor, hoverScale = true, type = 'button', onClick, className = '', + variant = '', + size = 'medium', + children, }) => { + const variantStyles = { + accept: { + textColor: 'text-white', + backgroundColor: 'bg-lime-500', + borderColor: 'border-black', + hoverColor: 'hover:brightness-125', + }, + reject: { + textColor: 'text-white', + backgroundColor: 'bg-red-500', + borderColor: 'border-black', + hoverColor: 'hover:brightness-125', + }, + default: { + textColor: 'text-black', + backgroundColor: 'bg-gray-200', + borderColor: 'border-gray-400', + hoverColor: 'hover:brightness-110', + }, + }; + + const sizeStyles = { + small: { + fontSize: 'text-md', + rounded: 'rounded-xl', + buttonSize: 'w-36 h-8', + px: 'px-2', + py: 'py-1', + }, + medium: { + fontSize: 'text-xl', + rounded: 'rounded-2xl', + buttonSize: 'w-44 h-12', + px: 'px-1', + py: 'py-1', + }, + large: { + fontSize: 'text-3xl', + rounded: 'rounded-3xl', + buttonSize: 'w-56 h-18', + px: 'px-4', + py: 'py-2', + }, + }; + + const chosenVariant = variant + ? variantStyles[variant] + : variantStyles.default; + const chosenSize = sizeStyles[size]; + return ( ); }; diff --git a/frontend/src/library/modal.tsx b/frontend/src/library/modal.tsx index dda5f4e..ea522b2 100644 --- a/frontend/src/library/modal.tsx +++ b/frontend/src/library/modal.tsx @@ -59,15 +59,15 @@ const Modal: React.FC = ({ onClose }) => { />
); diff --git a/frontend/src/pages/Error.tsx b/frontend/src/pages/Error.tsx index 7853bfb..5ed7b39 100644 --- a/frontend/src/pages/Error.tsx +++ b/frontend/src/pages/Error.tsx @@ -24,12 +24,13 @@ function Error() { Please return to the Homepage!

diff --git a/frontend/src/pages/Game.tsx b/frontend/src/pages/Game.tsx index 661bf03..1763f9c 100644 --- a/frontend/src/pages/Game.tsx +++ b/frontend/src/pages/Game.tsx @@ -71,12 +71,14 @@ const Game: React.FC = () => { {/* Player Mat */} diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index d7b87bf..6530038 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -32,23 +32,17 @@ const Home: React.FC = () => { /> + + {showModal && setShowModal(false)} />} diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index 4244d6d..61fa6a0 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -75,14 +75,14 @@ const Login: React.FC = () => {
diff --git a/frontend/src/pages/SignUp.tsx b/frontend/src/pages/SignUp.tsx index af6bfd5..a1017c0 100644 --- a/frontend/src/pages/SignUp.tsx +++ b/frontend/src/pages/SignUp.tsx @@ -95,14 +95,14 @@ const SignUp: React.FC = () => {