Last active
May 1, 2023 20:54
-
-
Save khleomix/57ef36c9bbe6cf2bc21ba28581242672 to your computer and use it in GitHub Desktop.
Theme.json and Tailwind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require( 'fs' ); | |
const path = require( 'path' ); | |
const themeJsonPath = path.join( __dirname, 'theme.json' ); | |
const themeJson = fs.readFileSync( themeJsonPath ); | |
const theme = JSON.parse( themeJson ); | |
const { palette } = theme.settings.color; | |
const colors = palette.reduce(( acc, item ) => { | |
const [color, number] = item.slug.split( '-' ); | |
if ( number ) { | |
// If there is a number identifier, make this an object | |
if ( ! acc[color] ) { | |
acc[color] = {}; | |
} | |
acc[color][number] = item.color; | |
} else { | |
acc[color] = item.color; | |
} | |
return acc; | |
}, {} ); | |
module.exports = { | |
theme: { colors }, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 2, | |
"settings": { | |
"color": { | |
"custom": true, | |
"palette": [ | |
{ | |
"color": "#f5f5f4", | |
"slug": "gray-100", | |
"name": "Gray 100" | |
}, | |
{ | |
"color": "#e7e5e4", | |
"slug": "gray-200", | |
"name": "Gray 200" | |
}, | |
{ | |
"color": "#d6d3d1", | |
"slug": "gray-300", | |
"name": "Gray 300" | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment