0
我創建了一個正在採用數組並將所有進度條堆疊成一個的反應組件。從反應循環中獲取索引值並將其傳遞給css
const ProgressBar = (props, {...customProps}) => {
const GroupProgressBar = [];
props.groups.map((group, i) => {
const widthValue = (group.value/group.max) * 100;
GroupProgressBar.push
(<div style={{width: `${widthValue}%`}}
key = {i}
className={`well-background--${group.concept}
animation
terra-ProgressGroup--progress
terra-ProgressBar--${props.heightSize}`}>
</div>);
})
return <div className='terra-ProgressGroup'> {GroupProgressBar} </div>
}
CSS(以下班我要轉換爲單班):
....
.well-background--concept1 {
animation-delay: 1s;
z-index: -1;
}
.well-background--concept2 {
animation-delay: 2s;
z-index: -2;
}
.well-background--concept3 {
animation-delay: 3s;
z-index: -3;
}
我想這些類轉換成一個,但有沒有運氣
:root {
--concept-code: key;
--concept-code2: key;
}
.animation {
animation-delay: var(--concept-code)s;
z-index: var(--concept-code2);
}
基本上我不想繼續添加那些類似的類,所以我試圖創建一個類並傳遞thos來自反應組分的電子號碼。可能使用key = {i}
我該如何做到這一點?
感謝您的回答。我是新來的反應。我怎麼能從字符串中提取數字值?字符串將像concept1,concept2等。我在className中以group.concept的形式訪問它。團體是一個概念和價值的數組。 – User7354632781
嘗試了一些東西。我如何在我的組件中實現這一點。 ''const constDelay = group.concept.match(/ \ d/g); animationDelay = animationDelay.join(「」);'' – User7354632781
我試圖實現它。得到這個'''警告:一個'div'標籤(owner:'ProgressBar')被傳入一個CSS屬性'animationDelay'(value:'1')的數字字符串值,在未來的版本中將被視爲無單位數字React.''' – User7354632781