From ea45c72a8b89e3889673ce574a1fe8f5b53624e0 Mon Sep 17 00:00:00 2001 From: sksmagr23 Date: Sun, 30 Jun 2024 10:36:00 +0530 Subject: [PATCH] frontend: Implemented fading in & out effect on opening and closing of sidebar and modal objects Added tailwind transition and transform properties with state change of sidebar and modal ,giving fading effect on opening and closing. fixes #131 --- frontend/src/Navbar.tsx | 156 ++++++++++---------- frontend/src/index.css | 22 +++ frontend/src/library/modal/Modal.tsx | 10 +- frontend/src/library/modal/ModalContext.tsx | 7 +- 4 files changed, 113 insertions(+), 82 deletions(-) diff --git a/frontend/src/Navbar.tsx b/frontend/src/Navbar.tsx index 9b75351a..0550fb5e 100644 --- a/frontend/src/Navbar.tsx +++ b/frontend/src/Navbar.tsx @@ -129,7 +129,6 @@ const rules = ( ); const Navbar: React.FC = () => { const [sidebarOpen, setSidebarOpen] = useState(false); - const auth = useAuth(); const modal = useModal(); const navigate = useNavigate(); @@ -194,96 +193,99 @@ const Navbar: React.FC = () => { )} - {sidebarOpen && ( -
-
- - {auth.isLoggedIn() ? ( - <> -
- {auth.getUser()?.name} -
- - - ) : ( - <> - - - )} -
+
+
+ + {auth.isLoggedIn() ? ( + <> +
+ {auth.getUser()?.name} +
-
-
+ + ) : ( + <> -
+ + )} +
+ +
+
+
-
- )} +
+
); }; diff --git a/frontend/src/index.css b/frontend/src/index.css index 9d5282c3..c7224e15 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -52,3 +52,25 @@ body { -1.35px 1.35px 0 black, 1.35px 1.35px 0 black; } + +.fade-enter { + display: none; + opacity: 0; +} + +.fade-enter-active { + display: block; + opacity: 1; + transition: opacity 500ms; +} + +.fade-exit { + display: block; + opacity: 1; +} + +.fade-exit-active { + opacity: 0; + transition: opacity 500ms; + display: none; +} diff --git a/frontend/src/library/modal/Modal.tsx b/frontend/src/library/modal/Modal.tsx index 659eff02..f8d196a9 100644 --- a/frontend/src/library/modal/Modal.tsx +++ b/frontend/src/library/modal/Modal.tsx @@ -7,6 +7,7 @@ type ModalContainerProps = { buttons: ModalButtonArgs[]; size: 'small' | 'large'; closeOnBlurClick?: boolean; // Add close prop + isVisible: boolean; }; const Modal: React.FC = ({ @@ -14,6 +15,7 @@ const Modal: React.FC = ({ buttons, size, closeOnBlurClick = true, + isVisible, }) => { const { hide } = useModal(); const modalRef = useRef(null); @@ -35,7 +37,7 @@ const Modal: React.FC = ({ return () => document.removeEventListener('keydown', handleEscape); }, [hide, closeOnBlurClick]); let modalClass = - 'bg-[rgb(222,209,209)] p-5 rounded-xl border-4 border-black shadow-md flex flex-col gap-10 items-center justify-center'; + 'bg-[rgb(222,209,209)] p-5 rounded-xl border-4 border-black shadow-md flex flex-col gap-10 items-center justify-center transition-all duration-500 transform'; if (size === 'small') { modalClass += ' w-11/12 h-1/2 sm:w-1/2 sm:h-1/2 md:w-1/3 md:h-1/3'; @@ -47,9 +49,11 @@ const Modal: React.FC = ({
-
+
{content} {buttons.map((button) => { return ( diff --git a/frontend/src/library/modal/ModalContext.tsx b/frontend/src/library/modal/ModalContext.tsx index a15d9c4c..96c587c9 100644 --- a/frontend/src/library/modal/ModalContext.tsx +++ b/frontend/src/library/modal/ModalContext.tsx @@ -73,7 +73,9 @@ export const ModalProvider: React.FC = ({ children }) => { function hide() { setcurrentlyActiveModalId(null); setIsVisible(false); - setModalContent(null); + setTimeout(() => { + setModalContent(null); + }, 500); } function updateContent(id: string, content: ReactNode) { if (id === currentlyActiveModalId) { @@ -84,12 +86,13 @@ export const ModalProvider: React.FC = ({ children }) => { return ( {children} - {isVisible && ( + {modalContent && ( )}