2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* The `classList` utility creates a list of class names by joining an object's
|
|
|
|
* keys, but only for values which are truthy.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* classList({ foo: true, bar: false, qux: 'qaz' });
|
|
|
|
* // "foo qux"
|
|
|
|
*
|
|
|
|
* @param {Object} classes
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
export default function classList(classes) {
|
2015-07-17 13:17:49 +08:00
|
|
|
let classNames;
|
2015-07-15 12:30:11 +08:00
|
|
|
|
2015-07-17 13:17:49 +08:00
|
|
|
if (classes instanceof Array) {
|
|
|
|
classNames = classes.filter(name => name);
|
|
|
|
} else {
|
|
|
|
classNames = [];
|
|
|
|
|
|
|
|
for (const i in classes) {
|
|
|
|
if (classes[i]) classNames.push(i);
|
|
|
|
}
|
2015-07-15 12:30:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return classNames.join(' ');
|
|
|
|
}
|