Skip to content

Instantly share code, notes, and snippets.

@t2
Last active February 9, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t2/d8ac9225d4f182281914057e39b7860d to your computer and use it in GitHub Desktop.
Save t2/d8ac9225d4f182281914057e39b7860d to your computer and use it in GitHub Desktop.
Visualize your projects Tailwind CSS color pallet.
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>
`;
}
@t2
Copy link
Author

t2 commented Feb 9, 2022

It gets the job done!

tailwind-colors-output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment