File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class Example extends PureComponent {
15
15
是否开启: { this . state . value1 ? 'YES' : 'NO' }
16
16
</ div >
17
17
< Switch
18
+ className = "hello"
18
19
isChecked = { this . state . value1 }
19
20
onChange = { this . handleChange ( 'value1' ) }
20
21
/>
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ import clx from 'classnames'
2
2
import React , { PureComponent } from 'react'
3
3
4
4
interface Props {
5
+ /**
6
+ * custom className
7
+ **/
8
+ className ?: string
5
9
/**
6
10
* whether the switch is checked or not
7
11
**/
@@ -15,12 +19,13 @@ interface Props {
15
19
16
20
export class Switch extends PureComponent < Props , { } > {
17
21
render ( ) {
18
- const isChecked = this . props . isChecked
22
+ const { isChecked, className } = this . props
19
23
const switchClass = clx (
20
24
{
21
25
'or-switch-checked' : isChecked
22
26
} ,
23
- 'or-switch'
27
+ 'or-switch' ,
28
+ className
24
29
)
25
30
return (
26
31
< div className = { switchClass } onClick = { this . handleClick } >
Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ import Switch from '../src'
6
6
const mockCallBack = jest . fn ( )
7
7
let wrapper
8
8
describe ( 'src/index' , ( ) => {
9
+ describe ( 'should render properly' , ( ) => {
10
+ it ( '#className' , ( ) => {
11
+ wrapper = mount ( < SwitchWrapper defaultChecked = { true } className = "hello" /> )
12
+ expect ( wrapper . find ( '.or-switch' ) . length ) . toBe ( 1 )
13
+ expect ( wrapper . find ( '.or-switch' ) . hasClass ( 'hello' ) ) . toBe ( true )
14
+ } )
15
+ } )
16
+
9
17
describe ( 'defalult checked' , ( ) => {
10
18
beforeEach ( ( ) => {
11
19
wrapper = mount ( < SwitchWrapper defaultChecked = { true } /> )
@@ -65,6 +73,7 @@ describe('src/index', () => {
65
73
66
74
interface Props {
67
75
defaultChecked : boolean
76
+ className ?: string
68
77
}
69
78
70
79
class SwitchWrapper extends PureComponent < Props , { } > {
@@ -73,7 +82,13 @@ class SwitchWrapper extends PureComponent<Props, {}> {
73
82
}
74
83
75
84
render ( ) {
76
- return < Switch isChecked = { this . state . value } onChange = { this . handleChange } />
85
+ return (
86
+ < Switch
87
+ isChecked = { this . state . value }
88
+ className = { this . props . className }
89
+ onChange = { this . handleChange }
90
+ />
91
+ )
77
92
}
78
93
79
94
handleChange = isChecked => {
You can’t perform that action at this time.
0 commit comments