klsx 0.2.0 → 0.2.2
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 +35 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# 🎨
|
|
1
|
+
# 🎨 𝒌𝒍𝒔𝒙
|
|
2
2
|
|
|
3
3
|
A simple replacement for [clsx](https://www.npmjs.com/package/clsx) **_you may not actually need_** (see the [benchmark](https://github.com/vuolter/klsx/blob/main/BENCHMARK.md))
|
|
4
4
|
|
|
5
|
+
Used to construct `class` conditionally with strings, arrays and key-value objects.
|
|
6
|
+
|
|
5
7
|
Developed as a case study, [Bun](https://bun.com) friendly. 🌿
|
|
6
8
|
|
|
7
9
|
### Features
|
|
@@ -13,7 +15,7 @@ Developed as a case study, [Bun](https://bun.com) friendly. 🌿
|
|
|
13
15
|
- ☀️ No "lite" mode (simply doesn't make any sense)
|
|
14
16
|
- 🎈 Only 277B (~190B compressed)
|
|
15
17
|
- 🐳 Deeply typed and tested
|
|
16
|
-
- 🚨 Experimental WASM variant (for research purposes, do not use it)
|
|
18
|
+
- 🚨 [Experimental WASM variant](https://github.com/vuolter/klsx/tree/wasm) (for research purposes, do not use it)
|
|
17
19
|
|
|
18
20
|
## Installation
|
|
19
21
|
|
|
@@ -32,19 +34,42 @@ npm install klsx
|
|
|
32
34
|
```typescript
|
|
33
35
|
import { klsx } from 'klsx'
|
|
34
36
|
|
|
35
|
-
klsx('foo', 'bar')
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
klsx('foo', 'bar', 'baz')
|
|
38
|
+
// => "foo bar baz"
|
|
39
|
+
|
|
40
|
+
klsx({foo: 'string', bar: true, bux: null }, 'baz')
|
|
41
|
+
// => "foo bar baz"
|
|
42
|
+
|
|
43
|
+
klsx(['foo', ['bar', true && 'baz']])
|
|
44
|
+
// => "foo bar baz"
|
|
38
45
|
```
|
|
39
46
|
|
|
40
|
-
or
|
|
47
|
+
or importing the short alias `cn`:
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
### React
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
import React, { useState } from 'react';
|
|
43
53
|
import { cn } from 'klsx'
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
const MyComponent = () => {
|
|
56
|
+
const [isActive, setIsActive] = useState(false);
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<div className={cn('base-class', isActive ? 'active' : 'inactive')}>
|
|
60
|
+
{/* ... */}
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div className={cn('base-class', {'active': isActive, 'inactive': !isActive})}>
|
|
64
|
+
{/* ... */}
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<div className={cn('base-class', [isActive && 'active', !isActive && 'inactive'])}>
|
|
68
|
+
{/* ... */}
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
48
73
|
```
|
|
49
74
|
|
|
50
75
|
## Integrations
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "klsx",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Walter Purcaro",
|
|
6
6
|
"url": "https://github.com/vuolter"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@prettier/plugin-oxc": "^0.0.5",
|
|
17
17
|
"@socketsecurity/bun-security-scanner": "^1.1.1",
|
|
18
18
|
"@types/bun": "^1.3.3",
|
|
19
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
19
|
+
"@typescript/native-preview": "^7.0.0-dev.20251123.1",
|
|
20
20
|
"classix": "^2.2.6",
|
|
21
21
|
"classnames": "^2.5.1",
|
|
22
22
|
"clsx": "^2.1.1",
|