I need to pass dynamic values to linear-gradient in such a way shown below. How would I do this? I have tried implementing the small example of Dynamic Values on the cssinjss web site without success.
const useStyles = createUseStyles({
card:{
background: 'linear-gradient(to top, orange, rgb(to top, 255, props.green, 0))',
width: '200px',
height: '240px',
margin: '50px',
display: "flex",
flexDirection: 'column',
justifyContent: 'space-around',
alignItems: 'center',
color: 'white',
fontFamily: 'arial',
padding: 6,
borderRadius: 15,
composes: 'shadow'
}
});
const WeatherCard = (props) => {
const classes = useStyles(props);
return (
<div>
<div className={classes.card}>
<Location />
<Icon />
<Tempature />
</div>
</div>
);
};
WeatherCard.defaultProps = {
green: 125
};
Your code is correct, just missing the callback that tells the variable props
with the values, try the following:
See in: https://cssinjs.org/react-jss/?v=v10.4.0#dynamic-values
const useStyles = createUseStyles({
card: {
background: props => `linear-gradient(to top, orange, rgb(to top, 255, ${props.green}, 0))`,
width: '200px',
height: '240px',
margin: '50px',
display: "flex",
flexDirection: 'column',
justifyContent: 'space-around',
alignItems: 'center',
color: 'white',
fontFamily: 'arial',
padding: 6,
borderRadius: 15,
composes: 'shadow'
}
});
const WeatherCard = (props) => {
const classes = useStyles({...props});
return (
<div>
<div className={classes.card}>
<Location />
<Icon />
<Tempature />
</div>
</div>
);
};