Skip to content

Commit 2606dcb

Browse files
committed
password module example simplified
1 parent 04bcf9f commit 2606dcb

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

example/scripts/Root.jsx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,45 @@ import ReactDOM from 'react-dom';
44

55
import Password from '../../src';
66

7-
const Root = () => (
8-
<div>
9-
<Password
10-
uppercase
11-
lowercase
12-
digits
13-
onChange={(valid, password) => { console.log(valid, password)}}
14-
/>
15-
</div>
16-
);
7+
class Root extends React.Component {
8+
constructor() {
9+
super();
10+
this.state = {
11+
passwordValid: false,
12+
password: '',
13+
};
14+
15+
this.handleOnChange = this.handleOnChange.bind(this);
16+
}
17+
18+
handleOnChange(passwordValid, password) {
19+
this.setState({
20+
passwordValid,
21+
password,
22+
});
23+
}
24+
25+
renderPasswordValidity() {
26+
return this.state.passwordValid ?
27+
<span style={{ color: 'green' }}>Valid</span> :
28+
<span style={{ color: 'red' }}>Invalid</span>
29+
}
30+
31+
render() {
32+
return (
33+
<div>
34+
<Password
35+
uppercase
36+
lowercase
37+
digits
38+
onChange={this.handleOnChange}
39+
/>
40+
<div>
41+
The password text is <b>{this.state.password}</b> and it is {this.renderPasswordValidity()} password
42+
</div>
43+
</div>
44+
)
45+
}
46+
}
1747

1848
ReactDOM.render(<Root />, document.getElementById('app'));

0 commit comments

Comments
 (0)