我有一个问题 - 我不知道如何使用 Prop 的颜色值更改复选框颜色。我的想法是通过样式属性给它,但我不知道如何切换它。我正在使用 rc-switch我想根据 Switch 状态更改他的背景。我现在有这样的东西
<Switch style={{ backgroundColor: mainColor }}/>
但它为两种状态都设置了这种颜色,我希望这个开关在关闭位置时变为“defaultColor”。
最佳答案
There is no style prop on the Switch Component, but there is a className prop, which you can use to add your custom class.
如果你正在使用 sass:
.mySwitch {
&-black {
background-color: black;
}
&-yellow {
background-color: yellow;
}
}
然后以编程方式切换类。
<Switch className={`mySwitch-${color}` ... />
我认为这可能是一种选择。
关于javascript - 如何将 React prop 传递给 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874128/