My JavaScript
file contains a list of color variables as an Object.
export const colors = [
{
colorVariable: "$ui-background"
},
{
colorVariable: "$ui-01"
},
{
colorVariable: "$ui-02"
},
...
]
The Object above is derived from a scss
file which holds 50 colors. I named the objects in line with the scss variables so I can easily use them in my React component.
$carbon--theme: (
ui-background: #ffffff,
ui-01: #f3f3f3,
ui-02: #ffffff,
...
)
I have imported these colors to my jsx
file from a color.js file.
import { colors } from './theme';
Now, I am trying to set the background of a div using one of those color variables. However, the usual approach is not working for me.
component.jsx
Code:
Object.keys(colors).map(key => {
return (
<div style={{ background: colors[key].colorVariable }} className={'theme-color')} />
)
})
I have tried different methods but none seem to be effective. Any assistance on this matter would be highly appreciated. (It would be preferable if I could also apply the variable in a css file within the theme-color
class. If not possible, that's okay too).
I am currently utilizing react 16. Your help and guidance would be greatly valued.