Skip to content

Instantly share code, notes, and snippets.

@bitfidget
Last active November 30, 2018 05:33
Show Gist options
  • Save bitfidget/bd5816315a9aceb3ff80eba3b8db3a2c to your computer and use it in GitHub Desktop.
Save bitfidget/bd5816315a9aceb3ff80eba3b8db3a2c to your computer and use it in GitHub Desktop.
/*
* @Author: Kriss Heimanis
* @Date: 2017-12-22 12:21:08
* @Last Modified by: Kriss Heimanis
* @Last Modified time: 2017-12-22 13:11:43
* Helper function to simplify conditional classNames.
* Accepts object as args.
* Object item key is the className, the value is the condition that must be met to include that className.
* Either item can be dynamic
*/
const conditionalClassNames = (args) => {
let ret = []
Object.keys(args).map(function (key) {
if (args[key]) {
ret.push(key)
}
})
return ret.join(' ')
}
export default conditionalClassNames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment