-
-
Save LZL0/21c6338404b50c98106e555e8ecbce20 to your computer and use it in GitHub Desktop.
A tailwind plugin for generating WordPress block editor (Gutenberg) color css styles from the tailwind palette
This file contains 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 _ = require('lodash') | |
const plugin = require('tailwindcss/plugin') | |
plugins: [ | |
plugin(function({ addComponents, theme }) { | |
const colors = theme('colors', {}) | |
const exclude = ['transparent', 'current'] | |
const paletteColors = [] | |
for (const [key, value] of Object.entries(colors)) { | |
if ('string' == typeof(value)) { | |
if (_.includes(exclude, key)) continue; | |
paletteColors[key] = value | |
} else { | |
for (const [subkey, subvalue] of Object.entries(value)) { | |
if (_.includes(exclude, key)) continue; | |
paletteColors[key+'-'+subkey] = subvalue | |
} | |
} | |
} | |
for (const [color, value] of Object.entries(paletteColors)) { | |
addComponents({ | |
[`.wp-block .has-${_.kebabCase(color)}-background-color`]: { | |
backgroundColor: value, | |
}, | |
[`.wp-block .has-${_.kebabCase(color)}-color`]: { | |
color: value, | |
} | |
}) | |
} | |
}) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment