Skip to content

Commit 89cc101

Browse files
Laurie BarthLaurie Barth
authored andcommitted
merge
2 parents b7ebd2b + e6ea48a commit 89cc101

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

packages/gatsby-plugin-theme-ui/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ prevent a flash of unstyled colors when using color modes.
2121
| Key | Default value | Description |
2222
| ------------------------ | ---------------- | -------------------------------------------------------------------------------- |
2323
| `prismPreset` | `null` | The name of the preset you'd like to use to style code blocks inside your markdown files. The available presets can be found in the [theme-ui docs](https://theme-ui.com/packages/prism/). You can also use a package string of your own choosing. |
24+
| `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. |
25+
26+
> Note that this plugin assumes the theme object is exported as `default`.
2427
2528
The theme module you include in options is considered your base theme. Any further customization and shadowing will be merged with it.
2629

@@ -33,6 +36,7 @@ module.exports = {
3336
{ resolve: 'gatsby-plugin-theme-ui',
3437
options: {
3538
prismPreset: 'night-owl'
39+
preset: '@theme-ui/preset-funk'
3640
}
3741
}],
3842
}

packages/gatsby-plugin-theme-ui/gatsby-node.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
const prismPresetDictionary = require(`./utils/preset-dictionary`)
22

33
exports.onPreInit = ({ reporter }, options) => {
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+
414
if (prismPreset in prismPresetDictionary) {
515
prismPreset = prismPresetDictionary[prismPreset]
616
}
@@ -20,17 +30,19 @@ exports.createSchemaCustomization = ({ actions }) => {
2030
createTypes(`
2131
type ThemeUiConfig implements Node {
2232
prismPreset: JSON,
33+
preset: JSON,
2334
}
2435
`)
2536
}
2637

2738
exports.sourceNodes = (
2839
{ actions, createContentDigest },
29-
{ prismPreset = {} }
40+
{ preset = {}, prismPreset = {} }
3041
) => {
3142
const { createNode } = actions
3243

3344
const themeUiConfig = {
45+
preset,
3446
prismPreset,
3547
}
3648

packages/gatsby-plugin-theme-ui/src/hooks/configOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const useThemeUiConfig = () => {
55
query {
66
themeUiConfig(id: { eq: "gatsby-plugin-theme-ui-config" }) {
77
prismPreset
8+
preset
89
}
910
}
1011
`)

packages/gatsby-plugin-theme-ui/src/provider.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import useThemeUiConfig from './hooks/configOptions'
66

77
const Root = ({ children }) => {
88
const themeUiConfig = useThemeUiConfig()
9-
const { prismPreset } = themeUiConfig
9+
const { preset, prismPreset } = themeUiConfig
1010

11-
const themeWithPrism = merge(
12-
{},
13-
{
14-
styles: {
15-
pre: prismPreset,
16-
},
17-
}
18-
)
11+
const theme = preset.default || preset
12+
13+
const themeWithPrism = merge(theme, {
14+
styles: {
15+
pre: prismPreset,
16+
},
17+
})
1918

2019
const fullTheme = merge(themeWithPrism, localTheme)
2120

0 commit comments

Comments
 (0)