Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[with-emotion-10,11] Update emotion examples to v10 & v11 (#9646)
* Update emotion to v10, use @emotion/core, @emotion/styled * Add with-emotion-11 and make review changes * Fix package names and run prettier * fix readmes Co-authored-by: Joe Haddad <timer150@gmail.com>
- Loading branch information
Showing
14 changed files
with
256 additions
and
63 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,50 @@ | ||
# Pass Server Data Directly to a Next.js Page during SSR | ||
|
||
Extract and inline critical css with | ||
[emotion](https://github.com/emotion-js/emotion/tree/master/packages/emotion), | ||
[emotion-server](https://github.com/emotion-js/emotion/tree/master/packages/emotion-server), | ||
[@emotion/core](https://github.com/emotion-js/emotion/tree/master/packages/core), | ||
and [@emotion/styled](https://github.com/emotion-js/emotion/tree/master/packages/styled). | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [ZEIT Now](https://zeit.co/now): | ||
|
||
[![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/new/project?template=https://github.com/zeit/next.js/tree/canary/examples/with-emotion-10) | ||
|
||
## How to use | ||
|
||
### Using `create-next-app` | ||
|
||
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: | ||
|
||
```bash | ||
npm init next-app --example with-emotion-10 with-emotion-10-app | ||
# or | ||
yarn create next-app --example with-emotion-10 with-emotion-10-app | ||
``` | ||
|
||
### Download manually | ||
|
||
Download the example: | ||
|
||
```bash | ||
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-emotion-10 | ||
cd with-emotion-10 | ||
``` | ||
|
||
Install it and run: | ||
|
||
```bash | ||
npm install | ||
npm run dev | ||
# or | ||
yarn | ||
yarn dev | ||
``` | ||
|
||
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)): | ||
|
||
```bash | ||
now | ||
``` |
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,20 @@ | ||
import * as React from 'react' | ||
import NextApp from 'next/app' | ||
import { CacheProvider } from '@emotion/core' | ||
|
||
// Use only { cache } from 'emotion'. Don't use { css }. | ||
import { cache } from 'emotion' | ||
|
||
import { globalStyles } from '../shared/styles' | ||
|
||
export default class App extends NextApp { | ||
render() { | ||
const { Component, pageProps } = this.props | ||
return ( | ||
<CacheProvider value={cache}> | ||
{globalStyles} | ||
<Component {...pageProps} /> | ||
</CacheProvider> | ||
) | ||
} | ||
} |
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
File renamed without changes.
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
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,24 @@ | ||
{ | ||
"name": "with-emotion-11", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"keywords": [], | ||
"author": "Thomas Greco", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@emotion/cache": "11.0.0-next.10", | ||
"@emotion/css": "11.0.0-next.10", | ||
"@emotion/react": "11.0.0-next.10", | ||
"@emotion/server": "11.0.0-next.10", | ||
"@emotion/styled": "11.0.0-next.10", | ||
"next": "latest", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0" | ||
} | ||
} |
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,17 @@ | ||
import * as React from 'react' | ||
import NextApp from 'next/app' | ||
import { CacheProvider } from '@emotion/react' | ||
import { cache } from '@emotion/css' | ||
import { globalStyles } from '../shared/styles' | ||
|
||
export default class App extends NextApp { | ||
render() { | ||
const { Component, pageProps } = this.props | ||
return ( | ||
<CacheProvider value={cache}> | ||
{globalStyles} | ||
<Component {...pageProps} /> | ||
</CacheProvider> | ||
) | ||
} | ||
} |
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,27 @@ | ||
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 } | ||
} | ||
|
||
render() { | ||
return ( | ||
<html> | ||
<Head> | ||
<style | ||
data-emotion-css={this.props.ids.join(' ')} | ||
dangerouslySetInnerHTML={{ __html: this.props.css }} | ||
/> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</html> | ||
) | ||
} | ||
} |
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 { Basic, Combined, Animated, bounce } from '../shared/styles' | ||
const Home = () => ( | ||
<div> | ||
<Basic>Cool Styles</Basic> | ||
<Combined> | ||
With <code>:hover</code>. | ||
</Combined> | ||
<Animated animation={bounce}>Let's bounce.</Animated> | ||
</div> | ||
) | ||
|
||
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,67 @@ | ||
import { keyframes, css, Global } from '@emotion/react' | ||
import styled from '@emotion/styled' | ||
|
||
export const globalStyles = ( | ||
<Global | ||
styles={css` | ||
html, | ||
body { | ||
padding: 3rem 1rem; | ||
margin: 0; | ||
background: papayawhip; | ||
min-height: 100%; | ||
font-family: Helvetica, Arial, sans-serif; | ||
font-size: 24px; | ||
} | ||
`} | ||
/> | ||
) | ||
|
||
export const basicStyles = css` | ||
background-color: white; | ||
color: cornflowerblue; | ||
border: 1px solid lightgreen; | ||
border-right: none; | ||
border-bottom: none; | ||
box-shadow: 5px 5px 0 0 lightgreen, 10px 10px 0 0 lightyellow; | ||
transition: all 0.1s linear; | ||
margin: 3rem 0; | ||
padding: 1rem 0.5rem; | ||
` | ||
|
||
export const hoverStyles = css` | ||
&:hover { | ||
color: white; | ||
background-color: lightgray; | ||
border-color: aqua; | ||
box-shadow: -15px -15px 0 0 aqua, -30px -30px 0 0 cornflowerblue; | ||
} | ||
` | ||
export const bounce = keyframes` | ||
from { | ||
transform: scale(1.01); | ||
} | ||
to { | ||
transform: scale(0.99); | ||
} | ||
` | ||
|
||
export const Basic = styled('div')` | ||
${basicStyles}; | ||
` | ||
|
||
export const Combined = styled('div')` | ||
${basicStyles}; | ||
${hoverStyles}; | ||
& code { | ||
background-color: linen; | ||
} | ||
` | ||
export const Animated = styled('div')` | ||
${basicStyles}; | ||
${hoverStyles}; | ||
& code { | ||
background-color: linen; | ||
} | ||
animation: ${props => props.animation} 0.2s infinite ease-in-out alternate; | ||
` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.