admin管理员组文章数量:1410705
Im using Material UI next and building a wrapper around the card ponent. This allows me to customise the ponent. Im able to extend the ponent such that the title and image present inside the card can be sent as props. However, the background color, which is injected into the classes attribute using the JS in CSS technique, Im unable to find a way to send the background color as props.
The classes which is set using the JSS technique is as follows:
const styles = {
card: {
maxWidth: 345,
backgroundColor: '#hexcodehere'
},
The ponent is as shown below:
const { classes,label } = props;
<Card className={classes.card}
label={label}
>
<CardText />
<CardMedia />
</Card>
How to set the background color using props?
Im using Material UI next and building a wrapper around the card ponent. This allows me to customise the ponent. Im able to extend the ponent such that the title and image present inside the card can be sent as props. However, the background color, which is injected into the classes attribute using the JS in CSS technique, Im unable to find a way to send the background color as props.
The classes which is set using the JSS technique is as follows:
const styles = {
card: {
maxWidth: 345,
backgroundColor: '#hexcodehere'
},
The ponent is as shown below:
const { classes,label } = props;
<Card className={classes.card}
label={label}
>
<CardText />
<CardMedia />
</Card>
How to set the background color using props?
Share asked Feb 21, 2018 at 11:19 SeaWarrior404SeaWarrior404 4,16816 gold badges47 silver badges66 bronze badges1 Answer
Reset to default 3Use classnames package to implement custom styling over React ponent.
import classnames from 'classnames';
const { classes, label, backgroundColor } = props;
<Card className={classnames(classes.card)} style={{ backgroundColor }}
label={label}
>
<CardText />
<CardMedia />
</Card>
This backgroudColor
props can be any string that is supported by CSS.
e.g:
- '#f0f' (#rgb)
- '#ff00ff' (#rrggbb)
- 'rgb(255, 0, 255)'
- 'rgba(255, 255, 255, 1.0)'
版权声明:本文标题:javascript - How to supply background color as a prop for cards using Material UI in React JS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745045022a2639309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论