-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 export email textfield component, improve logic and doc
- Loading branch information
1 parent
2a0a7f2
commit 9887480
Showing
6 changed files
with
130 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import { | ||
CircularProgress, IconButton, TextField, useTheme, TextFieldProps, | ||
} from '@mui/material'; | ||
import { Icon } from '@iconify/react'; | ||
import { ProviderConfig } from './AuthDialog'; | ||
|
||
export type EmailFieldProps = { | ||
TextFieldProps?: TextFieldProps, | ||
email: string; | ||
emailLoading?: boolean, | ||
emailProviderConfig?: ProviderConfig, | ||
onChangeEmail: (email: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void; | ||
onSubmitEmail: () => void; | ||
validEmail?: boolean | ||
} | ||
|
||
export function EmailField(props: EmailFieldProps) { | ||
const theme = useTheme(); | ||
return ( | ||
<TextField | ||
required | ||
fullWidth | ||
type="email" | ||
autoFocus | ||
value={props.email} | ||
onChange={(e) => props.onChangeEmail(e)} | ||
onKeyDown={async (e) => { | ||
if (e.key === 'Enter' && props.validEmail) { | ||
await props.onSubmitEmail(); | ||
} | ||
}} | ||
InputProps={{ | ||
startAdornment: ( | ||
<IconButton | ||
disableRipple | ||
sx={{ | ||
cursor: 'unset', | ||
}} | ||
> | ||
<Icon icon="mdi:email-outline" /> | ||
</IconButton> | ||
), | ||
endAdornment: ( | ||
<IconButton disabled={!props.validEmail} onClick={props.onSubmitEmail}> | ||
{props.emailLoading ? ( | ||
<CircularProgress size={theme.spacing(3)} /> | ||
) : ( | ||
<Icon icon="mdi:send-outline" /> | ||
)} | ||
</IconButton> | ||
), | ||
}} | ||
placeholder={props.emailProviderConfig?.name || props.emailProviderConfig?.placeholder || 'Email'} | ||
helperText={props.emailProviderConfig?.helperText || 'A sign-in link will be sent to your inbox.'} | ||
{...props.TextFieldProps} | ||
{...props.emailProviderConfig?.EmailFieldProps} | ||
/> | ||
); | ||
} |
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 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