Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 5e2ef1a

Browse files
committed
fix: react issues
1 parent 9f0efc1 commit 5e2ef1a

6 files changed

Lines changed: 31 additions & 6 deletions

File tree

packages/gatsby-plugin-perfect-dark-mode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"license": "MIT",
1515
"author": "Dylan Vann <dylan@dylanvann.com> (https://dylanvann.com)",
1616
"sideEffects": "false",
17-
"main": "dist/index.cjs.js",
18-
"module": "dist/index.esm.js",
19-
"types": "dist/index.d.ts",
17+
"main": "src/index.cjs.js",
18+
"module": "src/index.esm.js",
19+
"types": "src/index.d.ts",
2020
"files": [
2121
"gatsby-ssr.js",
2222
"dist"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('react-perfect-dark-mode')

packages/gatsby-plugin-perfect-dark-mode/src/index.ts renamed to packages/gatsby-plugin-perfect-dark-mode/src/index.d.ts

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'react-perfect-dark-mode'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "ES2020",
5+
"strict": true,
6+
"moduleResolution": "node",
7+
"esModuleInterop": true,
8+
"emitDeclarationOnly": true,
9+
"declaration": true,
10+
"declarationDir": "src",
11+
"skipLibCheck": true,
12+
"forceConsistentCasingInFileNames": true
13+
},
14+
"include": ["src"]
15+
}

packages/react-perfect-dark-mode/src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { useCallback, useLayoutEffect, useState } from 'react'
2-
import type { ColorMode, EnhancedUpdater, Updater } from 'perfect-dark-mode'
2+
import type {
3+
ColorMode,
4+
EnhancedUpdater,
5+
PerfectDarkMode,
6+
Updater,
7+
} from 'perfect-dark-mode'
38

49
export * from 'perfect-dark-mode'
5-
export const pdm = window.__pdm__
10+
11+
export const pdm: PerfectDarkMode =
12+
typeof window !== 'undefined' && (window.__pdm__ as any)
13+
614
export const usePerfectDarkMode = (): {
715
mode: ColorMode | undefined
816
setMode: (mode: ColorMode) => void
@@ -11,7 +19,7 @@ export const usePerfectDarkMode = (): {
1119
setModes: (modes: ColorMode[]) => void
1220
updateModes: (updater: Updater<ColorMode[]>) => void
1321
} => {
14-
const { mode: pdmMode, modes: pdmModes } = pdm
22+
const { mode: pdmMode, modes: pdmModes } = pdm || {}
1523
const [mode, setModeInternal] = useState<ColorMode | undefined>(undefined)
1624
const [modes, setModesInternal] = useState<ColorMode[]>(() => [])
1725
useLayoutEffect(() => pdm.mode.subscribe((v) => setModeInternal(v)), [])

0 commit comments

Comments
 (0)