Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. import React from 'react';
  2. import { TextValidator } from 'react-material-ui-form-validator';
  3. import { withStyles } from '@material-ui/core/styles';
  4. import { InputAdornment } from '@material-ui/core';
  5. import Visibility from '@material-ui/icons/Visibility';
  6. import VisibilityOff from '@material-ui/icons/VisibilityOff';
  7. import IconButton from '@material-ui/core/IconButton';
  8. const styles = theme => (
  9. {
  10. input: {
  11. "&::-ms-reveal": {
  12. display: "none"
  13. }
  14. }
  15. });
  16. class PasswordValidator extends React.Component {
  17. state = {
  18. showPassword: false
  19. };
  20. toggleShowPassword = () => {
  21. this.setState({
  22. showPassword: !this.state.showPassword
  23. });
  24. }
  25. render() {
  26. const { classes, ...rest } = this.props;
  27. return (
  28. <TextValidator
  29. {...rest}
  30. type={this.state.showPassword ? 'text' : 'password'}
  31. InputProps={{
  32. classes,
  33. endAdornment:
  34. <InputAdornment position="end">
  35. <IconButton
  36. aria-label="Toggle password visibility"
  37. onClick={this.toggleShowPassword}
  38. >
  39. {this.state.showPassword ? <Visibility /> : <VisibilityOff />}
  40. </IconButton>
  41. </InputAdornment>
  42. }}
  43. />
  44. );
  45. }
  46. }
  47. export default withStyles(styles)(PasswordValidator);