-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.js
78 lines (69 loc) · 1.53 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import ReactDom from 'react-dom';
import Switch from './index';
import React from 'react';
import './test.css';
class SwitchLabel extends React.Component {
constructor(props) {
super(props);
this.onValueChanged = this.onValueChanged.bind(this);
this.state = {
isOpen: true
};
}
onValueChanged(isOpen) {
this.setState({
isOpen
});
console.log(isOpen);
}
componentDidMount() {
let {
isOpen
} = this.props;
if(isOpen === false) {
this.setState({
isOpen
});
}
}
render() {
let {
isOpen
} = this.state;
return (
<div className="wrapper">
<label>{isOpen ? '开' : '关'}</label>
<Switch {...this.props} onValueChanged={this.onValueChanged}/>
</div>
);
}
}
class App extends React.Component {
constructor(props) {
super(props);
this.onBtnClick = this.onBtnClick.bind(this);
this.state = {
isOpen: false
}
this.onValueChanged = this.onValueChanged.bind(this);
}
onBtnClick() {
this.isOpen = !this.isOpen;
this.setState({
isOpen: this.isOpen
});
}
onValueChanged(isOpen) {
this.isOpen = isOpen;
}
render() {return (
<div>
<SwitchLabel/>
<SwitchLabel isOpen={true} color="blue" size="small"/>
<SwitchLabel isOpen={this.state.isOpen} onValueChanged={this.onValueChanged} color="blue"/>
<button onClick={this.onBtnClick}> Toggle </button>
</div>
);
}
}
ReactDom.render(<App/>,document.getElementById('app'))