我正在使用styled-components
我的组件的动态样式,但我似乎无法让它以我想要的方式工作。
我正在尝试在以ease-in-out
编程方式和动态聚焦的按钮上添加效果。
如您所见,样式已应用,但该transition
属性没有任何效果。有没有办法做到这一点?
就像信息说明一样,组件(按钮)每 3 秒重新渲染一次以进行切换,这可能是原因吗?如果是这样如何解决这个问题?
零件
class LanguageButton extends PureComponent {
render() {
const { children, theme, isFocussed, ...otherProps } = this.props;
const Button = styled.div`
border: 1px solid ${theme};
margin-top: 10px;
margin-bottom: 10px;
background-color: transparent;
text-align: center;
padding-top: 25px;
padding-bottom: 25px;
min-height: 0;
transition: all 0.1s ease-in-out;
:hover {
background-color: ${theme};
transition: all 0.1s ease-in-out;
}
:active {
background-color: ${theme};
}
&.isFocussed {
transition: all 0.1s ease-in-out;
background-color: #ebebeb;
:hover {
background-color: ${theme};
transition: all 0.1s ease-in-out;
}
:active {
background-color: ${theme};
}
}
`;
return (
<Button
className={classnames("BUTTON BUTTON--50 GM--noselect", { isFocussed })}
{...otherProps}
>
{children}
</Button>
);
}
}