将样式传递给material-ui-next中的子组件

时间:2018-04-17 13:59:27

标签: css reactjs material-ui

嗨:)让我说我有两个组件,一个人有文字"橙"作为一个常量而且我希望它的孩子有橙色文本..使用材料-ui-next,我使用withStyles和其他任何东西都不会影响文本的颜色...这里有一些代码:

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Card, { CardActions, CardContent } from 'material-ui/Card';
import Button from 'material-ui/Button';
import Typography from 'material-ui/Typography';

const styles = {
  card: {
    minWidth: 275,
  },
  bullet: {
    display: 'inline-block',
    margin: '0 2px',
    transform: 'scale(0.8)',
  },
  title: {
    marginBottom: 16,
    fontSize: 14,
  },
  pos: {
    marginBottom: 12,
  },
};

function SimpleCard(props) {
  const { classes } = props;
  const bull = <span className={classes.bullet}>•</span>;

  return (
    <div>
      <Card className={classes.card}>
        <CardContent>
          <Typography className={classes.title} color="textSecondary">
            Word of the Day
          </Typography>
          <Typography variant="headline" component="h2">
            be{bull}nev{bull}o{bull}lent
          </Typography>
          <Typography className={classes.pos} color="textSecondary">
            adjective
          </Typography>
          <!-- I want the text from here to become orange-->
          <Typography component="p">
            well meaning and kindly.<br />
            {'"a benevolent smile"'}
          </Typography>
        </CardContent>
        <CardActions>
          <Button size="small">Learn More</Button>
        </CardActions>
      </Card>
    </div>
  );
}

SimpleCard.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SimpleCard);

橙色将在this.props.color 我不介意它是&#34; material-ui / colors / orange&#34;我只想以某种方式从我的SimpleCard组件中解决该值并在构建样式时使用它(或者一起忽略样式并只使用颜色)

0 个答案:

没有答案