Skip to content

Instantly share code, notes, and snippets.

@LZL0
Forked from lgladdy/tailwind.config.js
Created January 14, 2023 00:48
Show Gist options
  • Save LZL0/21c6338404b50c98106e555e8ecbce20 to your computer and use it in GitHub Desktop.
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
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