Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在一个简单的 React 项目中尝试 Styled-components,我有一个传递给组件的主题对象,所以我可以这样做:
background-color: ${props => props.theme.primary};
我还使用 Polished 来修改传递的值,因此按钮使用较暗版本的颜色作为轮廓。我可以这样做:
border: 1px solid ${darken(0.05, '#00823b')};
但是我需要颜色值来自主题,我该如何传递主题属性?
谢谢!
像这样定义您的border样式定义:
border
border: 1px solid ${props => darken(0.05, props.theme.primary)};
工作演示