FILE / Unmei/Frontend
src/classNames.ts
Исходный файл и его история в репозитории.
32 lines
813 B
TypeScript
Executable File
32 lines
813 B
TypeScript
Executable File
export interface ObjectClassNames {
|
|
[index: string]: boolean;
|
|
}
|
|
|
|
export type ClassName = number | string | ObjectClassNames | false | null | undefined;
|
|
|
|
export default function classNames(...classNames: ClassName[]) {
|
|
let result: string[] = [];
|
|
|
|
classNames.forEach((item: ClassName): void => {
|
|
if(!item) {
|
|
return;
|
|
}
|
|
switch(typeof item) {
|
|
case 'string':
|
|
result.push(item);
|
|
break;
|
|
case 'object':
|
|
Object.keys(item).forEach((key: string) => {
|
|
if(item[key]) {
|
|
result.push(key);
|
|
}
|
|
});
|
|
break;
|
|
default:
|
|
result.push(`${item}`);
|
|
}
|
|
});
|
|
|
|
return result.join(' ');
|
|
}
|