How to move Icons in Material UI - css

How can I move my components on the image by using material UI ? I want to move my heart component to the top right corner of my image and ratings on the bottom of my image.
import image from "../../Assets/pic.jpg";
import React, { useState } from "react";
import { makeStyles } from "#material-ui/core/styles";
import Card from "#material-ui/core/Card";
import CardActionArea from "#material-ui/core/CardActionArea";
import FavoriteBorderIcon from "#material-ui/icons/FavoriteBorder";
import CardContent from "#material-ui/core/CardContent";
import CardMedia from "#material-ui/core/CardMedia";
import Typography from "#material-ui/core/Typography";
import Grid from "#material-ui/core/Grid";
import styles from "./Cards.module.css";
import Stars from "../Stars/Stars";
const useStyles = makeStyles({
root: {
maxWidth: 345,
display: "flex",
},
text: {
textAlign: "center",
color: "#333333",
},
textCardBottom: {
display: "flex",
justifyContent: "center",
},
textPrice: { color: "#333333" },
textStrike: { margin: "0px 10px 0px 10px" },
textDiscount: { color: "#ff6a6a" },
stars: {
right: 9,
},
ratings: {},
});
const Cards = () => {
const [showComponent, setShowComponent] = useState(false);
const classes = useStyles();
const handleToggleHoverIn = (event) => {
event.preventDefault();
setShowComponent(true);
};
const handleToggleHoverOut = (event) => {
event.preventDefault();
setShowComponent(false);
};
console.log("The state showComponent value is ", showComponent);
return (
<Card
onMouseEnter={handleToggleHoverIn}
onMouseLeave={handleToggleHoverOut}
className={classes.root}
>
<CardActionArea>
<CardMedia
component="img"
alt=""
image={image}
title="Contemplative Reptile"
/>
{/* {showComponent ? ( */}
<Grid container>
<Stars right="40%" /> // want this rating component on the centre of my image
<FavoriteBorderIcon fontSize="large" /> // want this heart to the top right corner
</Grid>
{/* ) : null} */}
<CardContent>
<Typography
gutterBottom
variant="h5"
component="h2"
className={classes.text}
>
Printed round Neck
</Typography>
<Typography
variant="body2"
color="textSecondary"
component="div"
className={classes.textCardBottom}
>
<Typography
variant="body2"
color="textSecondary"
component="b"
className={classes.textPrice}
>
Rs. 454
</Typography>
<Typography
variant="body2"
color="textSecondary"
component="strike"
className={classes.textStrike}
>
Rs. 699
</Typography>
<Typography
variant="body2"
color="textSecondary"
component="span"
className={classes.textDiscount}
>
(35 % off)
</Typography>
{/* <p>
<b>Rs. 454</b>
<strike>Rs. 699</strike>
<span style={{ color: "#FF7F7F" }}> (35 % off) </span>
</p> */}
</Typography>
</CardContent>
</CardActionArea>
</Card>
);
};
export default Cards;
I tried to use the position property of material UI but I wasn't able to move the components. I tried the Material UI docs but couldn't find properties that could help me moving the components.

did you tried to add inline styles like this:
<FavoriteBorderIcon fontSize="large" style={{ position: "absolute", top: "5px", right: "5px" }}/>
<Stars right="40%" style={{ position: "absolute", bottom: "5px" }}/>
and perhaps you need also add some position to Grid as well
<Grid style={{ position: "relative" }}>

Related

custom accordion in Mui Nextjs and mui

there is quite a new component introduced in #mui/lab which is Masonary which deals with accordions on the sidebar but not the one I posted above. so far I have achieved
import React from 'react';
import IconButton from '#mui/material/IconButton';
import FavoriteIcon from '#mui/icons-material/Favorite';
import Devider from '#mui/material/Divider';
import ExpandMoreIcon from '#mui/icons-material/ExpandMore';
import { styled } from '#mui/material/styles';
import { css } from '#emotion/react';
import { Rating, Paper, Card, Box, CardHeader, CardContent, CardMedia, CardActions, Toolbar, Typography, Collapse } from '#mui/material';
const ExpandMore = styled((props) => {
const { expand, ...other } = props;
return <IconButton {...other} />;
})(({ theme, expand }) => ({
transform: !expand ? 'rotate(0deg)' : 'rotate(180deg)',
marginLeft: 'auto',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shortest,
}),
}));
const DropDownPaperSection = ({ Pages, error }) => {
const [expanded, setExpanded] = React.useState(false);
const handleExpandClick = () => {
setExpanded(!expanded);
};
if (error) {
return <div className={style.Container} >An error occured: {error.message}</div>;
}
return (
<>
<Toolbar sx={{ bgcolor : '#f4f4f8'}}>
{Pages.data.map(Pages => (
//<div classname={style.main}>
<Box key={`$Pages.id`} variant='outlined' spacing={2 } elevation={1} style={{ margin: "16px 0px", border: "1px solid black" }}
css={css`
color: #20b2aa;
:hover {
color: #2e8b57;
}
`}>
{/* {Pages.attributes.Title}
{Pages.attributes.createdAt}
*/}
<Box>
<Typography variant="body2" color="text.secondary" className="hover:bg-violet-300">
{Pages.attributes.Title}</Typography>
</Box>
<Box enableSpacing>
<ExpandMore
expand={expanded}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="show more"
>
<ExpandMoreIcon />
</ExpandMore>
</Box>
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Typography paragraph padding="10px">
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Description} </Box></Typography>
<Devider />
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Content} </Box>
</Collapse>
</Box>
))} </Toolbar>
</>
)
}
export default DropDownPaperSection
But I am stuck with detaching those two elements as seen in the picture.
if you need you may find the rest of the code in github is there any possible way to achieve the closest one? I am not very sure how can i proceed next to detach this accordion. Maybe I am missing very evil details to detach them.
EDIT :
if we somehow use the portal and update the component it comes out as a combined section of multiple rows of data But not the desired output that I want.
```..........
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Portal container={container.current} key={`$Pages.id`}>
<Typography paragraph padding="10px">
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Description} </Box></Typography>
<Devider />
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Content} </Box>
</Portal>
</Collapse>
<Box sx={{ p: 1, my: 1, border: '1px solid' }} key={`$Pages.id`} ref={container} />
</Box>
))} </Toolbar>
</React.Fragment> ```

React JSX background position not placing image to center right in Material UI Grid item

I've just created a one page website portfolio and it is pretty much complete, but having issues with setting the background position of the home screen to center right. Here is my site:
https://berkley-portfolio.netlify.app/
My repo: https://github.com/Bolmstead/Portfolio
I just want the image of me to appear when resizing the window to mobile. I believe background-position would fix this right? The background size is cover, and I believe I am doing it correctly, but seem to be missing something. Below is my home component:
import React, { useEffect } from "react";
import Grid from "#material-ui/core/Grid";
import Typography from "#material-ui/core/Typography";
import { makeStyles } from "#material-ui/core/styles";
import Container from "#material-ui/core/Container";
const useStyles = makeStyles((theme) => ({
homeContainer: {
backgroundImage: `url(/images/home2.jpg)`,
height: "103vh",
backgroundSize: "cover",
backgoundPosition: "center right"
},
overlay: {
zIndex: 1,
height: "100%",
width: "100%",
backgroundSize: "cover",
background: "rgba(0, 0, 0, 0.5)",
},
firstName: {
fontWeight: "bold",
color: "white"
},
lastName: {
fontWeight: "bold",
color: "#FFC220"
},
caption: {
fontWeight: "bold",
color: "white"
},
}));
export default function Home() {
const classes = useStyles();
const [fadedIn, setFadedIn] = React.useState(false);
useEffect(() => {
async function fadeInHomeScreen() {
setFadedIn((prev) => !prev);
}
fadeInHomeScreen();
}, []);
return (
<Grid item xs={12} className={classes.homeContainer}>
<a id="Home">
<Grid
container
alignItems="center"
justify="center"
direction="row"
className={classes.overlay}
>
<Grid item xs={12} align="center" justify="center">
<Container maxWidth="md" align="center" justify="center" className={classes.container}>
<Typography
m={12}
variant="h2"
component="h2"
className={classes.firstName}
display="inline"
>
Berkley{" "}
</Typography>
<Typography
m={12}
variant="h2"
component="h2"
className={classes.lastName}
display="inline"
>
Olmstead
</Typography>
<Typography
m={12}
variant="h6"
component="h6"
className={classes.caption}
>
I'm a Full-Stack Developer
</Typography>
</Container>
</Grid>
</Grid>
</a>
</Grid>
);
}
You have a typo, backgoundPosition should be backgroundPosition
homeContainer: {
backgroundImage: `url(/images/home2.jpg)`,
height: "103vh",
backgroundSize: "cover",
backgroundPosition: "center right"
},

MaterialUI/CSS create this box

I'm trying to make this component with MaterialUI:
original box
How can I make this? I'm trying with the card component, but seems like:
sh*tty box
This is my makeStyles:
const useStyles = makeStyles(() => ({
cardHeader: {
color: "white",
borderRadius: "0"
},
cardDescription: {
display: "flex",
justifyContent: "center",
alignItems: "baseline",
backgroundColor: "#315059",
color: "cyan"
},
}));
const classes = useStyles();
And this is my card component:
<Card style={{borderRadius: "0"}}>
<CardHeader
title="VELOCIDAD MEDIA"
titleTypographyProps={{ align: "center" }}
subheaderTypographyProps={{ align: "center" }}
className={classes.cardHeader}
style={{backgroundColor:"#f92f3b"}}
/>
<CardContent style={{backgroundColor:"#f92f3b"}}>
<div className={classes.cardDescription}>
<Typography component="h2" variant="h3" color="cyan" >
262
</Typography>
<Typography variant="h6" color="white">
KM/H
</Typography>
</div>
</CardContent>
</Card>
your given code for sh*tty box and screenshot is not matching. Maybe other styles of the project are interfering with it. However, I made some changes to look similar to the required screenshot.
Note:- Fonts and card dimensions depend on the use case.
import { Card, CardContent, CardHeader, makeStyles, Typography } from "#material-ui/core";
import React from "react";
import "./styles.css";
export default function App() {
const classes = useStyles();
return (
<div>
<Card style={{borderRadius: "0",width:'380px'}}>
<CardHeader
title="VELOCIDAD MEDIA"
titleTypographyProps={{ align: "center" }}
subheaderTypographyProps={{ align: "center" }}
className={classes.cardHeader}
style={{backgroundColor:"#f92f3b"}}
/>
<CardContent style={{backgroundColor:"#f92f3b",padding:'8px'}}>
<div className={classes.cardDescription}>
<Typography component="h2" variant="h3" color="cyan" >
262
</Typography>
<Typography variant="h6" style={{marginLeft:'15px', color:'#fff'}} color="white">
KM/H
</Typography>
</div>
</CardContent>
</Card>
</div>
);
}
const useStyles = makeStyles(() => ({
cardHeader: {
color: "white",
borderRadius: "0",
},
cardDescription: {
display: "flex",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#315059",
color: "cyan",
height:'150px'
},
}));

Making the card component responsive using material ui

I am trying to make my card responsive to mobile applications
const styles = {
edit: {
width: "40%",
marginLeft: 270,
background: "#76ff03"
},
add: {
width: "100%",
background: "#18ffff",
size: "large"
},
root: {
minHeight: 210,
minWidth: 100
}
};
<Container maxWidth="md">
{/*marginTop:15*/}
<Typography component="div" style={{ borderColor:'#00c853' }}>
{/*style={{ height: '30vh' }}*/}
<Card style={styles.root}>
<Typography variant="overline" color="secondary" style={{fontFamily:'Roboto',margin:10}}>
All about your needs
</Typography>
<form onSubmit={this.validateItem} autoComplete='off'>
<TextField id="outlined-full-width" label="Input" style={{ width:'90%',marginTop:30 ,marginLeft:40 }}
placeholder="Add A Todo Item " margin="normal" InputLabelProps={{
shrink: true,
}} error={this.state.errorState} helperText={ this.state.errorState
&& "Item name can't be blank" } size="large" variant="outlined" value={newItem} onChange={handleInput} />
<Grid container justify='center' alignContent='center'>
<Grid item xs={12} md={6}>
{buttonChange()}
</Grid>
</Grid>
</form>
</Card>
</Typography>
</Container>
</div>
The above code is the user interface for the card component , i am trying to make the card component mobile responsive , but the interface i get instead is given below
The card and the text field should be able to be responsive to the screen size, but i am unable to make it work. Is there a way i can make it happen?
Hello and thank you for asking your question,
you can use the breakpoint of [theme.breakpoints.down("(XS, sm,md, lg, xl,)")] : {
maxWidth: 200 // you can change the size of your card component.
}
Here is a clearer example from the material ui Card component
Here is the component from the material UI Card component page, I only added the useTheme and useMediaQuery imports, and added a medium breakpoint inside useStyle under classes.root Here is a useful link on "useMediaQuery" https://material-ui.com/components/use-media-query/#usemediaquery
import { useTheme } from "#material-ui/styles";
import useMediaQuery from "#material-ui/core/useMediaQuery";
const useStyles = makeStyles(theme => ({
root: {
maxWidth: 345,
[theme.breakpoints.down("md")] : {
maxWidth: 200
}
},
media: {
height: 140
}
}));
const Card = () => {
const classes = useStyles();
const theme = useTheme();
const matches = useMediaQuery(theme.breakpoints.up("sm"));
return (
<Card className={classes.root}>
<CardActionArea>
<CardMedia
className={classes.media}
title="Contemplative Reptile"
/>
<CardContent>
<Typography gutterBottom variant="h5" component="h2">
Lizard
</Typography>
<Typography variant="body2" color="textSecondary" component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000
species, ranging across all continents except Antarctica
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
<Button size="small" color="primary">
Learn More
</Button>
</CardActions>
</Card>
);
}
Hope this helps

Pass style to child component in material-ui-next

hi :) lets say i have two components one who has the text "orange" as a const and I want its child to have orange text.. using material-ui-next, i'm using withStyles and anything else just doesn't affect the color of the text... here is some code:
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Card, { CardActions, CardContent } from 'material-ui/Card';
import Button from 'material-ui/Button';
import Typography from 'material-ui/Typography';
const styles = {
card: {
minWidth: 275,
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
marginBottom: 16,
fontSize: 14,
},
pos: {
marginBottom: 12,
},
};
function SimpleCard(props) {
const { classes } = props;
const bull = <span className={classes.bullet}>•</span>;
return (
<div>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary">
Word of the Day
</Typography>
<Typography variant="headline" component="h2">
be{bull}nev{bull}o{bull}lent
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
<!-- I want the text from here to become orange-->
<Typography component="p">
well meaning and kindly.<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</div>
);
}
SimpleCard.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleCard);
orange will be at this.props.color
I don't mind it being the object orange from "material-ui/colors/orange" I just want to somehow address that value from within my SimpleCard component and use it when building the styles (or ignore styles all together and just use the color)

Resources