Skip to content

Commit 2fd8c1a

Browse files
author
Víctor Borrego Pérez
committed
Update Readme.md - Adding classes to LoginForm component
1 parent b23ef61 commit 2fd8c1a

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

hooks/13_LoginForm/Readme.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const LoginPageInner = (props: Props) => {
166166
);
167167
};
168168

169-
export const LoginPage = withRouter<Props>(LoginPageInner);
169+
export const LoginPage = withRouter < Props > LoginPageInner;
170170
```
171171

172172
- This can be ok, but if we take a deeper look to this component, we could break down into two, one is the card itself the other the form dialog, so it should finally look like:
@@ -454,6 +454,62 @@ const LoginForm = (props: PropsForm) => {
454454
};
455455
```
456456

457+
- We will add material-ui classes to LoginForm component.
458+
459+
_./src/pages/loginPage.tsx_
460+
461+
```diff
462+
interface PropsForm {
463+
onLogin: () => void;
464+
onUpdateField: (name: string, value: any) => void;
465+
loginInfo : LoginEntity;
466+
}
467+
468+
+ // https://material-ui.com/styles/api/#makestyles-styles-options-hook
469+
+ const useFormStyles = makeStyles(theme =>
470+
+ createStyles({
471+
+ formContainer: {
472+
+ display: "flex",
473+
+ flexDirection: "column",
474+
+ justifyContent: "center"
475+
+ }
476+
+ })
477+
+ );
478+
479+
const LoginForm = (props: PropsForm) => {
480+
+ const classes = useFormStyles();
481+
const { onLogin, onUpdateField, loginInfo } = props;
482+
483+
// TODO: Enhacement move this outside the stateless component discuss why is a good idea
484+
const onTexFieldChange = (fieldId) => (e) => {
485+
onUpdateField(fieldId, e.target.value);
486+
}
487+
488+
return (
489+
- <div
490+
- style={{
491+
- display: "flex",
492+
- flexDirection: "column",
493+
- justifyContent: "center"
494+
- }}
495+
- >
496+
+ <div className={classes.formContainer}>
497+
<TextField label="Name" margin="normal"
498+
value={loginInfo.login}
499+
onChange={onTexFieldChange('login')}
500+
/>
501+
<TextField label="Password" type="password" margin="normal"
502+
value={loginInfo.password}
503+
onChange={onTexFieldChange('password')}
504+
/>
505+
<Button variant="contained" color="primary" onClick={onLogin}>
506+
Login
507+
</Button>
508+
</div>
509+
);
510+
};
511+
```
512+
457513
- Let's display a notification when the login validation fails.
458514

459515
- First we will create a simple notification component, base on _react material ui_ _snackbar_

0 commit comments

Comments
 (0)