@t2ca/gatsby-theme-showcase 1.0.114 → 1.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t2ca/gatsby-theme-showcase",
3
- "version": "1.0.114",
3
+ "version": "1.0.116",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
@@ -1,4 +1,4 @@
1
- import React from "react"
1
+ import React, { useState, useEffect } from "react"
2
2
  import styled from "@emotion/styled"
3
3
  import { useThemeUI } from "theme-ui"
4
4
 
@@ -87,20 +87,27 @@ const MoonMask = styled.div`
87
87
  `
88
88
 
89
89
  const ColorModeToggle = () => {
90
+ const [hasMounted, setHasMounted] = useState(false)
90
91
  const context = useThemeUI()
91
92
  const { theme, colorMode, setColorMode } = context
92
93
  const isDark = colorMode === `dark`
93
94
 
94
- // const toggleColorMode = (e) => {
95
- // e.preventDefault()
96
- // setColorMode(isDark ? `light` : `dark`)
97
- // }
95
+ useEffect(() => {
96
+ setHasMounted(true)
97
+ }, [])
98
+
99
+ if (!hasMounted) {
100
+ return null
101
+ }
102
+
103
+ const toggleColorMode = (e) => {
104
+ e.preventDefault()
105
+ setColorMode(isDark ? `default` : `dark`)
106
+ }
98
107
 
99
108
  return (
100
109
  <IconWrapper
101
- onClick={(e) => {
102
- setColorMode(colorMode === "default" ? "dark" : "default")
103
- }}
110
+ onClick={toggleColorMode}
104
111
  aria-label={isDark ? `Activate light mode` : `Activate dark mode`}
105
112
  title={isDark ? `Activate light mode` : `Activate dark mode`}
106
113
  >
@@ -86,7 +86,9 @@ export default ({
86
86
 
87
87
  {button}
88
88
 
89
- <ColorModeToggle />
89
+ <div sx={{ width: `30px` }}>
90
+ <ColorModeToggle />
91
+ </div>
90
92
  </div>
91
93
  </div>
92
94
  </Container>