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