我正在尝试对我的 React 表中的一行进行样式化,以便当某一行的数据发生变化时,背景具有应用于该行背景的线性渐变。我已经尝试了几件事,并通过示例查找了他们的文档,但没有成功。
我已经尝试了一些东西,并通过示例查找了他们的文档,但没有成功。
我已经将线性渐变设为一个变量,然后像这样将其插入到条件中:
const gradient = {
linearGradient: `(to left, #27293d 99%, #344675 1%)`
}
const getTrProps = (rowInfo) => {
if (rowInfo) {
return {
style: {
height: `60px`,
padding: `5px`,
margin: `5px`,
borderRadius: `5px`,
backdropFilter: `blur(15px)`,
background: rowInfo.status === 'created' ? linearGradient : `red`
}
}
}
return {};
}
与相关状态相关的列是这样的:
{
Header: 'Status',
accessor: 'status',
Cell: row => (
<div style={{
width: `${row.value}%`
}}>
<span>
{
row.value === 'created' ? <GreenStatusCircle /> :
row.value === 'awaiting_driver' ? <YellowStatusCircle /> :
row.value === 'delivered' ? <RedStatusCircle /> : "None Found"
}
</span>
</div>
)
},
它应该用线性渐变渲染,但我所有的行都是红色的。我看过此处显示的示例:
https://codesandbox.io/s/k3q43jpl47
看起来我做得很好,但它无法正确呈现。
最佳答案
您可以将其作为 HTML 属性而不是样式传递
代替:
const gradient = {
linearGradient: `(to left, #27293d 99%, #344675 1%)`
}
改成
const gradient = {
someColor: 'linear-gradient(to left, #27293d 99%, #344675 1%)'
}
和我们一样
const getTrProps = (rowInfo) => {
if (rowInfo) {
return {
style: {
height: `60px`,
padding: `5px`,
margin: `5px`,
borderRadius: `5px`,
backdropFilter: `blur(15px)`,
background: rowInfo.status === 'created' ? gradient.someColor: `red`
}
}
}
return {};
}
关于css - 为 react 表中的 getTrProps 设置条件背景线性渐变无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58667959/