Skip to content

Commit a48fc82

Browse files
author
Andrii Kirmas
committed
Add versus classnames
1 parent bd222bc commit a48fc82

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
"@types/react": ">=15"
4343
},
4444
"devDependencies": {
45+
"@types/classnames": "^2.2.11",
4546
"@types/node": "^14.14.25",
4647
"@types/react": "^17.0.1",
4748
"@types/react-dom": "^17.0.1",
49+
"classnames": "^2.2.6",
4850
"git-hooks-wrapper": "^0.7.1",
4951
"jest": "^26.6.3",
5052
"np": "^7.3.0",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type { ClassNames } from "./defs"
1+
export type { ClassNames, ClassValue } from "./defs"
22

33
import classNamingCtx from "./ctx"
44
import classNamesCheck from "./check"

src/versus-classnames.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {classNamesCheck, classNamingBasic, classNamingCtx} from "."
2+
3+
import classnames_default from "classnames"
4+
import classnames_bind from "classnames/bind"
5+
6+
const cssModule = {
7+
"class1": "hash1",
8+
"class2": "hash2"
9+
}
10+
, importRawCss = {}
11+
12+
13+
it("usage interface", () => {
14+
const {class1} = classNamesCheck(importRawCss)
15+
16+
expect(
17+
classNamingBasic({class1})
18+
).toStrictEqual({
19+
//@ts-expect-error `classnames` has no possibility for type hints
20+
className: classnames_default<"class2">("class1")
21+
})
22+
})
23+
24+
it("css module", () => expect({
25+
className: classnames_bind.bind(cssModule)(
26+
// No error on redundant CSS-class
27+
"class1", "class3"
28+
)
29+
}).toStrictEqual(
30+
classNamingCtx({classNames: cssModule})(
31+
"class1",
32+
//@ts-expect-error
33+
"class3"
34+
)
35+
))
36+

0 commit comments

Comments
 (0)