Skip to content

Commit 485c65e

Browse files
committed
chore: test styled-components
1 parent 9e0311c commit 485c65e

File tree

5 files changed

+343
-85
lines changed

5 files changed

+343
-85
lines changed

demos/default/pages/_app.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1-
import '../styles/globals.css'
1+
import { createGlobalStyle, ThemeProvider } from 'styled-components'
22

3-
function MyApp({ Component, pageProps }) {
4-
return <Component {...pageProps} />
3+
const GlobalStyle = createGlobalStyle`
4+
html,
5+
body {
6+
padding: 0;
7+
box-sizing: border-box;
8+
margin: 0;
9+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
10+
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
511
}
612
7-
export default MyApp
13+
a {
14+
color: inherit;
15+
text-decoration: none;
16+
}
17+
18+
* {
19+
box-sizing: border-box;
20+
}
21+
22+
`
23+
24+
const theme = {
25+
colors: {
26+
primary: '#0070f3',
27+
},
28+
}
29+
30+
export default function App({ Component, pageProps }) {
31+
return (
32+
<>
33+
<GlobalStyle />
34+
<ThemeProvider theme={theme}>
35+
<Component {...pageProps} />
36+
</ThemeProvider>
37+
</>
38+
)
39+
}

demos/default/pages/_document.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Document from 'next/document'
2+
import { ServerStyleSheet } from 'styled-components'
3+
4+
export default class MyDocument extends Document {
5+
static async getInitialProps(ctx) {
6+
const sheet = new ServerStyleSheet()
7+
const originalRenderPage = ctx.renderPage
8+
9+
try {
10+
ctx.renderPage = () =>
11+
originalRenderPage({
12+
enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
13+
})
14+
15+
const initialProps = await Document.getInitialProps(ctx)
16+
return {
17+
...initialProps,
18+
styles: (
19+
<>
20+
{initialProps.styles}
21+
{sheet.getStyleElement()}
22+
</>
23+
),
24+
}
25+
} finally {
26+
sheet.seal()
27+
}
28+
}
29+
}

demos/default/pages/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import dynamic from 'next/dynamic'
33
const Header = dynamic(() => import(/* webpackChunkName: 'header' */ '../components/Header'), { ssr: true })
44
import { useRouter } from 'next/router'
55

6+
import styled from 'styled-components'
7+
8+
const Title = styled.h1`
9+
font-size: 50px;
10+
color: ${({ theme }) => theme.colors.primary};
11+
`
12+
613
const Index = ({ shows }) => {
714
const { locale } = useRouter()
815

@@ -12,7 +19,7 @@ const Index = ({ shows }) => {
1219

1320
<Header />
1421

15-
<h1>NextJS on Netlify</h1>
22+
<Title>NextJS on Netlify</Title>
1623
<p>This is a demo of a NextJS application with Server-Side Rendering (SSR).</p>
1724

1825
<h2>Server-Side Rendering</h2>

0 commit comments

Comments
 (0)