= ({
styles.notion,
pageId === site.rootNotionPageId && 'index-page'
)}
+ darkMode={isDarkMode}
components={components}
recordMap={recordMap}
rootPageId={site.rootNotionPageId}
diff --git a/components/NotionPageHeader.tsx b/components/NotionPageHeader.tsx
index 1a8f401..6458305 100644
--- a/components/NotionPageHeader.tsx
+++ b/components/NotionPageHeader.tsx
@@ -1,37 +1,33 @@
import * as React from 'react'
import cs from 'classnames'
-import { useTheme } from 'next-themes'
import { IoSunnyOutline } from '@react-icons/all-files/io5/IoSunnyOutline'
import { IoMoonSharp } from '@react-icons/all-files/io5/IoMoonSharp'
import { Header, Breadcrumbs, Search, useNotionContext } from 'react-notion-x'
import * as types from 'notion-types'
+import { useDarkMode } from 'lib/use-dark-mode'
import { navigationStyle, navigationLinks, isSearchEnabled } from 'lib/config'
import styles from './styles.module.css'
const ToggleThemeButton = () => {
const [hasMounted, setHasMounted] = React.useState(false)
- const { resolvedTheme, setTheme } = useTheme()
+ const { isDarkMode, toggleDarkMode } = useDarkMode()
React.useEffect(() => {
setHasMounted(true)
}, [])
const onToggleTheme = React.useCallback(() => {
- setTheme(resolvedTheme === 'light' ? 'dark' : 'light')
- }, [resolvedTheme, setTheme])
+ toggleDarkMode()
+ }, [toggleDarkMode])
return (
- {hasMounted && resolvedTheme === 'dark' ? (
-
- ) : (
-
- )}
+ {hasMounted && isDarkMode ? : }
)
}
diff --git a/components/PageSocial.module.css b/components/PageSocial.module.css
index 37ff001..bb16f8d 100644
--- a/components/PageSocial.module.css
+++ b/components/PageSocial.module.css
@@ -68,7 +68,7 @@
fill: var(--bg-color);
}
-:global([data-theme='dark']) .action:hover svg {
+:global(.dark-mode) .action:hover svg {
fill: var(--fg-color);
}
diff --git a/lib/use-dark-mode.ts b/lib/use-dark-mode.ts
new file mode 100644
index 0000000..1e6a1d2
--- /dev/null
+++ b/lib/use-dark-mode.ts
@@ -0,0 +1,10 @@
+import useDarkModeImpl from '@fisch0920/use-dark-mode'
+
+export function useDarkMode() {
+ const darkMode = useDarkModeImpl(false, { classNameDark: 'dark-mode' })
+
+ return {
+ isDarkMode: darkMode.value,
+ toggleDarkMode: darkMode.toggle
+ }
+}
diff --git a/package.json b/package.json
index 196cdc4..0b956e1 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,7 @@
"test:prettier": "prettier '**/*.{js,jsx,ts,tsx}' --check"
},
"dependencies": {
+ "@fisch0920/use-dark-mode": "^2.4.0",
"@keyvhq/core": "^1.6.9",
"@keyvhq/redis": "^1.6.10",
"@react-icons/all-files": "^4.1.0",
@@ -37,7 +38,6 @@
"lqip-modern": "^1.2.0",
"next": "^12.1.1",
"next-api-og-image": "^2.2.1",
- "next-themes": "^0.1.1",
"node-fetch": "^2.6.1",
"notion-client": "^6.12.0",
"notion-types": "^6.11.0",
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 44bfc19..0b1961f 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -23,7 +23,6 @@ import * as React from 'react'
import * as Fathom from 'fathom-client'
import type { AppProps } from 'next/app'
import { useRouter } from 'next/router'
-import { ThemeProvider } from 'next-themes'
import posthog from 'posthog-js'
import { bootstrap } from 'lib/bootstrap-client'
@@ -68,9 +67,5 @@ export default function App({ Component, pageProps }: AppProps) {
}
}, [router.events])
- return (
-
-
-
- )
+ return
}
diff --git a/pages/_document.tsx b/pages/_document.tsx
index 9dfba43..a60676d 100644
--- a/pages/_document.tsx
+++ b/pages/_document.tsx
@@ -20,6 +20,46 @@ export default class MyDocument extends Document {
+
diff --git a/styles/notion.css b/styles/notion.css
index e7405cd..acf79e4 100644
--- a/styles/notion.css
+++ b/styles/notion.css
@@ -327,15 +327,15 @@
}
/* disable highlighting in dark mode */
-[data-theme='dark'] .notion-red_background,
-[data-theme='dark'] .notion-pink_background,
-[data-theme='dark'] .notion-blue_background,
-[data-theme='dark'] .notion-purple_background,
-[data-theme='dark'] .notion-teal_background,
-[data-theme='dark'] .notion-yellow_background,
-[data-theme='dark'] .notion-orange_background,
-[data-theme='dark'] .notion-brown_background,
-[data-theme='dark'] .notion-gray_background {
+.dark-mode .notion-red_background,
+.dark-mode .notion-pink_background,
+.dark-mode .notion-blue_background,
+.dark-mode .notion-purple_background,
+.dark-mode .notion-teal_background,
+.dark-mode .notion-yellow_background,
+.dark-mode .notion-orange_background,
+.dark-mode .notion-brown_background,
+.dark-mode .notion-gray_background {
padding: 0;
margin: 0;
border-radius: 0;
@@ -357,7 +357,7 @@
backdrop-filter: saturate(180%) blur(16px);
}
-[data-theme='dark'] .notion-header {
+.dark-mode .notion-header {
background: transparent;
box-shadow: inset 0 -1px 0 0 rgba(0, 0, 0, 0.1);
backdrop-filter: saturate(180%) blur(8px);
@@ -365,7 +365,7 @@
/* Workaround for Firefox not supporting backdrop-filter yet */
@-moz-document url-prefix() {
- [data-theme='dark'] .notion-header {
+ .dark-mode .notion-header {
background: hsla(203, 8%, 20%, 0.8);
}
}
diff --git a/yarn.lock b/yarn.lock
index 165a31f..cf34ead 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -29,6 +29,14 @@
resolved "https://registry.npmjs.org/@fisch0920/medium-zoom/-/medium-zoom-1.0.7.tgz"
integrity sha512-hPUrgVM/QvsZdZzDTPyL1C1mOtEw03RqTLmK7ZlJ8S/64u4O4O5BvPvjB/9kyLtE6iVaS9UDRAMSwmM9uh2JIw==
+"@fisch0920/use-dark-mode@^2.4.0":
+ version "2.4.0"
+ resolved "https://registry.yarnpkg.com/@fisch0920/use-dark-mode/-/use-dark-mode-2.4.0.tgz#92ba90c313a37099879a7b0405280933f9105cdc"
+ integrity sha512-R5onciu81CCOxWVIJcRjp1PfSfBI5fIfxYR2jqydc0nuGWrn4ZB4ciDXiv36PNX5mFIbAgPfjUF0Z5lhSI62TA==
+ dependencies:
+ "@use-it/event-listener" "^0.1.2"
+ use-persisted-state "^0.3.0"
+
"@humanwhocodes/config-array@^0.9.2":
version "0.9.5"
resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz"
@@ -612,6 +620,11 @@
"@typescript-eslint/types" "5.18.0"
eslint-visitor-keys "^3.0.0"
+"@use-it/event-listener@^0.1.2":
+ version "0.1.7"
+ resolved "https://registry.yarnpkg.com/@use-it/event-listener/-/event-listener-0.1.7.tgz#443a9b6df87f2f2961b74d42997ce723a7078623"
+ integrity sha512-hgfExDzUU9uTRTPDCpw2s9jWTxcxmpJya3fK5ADpf5VDpSy8WYwY/kh28XE0tUcbsljeP8wfan48QvAQTSSa3Q==
+
"@xobotyi/scrollbar-width@^1.9.5":
version "1.9.5"
resolved "https://registry.npmjs.org/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz"
@@ -2368,11 +2381,6 @@ next-api-og-image@^2.2.1:
puppeteer-core "^10.4.0"
twemoji "^13.1.0"
-next-themes@^0.1.1:
- version "0.1.1"
- resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.1.1.tgz#122113a458bf1d1be5ffed66778ab924c106f82a"
- integrity sha512-Iqxt6rhS/KfK/iHJ0tfFjTcdLEAI0AgwFuAFrMwLOPK5e+MI3I+fzyvBoS+VaOS+NldUiazurhgwYhrfV0VXsQ==
-
next@^12.1.1:
version "12.1.3"
resolved "https://registry.npmjs.org/next/-/next-12.1.3.tgz"
@@ -3763,6 +3771,13 @@ use-callback-ref@^1.2.3:
resolved "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.2.5.tgz"
integrity sha512-gN3vgMISAgacF7sqsLPByqoePooY3n2emTH59Ur5d/M8eg4WTWu1xp8i8DHjohftIyEx0S08RiYxbffr4j8Peg==
+use-persisted-state@^0.3.0:
+ version "0.3.3"
+ resolved "https://registry.yarnpkg.com/use-persisted-state/-/use-persisted-state-0.3.3.tgz#5e0f2236967cec7c34de33abc07ae6818e7c7451"
+ integrity sha512-pCNlvYC8+XjRxwnIut4teGC9f2p9aD88R8OGseQGZa2dvqG/h1vEGk1vRE1IZG0Vf161UDpn+NlW4+UGubQflQ==
+ dependencies:
+ "@use-it/event-listener" "^0.1.2"
+
use-sidecar@^1.0.1:
version "1.0.5"
resolved "https://registry.npmjs.org/use-sidecar/-/use-sidecar-1.0.5.tgz"