classix 2.1.11 → 2.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -13
- package/dist/cjs/classix.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,35 +47,46 @@ cx(...["class1", "class2", "class3"]);
|
|
|
47
47
|
cx(
|
|
48
48
|
"flex",
|
|
49
49
|
isPrimary ? "bg-primary-100" : "bg-secondary-100",
|
|
50
|
-
isLarge ? "m-4 p-4" : "m-2
|
|
50
|
+
isLarge ? "m-4 p-4" : "m-2 p-2"
|
|
51
51
|
);
|
|
52
52
|
// => "flex bg-primary-100 m-2 p-2" *assuming isPrimary is true and isLarge is false
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Why?
|
|
56
|
+
|
|
57
|
+
classix considers string expressions faster to type and easier to reason about (conditions first, followed by classNames) than the alternative:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
// 🚫
|
|
61
|
+
clsx({ "class-1": isPrimary });
|
|
62
|
+
// ✅
|
|
63
|
+
cx(isPrimary && "class-1");
|
|
64
|
+
|
|
65
|
+
// 🚫
|
|
66
|
+
clsx({ "class-1": isPrimary && isLarge, "class-2": !isPrimary || !isLarge });
|
|
67
|
+
// ✅
|
|
68
|
+
cx(isPrimary && isLarge ? "class-1" : "class-2");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This reasoning enables classix to simplify its API by allowing only string expressions as arguments. Not only does it provide a consistent way of joining classNames, but using classix also leads to [better performance](#comparison) and a [smaller bundle size](#comparison) for your application.
|
|
72
|
+
|
|
55
73
|
## Comparison
|
|
56
74
|
|
|
57
75
|

|
|
58
76
|
|
|
59
|
-
Sources: [classix](https://bundlejs.com
|
|
77
|
+
Sources: [classix](https://bundlejs.com/api?q=classix), [clsx](https://bundlejs.com/api?q=clsx), [classnames](https://bundlejs.com/api?q=classnames)
|
|
60
78
|
|
|
61
79
|

|
|
62
80
|
|
|
63
81
|
Sources: Ran [benchmark](benchmark/) on an AMD Ryzen 5 5600x.
|
|
64
82
|
|
|
65
|
-
Compared to other libraries, classix simplifies its API by omitting the use of object arguments, which it considers less ergonomic than string expressions:
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
// 🚫
|
|
69
|
-
cx({ "class-1": isPrimary && isLarge, "class-2": !isPrimary || !isLarge });
|
|
70
|
-
// ✅
|
|
71
|
-
cx(isPrimary && isLarge ? "class-1" : "class-2");
|
|
72
|
-
```
|
|
73
|
-
|
|
74
83
|
## Highlights
|
|
75
84
|
|
|
76
|
-
-
|
|
85
|
+
- Supports all major browsers
|
|
86
|
+
- Supports all versions of Node.js
|
|
87
|
+
- Works with both ES Modules and CommonJS
|
|
77
88
|
- Zero dependencies
|
|
78
|
-
- Fully typed
|
|
89
|
+
- Fully typed with TypeScript
|
|
79
90
|
- Fully tested
|
|
80
91
|
- [Semver](https://semver.org/) compliant
|
|
81
92
|
|
package/dist/cjs/classix.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(){let e,t="",r=0;for(;r<arguments.length;)(e=arguments[r++])&&"string"==typeof e&&(t&&(t+=" "),t+=e);return t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.cx=e,exports.default=e;
|