dynamic-class-list
A tiny, no-dependency library for creating conditional css classes.
Features:
- Support string arguments.
- Support number arguments.
- Support object arguments.
- Support array arguments.
- Support function arguments.
- No dependency.
Quickstart - CommonJS
npm install dynamic-class-list
Or using yarn
yarn add dynamic-class-list
Then require it in your module ...
var getClassNames = getClassNames; // deprecatedvar classList = classList;
OR using ES6 imports
;
Note that getClassNames
is deprecated and will be removed in next major release. You should use classList
moving forward.
API
Arguments as strings
// As Arguments; // Output ==> "class1 class2"// OR; // Output ==> "class1 class2"
Arguments as an array of strings
; // Output ==> "class1 class2" ; // Output ==> "3 class1 class2"
Arguments as an object
Note that the key is used as the class if its value is truthy
; // Output ==> "class1" ; // Output ==> "class3"
Note that the function must return a boolean.
; // Output ==> "class2"
Hybrid Arguments
; // Output ==> "class1 class2 2 class3 4 class4 class6 class8"