Created
September 2, 2019 14:04
-
-
Save ovpv/789f1670cb85400935b564386bf699a2 to your computer and use it in GitHub Desktop.
Meter component to show the password strength
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Meter extends React.Component{ | |
constructor(){ | |
super(); | |
this.state={ | |
status: "low" | |
} | |
} | |
componentDidUpdate(prevprops,state){ | |
this.changeStatus(this.props.value); | |
} | |
changeStatus = (value) => { | |
switch(value){ | |
case 10: | |
this.setState({ | |
status: "low" | |
}) | |
break; | |
case 50: | |
this.setState({ | |
status: "medium" | |
}) | |
break; | |
case 100: | |
this.setState({ | |
status: "high" | |
}) | |
break; | |
} | |
} | |
render(){ | |
return ( | |
<span className={`progress ${this.state.status}`}></span> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment