Skip to content

duylong86/react-add-class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-add-class

Support React to add class names from css module

How to use

<!-- expected result -->
<div class="header__ab _block_xy -fixed__zh">
  <div class="header__ab _logo__yd -dark__ka"></div>
  <div class="header__ab _title__xn -global-text -big__xa"></div>
  <div class="header__ab _menu__ph -expanded__xh"></div>
</div>
import initClassName from 'react-add-class';
import styles from './styles.css';

const addClass = initClassName(styles);

/*
  styles = {
    header: 'header__ab',
    _block: '_block_xy',
    _logo: '_logo__yd',
    _title: '_title__xn',
    _menu: '_menu__ph',
    '-fixed': '-fixed__zh',
    '-dark': '-dark__ka',
    '-expanded': '-expanded__xh',
    '-big': '-big__xa'
  };
*/

render() {
  return (
    <div {...addClass('_block')}>
      <div {...addClass('_logo', '-dark')}></div>
      <div {...addClass('_title', [ '-global-text' ], [{ '-big': true }])}></div>
      <div {...addClass('_menu', { '-expanded': true })}></div>
    </div>
  )
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published