2
是否有可能使用伪类作为样式组件。我有复选框应该显示SVG图像:选中/未选中显示状态为选中/未选中。我可以通过父母传递道具来做到这一点。但是我被告知只有css(风格化的组件)才有可能。我的代码 部分:ReactJS +样式组件+伪类
const CheckboxInput = styled.input`
&:checked, &:not(:checked) {
display: none;
}`;
const CheckboxLabel = styled.label`
cursor: pointer;
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
`;
function Checkbox(props) {
return (
<CheckboxLabel htmlFor="id" onChange={() => { props.onchange(); }}>
<CheckboxInput id="id" type="checkbox" checked={props.checked} value="cb" name="cb" />
<Span><SVG glyph={checked} width={17} height={17} /></Span>
<Span><SVG glyph={unchecked} width={17} height={17} /></Span>
{props.children}
</CheckboxLabel>
);
}
这位先生!谢谢 – spences10