-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
33 lines (27 loc) · 1.01 KB
/
gatsby-browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React, { useState } from 'react'
import { ReactBricks } from 'react-bricks/frontend'
import config from './src/react-bricks/config'
import './src/css/style.css'
const ReactBricksApp = ({ element }) => {
const savedColorMode =
typeof window === 'undefined' ? '' : localStorage.getItem('color-mode')
const [colorMode, setColorMode] = useState(savedColorMode || 'light')
const toggleColorMode = () => {
const newColorMode = colorMode === 'light' ? 'dark' : 'light'
setColorMode(newColorMode)
localStorage.setItem('color-mode', newColorMode)
}
const reactBricksConfig = {
...config,
isDarkColorMode: colorMode === 'dark',
toggleColorMode,
contentClassName: `${colorMode} ${
colorMode === 'dark' ? 'dark darkContentClass' : 'light whiteContentClass'
}`,
}
return <ReactBricks {...reactBricksConfig}>{element}</ReactBricks>
}
// Wraps every page in ReactBricks component
export const wrapPageElement = ({ element }) => {
return <ReactBricksApp element={element} />
}