Last active
August 29, 2015 14:17
-
-
Save AndrewRayCode/b4ac61b6d301e30d37e9 to your computer and use it in GitHub Desktop.
Better React ClassSet
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
| // Lets you call classSet with strings *and* objects | |
| // Usage: classSet({a: true, b: false}, 'class1', null, 'class2'); class="a class1 class2" | |
| function classSet() { | |
| var classes = [], | |
| arg, x, key; | |
| for( x = 0; x < arguments.length; x++ ) { | |
| arg = arguments[ x ]; | |
| if( typeof arg === 'object' ) { | |
| for( key in arg ) { | |
| if( arg[ key ] ) { | |
| classes.push( key ); | |
| } | |
| } | |
| } else if( arg ) { | |
| classes.push( arg ); | |
| } | |
| } | |
| return classes.join(' '); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment