-
-
Save nilportugues/9fbbd8d618d6a097f2a8c1879d26dddc to your computer and use it in GitHub Desktop.
A simple plugin that exposes all tailwind colors as css variables on :root
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
function ({ addBase, theme }) { | |
function extractColorVars(colorObj, colorGroup = '') { | |
return Object.keys(colorObj).reduce((vars, colorKey) => { | |
const value = colorObj[colorKey]; | |
const newVars = | |
typeof value === 'string' | |
? { [`--color${colorGroup}-${colorKey}`]: value } | |
: extractColorVars(value, `-${colorKey}`); | |
return { ...vars, ...newVars }; | |
}, {}); | |
} | |
addBase({ | |
':root': extractColorVars(theme('colors')), | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment