@t2ca/gatsby-theme-showcase 1.0.113 → 1.0.115

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.113",
3
+ "version": "1.0.115",
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,18 +87,29 @@ 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`)
95
+ useEffect(() => {
96
+ setHasMounted(true)
97
+ }, [])
98
+
99
+ if (!hasMounted) {
100
+ return null
97
101
  }
98
102
 
103
+ // const toggleColorMode = (e) => {
104
+ // e.preventDefault()
105
+ // setColorMode(isDark ? `light` : `dark`)
106
+ // }
107
+
99
108
  return (
100
109
  <IconWrapper
101
- onClick={toggleColorMode}
110
+ onClick={(e) => {
111
+ setColorMode(colorMode === "default" ? "dark" : "default")
112
+ }}
102
113
  aria-label={isDark ? `Activate light mode` : `Activate dark mode`}
103
114
  title={isDark ? `Activate light mode` : `Activate dark mode`}
104
115
  >
@@ -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>