2020-08-31 16:53:19 +08:00
|
|
|
import { isArray, isString, isObject } from './util';
|
2020-10-13 22:26:56 +08:00
|
|
|
function classNames(...args: any[]) {
|
|
|
|
const classes = [];
|
|
|
|
for (let i = 0; i < args.length; i++) {
|
|
|
|
const value = args[i];
|
2020-10-02 15:44:10 +08:00
|
|
|
if (!value) continue;
|
2020-08-31 17:16:16 +08:00
|
|
|
if (isString(value)) {
|
|
|
|
classes.push(value);
|
|
|
|
} else if (isArray(value)) {
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
|
|
|
const inner = classNames(value[i]);
|
|
|
|
if (inner) {
|
|
|
|
classes.push(inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (isObject(value)) {
|
|
|
|
for (const name in value) {
|
|
|
|
if (value[name]) {
|
|
|
|
classes.push(name);
|
|
|
|
}
|
2020-08-31 16:53:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 17:16:16 +08:00
|
|
|
return classes.join(' ');
|
2020-08-31 16:53:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default classNames;
|