|
| 1 | +import { useState } from "react"; |
| 2 | +import { styled, alpha } from "@mui/material/styles"; |
| 3 | +import Box from "@mui/material/Box"; |
| 4 | +import AppBar from "@mui/material/AppBar"; |
| 5 | +import Toolbar from "@mui/material/Toolbar"; |
| 6 | +import Button from "@mui/material/Button"; |
| 7 | +import IconButton from "@mui/material/IconButton"; |
| 8 | +import Container from "@mui/material/Container"; |
| 9 | +import MenuItem from "@mui/material/MenuItem"; |
| 10 | +import Drawer from "@mui/material/Drawer"; |
| 11 | +import MenuIcon from "@mui/icons-material/Menu"; |
| 12 | +import CloseRoundedIcon from "@mui/icons-material/CloseRounded"; |
| 13 | +import ThemeSwitch from "../ThemeSwitch"; |
| 14 | +import { useTheme } from "@mui/material/styles"; |
| 15 | +import { useSelector } from "react-redux"; |
| 16 | +import { useLocation, useNavigate } from "react-router-dom"; |
| 17 | + |
| 18 | +const StyledToolbar = styled(Toolbar)(({ theme, mode }) => ({ |
| 19 | + display: "flex", |
| 20 | + alignItems: "center", |
| 21 | + justifyContent: "space-between", |
| 22 | + flexShrink: 0, |
| 23 | + borderRadius: `calc(${theme.shape.borderRadius}px + 4px)`, |
| 24 | + backdropFilter: "blur(24px)", |
| 25 | + border: "1px solid", |
| 26 | + borderColor: |
| 27 | + mode === "light" |
| 28 | + ? alpha(theme.palette.common.black, 0.1) |
| 29 | + : alpha(theme.palette.common.white, 0.1), |
| 30 | + backgroundColor: |
| 31 | + mode === "light" |
| 32 | + ? alpha(theme.palette.common.white, 0.4) |
| 33 | + : alpha(theme.palette.common.black, 0.4), |
| 34 | + boxShadow: theme.shadows[3], |
| 35 | + padding: "8px 12px", |
| 36 | +})); |
| 37 | + |
| 38 | +const StyledMenuItem = styled(MenuItem)(({ theme }) => ({ |
| 39 | + fontSize: "1.1rem", |
| 40 | + margin: theme.spacing(4, 2), |
| 41 | +})); |
| 42 | + |
| 43 | +const AppAppBar = () => { |
| 44 | + const [open, setOpen] = useState(false); |
| 45 | + const theme = useTheme(); |
| 46 | + const mode = useSelector((state) => state.ui.mode); |
| 47 | + const location = useLocation(); |
| 48 | + const navigate = useNavigate(); |
| 49 | + |
| 50 | + // Debugging: Log the current theme mode |
| 51 | + console.log("Current theme mode:", mode); |
| 52 | + |
| 53 | + const logoSrc = |
| 54 | + mode === "light" ? "/images/prism-black.png" : "/images/prism-white.png"; |
| 55 | + |
| 56 | + const toggleDrawer = (newOpen) => () => { |
| 57 | + setOpen(newOpen); |
| 58 | + }; |
| 59 | + |
| 60 | + const handleScroll = (id) => { |
| 61 | + if (location.pathname === "/") { |
| 62 | + const element = document.getElementById(id); |
| 63 | + if (element) { |
| 64 | + element.scrollIntoView({ behavior: "smooth" }); |
| 65 | + } |
| 66 | + } else { |
| 67 | + navigate(`/#${id}`); |
| 68 | + } |
| 69 | + }; |
| 70 | + |
| 71 | + return ( |
| 72 | + <AppBar |
| 73 | + position="fixed" |
| 74 | + sx={{ |
| 75 | + boxShadow: 0, |
| 76 | + bgcolor: "transparent", |
| 77 | + backgroundImage: "none", |
| 78 | + border: "none", |
| 79 | + mt: "calc(var(--template-frame-height, 0px) + 28px)", |
| 80 | + }} |
| 81 | + > |
| 82 | + <Container maxWidth="lg"> |
| 83 | + <StyledToolbar |
| 84 | + variant="dense" |
| 85 | + disableGutters |
| 86 | + mode={mode} |
| 87 | + > |
| 88 | + <Box sx={{ flexGrow: 1, display: "flex", alignItems: "center", px: 0 }}> |
| 89 | + <img |
| 90 | + src={logoSrc} |
| 91 | + alt="Prism Logo" |
| 92 | + style={{ |
| 93 | + height: "auto", |
| 94 | + width: "auto", |
| 95 | + marginRight: "10px", |
| 96 | + maxHeight: "32px", |
| 97 | + }} |
| 98 | + /> |
| 99 | + <Box sx={{ display: { xs: "none", md: "flex" } }}> |
| 100 | + <Button |
| 101 | + variant="text" |
| 102 | + color="info" |
| 103 | + size="large" |
| 104 | + onClick={() => handleScroll("features")} |
| 105 | + > |
| 106 | + Features |
| 107 | + </Button> |
| 108 | + <Button |
| 109 | + variant="text" |
| 110 | + color="info" |
| 111 | + size="large" |
| 112 | + onClick={() => handleScroll("highlights")} |
| 113 | + > |
| 114 | + Highlights |
| 115 | + </Button> |
| 116 | + <Button |
| 117 | + variant="text" |
| 118 | + color="info" |
| 119 | + size="large" |
| 120 | + onClick={() => handleScroll("faq")} |
| 121 | + > |
| 122 | + FAQ |
| 123 | + </Button> |
| 124 | + <Button |
| 125 | + variant="text" |
| 126 | + color="info" |
| 127 | + size="large" |
| 128 | + href="https://uprock.com/blog" |
| 129 | + > |
| 130 | + Blog |
| 131 | + </Button> |
| 132 | + </Box> |
| 133 | + </Box> |
| 134 | + <Box |
| 135 | + sx={{ |
| 136 | + display: { xs: "none", md: "flex" }, |
| 137 | + gap: 1, |
| 138 | + alignItems: "center", |
| 139 | + }} |
| 140 | + > |
| 141 | + {/* <Button color="primary" variant="text" size="small"> |
| 142 | + Sign in |
| 143 | + </Button> |
| 144 | + <Button color="primary" variant="contained" size="small"> |
| 145 | + Sign up |
| 146 | + </Button> */} |
| 147 | + </Box> |
| 148 | + <Box |
| 149 | + sx={{ |
| 150 | + display: { xs: "flex", md: "none" }, |
| 151 | + |
| 152 | + gap: 1, |
| 153 | + }} |
| 154 | + > |
| 155 | + <IconButton |
| 156 | + aria-label="Menu button" |
| 157 | + onClick={toggleDrawer(true)} |
| 158 | + > |
| 159 | + <MenuIcon sx={{ color: theme.palette.text.primary }} /> |
| 160 | + </IconButton> |
| 161 | + <Drawer |
| 162 | + anchor="top" |
| 163 | + open={open} |
| 164 | + onClose={toggleDrawer(false)} |
| 165 | + PaperProps={{ |
| 166 | + sx: { |
| 167 | + top: 0, |
| 168 | + marginTop: 0, |
| 169 | + borderRadius: 0, |
| 170 | + backgroundColor: theme.palette.background.paper, |
| 171 | + }, |
| 172 | + }} |
| 173 | + > |
| 174 | + <Box sx={{ p: 4, backgroundColor: theme.palette.background.main }}> |
| 175 | + <Box |
| 176 | + sx={{ |
| 177 | + display: "flex", |
| 178 | + justifyContent: "flex-end", |
| 179 | + }} |
| 180 | + > |
| 181 | + <IconButton onClick={toggleDrawer(false)}> |
| 182 | + <CloseRoundedIcon sx={{ color: theme.palette.text.primary }} /> |
| 183 | + </IconButton> |
| 184 | + </Box> |
| 185 | + |
| 186 | + <StyledMenuItem>Features</StyledMenuItem> |
| 187 | + <StyledMenuItem>Testimonials</StyledMenuItem> |
| 188 | + <StyledMenuItem>Highlights</StyledMenuItem> |
| 189 | + <StyledMenuItem>FAQ</StyledMenuItem> |
| 190 | + <StyledMenuItem |
| 191 | + component="a" |
| 192 | + href="https://uprock.com/blog" |
| 193 | + > |
| 194 | + Blog |
| 195 | + </StyledMenuItem> |
| 196 | + {/* <MenuItem> |
| 197 | + <Button color="primary" variant="contained" fullWidth> |
| 198 | + Sign up |
| 199 | + </Button> |
| 200 | + </MenuItem> |
| 201 | + <MenuItem> |
| 202 | + <Button color="primary" variant="outlined" fullWidth> |
| 203 | + Sign in |
| 204 | + </Button> |
| 205 | + </MenuItem> */} |
| 206 | + </Box> |
| 207 | + </Drawer> |
| 208 | + </Box> |
| 209 | + <ThemeSwitch /> |
| 210 | + </StyledToolbar> |
| 211 | + </Container> |
| 212 | + </AppBar> |
| 213 | + ); |
| 214 | +}; |
| 215 | + |
| 216 | +export default AppAppBar; |
0 commit comments