I would like a simple method, whereby you hover over them and they are a solid yellow.
const styles = theme => ({
root: {
flexGrow: 1,
overflow: 'hidden',
padding: theme.spacing(0, 3),
},
paper: {
maxWidth: 800,
margin: `${theme.spacing(2)}px auto`,
padding: theme.spacing(2),
},
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
width: 200,
},
playButton: {
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
position: "relative",
"& .playButton": {
position: "absolute",
top: "60%",
left: "-55px",
transform: "translateY(-50%)",
},
}
});
function Tasks(props) {
const { classes } = props;
return (
<div className={classes.root}>
<Paper className={classes.paper}>
<Grid container spacing={2}>
<Grid item xs={12} sm container>
<Grid item xs container direction="column" spacing={2}>
<Grid item xs>
<div className="name-label">
Name
</div>
<Typography variant="h6" gutterBottom>
{props.name}
</Typography>
<div className="form-divider"></div>
<Typography variant="body2" color="textSecondary">
{props.description}
</Typography>
</Grid>
</Grid>
<Grid item classes={{ root: props.classes.playButton}}>
<Grid item xs={3} className="playButton">
<i class="far fa-play-circle fa-2x"></i>
</Grid>
<div className="workers-assigned-label">
Workers Assigned
</div>
<Typography variant="h6" gutterBottom>
0/25
</Typography>
<div class="star-rating">
<label class="far fa-star fa-2x"></label>
<label class="far fa-star fa-2x"></label>
<label class="far fa-star fa-2x"></label>
</div>
<div>
unassigned
</div>
</Grid>
</Grid>
</Grid>
</Paper>
</div>
);
}
export default withStyles(styles)(Tasks);
If anyone has any suggestions as to how to get them to change from https://fontawesome.com/v4.7.0/icon/star-o to having the centre fill with yellow that would be much appreciated. Whether it be best done with CSS or something using React.
Taking a look at the content of that particular font, the 2 you'll use are content: "\f006" and content: "\f005". f005 is the filled star that you'll want to turn yellow.
const styles = theme => ({
playButton: {
"& .rating": {
"& .fa-star-o": {
"&:hover": {
"&::before": {
content: "\f005",
color: "yellow"
}
}
}
},
},
});
And like the other person said, make sure the package is working.
Did you check the version of Font Awesome you use? This icon seems to be in the 4.7.0. I've had multiple problems with icons not showing and usually it was because I was using an outdated version or the icon I wanted to use was in a newer version of Font Awesome.
And if you use a newer one, check if the icon still exists for this version, it may have been removed or renamed.
Related
I need to create an overlay that spans the whole image. But I am not sure how to do that.
I tried with relative and absolute positions on CSS. Any way, with CSS or without CSS will do.
Code is available in this playCode.
import React from 'react';
import { Container } from '#mui/material';
import Grid from '#mui/material/Unstable_Grid2';
export function App(props) {
return (
<div className='App'>
<Grid container>
<Grid>
<h1>Do not hide me.</h1>
</Grid>
<Grid>
<Container
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'blue',
}}
>
<img
style={{
maxHeight: 300,
}}
src={
'https://images.unsplash.com/photo-1518133910546-b6c2fb7d79e3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=735&q=80'
}
alt='img'
></img>
<h1
style={{
position: 'absolute',
left: 0,
top: 0,
opacity: 0.7,
backgroundColor: 'red',
width: 400,
}}
>
Hi there, this text should be only over the image.
</h1>
</Container>
</Grid>
</Grid>
</div>
);
}
// Log to console
console.log('Hello console');
I have played with the code in the provide platform and you can copy the following code and paste it in the playground.
import React from 'react';
import { Container } from '#mui/material';
import Grid from '#mui/material/Unstable_Grid2';
export function App(props) {
return (
<div className='App'>
<Grid container>
<Grid>
<h1>Do not hide me.</h1>
{/*<another image/>*/}
</Grid>
<Grid>
<Container
style={{
display:"flex",
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'blue',
position: "relative"
}}
>
<img
style={{
maxHeight: 300,
}}
src={
'https://images.unsplash.com/photo-1518133910546-b6c2fb7d79e3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=735&q=80'
}
alt='img'
></img>
<h1
style={{
position: 'absolute',
top: "-21px",
padding: "0 20px",
opacity: 0.7,
height: "100%",
backgroundColor: 'red',
}}
>
Hi there, this text should be only over the image.
</h1>
</Container>
</Grid>
</Grid>
</div>
);
}
// Log to console
console.log('Hello console');
Changes
I have changed style of Container
gave it a position of relative so that the h1 tag's position becomes absolute relative to container and not relative to whole page.
rest of the changes are in visible in h1 tag
I am creating a Grid layout that has nested Grid components in it. However, for some reason I do not understand, using an inline style in the Grid item component does not work. Please help, I am quite new in using MaterialUI in ReactJS. The Grid is encapsulated inside a Hide component that only shows in mobile devices.
What I am trying to achieve is that the Grid item change color on
hover
Here is what I did:
<Hidden mdUp='hide'>
<Grid
container
xs={12}
style={{
fontFamily: 'Old Newspaper',
background: '#f49275',
'&:hover': { background: 'black' },
marginLeft: '4px',
marginRight: '4px',
}}
>
<Grid
item
xs={4}
style={{
justifyContent: 'center',
display: 'flex',
}}
>
<a href='#'>
♦ Github ♦
</a>
</Grid>
<Grid
item
xs={4}
style={{ justifyContent: 'center', display: 'flex' }}
>
<a
href='#'
target='_blank'
>
♦ LinkedIn ♦
</a>
</Grid>
<Grid
item
xs={4}
style={{ justifyContent: 'center', display: 'flex' }}
>
<a
href='#'
target='_blank'
>
♦ Codewars ♦
</a>
</Grid>
</Grid>
</Hidden>
To get hover style on grid items you've to add hover style on grid items. And you can't add hover styles on an element in inline CSS way. Give a className to grid items and then add hover styles on those.
import React from "react";
import { makeStyles } from "#material-ui/core/styles";
import Grid from "#material-ui/core/Grid";
import { Hidden } from "#material-ui/core";
const useStyles = makeStyles((theme) => ({
item:{
color:'#fff',
justifyContent: "center",
display: "flex",
'&:hover':{
'&>a':{
color:'green'
}
}
}
}));
export default function SpacingGrid() {
const classes = useStyles();
return (
<Hidden mdUp="hide">
<Grid
container
className={classes.container}
xs={12}
style={{
fontFamily: "Old Newspaper",
background: "#f49275",
marginLeft: "4px",
marginRight: "4px"
}}
>
<Grid
item
xs={4}
className={classes.item}
>
♦ Github ♦
</Grid>
<Grid item xs={4} className={classes.item}>
<a href="#" target="_blank">
♦ LinkedIn ♦
</a>
</Grid>
<Grid item xs={4} className={classes.item}>
<a href="#" target="_blank">
♦ Codewars ♦
</a>
</Grid>
</Grid>
</Hidden>
);
}
codesandbox link:- https://codesandbox.io/s/o8b52
And can you please elaborate more your doubt about using inline style in grid item.
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
I am trying to add Unassigned Text to the bottom of my Container, as shown in this mockup:
Below is the code, that I have so far. I am struggling to get the border between the play button working too. I have tried the usual css: bottom:0 and position:relevant Along with Flexbox but it doesn't seem to want to go to the very bottom of the container.
const styles = theme => ({
root: {
flexGrow: 1,
overflow: 'hidden',
padding: theme.spacing(0, 3),
},
paper: {
maxWidth: 800,
margin: `${theme.spacing(2)}px auto`,
padding: theme.spacing(2),
},
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
width: 200,
},
playButton: {
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
position: "relative",
"& .playButton": {
position: "absolute",
top: "60%",
left: "-55px",
transform: "translateY(-50%)",
},
"& .star-rating": {
"& .fa-star": {
"&:hover": {
"&::before": {
content: "\f005",
color: "yellow"
}
}
}
},
},
});
function Tasks(props) {
const { classes } = props;
return (
<div className={classes.root}>
<Paper className={classes.paper}>
<Grid container spacing={2}>
<Grid item xs={12} sm container>
<Grid item xs container direction="column" spacing={2}>
<Grid item xs>
<div className="name-label">
Name
</div>
<Typography variant="h6" gutterBottom>
{props.name}
</Typography>
<div className="form-divider"></div>
<Typography variant="body2" color="textSecondary">
{props.description}
</Typography>
</Grid>
</Grid>
<Grid item classes={{ root: props.classes.playButton}}>
<Grid item xs={3} className="playButton">
<i class="far fa-play-circle fa-2x"></i>
</Grid>
<div className="workers-assigned-label">
Workers Assigned
</div>
<Typography variant="h6" gutterBottom>
0/25
</Typography>
<div class="star-rating">
<label class="far fa-star fa-2x"></label>
<label class="far fa-star fa-2x"></label>
<label class="far fa-star fa-2x"></label>
</div>
<div className="dropdown-menu">
<h5>Unnassigned</h5>
</div>
</Grid>
</Grid>
</Grid>
</Paper>
</div>
);
}
export default withStyles(styles)(Tasks);
Any input would be great.
I would recommend starting with a Grid 'skeleton' that looks something like:
<Grid container>
<Grid item container xs={8} direction="column" justify="flex-start">
// Left column contents, with each row as a <Grid item>
</Grid>
<Fab className={classes.fab}><PlayIcon /><Fab>
<Grid item container xs={4} direction="column" justify="space-between" className={classes.right}>
// Right column contents, with each row as a <Grid item>
</Grid>
</Grid>
The direction=column will help you position items vertically within each container. The justify=space-between will ensure that your first item is at the top of the container and your last item (the unassigned text) is at the bottom.
The "right" css class looks like:
right: {
borderLeft: `1px solid ${theme.palette.grey[500]}`,
position: "relative"
}
You can give it a position of "relative" to make it easier to position the fab relative to the column. The "fab" class looks like:
fab: {
position: "absolute",
margin: "auto",
top: 0,
bottom: 0,
left: -28
}
The margin, top, and bottom properties help center the fab vertically, and the left is a bit of a hack based on the dimensions of the fab to center it over the border.
Here's a working draft that brings everything together: https://codesandbox.io/s/tender-torvalds-dlbke?fontsize=14
You can try something like this, or give flex: 1 to anything in the column to make it stretch.
const styles = theme => ({
playButton: {
'& .dropdown-menu': {
marginTop: "auto"
}
}
})
I am looking for some advice as I can't seem to get these items positioned on the modal. I am looking to get add the item counter as text and stars underneath. With the unassigned text at the bottom. I have tried many layouts. This is my code so far:
const styles = theme => ({
root: {
flexGrow: 1,
overflow: 'hidden',
padding: theme.spacing(0, 3),
},
paper: {
maxWidth: 800,
margin: `${theme.spacing(2)}px auto`,
padding: theme.spacing(2),
},
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
width: 200,
},
playButton: {
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
"& .rating": {
flex: 1
},
}
});
function Tasks(props) {
const { classes } = props;
return (
<div className={classes.root}>
<Paper className={classes.paper}>
<Grid container spacing={2}>
<Grid item xs={12} sm container>
<Grid item xs container direction="column" spacing={2}>
<Grid item xs>
<div className="name-label">
Name
</div>
<Typography variant="h6">
Order cofee beans
</Typography>
<div className="form-divider"></div>
<Typography variant="body2" color="textSecondary">
Process of Description
</Typography>
</Grid>
</Grid>
<Grid item classes={{ root: props.classes.playButton}}>
<Grid item xs={3} className="playButton">
<i class="far fa-play-circle fa-2x"></i>
</Grid>
<div className="workers-assigned-label">
Workers Assigned
</div>
<div>
count / total
</div>
<div className="rating">
Stars go here
</div>
<div>
unassigned
</div>
</Grid>
</Grid>
</Grid>
</Paper>
</div>
);
}
export default withStyles(styles)(Tasks);
I have added an image of a screenshot of the design so that it is clear what I am trying to achieve.
Image: enter image description here
You're going to want something like this, where the flex: 1 is whatever you want to be stretching and taking up any extra space.
const styles = theme => ({
playButton: {
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
position: "relative",
"& .playButton": {
position: "absolute",
top: "80%",
left: "-55px",
transform: "translateY(-50%)",
},
"& .rating": {
flex: 1
}
}
});
const YourComponent = props => (
{...}
<Grid item classes={{ root: props.classes.playButton}}>
<Grid item xs={3} className="playButton">
<i class="far fa-play-circle fa-2x"></i>
</Grid>
<div className="workers-assigned-label">
Workers Assigned
</div>
<div>
count / total
</div>
<div className="rating">
stars go here
</div>
<div>
unassigned
</div>
</Grid>
{...}
);
I suggest you checkout this resource to see what you can do with flex.