Skip to content

Commit 9bb2333

Browse files
committed
Add Page component for layout
1 parent b4688bc commit 9bb2333

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react'
2+
import { shallow } from 'enzyme'
3+
import Page from './Page'
4+
5+
describe('<Page />', () => {
6+
it('should use children', () => {
7+
const page = shallow(<Page title='title'>Cool</Page>)
8+
expect(page).toIncludeText('Cool')
9+
})
10+
})

components/Common/components/Page.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react'
2+
import Head from 'next/head'
3+
4+
export default ({ title, children }) =>
5+
<div>
6+
<style jsx>{`
7+
main {
8+
margin: 6em auto;
9+
width: 40em;
10+
}
11+
`}</style>
12+
13+
<Head>
14+
<title>{title}</title>
15+
</Head>
16+
17+
<main>
18+
{children}
19+
</main>
20+
</div>

components/Common/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Page from './components/Page'
2+
3+
export { Page }

pages/users/profile.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import * as React from 'react'
22
import app from '../../lib/app'
3+
import User from '../../lib/user/User'
4+
import { Page } from '../../components/Common'
35
import { Profile } from '../../components/User'
46

57
export default app.page(class extends React.Component {
68
props: {
7-
user: {
8-
name: string,
9-
biography: string,
10-
twitter: string
11-
}
9+
user: User
1210
}
1311

1412
render () {
1513
return (
16-
<div>
17-
<h1>Hello world!</h1>
18-
14+
<Page title={this.props.user.name}>
1915
<Profile {...this.props.user} />
20-
</div>
16+
</Page>
2117
)
2218
}
2319
})

0 commit comments

Comments
 (0)