I have created a web app with the base coming from the Material-UI Example on a responsive drawer
I am trying to get a table to resize responsively to the screen width, but, for some reason, the ResponsiveDrawer container provided by Material-UI is breaking the responsiveness of the contents (i.e. the table)
Here is an example that I wrote that is perfectly responsive:
App.js
import React from "react";
import ReactDOM from "react-dom";
import Table from "#material-ui/core/Table/Table";
import TableHead from "#material-ui/core/TableHead/TableHead";
import TableRow from "#material-ui/core/TableRow/TableRow";
import TableCell from "#material-ui/core/TableCell/TableCell";
import TableBody from "#material-ui/core/TableBody/TableBody";
import Paper from "#material-ui/core/Paper/Paper";
import Grid from "#material-ui/core/Grid/Grid";
import "./styles.css";
function App() {
return (
<div className="App">
<Grid container justify={"center"}>
<Grid item xs={12} md={10} style={{ padding: "8px" }}>
<Paper style={{ overflowX: "auto" }}>
<Table style={{ minWidth: "340px" }}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Column</TableCell>
<TableCell>Operating System</TableCell>
<TableCell>Status</TableCell>
<TableCell>CPU Cores</TableCell>
<TableCell>Memory (MB)</TableCell>
<TableCell>IP Address</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
</TableBody>
</Table>
</Paper>
</Grid>
</Grid>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
And here is that same example using a modified (changed the content to this.props.children instead of static) version of Material-UI's ResponsiveDrawer
ResponsiveDrawer.js
import React from "react";
import PropTypes from "prop-types";
import AppBar from "#material-ui/core/AppBar";
import CssBaseline from "#material-ui/core/CssBaseline";
import Divider from "#material-ui/core/Divider";
import Drawer from "#material-ui/core/Drawer";
import Hidden from "#material-ui/core/Hidden";
import IconButton from "#material-ui/core/IconButton";
import InboxIcon from "#material-ui/icons/MoveToInbox";
import List from "#material-ui/core/List";
import ListItem from "#material-ui/core/ListItem";
import ListItemIcon from "#material-ui/core/ListItemIcon";
import ListItemText from "#material-ui/core/ListItemText";
import MailIcon from "#material-ui/icons/Mail";
import MenuIcon from "#material-ui/icons/Menu";
import Toolbar from "#material-ui/core/Toolbar";
import Typography from "#material-ui/core/Typography";
import { withStyles } from "#material-ui/core/styles";
const drawerWidth = 240;
const styles = theme => ({
root: {
display: "flex"
},
drawer: {
[theme.breakpoints.up("sm")]: {
width: drawerWidth,
flexShrink: 0
}
},
appBar: {
marginLeft: drawerWidth,
[theme.breakpoints.up("sm")]: {
width: `calc(100% - ${drawerWidth}px)`
}
},
menuButton: {
marginRight: 20,
[theme.breakpoints.up("sm")]: {
display: "none"
}
},
toolbar: theme.mixins.toolbar,
drawerPaper: {
width: drawerWidth
},
content: {
flexGrow: 1,
padding: theme.spacing.unit * 3
}
});
class ResponsiveDrawer extends React.Component {
state = {
mobileOpen: false
};
handleDrawerToggle = () => {
this.setState(state => ({ mobileOpen: !state.mobileOpen }));
};
render() {
const { classes, theme } = this.props;
const drawer = (
<div>
<div className={classes.toolbar} />
<Divider />
<List>
{["Inbox", "Starred", "Send email", "Drafts"].map((text, index) => (
<ListItem button key={text}>
<ListItemIcon>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
<List>
{["All mail", "Trash", "Spam"].map((text, index) => (
<ListItem button key={text}>
<ListItemIcon>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
</div>
);
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<IconButton
color="inherit"
aria-label="Open drawer"
onClick={this.handleDrawerToggle}
className={classes.menuButton}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" noWrap>
Responsive drawer
</Typography>
</Toolbar>
</AppBar>
<nav className={classes.drawer}>
{/* The implementation can be swapped with js to avoid SEO duplication of links. */}
<Hidden smUp implementation="css">
<Drawer
container={this.props.container}
variant="temporary"
anchor={theme.direction === "rtl" ? "right" : "left"}
open={this.state.mobileOpen}
onClose={this.handleDrawerToggle}
classes={{
paper: classes.drawerPaper
}}
>
{drawer}
</Drawer>
</Hidden>
<Hidden xsDown implementation="css">
<Drawer
classes={{
paper: classes.drawerPaper
}}
variant="permanent"
open
>
{drawer}
</Drawer>
</Hidden>
</nav>
<main className={classes.content}>
<div className={classes.toolbar} />
{this.props.children}
</main>
</div>
);
}
}
ResponsiveDrawer.propTypes = {
classes: PropTypes.object.isRequired,
// Injected by the documentation to work in an iframe.
// You won't need it on your project.
container: PropTypes.object,
theme: PropTypes.object.isRequired
};
export default withStyles(styles, { withTheme: true })(ResponsiveDrawer);
App.js
import React from "react";
import ReactDOM from "react-dom";
import Table from "#material-ui/core/Table/Table";
import TableHead from "#material-ui/core/TableHead/TableHead";
import TableRow from "#material-ui/core/TableRow/TableRow";
import TableCell from "#material-ui/core/TableCell/TableCell";
import TableBody from "#material-ui/core/TableBody/TableBody";
import Paper from "#material-ui/core/Paper/Paper";
import ResponsiveDrawer from "./ResponsiveDrawer";
import Grid from "#material-ui/core/Grid/Grid";
import "./styles.css";
function App() {
return (
<div className="App">
<ResponsiveDrawer>
<Grid container justify={"center"}>
<Grid item xs={12} md={10} style={{ padding: "8px" }}>
<Paper style={{ overflowX: "auto" }}>
<Table style={{ minWidth: "340px" }}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Column</TableCell>
<TableCell>Operating System</TableCell>
<TableCell>Status</TableCell>
<TableCell>CPU Cores</TableCell>
<TableCell>Memory (MB)</TableCell>
<TableCell>IP Address</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
</TableBody>
</Table>
</Paper>
</Grid>
</Grid>
</ResponsiveDrawer>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
I just can't seem to figure out what it is inside the ResponsiveDrawer container that is causing the responsiveness to break.
All help appreciated.
UPDATE (1/7/2019):
It looks like removing display: flex from the root solves the issue, but then I have the issue of it not honoring the left drawer.
UPDATE (1/9/2019):
As suggested by #Gaurav Rana, I have added width: 100%; to the main element and it has half solved the problem. Now, the table will overflow / scroll properly when the sidebar is not visible. But, when the sidebar is still visible but the screen isn't wide enough for the whole table, the table scrolls under the sidebar.
After a bit of troubleshooting, I have come up with a solution:
The styles for content need to be updated as follows (This will force the width of the content element to fit the width of the screen minus the drawer if necessary):
content: {
[theme.breakpoints.up("sm")]: {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`
}
},
And display: flex needs to be removed from root
https://codesandbox.io/s/1zxp2qjmoj
this is a problem width css width. You must specify whole parents width: 100% like this
body {
width: 100%
}
.grandparent {
width: 100%
}
.parent {
width: 100%
}
.tableContainer {
width: 100%
}
add style below style in your styles.css . hope this will solve your issue.
main {
width: 100%;
}
Related
I am trying to avoid using Redux and want to share search results to components outside the header. My header appears on every page and the data is inside Lessons component. I want to search in the header and transfer the result to Lessons component and also to Students component. Any leads, please?
Below is my code.
app.js
import "./App.css";
import Lessons from "./components/Lessons";
import LoadingHOC from "./components/LoadingHOC";
import React, { useEffect, useState } from "react";
import { Route, BrowserRouter as Router, Switch, matchPath } from "react-router-dom";
import { ThemeProvider } from "#material-ui/core/styles";
import Header from "./components/Header";
import Footer from "./components/Footer";
import UpdateForm from "./components/UpdateForm";
import Register from "./components/Register";
import CreateLesson from "./components/CreateLesson";
import DeleteLesson from "./components/DeleteLesson";
import Students from "./components/Students";
import UpdateStudent from "./components/UpdateStudent"
import Login from "./components/Login";
import AddStudent from "./components/AddStudent";
import DeleteStudent from "./components/DeleteStudent";
import theme from "./theme";
function App() {
// const LessonsLoading = LoadingHOC(Lessons);
// // const StudentsLoading = LoadingHOC(Students);
/
// };
const [appState, setAppState] = useState({ loading: false, lessons: [] });
useEffect(() => {
console.log("debug app state");
setAppState({ loading: true });
// const apiUrl = "http://127.0.0.1:8000/api/";
// fetch(apiUrl)
// .then((data) => data.json())
// .then((lessons) => {
// debugger;
// setAppState({ loading: false, lessons: lessons });
// // console.log(lessons);
// });
}, []);
// console.log('debug loading', appState.loading)
// console.log('debug loading', appState.lessons)
return (
// console.log('debug lessons', appState.lessons),
// <div className="app">
// <LessonsLoading isLoading={appState.loading} lessons={appState.lessons}/>
// {/* <StudentsLoading isLoading={appState.loading} students={appState.students}/> */}
// </div>
<ThemeProvider theme={theme}>
{/* <Router> */}
<React.StrictMode>
<Header />
{/* <LoadingHOC /> */}
<Switch>
{console.log("debug lessons", appState.lessons)}
<Route
exact
path="/"
component={Lessons}
// lessons={appState.lessons}
/>
<Route exact path="/account/register" component={Register} />
<Route exact path="/account/login" component={Login} />
<Route path="/create/" component={CreateLesson} />
<Route path="/delete/" component={DeleteLesson} />
<Route path="/students" component={Students} />
<Route path="/student/:id" component={UpdateStudent}/>
<Route path="/lessons/:id" component={UpdateForm} />
<Route path="/add_student" component={AddStudent} />
{/* <Route exact path="/" component={App} /> */}
</Switch>
{/* if (!appState.loading) return <Lessons lessons={appState.lessons} />; */}
{/* <Footer /> */}
</React.StrictMode>
{/* </Router> */}
</ThemeProvider>
);
}
export default App;
header.js
import React, { useState, useEffect } from "react";
import {
fade,
makeStyles,
ThemeProvider,
createMuiTheme,
} from "#material-ui/core/styles";
import AppBar from "#material-ui/core/AppBar";
import Toolbar from "#material-ui/core/Toolbar";
import Typography from "#material-ui/core/Typography";
import IconButton from "#material-ui/core/IconButton";
import MenuIcon from "#material-ui/icons/Menu";
import AccountCircle from "#material-ui/icons/AccountCircle";
import Switch from "#material-ui/core/Switch";
import FormControlLabel from "#material-ui/core/FormControlLabel";
import FormGroup from "#material-ui/core/FormGroup";
import MenuItem from "#material-ui/core/MenuItem";
import Menu from "#material-ui/core/Menu";
import InputBase from "#material-ui/core/InputBase";
import SearchIcon from "#material-ui/icons/Search";
import { Link } from "react-router-dom";
import { useHistory } from "react-router-dom";
import { HistoryTwoTone } from "#material-ui/icons";
import axiosInstance from "./../axios";
import Students from './Students';
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
},
mainTitle: {
textAlign: "center",
fontWeight: "700",
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
flexGrow: 1,
},
tableTitle: {
textAlign: "center",
},
search: {
position: "relative",
borderRadius: theme.shape.borderRadius,
backgroundColor: fade(theme.palette.common.white, 0.15),
"&:hover": {
backgroundColor: fade(theme.palette.common.white, 0.25),
},
marginLeft: 0,
width: "100%",
[theme.breakpoints.up("sm")]: {
marginLeft: theme.spacing(1),
width: "auto",
},
},
searchIcon: {
padding: theme.spacing(0, 2),
height: "100%",
position: "absolute",
pointerEvents: "none",
display: "flex",
alignItems: "center",
justifyContent: "center",
},
inputRoot: {
color: "inherit",
},
inputInput: {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(4)}px)`,
transition: theme.transitions.create("width"),
width: "100%",
[theme.breakpoints.up("sm")]: {
width: "12ch",
"&:focus": {
width: "20ch",
},
},
},
}));
// Components lib - material, bootstrap, fabric, antd
// css-in-js: styled-components, theme-ui
export default function MenuAppBar() {
const classes = useStyles();
const [auth, setAuth] = React.useState(true);
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);
// const [studentsData, setStudentsData] = useState("");
// useEffect(() => {
// axiosInstance.get("/students").then((res) => {
// setStudentsData({ ...studentsData, students: res.data });
// });
// }, []);
const handleChange = (event) => {
setAuth(event.target.checked);
};
const handleMenu = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<div className={classes.root}>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={auth}
onChange={handleChange}
aria-label="login switch"
/>
}
label={auth ? "Logout" : "Login"}
/>
</FormGroup>
<AppBar position="static" color="primary">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
onClick={handleMenu}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" className={classes.title}>
Anat
</Typography>
{auth && (
<div>
<IconButton
aria-label="account of current user"
aria-controls="menu-appbar"
aria-haspopup="true"
// onClick={handleMenu}
color="inherit"
>
<AccountCircle />
</IconButton>
<Menu
id="menu-appbar"
anchorEl={anchorEl}
anchorOrigin={{
vertical: "top",
horizontal: "right",
}}
keepMounted
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
open={open}
onClose={handleClose}
>
<MenuItem onClick={handleClose}>Profile</MenuItem>
{/* <Link href={"/students"} studentsList={studentsData.students}> */}
{/* <Link
to={{
pathname: "/students",
state: { studentsList: studentsData.students },
}}
> */}
<MenuItem component={Link} to={'/students'} onClick={handleClose}> Manage Students</MenuItem>
{/* </Link> */}
</Menu>
</div>
)}
<div className={classes.search}>
<div className={classes.searchIcon}>
<SearchIcon />
</div>
<InputBase
placeholder="Search…"
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}
inputProps={{ "aria-label": "search" }}
/>
</div>
</Toolbar>
</AppBar>
{/* <div><Typography variant="h6" className="mainTitle">Student Lessons
</Typography>
</div> */}
{/* <div>
<h1 className={classes.tableTitle}>Student Lessons</h1>
</div> */}
</div>
);
}
lessons.js
import React, { useEffect, useState } from "react";
import { makeStyles,fade } from "#material-ui/core/styles";
import Table from "#material-ui/core/Table";
import TableBody from "#material-ui/core/TableBody";
import TableCell from "#material-ui/core/TableCell";
import TableContainer from "#material-ui/core/TableContainer";
import TableHead from "#material-ui/core/TableHead";
import TableRow from "#material-ui/core/TableRow";
import Paper from "#material-ui/core/Paper";
import UpdateLesson from "./UpdateLesson";
import DeleteLesson from "./DeleteLesson";
import Container from "#material-ui/core/Container";
import Typography from "#material-ui/core/Typography";
import IconButton from "#material-ui/core/IconButton";
import EditIcon from "#material-ui/icons/Edit";
import Link from "#material-ui/core/Link";
import AddIcon from "#material-ui/icons/Add";
import Fab from '#material-ui/core/Fab';
import Grid from '#material-ui/core/Grid';
const useStyles = makeStyles((theme)=>({
table: {
minWidth: "450",
},
tableTitle: {
textAlign: "center",
},
title: {
textAlign: "center",
},
tablerow: {
fontWeight: "bold",
},
root: {
marginTop: theme.spacing(8),
paddingTop: theme.spacing(3),
paddingBottom: theme.spacing(3),
},
fab: {
backgroundColor: fade(theme.palette.primary.light),
// paddingHorizontal: auto,
}
}));
const Lessons = (props) => {
const [lessons, setLessons] = useState([]);
const apiUrl = "http://127.0.0.1:8000/api/";
useEffect(() => {
fetch(apiUrl)
.then((data) => data.json())
.then((lessons) => {
// debugger;
setLessons(lessons || []);
// console.log(lessons);
});
// setAppState({ loading: true });
}, []);
// const { lessons } = props;
console.log({ lessons });
const classes = useStyles();
// if (lessons === null) {
// return <div>No data</div>;
// }
return (
<React.Fragment>
<Container>
<div>
<h1 className={classes.tableTitle}>Student Lessons</h1>
</div>
<Paper>
<TableContainer component={Paper}>
<Table className={classes?.table} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell className={classes.tablerow}>Id</TableCell>
<TableCell align="right" className={classes.tablerow}>
Student
</TableCell>
<TableCell align="right" className={classes.tablerow}>
Title
</TableCell>
<TableCell align="right" className={classes.tablerow}>
lesson date
</TableCell>
<TableCell align="right" className={classes.tablerow}>
payment
</TableCell>
<TableCell
align="right"
className={classes.tablerow}
></TableCell>
<TableCell
align="right"
className={classes.tablerow}
></TableCell>
</TableRow>
</TableHead>
<TableBody>
{lessons ? (
lessons.map((lesson) => (
<TableRow key={lesson.id}>
<TableCell component="th">{lesson.id}</TableCell>
<TableCell align="right">{lesson.student}</TableCell>
<TableCell align="right">{lesson.title}</TableCell>
<TableCell align="right">{lesson.lesson_date}</TableCell>
<TableCell align="right">{lesson.paid}</TableCell>
<TableCell align="center">
{/* <UpdateLesson lesson={lesson.id} /> */}
<Link href={"/lessons/" + lesson.id}>
<IconButton className={classes.icon}>
<EditIcon />
</IconButton>
</Link>
</TableCell>
<TableCell align="right">
<DeleteLesson lessonId={lesson.id} />
</TableCell>
</TableRow>
))
) : (
<div>No data</div>
)}
</TableBody>
</Table>
</TableContainer>
</Paper>
</Container>
<Container maxWidth="md" className={classes.root}>
<Grid container spacing={2}>
<Link href={'/create'}>
<Fab className={classes.fab} >
<AddIcon />
</Fab>
</Link>
<Link href={'/students'}>
<Fab className={classes.fab} >
<AddIcon />
</Fab>
</Link>
</Grid>
</Container>
</React.Fragment>
);
};
export default Lessons;
you can store value inside variable...
app.js
import {useRef, useState, useEffect} from 'react'
import Header from './Header';
const app = () => {
const searchRef = useRef(null);
const [searchValue, setSearchValue] = useState(null);
useEffect(() => {
setSearchValue(searchRef.current.value);
})
return (
<Header ref={searchRef} />
)
}
header.js
import {forwardRef} from 'react'
const Header = ({other props like children etc.}, ref) => {
return (
<header>
<input ref={ref} type="text" placeholder="search" />
</header>
)}
const ForwardHeader = forwardRef(Header);
export default ForwardHeader;
From that point you can do what ever you want to do with searchValue variable inside app.js or forward it to some of the components. But better idia will be to use simple context to manage state of search input
Trying to render a component conditionally. I have a drawHelper variable & a function to toggle it true or false. The component renders or not based on the initial value of drawHelper. (false, doesn't render, true it does).
The toggle function changes the value. I checked with console.log(drawHelper) But changing the value does not make the component appear or disappear.
Am I missing something here?
import React from 'react';
import AppBar from '#material-ui/core/AppBar';
import CssBaseline from '#material-ui/core/CssBaseline';
import Divider from '#material-ui/core/Divider';
import Drawer from '#material-ui/core/Drawer';
import Hidden from '#material-ui/core/Hidden';
import IconButton from '#material-ui/core/IconButton';
import List from '#material-ui/core/List';
import ListItem from '#material-ui/core/ListItem';
import ListItemIcon from '#material-ui/core/ListItemIcon';
import ListItemText from '#material-ui/core/ListItemText';
import DashboardIcon from '#material-ui/icons/Dashboard';
import MenuIcon from '#material-ui/icons/Menu';
import Toolbar from '#material-ui/core/Toolbar';
import Typography from '#material-ui/core/Typography';
import { makeStyles, useTheme, Theme, createStyles } from '#material-ui/core/styles';
import { User } from './User';
import { Draw } from "components/Layout/Countryballs/Draw";
const drawerWidth = 240;
export const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
display: 'flex',
color: '#fff',
},
drawer: {
[theme.breakpoints.up('sm')]: {
width: drawerWidth,
flexShrink: 0,
},
},
appBar: {
marginLeft: drawerWidth,
[theme.breakpoints.up('sm')]: {
width: `calc(100% - ${drawerWidth}px)`,
},
},
menuButton: {
marginRight: theme.spacing(2),
[theme.breakpoints.up('sm')]: {
display: 'none',
},
},
toolbar: theme.mixins.toolbar,
drawerPaper: {
width: drawerWidth,
backgroundColor: theme.palette.primary.main
},
content: {
flexGrow: 1,
},
menuItem: {
color: '#fff',
},
}),
);
export const Layout: React.FC<LayoutProps> = (props) => {
const { container } = props;
const classes = useStyles();
const theme = useTheme();
const [mobileOpen, setMobileOpen] = React.useState(false);
function handleDrawerToggle() {
setMobileOpen(!mobileOpen);
}
// Display Draw component
// 1 Create property
var drawHelper: Boolean = false;
function toggleDraw() {
console.log(drawHelper);
drawHelper = !drawHelper;
}
const drawer = (
<div>
<div className={classes.toolbar} />
<Divider />
<List>
{['Draw'].map((text) => (
<ListItem button key={text} onClick={toggleDraw} className={classes.menuItem}>
<ListItemIcon className={classes.menuItem}><DashboardIcon /></ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
</div>
);
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
edge="start"
onClick={handleDrawerToggle}
className={classes.menuButton}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" noWrap>
Project name
</Typography>
<User/>
</Toolbar>
</AppBar>
<nav className={classes.drawer} aria-label="mailbox folders">
{/* The implementation can be swapped with js to avoid SEO duplication of links. */}
<Hidden smUp implementation="css">
<Drawer // this one is for mobile
container={container}
variant="temporary"
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
open={mobileOpen}
onClose={handleDrawerToggle}
classes={{
paper: classes.drawerPaper,
}}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
>
{drawer}
</Drawer>
</Hidden>
<Hidden xsDown implementation="css">
<Drawer // This one is for desktop
classes={{
paper: classes.drawerPaper,
}}
variant="permanent"
open
>
{drawer}
</Drawer>
</Hidden>
</nav>
<main className={classes.content}>
{/* This is where my components renders */}
{
drawHelper === true && (<Draw/>)
}
<div className={classes.toolbar} />
{props.children}
</main>
</div>
);
}
The variable drawHelper in your code is instantiated on every render. You'd want to use React's state to make sure your drawHelper's value is preserved on the next re-renders.
const [drawHelper, toggleDrawHelper] = React.useState(false)
function toggleDraw() {
toggleDrawHelper(!drawHelper);
}
I'm trying to use a Drawer in Material UI.
I want the width of the main div to take up whatever available space is left in the viewport after the menu drawer has used its space.
This is my component. I've tried setting width to auto and inherit on the content class, but it doesn't change anything.
I want the main div (where the content for a list item in the drawer) is rendered, to take only as much space is available without scrolling horizontally.
This code sandbox shows the problem: https://codesandbox.io/s/material-tab-scrolling-h13pi?file=/test.jsx
import React, { useState, useEffect } from 'react';
import { Switch, Route, Link, BrowserRouter } from "react-router-dom";
import clsx from 'clsx';
import { makeStyles, useTheme } from '#material-ui/core/styles';
import Drawer from '#material-ui/core/Drawer';
import AppBar from '#material-ui/core/AppBar';
import Toolbar from '#material-ui/core/Toolbar';
import List from '#material-ui/core/List';
import CssBaseline from '#material-ui/core/CssBaseline';
import Typography from '#material-ui/core/Typography';
import Divider from '#material-ui/core/Divider';
import IconButton from '#material-ui/core/IconButton';
import Menu from '#material-ui/core/Menu';
import MenuItem from '#material-ui/core/MenuItem';
import Container from '#material-ui/core/Container'
import MenuIcon from '#material-ui/icons/Menu';
import ChevronLeftIcon from '#material-ui/icons/ChevronLeft';
import ChevronRightIcon from '#material-ui/icons/ChevronRight';
import ListItem from '#material-ui/core/ListItem';
import ListItemIcon from '#material-ui/core/ListItemIcon';
import ListItemText from '#material-ui/core/ListItemText';
import InboxIcon from '#material-ui/icons/MoveToInbox';
import MailIcon from '#material-ui/icons/Mail';
import AccountCircle from '#material-ui/icons/AccountCircle';
import PaletteIcon from '#material-ui/icons/Palette';
import CenterFocusWeakIcon from '#material-ui/icons/CenterFocusWeak';
import RoomServiceIcon from '#material-ui/icons/RoomService';
import StorefrontIcon from '#material-ui/icons/Storefront';
import AssignmentIcon from '#material-ui/icons/Assignment';
import NotificationsIcon from '#material-ui/icons/Notifications';
import AccountBoxIcon from '#material-ui/icons/AccountBox';
import ContactSupportIcon from '#material-ui/icons/ContactSupport';
import BookIcon from '#material-ui/icons/Book';
import TuneIcon from '#material-ui/icons/Tune';
import SettingsIcon from '#material-ui/icons/Settings';
import CloseIcon from '#material-ui/icons/Close';
import DashboardFooter from "./DashboardFooter";
const drawerWidth = 240;
const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
appBarShift: {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
menuButton: {
marginRight: 36,
},
hide: {
display: 'none',
},
drawer: {
width: drawerWidth,
flexShrink: 0,
whiteSpace: 'nowrap',
},
drawerOpen: {
width: drawerWidth,
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
drawerClose: {
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
overflowX: 'hidden',
width: theme.spacing(7) + 1,
[theme.breakpoints.up('sm')]: {
width: theme.spacing(9) + 1,
},
},
toolbar: {
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
padding: theme.spacing(0, 1),
// necessary for content to be below app bar
...theme.mixins.toolbar,
},
content: {
flexGrow: 1,
padding: theme.spacing(3),
// autoWidth: false
},
container: {
paddingTop: theme.spacing(4),
paddingBottom: theme.spacing(4),
},
}));
export default function MiniDrawer() {
const classes = useStyles();
const theme = useTheme();
const [open, setOpen] = React.useState(false);
// const { performingAction, user, userData, roles } = this.props;
const handleDrawerOpen = () => {
setOpen(true);
};
const handleDrawerClose = () => {
setOpen(false);
};
return (
<div className={classes.root}>
<CssBaseline />
<AppBar
position="fixed"
className={clsx(classes.appBar, {
[classes.appBarShift]: open,
})}
>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={handleDrawerOpen}
edge="start"
className={clsx(classes.menuButton, {
[classes.hide]: open,
})}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" noWrap>
{process.env.REACT_APP_TITLE}
</Typography>
<IconButton color="inherit"><CloseIcon /></IconButton>
</Toolbar>
</AppBar>
<BrowserRouter>
<Drawer
variant="permanent"
className={clsx(classes.drawer, {
[classes.drawerOpen]: open,
[classes.drawerClose]: !open,
})}
classes={{
paper: clsx({
[classes.drawerOpen]: open,
[classes.drawerClose]: !open,
}),
}}
>
<div className={classes.toolbar}>
<IconButton onClick={handleDrawerClose}>
{theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
</div>
<List>
<ListItem button key="1" component={Link} to={"/DSM" }>
<ListItemIcon><PaletteIcon /></ListItemIcon>
<ListItemText primary="DS"></ListItemText>
</ListItem>
<ListItem button key="2" component={Link} to={"/MMM" }>
<ListItemIcon><CenterFocusWeakIcon /></ListItemIcon>
<ListItemText>MM</ListItemText>
</ListItem>
<ListItem button key="3" component={Link} to={"/RCM" }>
<ListItemIcon><StorefrontIcon /></ListItemIcon>
<ListItemText>Centre</ListItemText>
</ListItem>
<ListItem button key="4" component={Link} to={"/TT" }>
<ListItemIcon><AssignmentIcon /></ListItemIcon>
<ListItemText>TT</ListItemText>
</ListItem>
</List>
<Divider />
<List>
<ListItem button key="5" component={Link} to={"/Profile" }>
<ListItemIcon> <AccountBoxIcon /></ListItemIcon>
<ListItemText>Profile</ListItemText>
</ListItem>
<ListItem button key="6" component={Link} to={"/Account" }>
<ListItemIcon> <SettingsIcon /></ListItemIcon>
<ListItemText>Account</ListItemText>
</ListItem>
<ListItem button key="7" component={Link} to={"/Mail" }>
<ListItemIcon> <MailIcon /></ListItemIcon>
<ListItemText>Mail</ListItemText>
</ListItem>
<ListItem button key="8" component={Link} to={"/Notifications" }>
<ListItemIcon> <NotificationsIcon /></ListItemIcon>
<ListItemText>Notifications</ListItemText>
</ListItem>
</List>
<Divider />
<List>
<ListItem button key="9" component={Link} to={"/CM" }>
<ListItemIcon> <BookIcon /></ListItemIcon>
<ListItemText>Centre</ListItemText>
</ListItem>
<ListItem button key="10" component={Link} to={"/DCM" }>
<ListItemIcon><RoomServiceIcon /></ListItemIcon>
<ListItemText>Desk</ListItemText>
</ListItem>
<ListItem button key="11" component={Link} to={"/Support" }>
<ListItemIcon> <ContactSupportIcon /></ListItemIcon>
<ListItemText>Help and Support</ListItemText>
</ListItem>
</List>
</Drawer>
<main className={classes.content}>
<div className={classes.toolbar} />
<Switch>
<Route path="/DCM" component={""} />
<Route path="/MMM" render={() => <div>Page mm</div>} />
</Switch>
<DashboardFooter />
</main>
</BrowserRouter>
</div>
);
}
The main issue is the following in dash.jsx:
root: {
display: 'flex',
},
This is somehow defeating the mechanism in Tabs for its "scrollable tabs" functionality and results in the Tabs taking up as much width as is needed to display all of its tab buttons instead of showing scroll buttons. display: 'flex' makes it a little easier to manage the content width (such that it automatically adjusts based on the drawer width), but it isn't difficult to manage this in other ways.
Alternative 1
In my modified version of your sandbox, to remediate the effects of removing display: 'flex' from the root, I'm adding padding-left to the content with the same width as the drawer:
content: {
padding: theme.spacing(3),
paddingLeft: theme.spacing(7) + 1,
[theme.breakpoints.up("sm")]: {
paddingLeft: theme.spacing(9) + 1
}
},
contentDrawerOpen: {
paddingLeft: drawerWidth
},
...
<main className={clsx(classes.content, {[classes.contentDrawerOpen]: open})}>
Alternative 2
Another alternative is to leave display: 'flex', but specify the max-width appropriately on the content.
content: {
padding: theme.spacing(3),
maxWidth: `calc(100vw - ${theme.spacing(7) + 1}px)`,
[theme.breakpoints.up("sm")]: {
maxWidth: `calc(100vw - ${theme.spacing(9) + 1}px)`
}
},
contentDrawerOpen: {
maxWidth: `calc(100vw - ${drawerWidth}px)`
},
Alternative 3 (inspired by Ahmed Mokhtar's answer)
It also appears to be sufficient to just add overflow: "auto" to the content class for the <main> element:
content: {
padding: theme.spacing(3),
overflow: "auto"
},
This last alternative is definitely the simplest.
I fixed that by adding overflow: auto to main which I changed to use the Container component:
container: {
overflow: "auto"
}
{/* I added overflow: auto to this container*/}
<Container
component="main"
maxWidth={false}
className={classes.container}
>
<div className={classes.toolbar} />
<Switch>
<Route path="/dash" component={Dash} />
<Route path="/MatchmakerMenu" component={Dash} />
</Switch>
</Container>
CodeSandbox
I'm using react Material UI in an application, but found some missing logic with my react code.
My complete App.js source file is written below
import React from 'react';
import { fade,makeStyles } from '#material-ui/core/styles';
import Paper from '#material-ui/core/Paper';
import Grid from '#material-ui/core/Grid';
import Icon from '#material-ui/core/Icon';
// import { browserHistory, Router, Route } from 'react-router';
import { BrowserRouter as Router, Route,Redirect } from "react-router-dom";
import './App.css';
/* AppBar*/
//import { fade, makeStyles } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Toolbar from '#material-ui/core/Toolbar';
import IconButton from '#material-ui/core/IconButton';
import Typography from '#material-ui/core/Typography';
import InputBase from '#material-ui/core/InputBase';
import Badge from '#material-ui/core/Badge';
import MenuItem from '#material-ui/core/MenuItem';
import Menu from '#material-ui/core/Menu';
import MenuIcon from '#material-ui/icons/Menu';
import SearchIcon from '#material-ui/icons/Search';
import AccountCircle from '#material-ui/icons/AccountCircle';
import MailIcon from '#material-ui/icons/Mail';
import NotificationsIcon from '#material-ui/icons/Notifications';
import MoreIcon from '#material-ui/icons/MoreVert';
/*App bar */
import ImgMediaCard from './ImgMediaCard';
import GridList from '#material-ui/core/GridList';
import GridListTile from '#material-ui/core/GridListTile';
import DemoCarousel from './MCarousel'
import Register from './Register'
var gridListStyle = {
marginLeft: "40px"
};
const useStyles = makeStyles(theme => ({
grow: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
display: 'none',
[theme.breakpoints.up('sm')]: {
display: 'block',
},
},
search: {
position: 'relative',
borderRadius: theme.shape.borderRadius,
backgroundColor: fade(theme.palette.common.white, 0.15),
'&:hover': {
backgroundColor: fade(theme.palette.common.white, 0.25),
},
marginRight: theme.spacing(2),
marginLeft: 0,
width: '100%',
[theme.breakpoints.up('sm')]: {
marginLeft: theme.spacing(3),
width: 'auto',
},
},
searchIcon: {
width: theme.spacing(7),
height: '100%',
position: 'absolute',
pointerEvents: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
inputRoot: {
color: 'inherit',
},
inputInput: {
padding: theme.spacing(1, 1, 1, 7),
transition: theme.transitions.create('width'),
width: '100%',
[theme.breakpoints.up('md')]: {
width: 200,
},
},
sectionDesktop: {
display: 'none',
[theme.breakpoints.up('md')]: {
display: 'flex',
},
},
sectionMobile: {
display: 'flex',
[theme.breakpoints.up('md')]: {
display: 'none',
},
}
}));
/*end App bar work*/
const useGridStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
},
paper: {
// padding: theme.spacing(2),
// textAlign: 'center',
// color: theme.palette.text.secondary,
},
}));
function App() {
const Gridclasses = useGridStyles();
const classes = useStyles();
const [anchorEl, setAnchorEl] = React.useState(null);
const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = React.useState(null);
const isMenuOpen = Boolean(anchorEl);
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl);
const handleProfileMenuOpen = event => {
setAnchorEl(event.currentTarget);
};
const handleMobileMenuClose = () => {
setMobileMoreAnchorEl(null);
};
const handleMenuClose = () => {
setAnchorEl(null);
handleMobileMenuClose();
};
const handleMobileMenuOpen = event => {
setMobileMoreAnchorEl(event.currentTarget);
};
const onRegisterClick = () => {
debugger;
//if(userFound){
<Router>
<Route exact path="/Register" component={Register} />
return <Redirect to="/Register" />
</Router>
// }
};
// const addRoutes = () =>{
// };
let nums = Array.from(Array(40).keys());
const menuId = 'primary-search-account-menu';
const renderMenu = (
<Menu
anchorEl={anchorEl}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
id={menuId}
keepMounted
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
open={isMenuOpen}
onClose={handleMenuClose}
>
<MenuItem onClick={handleMenuClose}>Profile</MenuItem>
<MenuItem onClick={handleMenuClose}>My account</MenuItem>
</Menu>
);
const mobileMenuId = 'primary-search-account-menu-mobile';
const renderMobileMenu = (
<Menu
anchorEl={mobileMoreAnchorEl}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
id={mobileMenuId}
keepMounted
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
open={isMobileMenuOpen}
onClose={handleMobileMenuClose}
>
<MenuItem>
<Icon className="fa fa-plus-circle" />
</MenuItem>
<MenuItem>
<IconButton aria-label="show 4 new mails" color="inherit">
<Badge badgeContent={4} color="secondary">
<MailIcon />
</Badge>
</IconButton>
<p>Messages</p>
</MenuItem>
<MenuItem>
<IconButton aria-label="show 11 new notifications" color="inherit">
<Badge badgeContent={11} color="secondary">
<NotificationsIcon />
</Badge>
</IconButton>
<p>Notifications</p>
</MenuItem>
<MenuItem onClick={handleProfileMenuOpen}>
<IconButton
aria-label="account of current user"
aria-controls="primary-search-account-menu"
aria-haspopup="true"
color="inherit"
>
<AccountCircle />
</IconButton>
<p>Profile</p>
</MenuItem>
</Menu>
);
return (
<div className={Gridclasses.root}>
<Grid container spacing={3}>
<Grid item xs={12}>
<Paper className={Gridclasses.paper}>
<div className={classes.grow}>
<AppBar position="static">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="open drawer"
>
<MenuIcon />
</IconButton>
<Typography className={classes.title} variant="h6" noWrap>
Shopping Center
</Typography>
<div className={classes.search}>
<div className={classes.searchIcon}>
<SearchIcon />
</div>
<InputBase
placeholder="Search…"
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}
inputProps={{ 'aria-label': 'search' }}
/>
</div>
<div className={classes.grow} />
<div className={classes.sectionDesktop}>
<IconButton aria-label="" color="inherit" onClick={onRegisterClick}> Sign Up
</IconButton>
<IconButton aria-label="show 4 new mails" color="inherit">
<Badge badgeContent={4} color="secondary">
<MailIcon />
</Badge>
</IconButton>
<IconButton aria-label="show 17 new notifications" color="inherit">
<Badge badgeContent={17} color="secondary">
<NotificationsIcon />
</Badge>
</IconButton>
<IconButton
edge="end"
aria-label="account of current user"
aria-controls={menuId}
aria-haspopup="true"
onClick={handleProfileMenuOpen}
color="inherit"
>
<AccountCircle />
</IconButton>
</div>
<div className={classes.sectionMobile}>
<IconButton
aria-label="show more"
aria-controls={mobileMenuId}
aria-haspopup="true"
onClick={handleMobileMenuOpen}
color="inherit"
>
<MoreIcon />
</IconButton>
</div>
</Toolbar>
</AppBar>
{renderMobileMenu}
{renderMenu}
</div>
</Paper>
</Grid>
<GridList cols={3} style={gridListStyle} cellHeight={"auto"}>
{nums.map(n => {
return (
<GridListTile key={n}>
<ImgMediaCard key={n} num={n} />
</GridListTile>
);
})}
</GridList>
<Grid item xs={6} sm={3}>
<Paper className={Gridclasses.paper}> <DemoCarousel />
</Paper>
</Grid>
</Grid>
</div>
);
}
export default App;
and following function don't take me into the second component. I don't know why.
const onRegisterClick = () => {
debugger;
//if(userFound){
<Router>
<Route exact path="/Register" component={Register} />
return <Redirect to="/Register" />
</Router>
// }
};
As I'm a newbie with react. What should I do in my code?
I've grabbed the example code for a menus and cards from here: https://material-ui.com
Application built with
{
"react": "16.13.0",
"react-dom": "^16.13.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"redux": "^4.0.4"
"#material-ui/core": "^4.9.5"
}
The Signup button don't allow me to navigate to Register react component.
Output: Sign Up button should allow me to redirect.
I tried to follow guides and looked up example implementations but could not solve the issue.
Only the render and functions called directly from render function are supposed to return JSX because these are the functions that render UI.
When you consider something like onRegisterClick function, this function is called in response to a button being clicked. Here you should be adding the imperative code to redirect the user to /redirect page. But the Route for redirect should be setup before this function is ever called so React Router knows which component to render.
Your whole app (generally) requires a single Router component and your whole App is wrapped into it, in you case consider something like:
import { BrowserRouter as Router } from "react-router-dom";
ReactDOM.render(<Router>
<Route path="/Register" component={Register} />
<Route exact path="/" component={App />
</Router>, document.getElementById("root") />
After this, you can navigate with:
function App({ history }) {
const onRegisterClick = () => {
history.push('/register');
}
}
There is a lot of assumptions here and I do think you need to check out React Router docs and understand the routing a little better before you can get started.
Making a Drawer in React.Js with Material-UI.
When I switch to the mobile view, the Drawer content automatically shifts to the right side with a lot of margin.
It works fine the in desktop view.
I am not able to find the error in this code.
Could anyone guide me how can I solve this issue?
The code for the drawer:
import React from 'react';
[import PropTypes from 'prop-types';
import AppBar from '#material-ui/core/AppBar';
import CssBaseline from '#material-ui/core/CssBaseline';
import Divider from '#material-ui/core/Divider';
import Drawer from '#material-ui/core/Drawer';
import Hidden from '#material-ui/core/Hidden';
import IconButton from '#material-ui/core/IconButton';
import List from '#material-ui/core/List';
import Toolbar from '#material-ui/core/Toolbar';
import Typography from '#material-ui/core/Typography';
import { makeStyles, useTheme } from '#material-ui/core/styles';
import { ListItem } from '#material-ui/core';
import { Data } from './data';
const drawerWidth = 240;
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
},
drawer: {
\[theme.breakpoints.up('sm')\]: {
width: drawerWidth,
flexShrink: 0,
},
},
appBar: {
marginLeft: drawerWidth,
\[theme.breakpoints.up('sm')\]: {
width: `calc(100% - ${drawerWidth}px)`,
},
},
menuButton: {
marginRight: theme.spacing(2),
\[theme.breakpoints.up('sm')\]: {
display: 'none',
},
},
toolbar: theme.mixins.toolbar,
drawerPaper: {
width: drawerWidth,
},
content: {
flexGrow: 1,
padding: theme.spacing(3),
},
}));
function ResponsiveDrawer(props) {
const { container } = props;
const classes = useStyles();
const theme = useTheme();
const \[mobileOpen, setMobileOpen\] = React.useState(false);
var \[index, changeindex\] = React.useState(1);
function handleDrawerToggle() {
setMobileOpen(!mobileOpen);
}
const drawer = (
<div>
<div className={classes.toolbar} />
<Divider></Divider>
<List>
<ListItem button primary full large onClick = {()=>changeindex(index = 1)} > <Typography variant="h6" noWrap>
Test 1
</Typography></ListItem>
<ListItem button primary full large onClick={() => changeindex(index = 2)} >
<Typography variant="h6" noWrap>
Test2
</Typography>
</ListItem>
<ListItem button primary full large onClick={() => changeindex(index = 3)} >
<Typography variant="h6" noWrap>
Test3
</Typography>
</ListItem>
</List>
</div>
);
console.log(props);
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
edge="start"
onClick={handleDrawerToggle}
className={classes.menuButton}
>
<i class="material-icons">view_headline</i>
</IconButton>
<Typography variant="h6" noWrap>
Responsive drawer
</Typography>
</Toolbar>
</AppBar>
<nav className={classes.drawer} aria-label="mailbox folders">
{/* The implementation can be swapped with js to avoid SEO duplication of links. */}
<Hidden smUp implementation="css">
<Drawer
container={container}
variant="temporary"
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
open={mobileOpen}
onClose={handleDrawerToggle}
classes={{
paper: classes.drawerPaper,
}}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
>
{drawer}
</Drawer>
</Hidden>
<Hidden xsDown implementation="css">
<Drawer
classes={{
paper: classes.drawerPaper,
}}
variant="permanent"
open
>
{drawer}
</Drawer>
</Hidden>
</nav>
<main className={classes.content}>
<div className={classes.toolbar} />
{/* {console.log(index)} */}
<Data index={index} ></Data>
</main>
</div>
);
}
ResponsiveDrawer.propTypes = {
/**
* Injected by the documentation to work in an iframe.
* You won't need it on your project.
*/
container: PropTypes.instanceOf(typeof Element === 'undefined' ? Object : Element),
};
export default ResponsiveDrawer;][1]
Example image