From 35b2cf21fa39f0e21e7dc3976462db02335b43b6 Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Tue, 19 Dec 2023 11:39:11 +0530 Subject: [PATCH] Added support for mobile application (#499) --- src/examples/Navbars/DefaultNavbar/index.tsx | 94 +++++++++++++++++++- src/pages/Presentation/sections/Counters.tsx | 77 ++++++++-------- 2 files changed, 126 insertions(+), 45 deletions(-) diff --git a/src/examples/Navbars/DefaultNavbar/index.tsx b/src/examples/Navbars/DefaultNavbar/index.tsx index 8f16af5e..629c45ee 100644 --- a/src/examples/Navbars/DefaultNavbar/index.tsx +++ b/src/examples/Navbars/DefaultNavbar/index.tsx @@ -20,13 +20,16 @@ import MKBox from "../../../components/MKBox"; // React example components import DefaultNavbarDropdown from "./DefaultNavbarDropdown"; - +import breakpoints from "../../../assets/theme/base/breakpoints"; +import MKButton from "../../../components/MKButton"; +import DefaultNavbarMobile from "./DefaultNavbarMobile"; function DefaultNavbar({ brand, routes, transparent, light, + action, sticky, relative, center @@ -38,6 +41,35 @@ function DefaultNavbar({ const [nestedDropdownEl, setNestedDropdownEl]: any = useState(""); const [nestedDropdownName, setNestedDropdownName]: any = useState(""); const [arrowRef, setArrowRef]: any = useState(null); + const [mobileNavbar, setMobileNavbar] = useState(false); + const [mobileView, setMobileView] = useState(false); + + const openMobileNavbar = () => setMobileNavbar(!mobileNavbar); + + React.useEffect(() => { + // A function that sets the display state for the DefaultNavbarMobile. + function displayMobileNavbar() { + if (window.innerWidth < breakpoints.values.lg) { + setMobileView(true); + setMobileNavbar(false); + } else { + setMobileView(false); + setMobileNavbar(false); + } + } + + /** + The event listener that's calling the displayMobileNavbar function when + resizing the window. + */ + window.addEventListener("resize", displayMobileNavbar); + + // Call the displayMobileNavbar function to set the state with the initial value. + displayMobileNavbar(); + + // Remove event listener on cleanup + return () => window.removeEventListener("resize", displayMobileNavbar); + }, []); const renderNavbarItems = routes.map( ({ name, icon, href, route, collapse }: any) => ( @@ -57,7 +89,6 @@ function DefaultNavbar({ }} onMouseLeave={() => collapse && setDropdown(null)} light={light} - /> ) ); @@ -439,7 +470,7 @@ function DefaultNavbar({ py={1} px={{ xs: 4, sm: transparent ? 2 : 3, lg: transparent ? 0 : 2 }} width="100%" - borderRadius="xl" + // borderRadius="xl" shadow={transparent ? "none" : "md"} color={light ? "white" : "dark"} position={relative ? "relative" : "absolute"} @@ -463,7 +494,7 @@ function DefaultNavbar({ @@ -483,6 +514,61 @@ function DefaultNavbar({ > {renderNavbarItems} + + {action && + (action.type === "internal" ? ( + + {action.label} + + ) : ( + + {action.label} + + ))} + + + {mobileNavbar ? "close" : "menu"} + + + + {mobileView && ( + + )} {dropdownMenu} diff --git a/src/pages/Presentation/sections/Counters.tsx b/src/pages/Presentation/sections/Counters.tsx index 7ea01178..636eed37 100644 --- a/src/pages/Presentation/sections/Counters.tsx +++ b/src/pages/Presentation/sections/Counters.tsx @@ -1,7 +1,6 @@ import * as React from "react"; // @mui material components import Grid from "@mui/material/Grid"; -import Divider from "@mui/material/Divider"; // React components import MKBox from "../../../components/MKBox"; @@ -12,47 +11,43 @@ import DefaultCounterCard from "../../../examples/Cards/CounterCards/DefaultCoun function Counters() { return ( - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + ); }