Skip to content

Commit d6f033e

Browse files
authored
add options validation for gatsby-plugin-emotion (#27369)
1 parent 072ef6c commit d6f033e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

packages/gatsby-plugin-emotion/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,25 @@ module.exports = {
2525
{
2626
resolve: `gatsby-plugin-emotion`,
2727
options: {
28-
// Accepts all options defined by `babel-plugin-emotion` plugin.
28+
// Accepts the following options, all of which are defined by `babel-plugin-emotion` plugin.
29+
// The values for each key in this example are the defaults the plugin uses.
30+
`sourceMap`: true,
31+
`autoLabel`: process.env.NODE_ENV !== 'production',
32+
`labelFormat`: `[local]`,
33+
`cssPropOptimization`: true
2934
},
3035
},
3136
],
3237
}
3338
```
39+
40+
## Options
41+
42+
The plugin supports the same options that you can pass into [`babel-plugin-emotion`](https://emotion.sh/docs/babel-plugin-emotion#options).
43+
44+
| Option | Type | Description | Default | Required |
45+
| ------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | -------- |
46+
| 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'` | |
48+
| 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]" | |
49+
| cssPropOptimization | boolean | Assumes that you are using something to make `@emotion/core`’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/gatsby-node.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,27 @@ export const onCreateBabelConfig = ({ actions }, pluginOptions) => {
88
},
99
})
1010
}
11+
12+
exports.pluginOptionsSchema = ({ Joi }) =>
13+
Joi.object({
14+
sourceMap: Joi.boolean()
15+
.default(true)
16+
.description(
17+
`This option tells the plugin to inject source maps for use in browser dev tools in development.`
18+
),
19+
autoLabel: Joi.boolean()
20+
.default(process.env.NODE_ENV !== `production`)
21+
.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`
23+
),
24+
labelFormat: Joi.string()
25+
.default(`[local]`)
26+
.description(
27+
`This option 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.`
28+
),
29+
cssPropOptimization: Joi.boolean()
30+
.default(true)
31+
.description(
32+
`This option assumes that you are using something to make @emotion/core’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.`
33+
),
34+
})

0 commit comments

Comments
 (0)