Refactor layout component styles

master^2
Tudor Stanciu 2024-03-25 03:19:58 +02:00
parent cbe251d776
commit ed94bb9510
5 changed files with 34 additions and 40 deletions

View File

@ -1,15 +1,14 @@
import React, { useState } from "react";
import { makeStyles } from "@mui/material/styles";
import { useTheme } from "@mui/material/styles";
import AppRoutes from "./AppRoutes";
import TopBar from "./TopBar";
import Sidebar from "./Sidebar";
import styles from "./styles";
const useStyles = makeStyles(styles);
import { getStyles } from "./styles";
const AppLayout = () => {
const [open, setOpen] = useState(false);
const classes = useStyles();
const theme = useTheme();
const styles = getStyles(theme);
const handleDrawerOpen = () => {
setOpen(true);
@ -20,11 +19,11 @@ const AppLayout = () => {
};
return (
<div className={classes.root}>
<div style={styles.root}>
<TopBar open={open} handleDrawerOpen={handleDrawerOpen} />
<Sidebar open={open} handleDrawerClose={handleDrawerClose} />
<main className={classes.content}>
<div className={classes.toolbar} />
<main style={styles.content}>
<div style={styles.toolbar} />
<AppRoutes />
</main>
</div>

View File

@ -7,16 +7,15 @@ import SettingsIcon from "@mui/icons-material/Settings";
import { useNavigate } from "react-router-dom";
import { useTuitioClient } from "@flare/tuitio-client-react";
import { useToast } from "../../hooks";
import styles from "./styles";
import { makeStyles } from "@mui/material/styles";
import { getStyles } from "./styles";
import { useTheme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
const useStyles = makeStyles(styles);
const ProfileButton = () => {
const navigate = useNavigate();
const { error } = useToast();
const classes = useStyles();
const theme = useTheme();
const styles = getStyles(theme);
const { t } = useTranslation();
const { logout } = useTuitioClient({
@ -67,7 +66,7 @@ const ProfileButton = () => {
handleClose();
}}
>
<ListItemIcon className={classes.menuItemIcon}>
<ListItemIcon sx={styles.menuItemIcon}>
<AccountBoxIcon fontSize="small" />
</ListItemIcon>
<Typography variant="inherit">{t("User.Profile.Label")}</Typography>
@ -78,13 +77,13 @@ const ProfileButton = () => {
handleClose();
}}
>
<ListItemIcon className={classes.menuItemIcon}>
<ListItemIcon sx={styles.menuItemIcon}>
<SettingsIcon fontSize="small" />
</ListItemIcon>
<Typography variant="inherit">{t("User.Settings")}</Typography>
</MenuItem>
<MenuItem onClick={logout}>
<ListItemIcon className={classes.menuItemIcon}>
<ListItemIcon sx={styles.menuItemIcon}>
<ExitToAppIcon fontSize="small" />
</ListItemIcon>
<Typography variant="inherit">{t("User.Logout")}</Typography>

View File

@ -1,7 +1,7 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import clsx from "clsx";
import { makeStyles, useTheme } from "@mui/material/styles";
import { useTheme } from "@mui/material/styles";
import { Drawer, List, Divider, IconButton, ListItemIcon, ListItemText } from "@mui/material";
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
@ -14,9 +14,7 @@ import DashboardIcon from "@mui/icons-material/Dashboard";
import FeaturedPlayListIcon from "@mui/icons-material/FeaturedPlayList";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import styles from "./styles";
const useStyles = makeStyles(styles);
import { getStyles } from "./styles";
const menu = [
{
@ -82,9 +80,8 @@ const sortedMenu = menu.sort((i1, i2) => i1 - i2);
const Sidebar = ({ open, handleDrawerClose }) => {
const [selected, setSelected] = useState(null);
const classes = useStyles();
const theme = useTheme();
const styles = getStyles(theme);
const navigate = useNavigate();
const { t } = useTranslation();
@ -98,18 +95,18 @@ const Sidebar = ({ open, handleDrawerClose }) => {
return (
<Drawer
variant="permanent"
className={clsx(classes.drawer, {
[classes.drawerOpen]: open,
[classes.drawerClose]: !open
sx={clsx(styles.drawer, {
[styles.drawerOpen]: open,
[styles.drawerClose]: !open
})}
classes={{
paper: clsx({
[classes.drawerOpen]: open,
[classes.drawerClose]: !open
[styles.drawerOpen]: open,
[styles.drawerClose]: !open
})
}}
>
<div className={classes.toolbar}>
<div style={styles.toolbar}>
<IconButton onClick={handleDrawerClose}>
{theme.direction === "rtl" ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>

View File

@ -1,24 +1,23 @@
import React from "react";
import PropTypes from "prop-types";
import clsx from "clsx";
import { makeStyles } from "@mui/material/styles";
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 styles from "./styles";
const useStyles = makeStyles(styles);
import { getStyles } from "./styles";
const TopBar = ({ open, handleDrawerOpen }) => {
const classes = useStyles();
const theme = useTheme();
const styles = getStyles(theme);
return (
<AppBar
position="fixed"
className={clsx(classes.appBar, {
[classes.appBarShift]: open
sx={clsx(styles.appBar, {
[styles.appBarShift]: open
})}
>
<Toolbar>
@ -27,13 +26,13 @@ const TopBar = ({ open, handleDrawerOpen }) => {
aria-label="open drawer"
onClick={handleDrawerOpen}
edge="start"
className={clsx(classes.menuButton, {
[classes.hide]: open
sx={clsx(styles.menuButton, {
[styles.hide]: open
})}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" noWrap className={classes.title}>
<Typography variant="h6" noWrap sx={styles.title}>
Network resurrector
</Typography>
<SensitiveInfoToggle />

View File

@ -1,6 +1,6 @@
const drawerWidth = 240;
const styles = theme => ({
const getStyles = theme => ({
root: {
display: "flex"
},
@ -68,4 +68,4 @@ const styles = theme => ({
}
});
export default styles;
export { getStyles };