-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
61 deletions.
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 |
---|---|---|
@@ -1,32 +1,52 @@ | ||
import React from 'react'; | ||
import { TextField, Grid, InputAdornment, IconButton } from '@material-ui/core'; | ||
import React, { useState } from "react"; | ||
import { TextField, Grid, InputAdornment, IconButton } from "@material-ui/core"; | ||
|
||
import Visibility from '@material-ui/icons/Visibility'; | ||
import VisibilityOff from '@material-ui/icons/VisibilityOff'; | ||
import Visibility from "@material-ui/icons/Visibility"; | ||
import VisibilityOff from "@material-ui/icons/VisibilityOff"; | ||
|
||
const Field = ({ name, handleChange, label, half, autoFocus, type, handleShowPassword, placeholder }) => ( | ||
<Grid item xs={12} sm={half ? 6 : 12}> | ||
<TextField | ||
name={name} | ||
onChange={handleChange} | ||
placeholder={placeholder} | ||
variant="outlined" | ||
required | ||
fullWidth | ||
label={label} | ||
autoFocus={autoFocus} | ||
type={type} | ||
InputProps={name === 'password' ? { | ||
endAdornment: ( | ||
<InputAdornment position="end"> | ||
<IconButton onClick={handleShowPassword}> | ||
{type === 'password' ? <Visibility /> : <VisibilityOff />} | ||
</IconButton> | ||
</InputAdornment> | ||
), | ||
} : null} | ||
/> | ||
</Grid> | ||
); | ||
const Field = ({ | ||
name, | ||
handleChange, | ||
label, | ||
half, | ||
autoFocus, | ||
type, | ||
placeholder, | ||
}) => { | ||
const [showPass, setShowPass] = useState(false); | ||
|
||
export default Field | ||
const togglePasswordVisibility = () => { | ||
setShowPass((show) => !show); | ||
}; | ||
|
||
return ( | ||
<Grid item xs={12} sm={half ? 6 : 12}> | ||
<TextField | ||
name={name} | ||
onChange={handleChange} | ||
placeholder={placeholder} | ||
variant="outlined" | ||
required | ||
fullWidth | ||
label={label} | ||
autoFocus={autoFocus} | ||
type={showPass ? "text" : type} | ||
InputProps={ | ||
name === "password" | ||
? { | ||
endAdornment: ( | ||
<InputAdornment position="end"> | ||
<IconButton onClick={togglePasswordVisibility}> | ||
{!showPass ? <Visibility /> : <VisibilityOff />} | ||
</IconButton> | ||
</InputAdornment> | ||
), | ||
} | ||
: null | ||
} | ||
/> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default Field; |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.