【发布时间】:2020-07-30 21:43:47
【问题描述】:
我有一个标签组件,它是一个跨度标签并接受道具重量和大小,如下所示,
interface Props {
weight?: 200 | 400 | 500 | 700 | 900;
}
const Label = styled.span<Props>`
margin: 0;
font-weight: ${p => p.weight || 200};
`;
现在我在其他组件中使用它,我需要在标签组件中添加边距,如下所示,
render = () => {
return (
<Label
weight={400}>
without using margin-right
</Label>
<Label
weight={700}
margin-right={5px} //here i want to add margin-right
</Label>
)
}
如何修改 Label 组件,使其接受 margin-right 属性,或者更好地添加具有四个值的 margin 属性,例如 margin = {0 0 0 5}px;
有人可以帮我解决这个问题吗?谢谢。
【问题讨论】:
标签: css reactjs typescript styled-components