Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import color variables to my styles

Tags:

I want to make file with variables of my colors and then import this file to my styles.

button: {  color: primarycolor  background: primarybackground } 

So I can change colors only in one place.

like image 423
rendom Avatar asked Mar 26 '17 12:03

rendom


People also ask

How do I import color into React?

To import color variables into styles with React Native, we can use export to export the color variables. export const COLORS = { white: '#fff', green: 'green', }; to create the color.

How do you use color variables?

Choose Edit > Find and Replace Color… From there, select the color or Color Variable you want to find within your design and the color or Color Variable you want to replace it with. Enable “Include all opacities of this color” to find all colors with different alphas, but the same RGB or HEX values.

What are color variables?

A color variable is a visual variable that defines the color of a symbol based on a numeric data value returned from a field or expression.


1 Answers

You can define a separate js file colors.js, that consists of the colors object and export it.

export const COLORS = {   white: '#fff',   black: '#000',   // your colors } 

Now import COLORS from the above file - import {COLORS} from './<Path>/colors.js' in your respective file that uses the defined colors. And use it as shown below.

button: {   color: COLORS.white,   backgroundColor: COLORS.black } 
like image 134
Aniruddha Shevle Avatar answered Oct 01 '22 01:10

Aniruddha Shevle