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
1 parent
aece17c
commit 26c7e61
Showing
5 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/yoroi-extension/app/assets/images/forms/close.inline.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/yoroi-extension/app/assets/images/forms/password-eye-close.inline.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/yoroi-extension/app/assets/images/forms/password-eye.inline.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions
94
packages/yoroi-extension/app/components/common/TextField.js
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,94 @@ | ||
/* eslint-disable no-nested-ternary */ | ||
// @flow | ||
import type { Node } from 'react'; | ||
import { IconButton, InputAdornment, TextField as TextFieldBase } from '@mui/material'; | ||
import ErrorIcon from '../../assets/images/forms/error.inline.svg'; | ||
import DoneIcon from '../../assets/images/forms/done.inline.svg'; | ||
import { styled } from '@mui/system'; | ||
import EyeIcon from '../../assets/images/forms/password-eye-close.inline.svg'; | ||
import CloseEyeIcon from '../../assets/images/forms/password-eye.inline.svg'; | ||
import React from 'react'; | ||
|
||
type Props = {| | ||
error?: boolean | string, | ||
done?: boolean, | ||
type: string, | ||
className?: string, | ||
value: any, | ||
disabled?: boolean, | ||
label?: string, | ||
|}; | ||
|
||
export default function TextField({ | ||
label, | ||
value, | ||
disabled, | ||
error, | ||
done, | ||
type, | ||
className, | ||
...props | ||
}: Props): Node { | ||
const [showPassword, setShowPassword] = React.useState(false); | ||
const handleClickShowPassword = () => { | ||
setShowPassword(prev => !prev); | ||
}; | ||
const handleMouseDownPassword = event => { | ||
event.preventDefault(); | ||
}; | ||
return ( | ||
<STextField | ||
fullWidth | ||
className={className} | ||
error={error} | ||
label={label} | ||
value={value} | ||
disabled={disabled} | ||
type={type !== 'password' ? type : showPassword ? 'text' : 'password'} | ||
InputProps={{ | ||
endAdornment: | ||
type === 'password' ? ( | ||
<InputAdornment | ||
position="end" | ||
sx={{ minWidth: '52px', display: 'flex', justifyContent: 'flex-end' }} | ||
> | ||
{error !== null && error === true ? ( | ||
<ErrorIcon /> | ||
) : done !== null && done === true ? ( | ||
<DoneIcon /> | ||
) : null} | ||
<IconButton | ||
aria-label="toggle password visibility" | ||
onClick={handleClickShowPassword} | ||
onMouseDown={handleMouseDownPassword} | ||
edge="end" | ||
> | ||
{showPassword ? <EyeIcon /> : <CloseEyeIcon />} | ||
</IconButton> | ||
</InputAdornment> | ||
) : ( | ||
<InputAdornment position="end"> | ||
{error !== null && error === true ? ( | ||
<ErrorIcon /> | ||
) : done !== null && done === true ? ( | ||
<DoneIcon /> | ||
) : null} | ||
</InputAdornment> | ||
), | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} | ||
TextField.defaultProps = { | ||
label: '', | ||
done: false, | ||
error: '', | ||
className: '', | ||
disabled: false, | ||
}; | ||
const STextField = styled(TextFieldBase)(({ theme }) => ({ | ||
paddingBottom: 20, | ||
marginTop: theme.name === 'classic' ? 0 : 10, | ||
marginBottom: 10, | ||
})); |
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