Skip to content

Commit b15a5ba

Browse files
authored
Merge pull request #1 from kimbaudi/master
update gatsby-plugin-emotion, gatsby docs, and packages references to emotion v11
2 parents be8533f + 3a527fe commit b15a5ba

File tree

17 files changed

+45
-46
lines changed

17 files changed

+45
-46
lines changed

docs/docs/emotion.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gatsby new emotion-tutorial https://github.com/gatsbyjs/gatsby-starter-hello-wor
1717
Second, install the necessary dependencies for Emotion and Gatsby.
1818

1919
```shell
20-
npm install gatsby-plugin-emotion @emotion/core @emotion/styled
20+
npm install gatsby-plugin-emotion @emotion/react @emotion/styled
2121
```
2222

2323
And then add the plugin to your site's `gatsby-config.js`:
@@ -35,7 +35,7 @@ Now create a sample Emotion page at `src/pages/index.js`:
3535
```jsx:title=src/pages/index.js
3636
import React from "react"
3737
import styled from "@emotion/styled"
38-
import { css } from "@emotion/core"
38+
import { css } from "@emotion/react"
3939

4040
const Container = styled.div`
4141
margin: 3rem auto;
@@ -123,7 +123,7 @@ To start, create a new Gatsby site with the [hello world starter](https://github
123123
```shell
124124
gatsby new global-styles https://github.com/gatsbyjs/gatsby-starter-hello-world
125125
cd global-styles
126-
npm install gatsby-plugin-emotion @emotion/core @emotion/styled
126+
npm install gatsby-plugin-emotion @emotion/react @emotion/styled
127127
```
128128

129129
Create `gatsby-config.js` and add the Emotion plugin:
@@ -138,7 +138,7 @@ Next, add a layout component at `src/components/layout.js`:
138138

139139
```jsx:title=src/components/layout.js
140140
import React from "react"
141-
import { Global, css } from "@emotion/core"
141+
import { Global, css } from "@emotion/react"
142142
import styled from "@emotion/styled"
143143

144144
const Wrapper = styled("div")`

docs/docs/recipes/styling-css.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ If fonts are not updating following steps above, make sure to replace the existi
323323
1. Install the [Gatsby Emotion plugin](/packages/gatsby-plugin-emotion/) and Emotion packages.
324324

325325
```shell
326-
npm install gatsby-plugin-emotion @emotion/core @emotion/styled
326+
npm install gatsby-plugin-emotion @emotion/react @emotion/styled
327327
```
328328

329329
2. Add the `gatsby-plugin-emotion` plugin to your `gatsby-config.js` file:
@@ -340,7 +340,7 @@ Import Emotion's `css` core package. You can then use the `css` prop to add [Emo
340340

341341
```jsx:title=src/pages/emotion-sample.js
342342
import React from "react"
343-
import { css } from "@emotion/core"
343+
import { css } from "@emotion/react"
344344

345345
export default function EmotionSample() {
346346
return (

docs/docs/tailwind-css.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ These steps assume you have a CSS-in-JS library already installed, and the examp
7171
1. Install the [Twin Babel Macro](https://github.com/ben-rogerson/twin.macro) and [Emotion](https://emotion.sh/docs/introduction)
7272

7373
```shell
74-
npm install -D twin.macro @emotion/core @emotion/styled gatsby-plugin-emotion
74+
npm install -D twin.macro @emotion/react @emotion/styled gatsby-plugin-emotion
7575
```
7676

7777
2. Import the Tailwind base styles

docs/docs/testing-css-in-js.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: Testing CSS-in-JS
33
---
44

5-
Popular CSS-in-JS libraries like [styled-components](https://github.com/styled-components/styled-components) or [emotion](https://github.com/emotion-js/emotion) can also be tested with the help of [jest-styled-components](https://github.com/styled-components/jest-styled-components) or [jest-emotion](https://github.com/emotion-js/emotion/tree/master/packages/jest-emotion) respectively. These packages improve Jest's built-in snapshot testing experience and are a great way to help avoid unintended changes to your website's UI. Please refer to your package's documentation to see if it also offers testing capabilities.
5+
Popular CSS-in-JS libraries like [styled-components](https://github.com/styled-components/styled-components) or [emotion](https://github.com/emotion-js/emotion) can also be tested with the help of [jest-styled-components](https://github.com/styled-components/jest-styled-components) or [@emotion/jest](https://github.com/emotion-js/emotion/tree/master/packages/jest) respectively. These packages improve Jest's built-in snapshot testing experience and are a great way to help avoid unintended changes to your website's UI. Please refer to your package's documentation to see if it also offers testing capabilities.
66

7-
_Snapshot serializers_ like `jest-styled-components` or `jest-emotion` modify the standard output to a more meaningful and readable snapshot, e.g. by removing unnecessary information or displaying data in another format. Which ultimately leads to more comparable and effective snapshot tests.
7+
_Snapshot serializers_ like `jest-styled-components` or `@emotion/jest` modify the standard output to a more meaningful and readable snapshot, e.g. by removing unnecessary information or displaying data in another format. Which ultimately leads to more comparable and effective snapshot tests.
88

99
By default snapshots of your styled components show the generated class names (which you didn't set) and no styling information. When changing the styles you'll only see the diff of some cryptic class names (hashes). That's why you should use the above mentioned _snapshot serializers_. They remove the hashes and format the CSS in style elements.
1010

@@ -13,10 +13,10 @@ For this example you'll use emotion. The testing utilities of emotion and glamor
1313
## Installation
1414

1515
```shell
16-
npm install --save-dev jest-emotion babel-plugin-emotion
16+
npm install --save-dev @emotion/jest @emotion/babel-plugin
1717
```
1818

19-
As [Gatsby's emotion plugin](/packages/gatsby-plugin-emotion/) is using `babel-plugin-emotion` under the hood you'll also need to install it so that Jest can use it.
19+
As [Gatsby's emotion plugin](/packages/gatsby-plugin-emotion/) is using `@emotion/babel-plugin` under the hood you'll also need to install it so that Jest can use it.
2020

2121
If you followed along with the [Unit testing guide](/docs/unit-testing) you'll have the file `jest-preprocess.js` at the root of your project. Open that file and add the plugin:
2222

@@ -34,8 +34,8 @@ module.exports = require("babel-jest").createTransformer(babelOptions)
3434
In order to tell Jest to use the serializer you'll need to create the file `setup-test-env.js` which will be run automatically before every test. Create the file `setup-test-env.js` at the root of your project. Insert this code into it:
3535

3636
```js:title=setup-test-env.js
37-
import { createSerializer } from "jest-emotion"
38-
import * as emotion from "@emotion/core"
37+
import { createSerializer } from "@emotion/jest"
38+
import * as emotion from "@emotion/react"
3939

4040
expect.addSnapshotSerializer(createSerializer(emotion))
4141
```
@@ -89,15 +89,15 @@ exports[`Button renders correctly 1`] = `
8989
If your styled component depends on `theme` via `ThemeProvider` you'll have two options:
9090

9191
- Wrap all your components with the `ThemeProvider`
92-
- Use API helpers (have a look at the library's documentation, e.g. [styled-components](https://github.com/styled-components/jest-styled-components#theming) or [emotion](https://github.com/emotion-js/emotion/tree/master/packages/emotion-theming#createbroadcast-function))
92+
- Use API helpers (have a look at the library's documentation, e.g. [styled-components](https://github.com/styled-components/jest-styled-components#theming) or [emotion](https://emotion.sh/docs/theming#api))
9393

9494
And this is where snapshots tests really shine. If you change, e.g. the primary color in your theme file you'll see which components get affected by this change. This way you can catch unintended changes to the style of your components.
9595

9696
This example uses the first option:
9797

9898
```js:title=src/components/Wrapper.test.js
9999
import React from "react"
100-
import { ThemeProvider } from "emotion-theming"
100+
import { ThemeProvider, withTheme } from "@emotion/react"
101101
import renderer from "react-test-renderer"
102102

103103
const theme = {

docs/docs/troubleshooting-common-errors.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ For some plugins like emotion, styled-components, or Sass, it won't be enough to
3232

3333
Here are some examples of plugins that require you to install more than just the plugin:
3434

35-
- [gatsby-plugin-emotion](/packages/gatsby-plugin-emotion/): `@emotion/core`, and `@emotion/styled`
35+
- [gatsby-plugin-emotion](/packages/gatsby-plugin-emotion/): `@emotion/react`, and `@emotion/styled`
3636
- [gatsby-plugin-styled-components](/packages/gatsby-plugin-styled-components/): `styled-components`, and `babel-plugin-styled-components`
3737
- [gatsby-plugin-sass](/packages/gatsby-plugin-sass/): `node-sass`, or `dart-sass`
3838
- [gatsby-plugin-material-ui](/packages/gatsby-plugin-material-ui/): `@material-ui/styles`
@@ -50,18 +50,18 @@ success run queries - 0.095s - 8/8 84.63/s
5050

5151
Generating SSR bundle failed
5252

53-
Can't resolve '@emotion/core' in '/Users/you/tmp/gatsby-site/.cache' // highlight-line
53+
Can't resolve '@emotion/react' in '/Users/you/tmp/gatsby-site/.cache' // highlight-line
5454
5555
File: .cache/develop-static-entry.js
5656
```
5757
58-
This error is a result of Gatsby having failed to find `@emotion/core` because `gatsby-plugin-emotion` has been installed and added to the `gatsby-config`, without installing the emotion library. Install it like this:
58+
This error is a result of Gatsby having failed to find `@emotion/react` because `gatsby-plugin-emotion` has been installed and added to the `gatsby-config`, without installing the emotion library. Install it like this:
5959
6060
```shell
61-
npm install @emotion/core
61+
npm install @emotion/react
6262
```
6363
64-
Or replace `@emotion/core` with the name of the library that is missing. Installing the plugin and any necessary libraries as well as adding the plugin to your `gatsby-config` should resolve this error.
64+
Or replace `@emotion/react` with the name of the library that is missing. Installing the plugin and any necessary libraries as well as adding the plugin to your `gatsby-config` should resolve this error.
6565
6666
### Issues with `fs` resolution
6767

docs/tutorial/building-a-theme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ You can make your theme styles extendable using the `gatsby-plugin-theme-ui` pac
10981098
Install dependencies:
10991099

11001100
```shell
1101-
yarn workspace gatsby-theme-events add gatsby-plugin-theme-ui theme-ui @emotion/core @emotion/styled @mdx-js/react
1101+
yarn workspace gatsby-theme-events add gatsby-plugin-theme-ui theme-ui @emotion/react @emotion/styled @mdx-js/react
11021102
```
11031103

11041104
Then, add the `gatsby-plugin-theme-ui` plugin to the `gatsby-theme-events/gatsby-config.js` file:
@@ -1344,8 +1344,8 @@ It's important to namespace your theme. It helps differentiate between published
13441344
"react-dom": "^16.8.6"
13451345
},
13461346
"dependencies": {
1347-
"@emotion/core": "^10.0.14",
1348-
"@emotion/styled": "^10.0.14",
1347+
"@emotion/react": "^11.0.0",
1348+
"@emotion/styled": "^11.0.0",
13491349
"@mdx-js/react": "^1.0.27",
13501350
"gatsby-plugin-theme-ui": "^0.2.6",
13511351
"gatsby-source-filesystem": "^2.1.5",

docs/tutorial/part-seven/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Return to `src/pages/index.js`, query for your markdown slugs, and create links.
306306

307307
```jsx:title=src/pages/index.js
308308
import React from "react"
309-
import { css } from "@emotion/core"
309+
import { css } from "@emotion/react"
310310
import { Link, graphql } from "gatsby" // highlight-line
311311
import { rhythm } from "../utils/typography"
312312
import Layout from "../components/layout"

docs/tutorial/part-six/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Like with the `src/pages/my-files.js` page, replace `src/pages/index.js` with th
8787
```jsx:title=src/pages/index.js
8888
import React from "react"
8989
import { graphql } from "gatsby"
90-
import { css } from "@emotion/core"
90+
import { css } from "@emotion/react"
9191
import { rhythm } from "../utils/typography"
9292
import Layout from "../components/layout"
9393

packages/gatsby-admin/src/components/recipes-gui/resource-message.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable */
33
import React from "react"
44
import { MdRefresh, MdBrightness1 } from "react-icons/md"
5-
import { keyframes } from "@emotion/core"
5+
import { keyframes } from "@emotion/react"
66
import { BaseAnchor, SuccessIcon } from "gatsby-interface"
77
import { makeResourceId } from "./utils"
88
import { jsx } from "theme-ui"

packages/gatsby-admin/src/pages/plugins.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { jsx, Flex } from "strict-ui"
33
import { PageProps } from "gatsby"
44
import { useQuery } from "urql"
55
import { Spinner } from "theme-ui"
6-
import { Global } from "@emotion/core"
6+
import { Global } from "@emotion/react"
77
import { useMutation } from "urql"
88
import { useState, Fragment, useEffect } from "react"
99
import {

packages/gatsby-plugin-emotion/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Provide support for using the css-in-js library
44
[Emotion](https://github.com/emotion-js/emotion) including server side
55
rendering.
66

7-
**This plugin supports Emotion v10+**
7+
**This plugin supports Emotion v11+**
88

99
Older versions should use versions of this plugin which support Emotion 8 and 9. Check out the Emotion 10 [migration
1010
guide](https://emotion.sh/docs/migrating-to-emotion-10#incremental-migration) for more information on how to upgrade.
1111

1212
## Install
1313

1414
```shell
15-
npm install gatsby-plugin-emotion @emotion/styled @emotion/react
15+
npm install gatsby-plugin-emotion @emotion/react @emotion/styled
1616
```
1717

1818
## How to use
@@ -25,10 +25,10 @@ module.exports = {
2525
{
2626
resolve: `gatsby-plugin-emotion`,
2727
options: {
28-
// Accepts the following options, all of which are defined by `babel-plugin-emotion` plugin.
28+
// Accepts the following options, all of which are defined by `@emotion/babel-plugin` plugin.
2929
// The values for each key in this example are the defaults the plugin uses.
3030
sourceMap: true,
31-
autoLabel: process.env.NODE_ENV !== "production",
31+
autoLabel: 'dev-only',
3232
labelFormat: `[local]`,
3333
cssPropOptimization: true,
3434
},
@@ -39,11 +39,11 @@ module.exports = {
3939

4040
## Options
4141

42-
The plugin supports the same options that you can pass into [`babel-plugin-emotion`](https://emotion.sh/docs/babel-plugin-emotion#options).
42+
The plugin supports the same options that you can pass into [`@emotion/babel-plugin`](https://emotion.sh/docs/@emotion/babel-plugin#options).
4343

4444
| Option | Type | Description | Default | Required |
4545
| ------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | -------- |
4646
| sourceMap | boolean | Tells the plugin to inject source maps for use in browser dev tools in development. | `true` | |
47-
| autoLabel | boolean | Automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in [`babel-plugin-emotion`'s docs](https://emotion.sh/docs/babel-plugin-emotion#autolabel) | `process.env.NODE_ENV !== 'production'` | |
47+
| autoLabel | `'dev-only' | 'always' | 'never'` | Automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in [`@emotion/babel-plugin`'s docs](https://emotion.sh/docs/@emotion/babel-plugin#autolabel) | `dev-only` | |
4848
| labelFormat | string | Only works when `autoLabel` is set to true. It allows you to define the format of the resulting label. The format is defined via string where variable parts are enclosed in square brackets []. For example `labelFormat: "my-classname--[local]"`, where `[local]` will be replaced with the name of the variable the result is assigned to. | "[local]" | |
4949
| cssPropOptimization | boolean | Assumes that you are using something to make `@emotion/react`’s jsx function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option. | `true` | |

packages/gatsby-plugin-emotion/src/__tests__/gatsby-node.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe(`gatsby-plugin-emotion`, () => {
1515
),
1616
options: {
1717
sourceMap: true,
18-
autoLabel: true,
18+
autoLabel: `dev-only`,
1919
},
2020
})
2121
})
@@ -33,7 +33,7 @@ describe(`gatsby-plugin-emotion`, () => {
3333
),
3434
options: {
3535
sourceMap: true,
36-
autoLabel: true,
36+
autoLabel: `dev-only`,
3737
useBuiltIns: true,
3838
},
3939
})
@@ -63,7 +63,7 @@ describe(`gatsby-plugin-emotion`, () => {
6363
),
6464
options: {
6565
sourceMap: false,
66-
autoLabel: false,
66+
autoLabel: `dev-only`,
6767
},
6868
})
6969
})

packages/gatsby-plugin-emotion/src/gatsby-node.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ exports.pluginOptionsSchema = ({ Joi }) =>
1616
.description(
1717
`This option tells the plugin to inject source maps for use in browser dev tools in development.`
1818
),
19-
autoLabel: Joi.boolean()
20-
.default(process.env.NODE_ENV !== `production`)
19+
autoLabel: Joi.string()
20+
.default(`dev-only`)
2121
.description(
22-
`This option automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in babel-plugin-emotion's docs: https://emotion.sh/docs/babel-plugin-emotion#autolabel`
22+
`This option automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in @emotion/babel-plugin's docs: https://emotion.sh/docs/@emotion/babel-plugin#autolabel`
2323
),
2424
labelFormat: Joi.string()
2525
.default(`[local]`)

packages/gatsby-recipes/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Install necessary NPM packages
7777
<!-- refer to the API in this doc to see what APIs are available, like `NPMPackage` -->
7878

7979
<NPMPackage name="gatsby-plugin-emotion" />
80-
<NPMPackage name="@emotion/core" />
80+
<NPMPackage name="@emotion/react" />
8181
<NPMPackage name="@emotion/styled" />
8282

8383
---

packages/gatsby-recipes/recipes/chakra-ui.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ This recipes sets up and configures [gatsby-plugin-chakra-ui](https://www.gatsby
88

99
## Installs necessary NPM packages
1010

11-
<NPMPackage name="@emotion/core" />
11+
<NPMPackage name="@emotion/react" />
1212
<NPMPackage name="@emotion/styled" />
13-
<NPMPackage name="emotion-theming" />
1413
<NPMPackage name="@chakra-ui/core" />
1514
<NPMPackage name="gatsby-plugin-chakra-ui" />
1615

packages/gatsby-recipes/recipes/emotion.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This recipe:
1111
Installs necessary NPM packages.
1212

1313
<NPMPackage name="gatsby-plugin-emotion" />
14-
<NPMPackage name="@emotion/core" />
14+
<NPMPackage name="@emotion/react" />
1515
<NPMPackage name="@emotion/styled" />
1616

1717
---

packages/gatsby/src/redux/actions/public.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ ${reservedFields.map(f => ` * "${f}"`).join(`\n`)}
366366
const truncatedPath = truncatePath(page.path)
367367
report.warn(
368368
report.stripIndent(`
369-
The path to the following page is longer than the supported limit on most
369+
The path to the following page is longer than the supported limit on most
370370
operating systems and will cause an ENAMETOOLONG error. The path has been
371-
truncated to prevent this.
371+
truncated to prevent this.
372372
373373
Original Path: ${page.path}
374374
@@ -1069,7 +1069,7 @@ actions.setBabelOptions = (options: Object, plugin?: ?Plugin = null) => {
10691069
* @param {Object} config.options Options to pass to the Babel plugin.
10701070
* @example
10711071
* setBabelPlugin({
1072-
* name: `babel-plugin-emotion`,
1072+
* name: `@emotion/babel-plugin`,
10731073
* options: {
10741074
* sourceMap: true,
10751075
* },

0 commit comments

Comments
 (0)