I use Material-Ui Appbar and want to simply center my logo and title in the middle (See the picture).
But I tried different methods, still nothing works. Following is my code, do you know what's wrong with my code?
You can also try the code in codesandbox:
https://codesandbox.io/s/material-ui-appbar-logo-7q80d?file=/src/MyAppBar.tsx:797-1455
Here is my clasess:
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
flexGrow: 1
},
menuButton: {
marginRight: theme.spacing(2)
},
title: {
flexGrow: 1,
textAlign: "center"
},
logo: {
maxWidth: 40,
marginRight: '10px'
}
})
);
Here is my component code:
export function ButtonAppBar() {
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
>
<MenuIcon />
</IconButton>
<img src={logo} alt="Kitty Katty!" className={classes.logo} />
<Typography variant="h6" className={classes.title}>
Kitty Katty!
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</div>
);
}
Thanks very much for the help!
Try this:
<Typography variant="h6" className={classes.title}>
<img src={logo} alt="Kitty Katty!" className={classes.logo} />
Kitty Katty!
</Typography>
import React from "react";
import { createStyles, makeStyles, Theme } 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 Button from "#material-ui/core/Button";
import IconButton from "#material-ui/core/IconButton";
import MenuIcon from "#material-ui/icons/Menu";
import logo from "./images/logo.png";
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
flexGrow: 1
},
menuButton: {
marginRight: theme.spacing(2)
},
toolbar:{
justifyContent:'space-between'
},
container:{
display:'flex',
alignItems:'center',
},
title: {
flexGrow: 1,
textAlign: "center"
},
logo: {
maxWidth: 40,
marginRight: '10px'
}
})
);
export function ButtonAppBar() {
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar classes={{root:classes.toolbar}}>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
>
<MenuIcon />
</IconButton>
<div className={classes.container}>
<img src={logo} alt="Kitty Katty!" className={classes.logo} />
<Typography variant="h6" className={classes.title}>
Kitty Katty!
</Typography>
</div>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</div>
);
}
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
>
<MenuIcon />
</IconButton>
<Typography variant="h6" className={classes.title} id="appBar">
<img src={logo} alt="Kitty Katty!" className={classes.logo} />
Kitty Katty!
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</div>
Then in your style.css add this
#appBar {
display: flex;
justify-content: center;
align-items: center;
}
Related
I have a navbar component that looks like
<AppBar position="static" color="inherit">
<Toolbar className={classes.toolbar}>
<IconButton edge="start" color="inherit" aria-label="menu" onClick={toggleDrawer(true)}>
<MenuIcon />
</IconButton>
<Link href="#" color="primary" underline="none" variant="h5" className={classes.brand}>
{brand}
</Link>
<Button variant="contained" color="secondary" className={classes.primaryAction}>{content['primary-action']}</Button>
</Toolbar>
However the <Button variant="contained> is placed before the Link, how can I place the button all the way to the end of the x axis?
This is the styles
const useStyles = makeStyles((theme: Theme) => ({
toolbar: {
minHeight: 200
},
brand: {
lineHeight: 1,
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)'
},
primaryAction: {
justifySelf: 'end'
},
iconWrapper: {
minWidth: 40,
},
}));
Try to apply flexGrow: 1 on the link and align it right:
<AppBar position="static" color="inherit">
<Toolbar className={classes.toolbar}>
<IconButton edge="start" color="inherit" aria-label="menu" onClick={toggleDrawer(true)}>
<MenuIcon />
</IconButton>
<Link href="#" color="primary" underline="none" variant="h5" sx={{ flexGrow: 1, textAlign: 'right' }}>
{brand}
</Link>
<Button variant="contained" color="secondary" className={classes.primaryAction}>{content['primary-action']}</Button>
</Toolbar>
Try using CSS flex to place the buttons and link inside the toolbar.
Here's a working CodeSandbox. (Note that if you want the Link to come after the Button, just move the component below the Button in the code as per the comment I left).
Here's the JSX:
<AppBar position="static" color="inherit">
<Toolbar className={classes.toolbar}>
<IconButton
edge="start"
color="inherit"
aria-label="menu"
onClick={toggleDrawer(true)}
>
<MenuIcon />
</IconButton>
<div className={classes.verticalCenter}>
{/* Just move this link to come after the Button below to change the order */}
<Link
href="#"
color="primary"
underline="none"
variant="h5"
className={classes.brand}
>
{brand}
</Link>
<Button
variant="contained"
color="secondary"
className={classes.primaryAction}
>
{content["primary-action"]}
</Button>
</div>
</Toolbar>
</AppBar>
And the CSS:
const useStyles = makeStyles((theme) => ({
toolbar: {
minHeight: 200,
display: "flex",
justifyContent: "space-between"
},
brand: {
lineHeight: 1,
padding: 16
},
primaryAction: {
justifySelf: "flex-end"
},
iconWrapper: {
minWidth: 40
},
verticalCenter: {
display: "flex",
alignItems: "center"
}
}));
During my running project, I was using Material UI. I was designing a dashboard for my site.
Then I noticed that my scroll bar was being blocked while every time I opened the menu list.
Just like the following image:
I copied this code from MaterialUI official webiste. I still its blocking the scroll bar. Where is the code:
import * as React from 'react';
import AppBar from '#mui/material/AppBar';
import Box from '#mui/material/Box';
import Toolbar from '#mui/material/Toolbar';
import IconButton from '#mui/material/IconButton';
import Typography from '#mui/material/Typography';
import Menu from '#mui/material/Menu';
import MenuIcon from '#mui/icons-material/Menu';
import Container from '#mui/material/Container';
import Avatar from '#mui/material/Avatar';
import Button from '#mui/material/Button';
import Tooltip from '#mui/material/Tooltip';
import MenuItem from '#mui/material/MenuItem';
const pages = ['Products', 'Pricing', 'Blog'];
const settings = ['Profile', 'Account', 'Dashboard', 'Logout'];
const ResponsiveAppBar = () => {
const [anchorElNav, setAnchorElNav] = React.useState<null | HTMLElement>(null);
const [anchorElUser, setAnchorElUser] = React.useState<null | HTMLElement>(null);
const handleOpenNavMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorElNav(event.currentTarget);
};
const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorElUser(event.currentTarget);
};
const handleCloseNavMenu = () => {
setAnchorElNav(null);
};
const handleCloseUserMenu = () => {
setAnchorElUser(null);
};
return (
<AppBar position="static">
<Container maxWidth="xl">
<Toolbar disableGutters>
<Typography
variant="h6"
noWrap
component="div"
sx={{ mr: 2, display: { xs: 'none', md: 'flex' } }}
>
LOGO
</Typography>
<Box sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}>
<IconButton
size="large"
aria-label="account of current user"
aria-controls="menu-appbar"
aria-haspopup="true"
onClick={handleOpenNavMenu}
color="inherit"
>
<MenuIcon />
</IconButton>
<Menu
id="menu-appbar"
anchorEl={anchorElNav}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'left',
}}
open={Boolean(anchorElNav)}
onClose={handleCloseNavMenu}
sx={{
display: { xs: 'block', md: 'none' },
}}
>
{pages.map((page) => (
<MenuItem key={page} onClick={handleCloseNavMenu}>
<Typography textAlign="center">{page}</Typography>
</MenuItem>
))}
</Menu>
</Box>
<Typography
variant="h6"
noWrap
component="div"
sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}
>
LOGO
</Typography>
<Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}>
{pages.map((page) => (
<Button
key={page}
onClick={handleCloseNavMenu}
sx={{ my: 2, color: 'white', display: 'block' }}
>
{page}
</Button>
))}
</Box>
<Box sx={{ flexGrow: 0 }}>
<Tooltip title="Open settings">
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
<Avatar alt="Remy Sharp" src="/static/images/avatar/2.jpg" />
</IconButton>
</Tooltip>
<Menu
sx={{ mt: '45px' }}
id="menu-appbar"
anchorEl={anchorElUser}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}
open={Boolean(anchorElUser)}
onClose={handleCloseUserMenu}
>
{settings.map((setting) => (
<MenuItem key={setting} onClick={handleCloseNavMenu}>
<Typography textAlign="center">{setting}</Typography>
</MenuItem>
))}
</Menu>
</Box>
</Toolbar>
</Container>
</AppBar>
);
};
export default ResponsiveAppBar;
What I have to do to fix this bug?
The issue is from the Menu component, when it is open it styles the body element overflow to hidden.
To stop that, Set the disableScrollLock prop to true.
<Menu
...others
disableScrollLock={true}
>
</Menu>
I'm not sure if this is a problem with your AppBar as much as your other code, which we cannot see.
But I'm guessing you have something like this:
export default function App(){
return (
<div className="root">
<ResponsiveAppBar />
<div className="image-background-1">
<h1>Some text</h1>
</div>
<div className="image-background-2">
<h1>Some text</h1>
</div>
<div className="image-background-3">
<h1>Some text</h1>
</div>
</div>
)
}
In this scenario, the whole "root" div is scrolling, but in your design we really just want to scroll through the divs with the image background.
To fix this, wrap those divs in a div that has overflow-y: scroll:
export default function App(){
return (
<div className="root">
<ResponsiveAppBar />
<div style={{overflowY: "scroll"}}>
<div className="image-background-1">
<h1>Some text</h1>
</div>
<div className="image-background-2">
<h1>Some text</h1>
</div>
<div className="image-background-3">
<h1>Some text</h1>
</div>
</div>
</div>
)
}
You might need to set overflow: "hidden" on the root div as well.
I built out a footer using Material-UI#next AppBar and I would like to center align the icons within the Grid and on being responsive, each grid-item should be in a new line center-aligned. Please advice. In desktop mode, they all should be in a straight line.
This is my code:
import {
AppBar,
Grid,
Link,
Stack,
Toolbar,
Typography
} from "#material-ui/core";
import React from "react";
import { Facebook, LinkedIn, Twitter } from "#material-ui/icons";
import { styled } from "#material-ui/core/styles";
const StyledLink = styled(Link)`
color: #ffffff;
& .MuiSvgIcon-root:hover {
color: #ffffff;
}
`;
const Footer = () => {
return (
<footer>
<AppBar sx={{ top: "auto", bottom: 0, backgroundColor: "#304659" }}>
<Toolbar variant="dense">
<Grid container spacing={{ xs: 1, sm: 2, md: 4 }}>
<Grid item xs={12} sm={4} justifyContent="center">
<Typography sx={{ color: "white" }}>
{new Date().getFullYear()}© All rights reserved.
</Typography>
</Grid>
<Grid item sm={4} xs={12} textAlign="center">
<Stack direction={"row"} spacing={{ sm: 2 }}>
<StyledLink
href="https://www.twitter.com"
underline="always"
sx={{ color: "white" }}
>
<Twitter />
</StyledLink>
<StyledLink href="https://www.linkedin.com" underline="always">
<LinkedIn />
</StyledLink>
<StyledLink href="https://www.facebook.com" underline="always">
<Facebook />
</StyledLink>
</Stack>
</Grid>
<Grid item xs={12} sm={4} textAlign="right">
<Link
href="https://privacy-policy/"
underline="always"
sx={{ color: "white" }}
>
Privacy Policy
</Link>
</Grid>
</Grid>
</Toolbar>
</AppBar>
<Toolbar />
</footer>
);
};
export default Footer;
CodeSandboxLink: Link
import {
AppBar,
Grid,
Link,
Stack,
Toolbar,
Typography
} from "#material-ui/core";
import React from "react";
import { Facebook, LinkedIn, Twitter } from "#material-ui/icons";
import { styled } from "#material-ui/core/styles";
const StyledLink = styled(Link)`
color: #ffffff;
& .MuiSvgIcon-root:hover {
color: #ffffff;
}
`;
const Footer = () => {
return (
<footer>
<AppBar sx={{ top: "auto", bottom: 0, backgroundColor: "#304659" }}>
<Toolbar variant="dense">
<Grid container spacing={{ xs: 1, sm: 2, md: 4 }}>
<Grid
item
xs={12}
sm={4}
sx={{ textAlign: "center" }}
>
<Typography sx={{ color: "white" }}>
{new Date().getFullYear()}© All rights reserved.
</Typography>
</Grid>
<Grid item sm={4} xs={12} style={{ textAlign: "center" }}>
<StyledLink
href="https://www.twitter.com"
underline="always"
sx={{ color: "white" }}
>
<Twitter />
</StyledLink>
<StyledLink href="https://www.linkedin.com" underline="always">
<LinkedIn />
</StyledLink>
<StyledLink href="https://www.facebook.com" underline="always">
<Facebook />
</StyledLink>
</Grid>
<Grid item xs={12} sm={4} style={{ textAlign: "center" }}>
<Link
href="https://privacy-policy/"
underline="always"
sx={{ color: "white" }}
>
Privacy Policy
</Link>
</Grid>
</Grid>
</Toolbar>
</AppBar>
<Toolbar />
</footer>
);
};
export default Footer;
I just changed some css styles. Try this.
I'm trying to add a badge to the mobileMenu (3 dots) but I can't.
On the right is a mockup of what I'm trying to do, done in Photoshop.
const renderMobileMenu = (
<Menu
anchorEl={mobileMoreAnchorEl}
anchorOrigin={{ vertical: "top", horizontal: "right" }}
id={mobileMenuId}
keepMounted
transformOrigin={{ vertical: "top", horizontal: "right" }}
open={isMobileMenuOpen}
onClose={handleMobileMenuClose}
>
<MenuItem>
<IconButton aria-label="show 11 new notifications" color="inherit">
<Badge badgeContent={cartBadge} color="secondary">
<ShoppingCartIcon />
</Badge>
</IconButton>
<p>Cart</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>
);
Just use
import React from "react";
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";
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: {
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("md")]: {
width: "20ch"
}
},
sectionDesktop: {
display: "none",
[theme.breakpoints.up("md")]: {
display: "flex"
}
},
sectionMobile: {
display: "flex",
[theme.breakpoints.up("md")]: {
display: "none"
}
}
}));
export default function PrimarySearchAppBar() {
const classes = useStyles();
const [anchorEl, setAnchorEl] = React.useState(null);
const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = React.useState(null);
const [messageCount, setMessageCount] = React.useState(4);
const [nottificationCount, setNottificationCount] = React.useState(11);
const [totalNotificationsCount, setTotalNotificationsCount] = React.useState(11);
React.useEffect(() => {
setTotalNotificationsCount(messageCount + nottificationCount);
}, [messageCount, nottificationCount])
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 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>
<IconButton aria-label="show 4 new mails" color="inherit">
<Badge badgeContent={messageCount} color="secondary">
<MailIcon />
</Badge>
</IconButton>
<p>Messages</p>
</MenuItem>
<MenuItem>
<IconButton aria-label="show 11 new notifications" color="inherit">
<Badge badgeContent={nottificationCount} 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={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>
Material-UI
</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="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"
>
<Badge badgeContent={totalNotificationsCount} color="secondary">
<MoreIcon />
</Badge>
</IconButton>
</div>
</Toolbar>
</AppBar>
{renderMobileMenu}
{renderMenu}
</div>
);
}
i am using react js and when i importing header file from view folder then getting error Module not found in react when i importing a file. i want add header file in my index page. when i use same code on index page then its working fine but when i want use this as a component in different file and folder then its showing error.
import React from 'react';
import { fade, makeStyles, Theme, createStyles } 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';
import CreateDialog from './Components/UserLoginSignUp/Signup';
import CreateDialogLogin from './Components/UserLoginSignUp/Login';
import './style.scss';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
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: {
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('md')]: {
width: '20ch',
},
},
sectionDesktop: {
display: 'none',
[theme.breakpoints.up('md')]: {
display: 'flex',
},
},
sectionMobile: {
display: 'flex',
[theme.breakpoints.up('md')]: {
display: 'none',
},
},
}),
);
export default function App() {
const classes = useStyles();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = React.useState<null | HTMLElement>(null);
const isMenuOpen = Boolean(anchorEl);
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl);
const handleProfileMenuOpen = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleMobileMenuClose = () => {
setMobileMoreAnchorEl(null);
};
const handleMenuClose = () => {
setAnchorEl(null);
handleMobileMenuClose();
};
const handleMobileMenuOpen = (event: React.MouseEvent<HTMLElement>) => {
setMobileMoreAnchorEl(event.currentTarget);
};
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}><CreateDialog/></MenuItem>
<MenuItem onClick={handleMenuClose}><CreateDialogLogin/></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>
<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={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>
Material-UI
</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="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>
);
}
Login
import React, { Fragment } from "react";
import {
Button,
FormControl,
TextField,
Grid,
List,
ListItem,
ListItemText,
Container
} from "#material-ui/core";
import {
Dialog,
DialogActions,
DialogContent,
DialogTitle
} from "#material-ui/core";
import { Component } from "react";
import FacebookIcon from '#material-ui/icons/Facebook';
function App() {
return (
<Container>
<div className="App">
<CreateDialogLogin />
</div>
</Container>
);
}
export default App;
class CreateDialogLogin extends Component {
state = {
open: false
};
handler = () => {
this.setState({
open: !this.state.open
});
};
render() {
const { open } = this.state;
return (
<Fragment>
<Button onClick={this.handler}>Login</Button>
<Dialog aria-labelledby="form-dialog-title" open={open} onClose={this.handler} className="form_popup">
<DialogContent>
<Grid container>
<Grid item xs={12} sm={6} id="content_side_userLS">
<Grid>
{" "}
<h1>Login</h1>
<p>Simplified Stock <br/>Investments Like <br/>Never Before</p>
<List >
<ListItem>
<ListItemText primary="Invest across multiple asset classes." />
</ListItem>
<ListItem>
<ListItemText primary="Manage your own personalized portfolio." />
</ListItem>
<ListItem>
<ListItemText primary="Build wealth with experts’stock recommendations." />
</ListItem>
</List>
</Grid>
</Grid>
<Grid item xs={12} sm={6} className="formSection formClass">
<Grid>
<form noValidate autoComplete="off">
<FormControl className="input_field" fullWidth>
<TextField id="standard-basic" type="tel" label="Enter Email/Mobile Number" />
</FormControl>
<FormControl className="input_field btnInput" fullWidth>
{" "}
<Button variant="contained" className="FormBtn" color="primary" disableElevation>
{" "}
Next{" "}
</Button>
</FormControl>
</form>
<div className="socialLogin">
<div className="fPass"><p>Forgot Password?</p></div>
<span className="devider"></span>
<p className="dviderV">New to invest19? Sign Up | Or Login using </p>
<img src="/images/icons/facebook.svg"/>Facebook
<img src="/images/icons/gmail.svg"/>Google
</div>
</Grid>
</Grid>
</Grid>
</DialogContent>
</Dialog>
</Fragment>
);
}
}