Debian Codegraph @

node/@patternfly/react-styles/src/index.ts

raw
1 /** Joins args into a className string
2 *
3 * @param {any} args list of objects, string, or arrays to reduce
4 */
5 export function css(...args: any): string {
6 // Adapted from https://github.com/JedWatson/classnames/blob/master/index.js
7 const classes = [] as string[];
8 const hasOwn = {}.hasOwnProperty;
9
10 args.filter(Boolean).forEach((arg: any) => {
11 const argType = typeof arg;
12
13 if (argType === 'string' || argType === 'number') {
14 classes.push(arg);
15 } else if (Array.isArray(arg) && arg.length) {
16 const inner = css(...(arg as any));
17 if (inner) {
18 classes.push(inner);
19 }
20 } else if (argType === 'object') {
21 for (const key in arg) {
22 if (hasOwn.call(arg, key) && arg[key]) {
23 classes.push(key);
24 }
25 }
26 }
27 });
28
29 return classes.join(' ');
30 }