MCPcopy
hub / github.com/callstack/linaria / cx

Function cx

packages/core/src/cx.ts:23–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 * @returns the combined, space separated class names that can be applied directly to the class attribute
22 */
23const cx: ICX = function cx() {
24 const presentClassNames: (ClassName | ClassName<LinariaClassName>)[] =
25 Array.prototype.slice
26 // eslint-disable-next-line prefer-rest-params
27 .call(arguments)
28 .filter(Boolean);
29
30 const atomicClasses: { [k: string]: string } = {};
31 const nonAtomicClasses: string[] = [];
32 presentClassNames.forEach((arg) => {
33 // className could be the output of a previous cx call, so split by ' ' first
34 const individualClassNames = arg ? arg.split(' ') : [];
35
36 individualClassNames.forEach((className) => {
37 if (className.startsWith('atm_')) {
38 const [, keyHash] = className.split('_');
39 atomicClasses[keyHash] = className;
40 } else {
41 nonAtomicClasses.push(className);
42 }
43 });
44 });
45
46 const result: string[] = [];
47
48 // eslint-disable-next-line no-restricted-syntax
49 for (const keyHash in atomicClasses) {
50 if (Object.prototype.hasOwnProperty.call(atomicClasses, keyHash)) {
51 result.push(atomicClasses[keyHash]);
52 }
53 }
54
55 result.push(...nonAtomicClasses);
56
57 return result.join(' ') as LinariaClassName;
58};
59
60export default cx;

Callers 4

renderFunction · 0.90
core.tsFile · 0.90
cx.test.tsFile · 0.85
IndexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected