【发布时间】:2020-08-31 01:07:04
【问题描述】:
使用样式化组件创建变体的最佳方法是什么?这是我目前正在做的事情。
const ButtonStyle = styled.button`
padding:8px 20px;
border:none;
outline:none;
font-weight:${props => props.theme.font.headerFontWeight};
font-size:${props => props.theme.font.headerFontSize};
display:block;
&:hover{
cursor:pointer;
}
${({ variant }) =>
variant == 'header' && css`
background-color:${props => props.theme.colors.lightblue};
color:${({ theme }) => theme.colors.white};
&:active{
background-color:${props => props.theme.colors.blue}
}
`
}
${({ variant }) =>
variant == 'white' && css`
background-color:white;
color:${({ theme }) => theme.colors.lightblue};
&:active{
color:${props => props.theme.colors.blue}
}
`
}
`;
我不知道这是否是标准的做事方式。 我也一直在使用其他组件作为基础来创建其他组件,同时更改一些内容
例如
const InnerDiv = styled(otherComponent)`
position: unset;
background-color: red;
overflow-x: hidden;
display: flex;
`;
哪种方法更好?有没有更好的选择?
【问题讨论】:
标签: css reactjs styled-components