From 14f16677c9c61a8f1ff31aa25b0949117aea2065 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 30 Mar 2024 10:33:40 +0200 Subject: [PATCH] Migrate TopBar component to typescript and MUI 5 --- frontend/src/components/layout/TopBar.js | 51 --------------- frontend/src/components/layout/TopBar.tsx | 72 +++++++++++++++++++++ frontend/src/components/layout/constants.ts | 1 + frontend/src/components/layout/styles.js | 3 - 4 files changed, 73 insertions(+), 54 deletions(-) delete mode 100644 frontend/src/components/layout/TopBar.js create mode 100644 frontend/src/components/layout/TopBar.tsx create mode 100644 frontend/src/components/layout/constants.ts diff --git a/frontend/src/components/layout/TopBar.js b/frontend/src/components/layout/TopBar.js deleted file mode 100644 index 355fd79..0000000 --- a/frontend/src/components/layout/TopBar.js +++ /dev/null @@ -1,51 +0,0 @@ -import React from "react"; -import PropTypes from "prop-types"; -import clsx from "clsx"; -import { useTheme } from "@mui/material/styles"; -import { AppBar, Toolbar, Typography, IconButton } from "@mui/material"; -import MenuIcon from "@mui/icons-material/Menu"; -import ProfileButton from "./ProfileButton"; -import LightDarkToggle from "./LightDarkToggle"; -import SensitiveInfoToggle from "./SensitiveInfoToggle"; -import { getStyles } from "./styles"; - -const TopBar = ({ open, handleDrawerOpen }) => { - const theme = useTheme(); - const styles = getStyles(theme); - - return ( - - - - - - - Network resurrector - - - - - - - ); -}; - -TopBar.propTypes = { - open: PropTypes.bool.isRequired, - handleDrawerOpen: PropTypes.func.isRequired -}; - -export default TopBar; diff --git a/frontend/src/components/layout/TopBar.tsx b/frontend/src/components/layout/TopBar.tsx new file mode 100644 index 0000000..c6ca569 --- /dev/null +++ b/frontend/src/components/layout/TopBar.tsx @@ -0,0 +1,72 @@ +import React from "react"; +import { Toolbar, Typography, IconButton, Box } from "@mui/material"; +import MuiAppBar, { AppBarProps as MuiAppBarProps } from "@mui/material/AppBar"; +import MenuIcon from "@mui/icons-material/Menu"; +import ProfileButton from "./ProfileButton"; +import LightDarkToggle from "./LightDarkToggle"; +import SensitiveInfoToggle from "./SensitiveInfoToggle"; +import { styled } from "@mui/material/styles"; +import { drawerWidth } from "./constants"; + +interface AppBarProps extends MuiAppBarProps { + open?: boolean; +} + +const AppBar = styled(MuiAppBar, { + shouldForwardProp: prop => prop !== "open" +})(({ theme, open }) => ({ + zIndex: theme.zIndex.drawer + 1, + transition: theme.transitions.create(["width", "margin"], { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen + }), + ...(open && { + marginLeft: drawerWidth, + width: `calc(100% - ${drawerWidth}px)`, + transition: theme.transitions.create(["width", "margin"], { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen + }) + }) +})); + +type TopBarProps = { + open: boolean; + onDrawerOpen: () => void; +}; + +const title = "Network resurrector"; +const TopBar: React.FC = ({ open, onDrawerOpen }) => { + // const { userInfo } = useTuitioUserInfo(); + // to do: Avatar: userInfo.profilePictureUrl + return ( + + + + + + + {title} + + + + + + + + + {/* */} + + ); +}; + +export default TopBar; diff --git a/frontend/src/components/layout/constants.ts b/frontend/src/components/layout/constants.ts new file mode 100644 index 0000000..eee33d4 --- /dev/null +++ b/frontend/src/components/layout/constants.ts @@ -0,0 +1 @@ +export const drawerWidth = 240; diff --git a/frontend/src/components/layout/styles.js b/frontend/src/components/layout/styles.js index 35f2258..0aaa9f6 100644 --- a/frontend/src/components/layout/styles.js +++ b/frontend/src/components/layout/styles.js @@ -56,9 +56,6 @@ const getStyles = theme => ({ // necessary for content to be below app bar ...theme.mixins.toolbar }, - title: { - flexGrow: 1 - }, content: { flexGrow: 1, padding: theme.spacing(2)