TailwindCSS guide
We provide a function to convert your design tokens JSON into a TailwindCSS theme object and vice versa.
TailwindCSS theme -> Design tokens JSON
Run our Anima CLI with the
generate-tokens
command:shanima generate-tokens -f tailwindcss -c tailwind.config.cjs -o ./design-tokens.json
We'll look at the existing tailwindCSS theme in your
tailwind.config.js
file and generate a new JSON file provided with the--output
.shroot-folder ├── ... ├── tailwind.config.cjs └── design-tokens.json # a new JSON file with your design tokens
Design tokens JSON -> TailwindCSS theme
On your
tailwind.config.js
file in your project root directory, import our converter functiongetTailwindTheme
js// tailwind.config.cjs import { getTailwindTheme } from '@animaapp/framework-helpers'
Import your design tokens JSON file
jsimport dsToken from './design-tokens.json' // path to your design tokens JSON file
Create a new Object with the converted theme
jsconst themeColors = getTailwindTheme(dsToken)
Remove your previous color config and add the converted theme to your Tailwind config
jsmodule.exports = { content: ['./src/**/*.{js,ts,jsx,tsx}'], theme: { extend: { colors: { your existing colors, } colors: themeColors.colors, } }, plugins: [] }
Your final tailwind.config.js
file should look like this:
Final result
js
// tailwind.config.cjs
import { getTailwindTheme } from '@animaapp/framework-helpers'
import dsToken from './design-tokens.json'
const themeColors = getTailwindTheme(dsToken)
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
colors: themeColors.colors,
}
},
plugins: []
}