【发布时间】:2018-01-19 09:36:25
【问题描述】:
随着 Material-UI@next 的到来,基于 CSS-to-JS 的样式取代了基于 LESS 的样式。但是,Material-UI's website 上的组件演示似乎忽略了基于道具的样式的创建。我正在尝试在我的页面上创建包含特定绝对高度的各种 Material-UI 组件的divs,但是,在类之外预定义样式表的要求意味着样式表中的属性不能基于传递给组件的道具。我错过了什么吗?
例如:
import React, {Component} from 'react';
import {withStyles, createStyleSheet} from 'material-ui/styles';
import Button from 'material-ui/Button';
const styleSheet = createStyleSheet({
container: {
position: "absolute",
top: /*How can this be dependent upon the props passed to the component?*/,
height: /*How can this be dependent upon the props passed to the component?*/,
}
});
class Foo extends Component {
render() {
let classes = this.props.classes;
return (
<div className={classes.container}>
<Button raised/>
</div>
);
}
}
export default withStyles(styleSheet)(Foo);
上面显示的示例组件不能有依赖props 的样式,因为在创建样式表时没有定义props。那么我该如何解决这个问题呢? 是否有解决办法吗?
【问题讨论】:
-
这还不被支持,有一个GitHub issue跟踪这个请求。
标签: reactjs material-ui