I created this repo to add the missing link between defining color schemes in Figma and have them available in Tailwind taken the following requirements into account:
dark:bg-primary-400
) for dark mode.All this is possible with Figma plugins, however I didn't succeed in generating a tailwind.config.js
with colors structured as described by the tailwind-mode-aware-colors plugin. So I wrote a simple script to accomplish this.
You will need the following properly installed on your computer:
$ git clone [email protected]:bazzel/figma-variables2css-to-tailwind-colors-converter.git
$ cd figma-variables2css-to-tailwind-colors-converter
$ chmod a+x var-parser
To run this script successfully, you need to define your colors as variables in Figma and the colors should have modes named light
and dark
. The image below shows an example - it uses the names Colors
for the collection, primary
, secondary
, etc. for the groups and has a variable every shade (50
, 100
, ...), however the names are subordinate, as long as the modes are named properly.
To work with variables, you need a paid account.
export.json
).$ cd figma-variables2css-to-tailwind-colors-converter
$ ./var-parser ./export.json
colors.js
. Move this file to the same folder where tailwind.config.js
is located.tailwind.config.js
as follows:const myColors = require(./colors);
module.exports = require('tailwind-mode-aware-colors')({
theme: {
colors: myColors.colors,
},
...
});
Notice that
require('tailwind-mode-aware-colors')
is added. You need this plugin for mode-aware colors.
And that's it.
Figma plugins: