Created
March 24, 2023 13:36
-
-
Save NataliaNagaeva/fc0e4769f8f4602faa432a6826e45590 to your computer and use it in GitHub Desktop.
This file contains 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
const generateClasses = (defaultClass: string) => | |
(childClass = '', props: Record<string, boolean> = {}, additionalClassName = '') => { | |
const baseClass = childClass ? `${defaultClass}__${childClass}` : defaultClass; | |
const classes = [baseClass]; | |
Object.keys(props).forEach(propName => { | |
if(props[propName]) { | |
classes.push(`${baseClass}--${propName}`); | |
} | |
}); | |
if(additionalClassName) { | |
classes.push(additionalClassName); | |
} | |
return classes.join(' '); | |
} | |
export default generateClasses; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment