Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 59 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from "react" |
||
2 | import type { ClassNames, ClassNamesProperty, ClassHash } from "../src/" |
||
3 | import classNaming from "../src/" |
||
4 | import expectRender from "../expect-to-same-render" |
||
5 | |||
6 | const {classnames}: ClassNames<typeof App> = { |
||
7 | classnames: { |
||
8 | "App__Item": "hash", |
||
9 | class1: "hash1", |
||
10 | class2: "hash2" |
||
11 | } |
||
12 | } |
||
13 | |||
14 | function App({classnames, className}: ClassNames< |
||
15 | true, |
||
16 | ClassNamesProperty<{App__Item: ClassHash}>, |
||
17 | typeof Component |
||
18 | >) { |
||
19 | return <Component {...{ |
||
20 | ...classNaming({ |
||
21 | classnames, className |
||
22 | })( |
||
23 | true, {App__Item: true} |
||
24 | ), |
||
25 | classnames |
||
26 | }}/> |
||
27 | } |
||
28 | |||
29 | function Component(props: ClassNames<true, ClassNamesProperty<{class1: ClassHash, class2: ClassHash}>>) { |
||
30 | const classes = classNaming(props) |
||
31 | return <> |
||
32 | <div {...classes(true, {class1: true, class2: false})}/> |
||
33 | <div {...classes({class2: true})}/> |
||
34 | </> |
||
35 | } |
||
36 | |||
37 | it("not propagate classnames", () => { |
||
38 | const App = ({classnames, className}: ClassNames< |
||
39 | true, |
||
40 | ClassNamesProperty<{App__Item: ClassHash}>, |
||
41 | typeof Component> |
||
42 | ) => |
||
43 | //@ts-expect-error Types of property classnames are incompatible Type undefined is not assignable |
||
44 | <Component { |
||
45 | ...classNaming({ |
||
46 | classnames, className |
||
47 | })( |
||
48 | true, {App__Item: true} |
||
49 | )} |
||
50 | /> |
||
51 | |||
52 | expectRender( |
||
53 | <App className="MyApp" classnames={classnames}/> |
||
54 | ).toSame( |
||
55 | <div className="MyApp hash class1" />, |
||
56 | <div className="class2" /> |
||
57 | ) |
||
58 | }) |
||
59 |