import React, { useState } from "react"; import PropTypes from "prop-types"; import clsx from "clsx"; import { makeStyles, useTheme } from "@material-ui/core/styles"; import { Drawer, List, Divider, IconButton, ListItemIcon, ListItemText } from "@material-ui/core"; import ChevronLeftIcon from "@material-ui/icons/ChevronLeft"; import ChevronRightIcon from "@material-ui/icons/ChevronRight"; import ListItem from "@material-ui/core/ListItem"; import BuildIcon from "@material-ui/icons/Build"; import DnsIcon from "@material-ui/icons/Dns"; import DeviceHubIcon from "@material-ui/icons/DeviceHub"; import SettingsIcon from "@material-ui/icons/Settings"; import DashboardIcon from "@material-ui/icons/Dashboard"; import FeaturedPlayListIcon from "@material-ui/icons/FeaturedPlayList"; import { useHistory } from "react-router-dom"; import { useTranslation } from "react-i18next"; import styles from "./styles"; const useStyles = makeStyles(styles); const menu = [ { order: 0, items: [ { code: "dashboard", name: "Menu.Dashboard", route: "/dashboard", icon: , order: 0 }, { code: "machines", name: "Menu.Machines", route: "/machines", icon: , order: 1 }, { code: "system", name: "Menu.System", route: "/system", icon: , order: 2 } ] }, { order: 1, items: [ { code: "administration", name: "Menu.Administration", route: "/administration", icon: , order: 0 }, { code: "settings", name: "Menu.Settings", route: "/settings", icon: , order: 1 } ] }, { order: 2, items: [ { code: "about", name: "Menu.About", route: "/about", icon: , order: 0 } ] } ]; const sortedMenu = menu.sort((i1, i2) => i1 - i2); const Sidebar = ({ open, handleDrawerClose }) => { const [selected, setSelected] = useState(null); const classes = useStyles(); const theme = useTheme(); const history = useHistory(); const { t } = useTranslation(); const handleClick = route => () => { setSelected(route); history.push(route); }; const isSelected = key => selected === key; return (
{theme.direction === "rtl" ? ( ) : ( )}
{sortedMenu.map((menu, index) => { const isLast = index === sortedMenu.length - 1; return ( {menu.items .sort((i1, i2) => i1 - i2) .map(item => ( {item.icon} ))} {!isLast && } ); })}
); }; Sidebar.propTypes = { open: PropTypes.bool.isRequired, handleDrawerClose: PropTypes.func.isRequired }; export default Sidebar;