Skip to content

Instantly share code, notes, and snippets.

@NataliaNagaeva
Created March 24, 2023 13:36
Show Gist options
  • Save NataliaNagaeva/fc0e4769f8f4602faa432a6826e45590 to your computer and use it in GitHub Desktop.
Save NataliaNagaeva/fc0e4769f8f4602faa432a6826e45590 to your computer and use it in GitHub Desktop.
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