Skip to content

Instantly share code, notes, and snippets.

@lgladdy
Last active April 3, 2024 00:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lgladdy/f11d71cba6ce5b6f460778e461dd84a7 to your computer and use it in GitHub Desktop.
Save lgladdy/f11d71cba6ce5b6f460778e461dd84a7 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
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