Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signup password indicator and strength bar
- Loading branch information
1 parent
65f4d2d
commit c40ef4d
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Tooltip } from '@material-ui/core'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
|
||
const HtmlTooltip = withStyles(theme => ({ | ||
tooltip: { | ||
backgroundColor: '#f5f5f9', | ||
color: 'rgba(0, 0, 0, 0.87)', | ||
maxWidth: 220, | ||
fontSize: theme.typography.pxToRem(12), | ||
border: '1px solid rgb(51, 115, 170)', | ||
left: '-5px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
arrow: { | ||
color: '#f5f5f9', | ||
"&::before": { | ||
border: '1px solid rgb(51, 115, 170)', | ||
} | ||
} | ||
}))(Tooltip); | ||
|
||
export default HtmlTooltip; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import PasswordStrengthBar from 'react-password-strength-bar'; | ||
import { TextField } from '@material-ui/core'; | ||
import { get } from 'lodash'; | ||
import HtmlTooltip from './HtmlTooltip'; | ||
import PasswordValidatorIndicator from './PasswordValidatorIndicator'; | ||
|
||
const PasswordFields = ({ | ||
onChange, password, passwordErrors, passwordFieldId, confirmPasswordFieldId | ||
}) => { | ||
const [tooltip, setTooltip] = React.useState(false); | ||
const onBlur = () => setTooltip(true); | ||
const onFocus = () => setTooltip(true) | ||
return ( | ||
<React.Fragment> | ||
<div style={{marginTop: '10px'}}> | ||
<HtmlTooltip | ||
arrow | ||
placement='right' | ||
open={tooltip} | ||
title={<PasswordValidatorIndicator password={password} />} | ||
> | ||
<TextField | ||
required | ||
error={Boolean(passwordErrors)} | ||
helperText={get(passwordErrors, '0')} | ||
label="Password" | ||
variant="outlined" | ||
id={passwordFieldId} | ||
onChange={onChange} | ||
type="password" | ||
fullWidth | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
/> | ||
</HtmlTooltip> | ||
</div> | ||
<div style={{marginTop: '10px'}}> | ||
<TextField | ||
required | ||
label="Confirm Password" | ||
variant="outlined" | ||
id={confirmPasswordFieldId} | ||
onChange={onChange} | ||
type="password" | ||
fullWidth | ||
/> | ||
</div> | ||
<PasswordStrengthBar password={password} minLength={8} className='password-strength' /> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default PasswordFields; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { | ||
CheckCircle as CorrectIcon, Cancel as WrongIcon | ||
} from '@material-ui/icons'; | ||
import { ERROR_RED, BLUE } from '../../common/constants'; | ||
import { merge } from 'lodash'; | ||
|
||
const correctIcon = <CorrectIcon color='primary' fontSize='inherit'/>; | ||
const incorrectIcon = <WrongIcon fontSize='inherit' style={{color: ERROR_RED}}/>; | ||
|
||
const Indicator = (predicate, label) => { | ||
const commonSpanStyles = {marginLeft: '5px'} | ||
const getStyles = predicate => predicate ? {color: BLUE} : {color: ERROR_RED}; | ||
|
||
return ( | ||
<div className='flex-vertical-center'> | ||
{ | ||
predicate ? correctIcon : incorrectIcon | ||
} | ||
<span style={merge(commonSpanStyles, getStyles(predicate))}> | ||
{label} | ||
</span> | ||
</div> | ||
)} | ||
|
||
const PasswordValidatorIndicator = ({password}) => { | ||
const hasMinLength = Boolean(password && password.length >= 8) | ||
const hasAlphabets = Boolean(password && password.match(new RegExp(/[a-zA-Z]/g))) | ||
|
||
return ( | ||
<React.Fragment> | ||
<div className='col-md-12 no-side-padding' style={{fontSize: '12px'}}> | ||
{ | ||
Indicator(hasMinLength, 'Must be min 8 Characters.') | ||
} | ||
{ | ||
Indicator(hasAlphabets, 'Must have alphabets (a-zA-Z).') | ||
} | ||
</div> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default PasswordValidatorIndicator; |
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