function cssHandles(...arguments) {
return arguments.reduce((acc, cur) => {
if (typeof cur === 'string') return acc + ` ${cur}`;
if (typeof cur === 'object') {
return Object.keys(cur).map((key) => {
if(cur[key]) return acc + ` ${key}`
return acc
}).filter(Boolean).join('').trim()
}
}, '')
}
cssHandles({ 'button--active': true, 'button--disabled': false, 'primary': true }, { 'is--open': false })
> 'button--active primary'
Last active
May 30, 2022 17:18
-
-
Save brenogcota/1242f784ed72649892c36119c4937de0 to your computer and use it in GitHub Desktop.
make dynamic css classes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment