【发布时间】:2020-11-04 19:51:34
【问题描述】:
我正在使用旧版本的 material-ui,无法升级。
我正在尝试根据一些道具组合来更改 Paper 组件的背景。我认为要求使用 makeStyles HOC 并不复杂。这可能吗?
我认为问题在于这一行: 类={{ 根:正确背景颜色.root }}
但https://v0.material-ui.com/#/components/paper 上的文档无济于事地说“其他属性(未记录)应用于根元素。”
import React from "react";
const correctBackgroundColor = {
root: {
width: 30,
height: 30,
border: "1px solid lightgrey",
backgroundColor: props => {
if (props.ledIsOn === true && props.ledColorType === "Green") {
return "#00FF00";
}
if (props.ledIsOn === true && props.ledColorType === "Orange") {
return "#FFA500";
}
}
}
};
class ColorChange extends React.Component {
render() {
const { classes } = this.props;
let textToRender = (
<Paper
id={this.props.id}
classes={{ root: correctBackgroundColor.root }}
/>
);
return (
<div>
<Typography variant="p" className={classes.typography_root}>
{this.props.textLabel}
</Typography>
{textToRender}
</div>
);
}
}
export default withStyles(styles)(ColorChange);
有一个沙盒位于:https://codesandbox.io/s/adoring-bell-oyzsnTIA!
【问题讨论】:
标签: javascript reactjs material-ui styling