【问题标题】:How to use Material colours in react styled components?如何在反应样式的组件中使用材质颜色?
【发布时间】:2021-01-16 16:13:48
【问题描述】:

是否可以在 react 样式的组件中使用 Material UI 颜色?如果是这样,它的语法是什么?

我正在尝试如下:

import styled from 'styled-components/macro';
import blue from '@material-ui/core/colors/blue';
import indigo from '@material-ui/core/colors/indigo';

export const Icons = styled.span`

    color: {  indigo['A400'] };
`
;

我也试过(所有猜测):

color: blue[500]
color: { blue[500] }
color: "blue[500]"

我找不到可行的方法。

【问题讨论】:

    标签: reactjs material-ui material-design styled-components


    【解决方案1】:

    您在模板文字中,因此如果您选择评估 JavaScript 表达式,请使用 ${} 语法

    export const Icons = styled.span`
      color: ${indigo['A400']};
    `;
    

    【讨论】:

    猜你喜欢
    • 2020-09-13
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 2020-06-28
    • 1970-01-01
    • 2020-02-23
    相关资源
    最近更新 更多