Commit af1d10c9 authored by Steven Bell's avatar Steven Bell Committed by Tim Neutkens

update with-emotion example to emotion 10 (#5770)

parent f1fe237b
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
"next/babel" "next/babel"
], ],
"plugins": [ "plugins": [
["emotion", { "inline": true }] ["emotion"]
] ]
} }
\ No newline at end of file
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"babel-plugin-emotion": "^8.0.4", "@emotion/core": "^10.0.0",
"emotion": "^8.0.5", "@emotion/styled": "^10.0.0",
"emotion-server": "^8.0.5", "babel-plugin-emotion": "^10.0.0",
"next": "latest", "next": "latest",
"react": "16.2.0", "react": "^16.3.0",
"react-dom": "16.2.0", "react-dom": "^16.3.0"
"react-emotion": "^8.0.5"
}, },
"license": "ISC" "license": "ISC"
} }
import Document, { Head, Main, NextScript } from 'next/document'
import { extractCritical } from 'emotion-server'
export default class MyDocument extends Document {
static getInitialProps ({ renderPage }) {
const page = renderPage()
const styles = extractCritical(page.html)
return { ...page, ...styles }
}
constructor (props) {
super(props)
const { __NEXT_DATA__, ids } = props
if (ids) {
__NEXT_DATA__.ids = ids
}
}
render () {
return (
<html>
<Head>
<style dangerouslySetInnerHTML={{ __html: this.props.css }} />
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
}
import React from 'react' import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import styled, { hydrate, keyframes, css, injectGlobal } from 'react-emotion' import styled from '@emotion/styled'
import { keyframes, css, Global } from '@emotion/core'
// Adds server generated styles to emotion cache.
// '__NEXT_DATA__.ids' is set in '_document.js'
if (typeof window !== 'undefined') {
hydrate(window.__NEXT_DATA__.ids)
}
injectGlobal`
html, body {
padding: 3rem 1rem;
margin: 0;
background: papayawhip;
min-height: 100%;
font-family: Helvetica, Arial, sans-serif;
font-size: 24px;
}
`
const basicStyles = css` const basicStyles = css`
background-color: white; background-color: white;
...@@ -69,7 +53,18 @@ const Animated = styled.div` ...@@ -69,7 +53,18 @@ const Animated = styled.div`
export default () => { export default () => {
return ( return (
<>' '<Head> <>' '<Global
styles={css`
html, body {
padding: 3rem 1rem;
margin: 0;
background: papayawhip;
min-height: 100%;
font-family: Helvetica, Arial, sans-serif;
font-size: 24px;
}
`}
/>' '<Head>
<title>With Emotion</title> <title>With Emotion</title>
</Head>' '<div> </Head>' '<div>
<Basic>Cool Styles</Basic> <Basic>Cool Styles</Basic>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment