Change the size of the icon - css

I have this project and I want to make a sidebar and inside the sidebar there are icons and a word that expresses this icon, the problem is that when I wanted to change the size of the icon in the “useStyles()” it didn’t change its size and I didn’t know why.
How can I solve this problem?
const useStyles = makeStyles((theme) => ({
item: {
display: "flex",
alignItems: "center",
marginBottom: theme.spacing(4),
[theme.breakpoints.up("sm")]: {
marginBottom: theme.spacing(3),
cursor: "pointer",
},
},
icon: {
marginRight: theme.spacing(1),
[theme.breakpoints.up("sm")]:{
fontSize: "18px"
}
},
text: {
fontWeight: 500,
[theme.breakpoints.down("sm")]: {
display: "none",
},
},
container: {
height: "100vh",
paddingTop: theme.spacing(2),
color: "white",
backgroundColor: theme.palette.primary.main,
[theme.breakpoints.up("sm")]:{
backgroundColor: 'white',
color: '#555',
border: '1px solid #ece7e7'
}
},
}));
const LeftBar = () => {
const classes = useStyles();
return (
<Container className={classes.container}>
<div className={classes.item}>
<Home className={classes.icon} />
<Typography className={classes.text}>HomePage</Typography>
</div>
<div className={classes.item}>
<Home className={classes.icon} />
<Typography className={classes.text}>HomePage</Typography>
</div>
<div className={classes.item}>
<Home className={classes.icon} />
<Typography className={classes.text}>HomePage</Typography>
</div>
<div className={classes.item}>
<Home className={classes.icon} />
<Typography className={classes.text}>HomePage</Typography>
</div>
</Container>
);
};
export default LeftBar;

If you want a quick fix, give your icon the sx prop and put your desired font size there.
<Home sx={{fontSize:"18px"}}/>
Otherwise make sure that your import statements are correct.
... from "#mui/material/styles"
Usually I use the mui styled for breakpoints, so something like
const IconWrapper = styled("div")(({ theme }) => ({
marginRight: theme.spacing(1),
[theme.breakpoints.up("sm")]: {
fontSize: 18,
},
}));
Then implement it like
<IconWrapper>
<Home />
</IconWrapper>

Related

Material Ui TextField how to change color of border

I haven't been able to find a way to change the color of the TextField border to something other than the grey color it starts off with. I want to change it to black.
Here is my UpdatePage.js file (simplified) :
const useStyles = makeStyles(() => ({
updatePage: {
display: 'flex',
justifyContent: 'center',
marginTop: '100px'
},
updateMovementDiv: {
background: '#00BFFF',
fontFamily: 'PT Sans Caption',
fontSize: '18px',
borderRadius: '10px',
padding: '20px',
marginTop: '50px',
},
textDiv: {
background: '#ffffff',
padding: '8px',
borderRadius: '10px',
},
}));
const UpdatePage = () => {
const classes = useStyles();
return (
<div>
<Header title="Update Movement" />
<div className={classes.updatePage}>
<div className={classes.updateMovementDiv}>
<form onSubmit={handleSubmit} >
<div className={classes.textDiv}>
<TextField
name="movementName"
variant="outlined"
label="Movement Name"
style={{ width:200 }}
value={move.movementName}
onChange={(e) => setMoveData({ ...moveData, movementName: e.target.value })}
/>
<TextField
name="movementWeight"
variant="outlined"
label="New One Rep Max"
style={{ width:200 }}
InputProps={{endAdornment: <InputAdornment position="end">lb</InputAdornment>}}
onChange={(e) => setMoveData({ ...moveData, movementWeight: e.target.value })}
/>
</div>
<div className={classes.buttonDiv}>
<Button className={classes.updateButton} variant="contained" type="submit" fullWidth endIcon={<LoopIcon />} >Update</Button>
</div>
</form>
</div>
</div>
</div>
);
};
export default UpdatePage;
I have tried adding a classname to my TextField tags and changing the color from there.
I have also tried adding the input property to the class like so:
textField: {
input: {
color: 'white'
}
and then adding:
InputProps={{
className: classes.input,
}}
None of these have worked, the TextField border stays grey. Any help would be appreciated.
I guess you are writing just 'color' property and the property for border color is 'borderColor', change it to borderColor from color and then check it.

How can I scroll on my Page when my Dialog Component has been opened

I want to scroll on the background, when my dialog component opens up. By default, you cannot scroll when the dialog appears. How can I scroll in the background ?
Following is the Code:-
import React, { useState } from 'react';
import {
makeStyles,
Grid,
Button,
Dialog,
DialogActions,
DialogTitle,
} from '#material-ui/core';
import ShoppingCartIcon from '#material-ui/icons/ShoppingCart';
import CloseIcon from '#material-ui/icons/Close';
const styles = makeStyles((theme) => ({
root: {
position: 'fixed',
bottom: '0 ',
left: '0',
right: '0',
boxShadow: '0 0 6px rgb(0 0 0 / 70%)',
backgroundColor: 'white',
height: '63px',
},
textStyle: {
fontFamily: 'Comfortaa',
},
icon: {
color: theme.palette.primary.dark,
},
btn: {
backgroundColor: theme.palette.primary.dark,
color: 'white',
fontFamily: 'Comfortaa',
'&:hover': {
backgroundColor: theme.palette.primary.dark,
},
},
title: {
display: 'flex',
justifyContent: 'flex-end',
borderBottom: '1px solid #e5e5e5',
},
closeIcon: {
color: theme.palette.primary.light,
'&:hover': {
color: 'black',
},
},
dialogStyle: {
backgroundColor: 'white',
position: 'absolute',
top: 0,
},
dialogContainer: {
opacity: 0,
},
dialogTitle: {
display: 'flex',
justifyContent: 'flex-end',
borderBottom: '1px solid #e5e5e5',
},
}));
const CartAppBar: React.FC = () => {
const classes = styles();
const [open, setOpen] = useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<>
<Grid
item
container
direction='row'
justify='space-around'
alignItems='center'
className={classes.root}
xs={12}
>
<div>
<ShoppingCartIcon
fontSize='large'
classes={{ root: classes.icon }}
onClick={handleClickOpen}
/>
</div>
<div>
<Button
className={classes.btn}
type='submit'
onClick={() => {
return (window.location.href = '/checkout');
}}
>
Checkout
</Button>
</div>
</Grid>
<Dialog
open={open}
onClose={handleClose}
aria-labelledby='alert-dialog-title'
aria-describedby='alert-dialog-description'
maxWidth='md'
fullWidth
classes={{
paper: classes.dialogStyle,
container: classes.dialogContainer,
}}
scroll='paper'
>
<DialogTitle className={classes.dialogTitle}>
<CloseIcon
onClick={handleClose}
classes={{ root: classes.closeIcon }}
/>
</DialogTitle>
{/* Footer */}
{/* <DialogActions className={classes.footer}>
<Button classes={{ root: classes.btn }}>Add To Cart</Button>
</DialogActions> */}
</Dialog>
</>
);
};
export default CartAppBar;
As you can see in the photo, there's opacity in the background and you cannot scroll. I want to override this and make the background scrollable
use disableScrollLock as prop will help

Elements overflowing through component in React

In a React project, I've create a Recharge Wallet page, which has Recharge button to recharge coins. A new page is created by overriding on another page. All the elements are created in Material UI. For some reason, all elements are overflowing through the components. Its probably CSS issue. What could be the best solution to prevent overflowing.
Following is the code reference
const navScrollStyle = makeStyles((theme) => ({
root: {
marginTop: '70px',
display: 'table',
overflowY: 'hidden',
maxWidth: 'auto',
display: 'flex',
justifyContent: 'center',
}
}));
const navBodyStyle = makeStyles((theme) => ({
root: {
flexGrow: 1,
top: "0px",
position: "absolute",
width: "100%",
height: '100vh',
textAlign: 'center',
background: 'white',
zIndex: '9',
height: '100%',
overflowY: 'auto'
},
menuButton: {
marginRight: theme.spacing(2),
color: "purple"
},
title: {
flexGrow: 1,
textAlign: "center",
color: "black"
}
}));
const gridClassStyle = makeStyles((theme) => ({
root: {
flexGrow: 1,
position: 'fixed',
top: '0px',
background: 'white',
flexWrap: "nowrap",
boxShadow: '5px 10px 18px #888888',
},
paper: {
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
},
menuButton: {
marginRight: theme.spacing(2),
color: "purple"
},
title: {
flexGrow: 1,
textAlign: "center",
color: "black"
}
}));
const useStyles5 = makeStyles((theme) => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
textAlign: 'center',
width: '100%'
},
}));
const NewPage = () => {
const navBody = navBodyStyle()
const navScroll = navScrollStyle()
const gridClass = gridClassStyle()
const classes5 = useStyles5()
const NavPart = () => (
<Grid className={gridClass.root} container spacing={3}>
<Grid item xs={4} style={{ textAlign: 'left' }}>
<IconButton
edge="start"
className={gridClass.menuButton}
color="inherit"
aria-label="menu"
>
<Link to="/">
<ArrowBackIcon />
</Link>
</IconButton>
</Grid>
<Grid item xs={4} style={{ textAlign: 'center', justifyContent: 'center' }}>
<Typography variant="h6" className={gridClass.title}>
<h2>Wallet</h2>
</Typography>
</Grid>
<Grid item xs={4} style={{ textAlign: 'right', marginTop: '2%' }}>
<IconButton
aria-label="account of current user"
aria-controls="menu-appbar"
aria-haspopup="true"
>
<AccountCircle style={{ fontSize: "30px" }} />
</IconButton>
</Grid>
</Grid>
)
return (
<div className={navBody.root}>
{NavPart()}
<div className={navScroll.root}>
<div className={classes5.root}>
<Button variant="contained" color="secondary">
<Link to="/purchaseCoins">
Recharge Wallet
</Link>
</Button>
<br />
<Button variant="contained" color="secondary">
<Link to="/purchaseCoins">
Recharge Wallet
</Link>
</Button>
<br />
</div>
</div>
</div>
)
}
I have purposefully added recharge wallet button to test the overflowing.
Here is the codesandbox link for much clarity: https://codesandbox.io/s/react-material-forked-71op5.
Please click on 'WALLET' button when page loads
I changed the marginTop of navScrollStyle, overflowY to auto, and assigned a zIndex to the gridClassStyle. I think it's what you were looking for. Please check the online version here on sandbox
You gave 70px to the Wallet component, and I think you can give the height value of calc (100% - 70px). You must adjust the height as much as the margin-top px.

Material UI Popper Styling

What I'm trying to achieve
What I currently have
I'm trying to achieve the following using flex. What's the best approach to handle this?
I'm finding it difficult to separate the gap between the two text fields (text && secondaryText)
popper: createStyles({
root: {
backgroundColor: white,
borderRadius: 4,
boxShadow: "0 2px 12px 0 rgba(0, 0, 0, 0.5)",
zIndex: 1301,
maxHeight: 200,
overflowY: "auto",
display: "flex",
flexDirection: "column",
},
}),
};
<Popper
className={toClassName(classes.popper)}
>
{children} // Component AutocompleteSelection
</Popper>
const AutocompleteSelection: FC<AutocompleteSelectionProps> = ({
text,
secondaryText,
}): JSX.Element => {
const classes = useMakeStyles(baseStyles) as Properties;
return (
<ListItem styles={listItem}>
<Typography classes={classes.typography}>
{text}
{secondaryText}
</Typography>
</ListItem>
);
};
const baseStyles: Properties = {
listItem: createStyles({
root: {
"&:hover": {
backgroundColor: greyTwo,
},
},
}),
typography: createStyles({
root: {
fontSize: 14,
lineHeight: 1,
},
}),
};
Ciao, to display secondaryText floated right in a flex display, to could use marginLeft: "auto" in secondayText class like:
<Typography class={classes.typography}>
<Typography class={classes.text}>{"hello"}</Typography>
<Typography class={classes.secondaryText}>{"there"}</Typography>
</Typography>
And style:
const useStyles = makeStyles((theme) => ({
typography: {
display: "flex"
},
text: {},
secondaryText: {
marginLeft: "auto" // secondary text floated to right
}
}));
Here a codesandbox example.

div alignment is not properly working on the header with menu [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
I try to align my menu properly but it's not working properly. So the way it's done is that when you arrive on my website and not logged in, the header below is displayed:
When the user is loggedin, the login/register is replaced by a scrolldown menu which is triggered by the click of an avatar. The scroll down works fine but the render of the menu is not aligned as you see below:
I am not able to make the avatar and the menu properly aligned as it's done at first.
below is code:
const fakeName = "First Last";
const isGuest = false;
const StyledProfileMenu = withStyles({
paper: {
border: '1px none',
borderRadius: "21px",
boxShadow: "0px 8px 18px 0 rgba(0,0,0,0.14)",
},
})((props) => (
<Menu
elevation={0}
getContentAnchorEl={null}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'center',
}}
{...props}
/>
));
const StyledProfileMenuItem = withStyles((theme) => ({
root: {
margin: "2px 30px 1px 10px",
fontFamily: "Source Sans Pro",
fontSize: "",
'&:hover': {
backgroundColor: "#ffffff",
color: '#ff7255'},
'&:focus': {
backgroundColor: "#ffffff",
color: '#ff7255'},
},
}))(MenuItem);
const useStyles = makeStyles(theme => ({
root: {
boxShadow: "none",
backgroundColor: "#ffffff",
marginTop: theme.spacing(3)
},
logo: {
width:"214px",
height:"28px",
marginLeft: theme.spacing(20),
marginRight: theme.spacing(3)
},
search: {
position: 'relative',
borderRadius: "21px",
backgroundColor: "#f4f7f8",
marginRight: theme.spacing(2),
marginLeft: theme.spacing(3),
width: "467px",
height: "40px",
// [theme.breakpoints.up('sm')]: {
// marginLeft: theme.spacing(3),
// width: 'auto',
// },
},
searchIcon: {
padding: theme.spacing(1, 2),
height: '18px',
width: '18px',
position: 'absolute',
pointerEvents: 'none',
alignItems: 'center',
justifyContent: 'center',
color: "#cecece"
},
inputRoot: {
color: "#cecece",
fontFamily: "Source Sans Pro",
fontSize: "18px"
},
inputInput: {
paddingLeft: `calc(1em + ${theme.spacing(4)}px)`,
width: "467px",
// [theme.breakpoints.up('md')]: {
// width: '20ch',
// },
},
menu: {
display: "flex",
marginLeft: theme.spacing(2),
margin: "auto",
},
menuItem: {
color: "#cecece",
fontSize: "20px",
fontFamily: "Fredoka One",
fontWeight: "bold",
'&:hover': {
backgroundColor: "#ffffff",
color: '#ff7255'},
'&:focus': {
backgroundColor: "#ffffff",
color: '#ff7255'},
marginRight: theme.spacing(3),
marginLeft: theme.spacing(3),
},
userName: {
fontFamily: "Source Sans Pro",
fontWeight: "Bold",
borderBottom: '3px solid #ff7255',
textAlign: "center",
margin: "2px 10px 2px 10px",
paddingBottom: "2px"
}
}));
function Header(){
let loginOrProfile;
const styles = useStyles();
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const profileMenu =
<div>
<IconButton
aria-controls="customized-menu"
aria-haspopup="true"
variant="contained"
color="primary"
onClick={handleClick}>
<Avatar alt="Avatar" src={DefaultAvatar} />
<ArrowDropDownIcon style={{ color: "#ff7255" }}/>
</IconButton>
<StyledProfileMenu
id="customized-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}>
<p className={styles.userName}> {fakeName} </p>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuProfile} />
</StyledProfileMenuItem>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuMessages} />
</StyledProfileMenuItem>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuSettings} />
</StyledProfileMenuItem>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuLogout} />
</StyledProfileMenuItem>
</StyledProfileMenu>
</div>;
const loginMenu =
<Typography className={styles.menuItem}> {TextContents.MenuLoginRegister} </Typography>;
if(isGuest){
loginOrProfile = loginMenu;
} else {
loginOrProfile = profileMenu;
}
return (
<div className={styles.root}>
<AppBar position="static" className={styles.root}>
<Toolbar>
<img src={VillageLogo} alt="logo" className={styles.logo}/>
<div className={styles.search}>
<div className={styles.searchIcon}>
<SearchIcon />
</div>
<InputBase
placeholder={TextContents.SearchPlaceHolder}
classes={{
root: styles.inputRoot,
input: styles.inputInput,
}}
inputProps={{ 'aria-label': 'search' }}
/>
</div>
<div className={styles.menu}>
<Typography className={styles.menuItem}> {TextContents.MenuDiscover} </Typography>
<Typography className={styles.menuItem}> {TextContents.MenuCreate} </Typography>
<Typography className={styles.menuItem}> {TextContents.MenuHiW} </Typography>
{isGuest && loginMenu}
{!isGuest && profileMenu}
</div>
</Toolbar>
</AppBar>
</div>
);
}
export default Header
If someone may have any idea how to make the alignment proper, I would be super happy
try this:
display: flex;
align-items: center;

Resources