-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix layout margin with material-ui CssBaseline
- Abstract components from App to files - Add tests for components
- Loading branch information
Showing
10 changed files
with
211 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
|
||
const About = () => ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<h2>About</h2> | ||
</React.Fragment> | ||
); | ||
|
||
export default About; |
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,12 @@ | ||
import React from 'react'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
|
||
|
||
const Home = () => ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<h2>Home</h2> | ||
</React.Fragment> | ||
); | ||
|
||
export default Home; |
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,92 @@ | ||
|
||
import React from 'react'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
import Button from '@material-ui/core/Button'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import FormControl from '@material-ui/core/FormControl'; | ||
import Input from '@material-ui/core/Input'; | ||
import InputLabel from '@material-ui/core/InputLabel'; | ||
import LockOutlinedIcon from '@material-ui/icons/LockOutlined'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { withTheme } from '@material-ui/core/styles'; | ||
import styled from 'styled-components'; | ||
|
||
const Base = styled.main` | ||
width: auto; | ||
display: block; | ||
margin-left: ${theme => theme.spacing.unit * 3}px; | ||
margin-right: ${theme => theme.spacing.unit * 3}px; | ||
${theme => theme.breakpoints.up('md')} { | ||
width: 400; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
;`; | ||
|
||
const PaperStyled = styled(Paper)` | ||
margin-top: ${theme => theme.spacing.unit * 8}px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: ${theme => theme.spacing.unit * 2}px ${theme => theme.spacing.unit * 3}px ${theme => theme.spacing.unit * 3}px; | ||
}} | ||
`; | ||
|
||
const AvatarStyled = styled(Avatar)` | ||
margin: ${theme => theme.spacing.unit}px; | ||
background-color: ${theme => theme.palette.secondary.main}; | ||
`; | ||
|
||
const Form = styled.form` | ||
width: 100%; | ||
margin-top: ${theme => theme.spacing.unit}px; | ||
`; | ||
|
||
const SubmitButtonStyled = styled(Button)` | ||
margin-top: ${theme => theme.spacing.unit * 3}px; | ||
`; | ||
|
||
const SignUp = (props) => { | ||
// eslint-disable-next-line react/prop-types | ||
const { theme } = props; | ||
const { zIndex, ...rest } = theme; | ||
return ( | ||
<Base {...rest}> | ||
<CssBaseline /> | ||
<PaperStyled {...rest}> | ||
<AvatarStyled {...rest}> | ||
<LockOutlinedIcon /> | ||
</AvatarStyled> | ||
<Typography component="h1" variant="h5"> | ||
Sign up | ||
</Typography> | ||
<Form {...rest}> | ||
<FormControl margin="normal" required fullWidth> | ||
<InputLabel htmlFor="email">Email Address</InputLabel> | ||
<Input id="email" name="email" autoComplete="email" autoFocus /> | ||
</FormControl> | ||
<FormControl margin="normal" required fullWidth> | ||
<InputLabel htmlFor="password">Password</InputLabel> | ||
<Input name="password" type="password" id="password" autoComplete="current-password" /> | ||
</FormControl> | ||
<FormControl margin="normal" required fullWidth> | ||
<InputLabel htmlFor="confirm-password">Password</InputLabel> | ||
<Input name="confirm-password" type="password" id="confirm-password" autoComplete="current-password" /> | ||
</FormControl> | ||
<SubmitButtonStyled | ||
type="submit" | ||
fullWidth | ||
variant="contained" | ||
color="primary" | ||
{...rest} | ||
> | ||
Sign up | ||
</SubmitButtonStyled> | ||
</Form> | ||
</PaperStyled> | ||
</Base> | ||
); | ||
}; | ||
|
||
export default withTheme()(SignUp); |
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,11 @@ | ||
import React from 'react'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
|
||
const Users = () => ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<h2>Users</h2> | ||
</React.Fragment> | ||
); | ||
|
||
export default Users; |
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,26 @@ | ||
import React from 'react'; | ||
import { render, waitForElement } from 'react-testing-library'; | ||
import { | ||
Router, | ||
} from 'react-router-dom'; | ||
import { createMemoryHistory } from 'history'; | ||
import About from '../About'; | ||
|
||
const renderWithRouter = ( | ||
ui, | ||
{ route = '/', history = createMemoryHistory({ initialEntries: [route] }) } = {}, | ||
) => ({ | ||
...render(<Router history={history}>{ui}</Router>), | ||
history, | ||
}); | ||
|
||
const renderComponent = () => renderWithRouter( | ||
<About />, | ||
); | ||
|
||
describe('Test About', () => { | ||
test('it renders About text', async () => { | ||
const { getByText } = renderComponent(); | ||
await waitForElement(() => getByText(/About/i)); | ||
}); | ||
}); |
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,26 @@ | ||
import React from 'react'; | ||
import { render, waitForElement } from 'react-testing-library'; | ||
import { | ||
Router, | ||
} from 'react-router-dom'; | ||
import { createMemoryHistory } from 'history'; | ||
import Home from '../Home'; | ||
|
||
const renderWithRouter = ( | ||
ui, | ||
{ route = '/', history = createMemoryHistory({ initialEntries: [route] }) } = {}, | ||
) => ({ | ||
...render(<Router history={history}>{ui}</Router>), | ||
history, | ||
}); | ||
|
||
const renderComponent = () => renderWithRouter( | ||
<Home />, | ||
); | ||
|
||
describe('Test Home', () => { | ||
test('it renders Home text', async () => { | ||
const { getByText } = renderComponent(); | ||
await waitForElement(() => getByText(/Home/i)); | ||
}); | ||
}); |
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,26 @@ | ||
import React from 'react'; | ||
import { render, waitForElement } from 'react-testing-library'; | ||
import { | ||
Router, | ||
} from 'react-router-dom'; | ||
import { createMemoryHistory } from 'history'; | ||
import SignUp from '../SignUp'; | ||
|
||
const renderWithRouter = ( | ||
ui, | ||
{ route = '/', history = createMemoryHistory({ initialEntries: [route] }) } = {}, | ||
) => ({ | ||
...render(<Router history={history}>{ui}</Router>), | ||
history, | ||
}); | ||
|
||
const renderComponent = () => renderWithRouter( | ||
<SignUp />, | ||
); | ||
|
||
describe('Test SignUp', () => { | ||
test('it renders Sign up text', async () => { | ||
const { getByText } = renderComponent(); | ||
await waitForElement(() => getByText(/Sign up/i)); | ||
}); | ||
}); |