Skip to content

Commit de70bb6

Browse files
authored
Merge pull request #201 from chakra-ui/refactor/chakra-plugin-to-local
refactor: remove chakra plugin in favor of local setup
2 parents f6c6234 + 242fba6 commit de70bb6

File tree

8 files changed

+55
-40
lines changed

8 files changed

+55
-40
lines changed

gatsby-browser.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as React from "react";
2+
import type { GatsbyBrowser } from "gatsby";
3+
import { WrapRootElement } from "./src/provider";
4+
5+
export const wrapRootElement: GatsbyBrowser['wrapRootElement'] = ({ element }) => (
6+
<WrapRootElement element={element} />
7+
)

gatsby-config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ const config: GatsbyConfig = {
88
// If you use VSCode you can also use the GraphQL plugin
99
// Learn more at: https://gatsby.dev/graphql-typegen
1010
graphqlTypegen: true,
11-
plugins: [
12-
{
13-
// https://chakra-ui.com/getting-started/gatsby-guide
14-
resolve: "@chakra-ui/gatsby-plugin",
15-
options: {},
16-
},
17-
],
1811
};
1912

2013
export default config;

gatsby-ssr.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from "react";
2+
import type { GatsbySSR } from "gatsby";
3+
import { ColorModeScript } from "@chakra-ui/react";
4+
import { WrapRootElement } from "./src/provider";
5+
import { customTheme } from "./src/theme";
6+
7+
export const onRenderBody: GatsbySSR['onRenderBody'] = ({ setPreBodyComponents }) => {
8+
setPreBodyComponents([
9+
<ColorModeScript
10+
initialColorMode={customTheme.config.initialColorMode}
11+
key="chakra-ui-no-flash"
12+
/>,
13+
])
14+
}
15+
16+
export const wrapRootElement: GatsbySSR['wrapRootElement'] = ({ element }) => (
17+
<WrapRootElement element={element} />
18+
)

package-lock.json

Lines changed: 12 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
"serve": "gatsby serve",
1616
"clean": "gatsby clean",
1717
"typecheck": "tsc --noEmit",
18-
"theme": "chakra-cli tokens path/to/theme.ts",
19-
"theme:watch": "chakra-cli tokens path/to/theme.ts --watch"
18+
"theme": "chakra-cli tokens src/theme/index.ts",
19+
"theme:watch": "chakra-cli tokens src/theme/index.ts --watch"
2020
},
2121
"dependencies": {
22-
"@chakra-ui/gatsby-plugin": "^3.1.1",
2322
"@chakra-ui/react": "^2.5.5",
2423
"@emotion/react": "^11.10.6",
2524
"@emotion/styled": "^11.10.6",
@@ -35,4 +34,4 @@
3534
"@types/react-dom": "^18.0.11",
3635
"typescript": "^5.0.2"
3736
}
38-
}
37+
}

src/provider.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from "react";
2+
import { ChakraProvider } from "@chakra-ui/react";
3+
import type { WrapRootElementBrowserArgs } from "gatsby";
4+
import { customTheme } from "./theme";
5+
export const WrapRootElement = ({ element }: Pick<WrapRootElementBrowserArgs, 'element'>) => (
6+
// Or ChakraBaseProvider if you only want to compile the default Chakra theme tokens
7+
<ChakraProvider theme={customTheme}>
8+
{element}
9+
</ChakraProvider>
10+
)

src/theme/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { extendTheme } from "@chakra-ui/react";
2+
3+
// Or export `extendBaseTheme` if you only want the default Chakra theme tokens to extend (no default component themes)
4+
export const customTheme = extendTheme({})

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@
9898
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
9999
"skipLibCheck": true /* Skip type checking all .d.ts files. */
100100
},
101-
"include": ["./src/**/*", "./gatsby-node.ts", "./gatsby-config.ts", "./plugins/**/*"]
101+
"include": ["./src/**/*", "./gatsby-node.ts", "./gatsby-config.ts", "./plugins/**/*"],
102102
}

0 commit comments

Comments
 (0)