【发布时间】:2022-01-25 08:38:58
【问题描述】:
我想改变 StyledButton 取决于传递的道具。当complex 为true 时,它应该去complexMixin 然后确定whiteColor 传递的内容。但即使我用true 传递whiteColor,颜色也是黑色,而不是白色。
有人知道这是怎么回事吗?谢谢!
import styled, { css } from "styled-components";
const complexMixin = css`
color: ${({ whiteColor }) => (whiteColor ? "white" : "black")};
`;
const StyledButton = styled.div`
border: 1px solid red;
height: 100px;
text-align: center;
margin: 20px;
font-weight: 700;
font-size: 40px;
color: ${({ complex }) => (complex ? complexMixin : "green")};
`;
const App = () => {
const isComplex = true;
const isWhite = true;
return (
<>
<StyledButton whiteColor={isWhite} complex={isComplex}>
ccc
</StyledButton>
<StyledButton complex={!isComplex}>BBB</StyledButton>
</>
);
};
【问题讨论】:
标签: styled-components react-props