Skip to content

Commit 3443127

Browse files
committed
add layout and theme components
1 parent 077e274 commit 3443127

File tree

8 files changed

+76
-2
lines changed

8 files changed

+76
-2
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"presets": [
1212
"next/babel",
1313
"@zeit/next-typescript/babel"
14-
]
14+
],
1515
"plugins": [["styled-components", { "ssr": true }]]
1616
},
1717
"test": {

pages/_app.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import App, { Container } from 'next/app'
2+
import * as React from 'react'
3+
4+
import { Layout } from "../src/components/Layout"
5+
6+
export default class MyApp extends App {
7+
public render () {
8+
const { Component, pageProps } = this.props
9+
return (
10+
<Container>
11+
<Layout>
12+
<Component {...pageProps} />
13+
</Layout>
14+
</Container>
15+
)
16+
}
17+
}

src/components/Layout.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Head from 'next/head'
2+
import * as React from "react"
3+
4+
import { LayoutProps } from "./types"
5+
6+
import { ThemeProvider } from "../theme/styled-components"
7+
import { defaultTheme } from "../theme/theme"
8+
9+
export const Layout: React.SFC<LayoutProps> = ({
10+
children,
11+
title = "Next.js Boilerplate",
12+
theme = defaultTheme
13+
}) => (
14+
<ThemeProvider theme={theme}>
15+
<React.Fragment>
16+
<Head>
17+
<title>{title}</title>
18+
<meta charSet='utf-8' />
19+
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
20+
</Head>
21+
22+
{children}
23+
</React.Fragment>
24+
25+
</ThemeProvider>
26+
);

src/components/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { IThemeInterface } from "../theme/types"
2+
3+
export type LayoutProps = {
4+
title?: string;
5+
theme?: IThemeInterface;
6+
}

src/theme/styled-components.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as styledComponents from "styled-components";
2+
import { ThemedStyledComponentsModule } from "styled-components";
3+
4+
import { IThemeInterface } from "./types";
5+
6+
const {
7+
default: styled,
8+
css,
9+
createGlobalStyle,
10+
keyframes,
11+
ThemeProvider
12+
} = styledComponents as ThemedStyledComponentsModule<IThemeInterface>;
13+
14+
export { css, createGlobalStyle, keyframes, ThemeProvider };
15+
export default styled;

src/theme/theme.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { IThemeInterface } from "./types";
2+
3+
export const defaultTheme: IThemeInterface = {
4+
primaryColor: "#000"
5+
};

src/theme/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface IThemeInterface {
2+
primaryColor: string;
3+
}

tslint.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"defaultSeverity": "error",
33
"extends": ["tslint:recommended", "tslint-config-prettier"],
44
"jsRules": {},
5-
"rules": {},
5+
"rules": {
6+
"interface-over-type-literal": false
7+
},
68
"rulesDirectory": []
79
}

0 commit comments

Comments
 (0)