Prettier support
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, {Component} from 'react';
|
||||
import React, { Component } from 'react';
|
||||
import './Password.css';
|
||||
import {faEye, faEyeSlash} from '@fortawesome/free-solid-svg-icons';
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||
import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
|
||||
export default class Password extends Component {
|
||||
state = {
|
||||
@@ -12,14 +12,14 @@ export default class Password extends Component {
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
if (!this.props.value || (this.props.value.length === 0)) {
|
||||
if (!this.props.value || this.props.value.length === 0) {
|
||||
this.setState({
|
||||
...this.state,
|
||||
button_text: 'set',
|
||||
password: '',
|
||||
password2: '',
|
||||
show_password: false,
|
||||
})
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
...this.state,
|
||||
@@ -27,7 +27,7 @@ export default class Password extends Component {
|
||||
password: this.props.value,
|
||||
password2: '',
|
||||
show_password: false,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,20 +48,26 @@ export default class Password extends Component {
|
||||
this.props.changed(this.state.password);
|
||||
this.setState({
|
||||
...this.state,
|
||||
button_text: this.state.password && this.state.password.length > 0 ? 'clear' : 'set',
|
||||
button_text:
|
||||
this.state.password && this.state.password.length > 0
|
||||
? 'clear'
|
||||
: 'set',
|
||||
password2: '',
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
...this.state,
|
||||
button_text: 'set',
|
||||
password: '',
|
||||
password2: '',
|
||||
}, () => {
|
||||
if (this.props.mismatchHandler) {
|
||||
this.props.mismatchHandler();
|
||||
this.setState(
|
||||
{
|
||||
...this.state,
|
||||
button_text: 'set',
|
||||
password: '',
|
||||
password2: '',
|
||||
},
|
||||
() => {
|
||||
if (this.props.mismatchHandler) {
|
||||
this.props.mismatchHandler();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -79,7 +85,7 @@ export default class Password extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
handlePasswordChanged = e => {
|
||||
handlePasswordChanged = (e) => {
|
||||
if (this.state.button_text === 'set') {
|
||||
this.setState({
|
||||
...this.state,
|
||||
@@ -93,8 +99,11 @@ export default class Password extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
handlePasswordKeyUp = e => {
|
||||
if ((e.keyCode === 13) && ((this.state.button_text === 'confirm') || (this.state.button_text === 'set'))) {
|
||||
handlePasswordKeyUp = (e) => {
|
||||
if (
|
||||
e.keyCode === 13 &&
|
||||
(this.state.button_text === 'confirm' || this.state.button_text === 'set')
|
||||
) {
|
||||
this.handleActionClick();
|
||||
}
|
||||
};
|
||||
@@ -108,28 +117,41 @@ export default class Password extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className={'PasswordOwner'} style={{...this.props.style}}>
|
||||
{
|
||||
this.props.readOnly ? null : <a href={'#'}
|
||||
className={'PasswordLink'}
|
||||
onClick={this.handleActionClick}>
|
||||
<div className={'PasswordOwner'} style={{ ...this.props.style }}>
|
||||
{this.props.readOnly ? null : (
|
||||
<a
|
||||
href={'#'}
|
||||
className={'PasswordLink'}
|
||||
onClick={this.handleActionClick}
|
||||
>
|
||||
<u>{this.state.button_text}</u>
|
||||
</a>
|
||||
}
|
||||
<input autoFocus={this.props.autoFocus}
|
||||
readOnly={this.props.readOnly}
|
||||
className={'PasswordInput'}
|
||||
disabled={this.props.readOnly || (this.state.button_text === 'clear')}
|
||||
onChange={this.handlePasswordChanged}
|
||||
onKeyUp={this.handlePasswordKeyUp}
|
||||
type={this.state.show_password ? 'text' : 'password'}
|
||||
value={(this.state.button_text === 'confirm') ? this.state.password2 : this.state.password}/>
|
||||
<a href={'#'}
|
||||
className={'PasswordShowHide'}
|
||||
onClick={this.handleShowHideClick}>
|
||||
<FontAwesomeIcon icon={this.state.show_password ? faEye : faEyeSlash} fixedWidth/>
|
||||
)}
|
||||
<input
|
||||
autoFocus={this.props.autoFocus}
|
||||
readOnly={this.props.readOnly}
|
||||
className={'PasswordInput'}
|
||||
disabled={this.props.readOnly || this.state.button_text === 'clear'}
|
||||
onChange={this.handlePasswordChanged}
|
||||
onKeyUp={this.handlePasswordKeyUp}
|
||||
type={this.state.show_password ? 'text' : 'password'}
|
||||
value={
|
||||
this.state.button_text === 'confirm'
|
||||
? this.state.password2
|
||||
: this.state.password
|
||||
}
|
||||
/>
|
||||
<a
|
||||
href={'#'}
|
||||
className={'PasswordShowHide'}
|
||||
onClick={this.handleShowHideClick}
|
||||
>
|
||||
<FontAwesomeIcon
|
||||
icon={this.state.show_password ? faEye : faEyeSlash}
|
||||
fixedWidth
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user