RAG-ui/src/utils/cn.ts
2024-12-05 15:59:08 -05:00

26 lines
No EOL
668 B
TypeScript

type ClassValue = string | number | boolean | undefined | null;
type ClassArray = ClassValue[];
type ClassObject = { [key: string]: any };
type ClassInput = ClassValue | ClassArray | ClassObject;
export function cn(...inputs: ClassInput[]): string {
const classes = [];
for (const input of inputs) {
if (!input) continue;
if (typeof input === 'string') {
classes.push(input);
} else if (Array.isArray(input)) {
classes.push(cn(...input));
} else if (typeof input === 'object') {
for (const key in input) {
if (input[key]) {
classes.push(key);
}
}
}
}
return classes.join(' ');
}