File tree Expand file tree Collapse file tree 7 files changed +123
-12
lines changed
packages/gatsby-plugin-theme-ui Expand file tree Collapse file tree 7 files changed +123
-12
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = require ( 'babel-jest' ) . createTransformer ( {
2
+ presets : [ 'babel-preset-gatsby' ] ,
3
+ } )
Original file line number Diff line number Diff line change 96
96
],
97
97
"setupFiles" : [
98
98
" jest-canvas-mock"
99
- ]
99
+ ],
100
+ "transform" : {
101
+ "^.+\\ .jsx?$" : " <rootDir>/jest-preprocess.js"
102
+ }
100
103
},
101
104
"husky" : {
102
105
"hooks" : {
Original file line number Diff line number Diff line change @@ -16,6 +16,31 @@ module.exports = {
16
16
In addition to providing context, this plugin will also
17
17
prevent a flash of unstyled colors when using color modes.
18
18
19
+ ## Options
20
+
21
+ | Key | Default value | Description |
22
+ | ------------------------ | ---------------- | -------------------------------------------------------------------------------- |
23
+ | ` preset ` | ` null ` | This can be a JSON theme object or a string package name. Make sure the package you're requiring is installed in your dependencies. |
24
+
25
+ > Note that this plugin assumes the theme object is exported as ` default ` .
26
+
27
+ The theme module you include in options is considered your base theme. Any further customization and shadowing will be merged with it.
28
+
29
+ ### Using options
30
+
31
+ ``` js
32
+ // gatsby-config.js
33
+ module .exports = {
34
+ plugins: [
35
+ { resolve: ' gatsby-plugin-theme-ui' ,
36
+ options: {
37
+ preset: ' @theme-ui/preset-funk'
38
+ // or require('@theme-ui/preset-funk')
39
+ }
40
+ }],
41
+ }
42
+ ```
43
+
19
44
## Customizing the theme
20
45
21
46
To customize the theme used in your Gatsby site,
Original file line number Diff line number Diff line change
1
+ exports . onPreInit = ( __ , options ) => {
2
+ let { preset } = options
3
+
4
+ if ( typeof preset === 'string' ) {
5
+ try {
6
+ options . preset = require ( preset )
7
+ } catch {
8
+ reporter . warn (
9
+ `It appears your theme dependency is not installed. Only local styles will appear.`
10
+ )
11
+ }
12
+ }
13
+ }
14
+
15
+ exports . createSchemaCustomization = ( { actions } ) => {
16
+ const { createTypes } = actions
17
+
18
+ createTypes ( `
19
+ type ThemeUiConfig implements Node {
20
+ preset: JSON,
21
+ }
22
+ ` )
23
+ }
24
+
25
+ exports . sourceNodes = ( { actions, createContentDigest } , { preset = { } } ) => {
26
+ const { createNode } = actions
27
+
28
+ const themeUiConfig = {
29
+ preset,
30
+ }
31
+
32
+ createNode ( {
33
+ ...themeUiConfig ,
34
+ id : `gatsby-plugin-theme-ui-config` ,
35
+ parent : null ,
36
+ children : [ ] ,
37
+ internal : {
38
+ type : `ThemeUiConfig` ,
39
+ contentDigest : createContentDigest ( themeUiConfig ) ,
40
+ content : JSON . stringify ( themeUiConfig ) ,
41
+ description : `Options for gatsby-plugin-theme-ui` ,
42
+ } ,
43
+ } )
44
+ }
Original file line number Diff line number Diff line change
1
+ import { useStaticQuery , graphql } from 'gatsby'
2
+
3
+ const useThemeUiConfig = ( ) => {
4
+ const data = useStaticQuery ( graphql `
5
+ query {
6
+ themeUiConfig(id: { eq: "gatsby-plugin-theme-ui-config" }) {
7
+ preset
8
+ }
9
+ }
10
+ ` )
11
+
12
+ return data . themeUiConfig
13
+ }
14
+
15
+ export default useThemeUiConfig
Original file line number Diff line number Diff line change 1
1
/** @jsx jsx */
2
- import {
3
- jsx ,
4
- ThemeProvider ,
5
- } from 'theme-ui'
6
- import theme from './index'
2
+ import { jsx , ThemeProvider , merge } from 'theme-ui'
3
+ import localTheme from './index'
7
4
import components from './components'
5
+ import useThemeUiConfig from './hooks/configOptions'
8
6
9
- export const wrapRootElement = ( { element } ) =>
10
- jsx ( ThemeProvider , {
11
- theme,
12
- components,
13
- } ,
14
- element ,
7
+ const Root = ( { children } ) => {
8
+ const themeUiConfig = useThemeUiConfig ( )
9
+ const { preset } = themeUiConfig
10
+
11
+ const theme = preset . default || preset
12
+
13
+ const fullTheme = merge ( theme , localTheme )
14
+
15
+ return (
16
+ < ThemeProvider theme = { fullTheme } components = { components } >
17
+ { children }
18
+ </ ThemeProvider >
15
19
)
20
+ }
21
+
22
+ export const wrapRootElement = ( { element } ) => {
23
+ return < Root > { element } </ Root >
24
+ }
Original file line number Diff line number Diff line change
1
+ const React = require ( 'react' )
2
+ const gatsby = jest . requireActual ( 'gatsby' )
3
+
4
+ module . exports = {
5
+ ...gatsby ,
6
+ graphql : jest . fn ( ) ,
7
+ useStaticQuery : jest . fn ( ( ) => ( {
8
+ themeUiConfig : {
9
+ preset : { } ,
10
+ } ,
11
+ } ) ) ,
12
+ }
You can’t perform that action at this time.
0 commit comments