react-feather#EyeOff TypeScript Examples
The following examples show how to use
react-feather#EyeOff.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PasswordTextField.tsx From firebase-react-typescript-project-template with MIT License | 4 votes |
PasswordTextField = ({
onChangePassword,
onChangeValid,
onChangeShowPassword,
showPassword,
className,
}: Props) => {
const classes = useStyles();
const [errors, setErrors] = useState<string[]>([]);
const handleChange = () => {
if (errors.length > 0) {
setErrors([]);
onChangeValid(true);
}
};
const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
const password = event.target.value;
if (password) {
onChangePassword(password);
const errors = [];
// length
if (password.match(/^(?=.{6,26})/g) === null)
errors.push(errorMessages.length);
// lower case
if (password.match(/^(?=.*[a-z])/g) === null)
errors.push(errorMessages.lowerCase);
// upper case
if (password.match(/^(?=.*[A-Z])/g) === null)
errors.push(errorMessages.upperCase);
// number
if (password.match(/^(?=.*[0-9])/g) === null)
errors.push(errorMessages.number);
// special char
// if (password.match(/^(?=.*[!@#$%^&*])/g) === null) errors.push(errorMessages.specialChar);
// spaces
if (password.match(/\s/g) !== null) errors.push(errorMessages.noSpaces);
onChangeValid(errors.length === 0);
setErrors(errors);
}
};
return (
<TextField
id="email"
color="secondary"
name="password"
autoComplete="password"
onChange={handleChange}
onBlur={handleBlur}
label="Password"
variant="outlined"
type={showPassword ? "text" : "password"}
size="small"
required
className={className}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
aria-label="Toggle password visibility"
onClick={onChangeShowPassword}
className={classes.iconButton}
>
{showPassword ? <EyeOff size={20} /> : <Eye size={20} />}
</IconButton>
</InputAdornment>
),
}}
error={Boolean(errors.length)}
helperText={
errors.length > 0 && (
<>
<FormHelperText id="name-error-text">
Password must contain:
</FormHelperText>
{errors.map((error) => (
<FormHelperText id="name-error-text">- {error}</FormHelperText>
))}
</>
)
}
/>
);
}