样式化组件:根据条件更改文本颜色
我有一个表,如果交易金额 <= 0,则显示字符串提款,否则存款。
在这种情况下如何改变文本颜色?
我知道我需要使用道具,但似乎无法解决?
jsx:
<TransactionType>
{transaction.amount <= 0 ? "withdraw" : "deposit"}
</TransactionType>
样式组件:
export const TransactionType = styled.div<ITransactionType>`
color: ${(prop) => (prop.TransactionType ? "red" : "green")};
`;
谢谢!
I have a table that renders out the string withdraw if the transaction amount is <= 0 else deposit.
How do I get the text color to change on this condition?
I know I need to use props, but can't seem to work it out?
jsx:
<TransactionType>
{transaction.amount <= 0 ? "withdraw" : "deposit"}
</TransactionType>
Styled component:
export const TransactionType = styled.div<ITransactionType>`
color: ${(prop) => (prop.TransactionType ? "red" : "green")};
`;
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将您的道具重命名为 type 以提高可读性,但概念是相同的。并使用 props 参数的解构来获取可直接访问的类型。
I renamed your prop to type for improved readability, but the concept is the same. And used destructing of the props argument to get type directly accessible.