Last active
February 9, 2022 16:30
-
-
Save t2/d8ac9225d4f182281914057e39b7860d to your computer and use it in GitHub Desktop.
Visualize your projects Tailwind CSS color pallet.
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
var http = require('http'); | |
var tailwind = require('./tailwind.config.js'); | |
http | |
.createServer(function (req, res) { | |
var html = buildHtml(req); | |
res.writeHead(200, { | |
'Content-Type': 'text/html', | |
'Content-Length': html.length, | |
Expires: new Date().toUTCString(), | |
}); | |
res.end(html); | |
}) | |
.listen(8080); | |
function buildHtml(req) { | |
var colors = tailwind.theme.colors; | |
return ` | |
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body> | |
<div style="padding:20px;"> | |
${buildColorHtml(colors)} | |
</div> | |
</body> | |
</html> | |
`; | |
} | |
function buildColorHtml(colors) { | |
return Object.keys(colors) | |
.map((color) => { | |
return ` | |
<div style="padding-bottom:32px;"> | |
<div style="padding-bottom:4px;">${color}</div> | |
<div style="display:flex;flex-direction:row;"> | |
${buildColorDivs(colors[color])} | |
</div> | |
</div> | |
`; | |
}) | |
.join(''); | |
} | |
function buildColorDivs(colors) { | |
if (typeof colors !== 'object') { | |
return buildSingleColorDiv(colors, colors); | |
} | |
return Object.keys(colors) | |
.map((variant) => { | |
return buildSingleColorDiv(colors[variant], variant); | |
}) | |
.join(''); | |
} | |
function buildSingleColorDiv(color, title) { | |
return ` | |
<div> | |
<div style="height:50px;width:50px;margin-bottom:4px;background-color:${color}"></div> | |
<div>${title}</div> | |
</div> | |
`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It gets the job done!