I have list of color variables in JavaScript
file as an Object.
export const colors = [
{
colorVariable: "$ui-background"
},
{
colorVariable: "$ui-01"
},
{
colorVariable: "$ui-02"
},
...
]
I created above object file based on scss
file which have list of 50 colors. I used same name as scss variable So, i can use scss variable in my React component.
$carbon--theme: (
ui-background: #ffffff,
ui-01: #f3f3f3,
ui-02: #ffffff,
...
)
I imported those colors to jsx
file from color.js file.
import { colors } from './theme';
And i want use that color variable to give background of following div. I tried following way So, i can apply scss variable. But, not working.
component.jsx
Code:
Object.keys(colors).map(key => {
return (
<div style={{ background: colors[key].colorVariable }} className={'theme-color')} />
)
})
I tried many things but nothing worked. Any help would be greatly appreciated. (It would be nice if i can use that variable in css (component.scss) file inside theme-color
class. If not then ok ).
I am using react 16. Any help would be greatly appreciated and let me know if any questions.