Created
September 5, 2022 13:09
-
-
Save danecando/33b63339cfb700899024b030909fd3fa 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