@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,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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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={
|
|
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
|
>
|