Skip to content

Commit

Permalink
Fixed #239
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Dec 10, 2017
1 parent 745c340 commit 7b69da7
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions src/components/password/Password.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class Password extends Component {
};

static propTypes = {
promptLabel:PropTypes.string,
weakLabel:PropTypes.string,
mediumLabel:PropTypes.string,
promptLabel: PropTypes.string,
weakLabel: PropTypes.string,
mediumLabel: PropTypes.string,
strongLabel:PropTypes.string,
feedback:PropTypes.bool
feedback: PropTypes.bool
};

constructor(props) {
Expand All @@ -31,55 +31,62 @@ export class Password extends Component {
}

onFocus(e) {
if(!this.panel) {
this.createPanel();
if (this.props.feedback) {
if (!this.panel) {
this.createPanel();
}

this.panel.style.zIndex = String(DomHandler.getZindex());
DomHandler.absolutePosition(this.panel, this.inputEl);
this.panel.style.display = 'block';
DomHandler.fadeIn(this.panel, 250);
}
this.panel.style.zIndex = String(DomHandler.getZindex());
DomHandler.absolutePosition(this.panel, this.inputEl);
this.panel.style.display = 'block';
DomHandler.fadeIn(this.panel, 250);

if(this.props.onFocus) {

if (this.props.onFocus) {
this.props.onFocus(e);
}
}

onBlur(e) {
this.panel.style.display = 'none';
if (this.props.feedback) {
this.panel.style.display = 'none';
}

if (this.props.onBlur) {
this.props.onBlur(e);
}
}

onKeyup(e) {
let value = e.target.value,
label = null,
meterPos = null;

if(value.length === 0) {
label = this.props.promptLabel;
meterPos = '0px 0px';
}
else {
var score = this.testStrength(value);

if(score < 30) {
label = this.props.weakLabel;
meterPos = '0px -10px';
if(this.props.feedback) {
let value = e.target.value,
label = null,
meterPos = null;

if(value.length === 0) {
label = this.props.promptLabel;
meterPos = '0px 0px';
}
else if(score >= 30 && score < 80) {
label = this.props.mediumLabel;
meterPos = '0px -20px';
}
else if(score >= 80) {
label = this.props.strongLabel;
meterPos = '0px -30px';
else {
var score = this.testStrength(value);

if(score < 30) {
label = this.props.weakLabel;
meterPos = '0px -10px';
}
else if(score >= 30 && score < 80) {
label = this.props.mediumLabel;
meterPos = '0px -20px';
}
else if(score >= 80) {
label = this.props.strongLabel;
meterPos = '0px -30px';
}
}
}

this.meter.style.backgroundPosition = meterPos;
this.info.textContent = label;
this.meter.style.backgroundPosition = meterPos;
this.info.textContent = label;
}

if (this.props.onKeyUp) {
this.props.onKeyUp(e);
Expand Down Expand Up @@ -131,7 +138,7 @@ export class Password extends Component {
}

componentWillUnmount() {
if(this.panel) {
if(this.feedback && this.panel) {
this.panel.removeChild(this.meter);
this.panel.removeChild(this.info);
document.body.removeChild(this.panel);
Expand Down

0 comments on commit 7b69da7

Please sign in to comment.