Skip to content

Commit

Permalink
Merge branch 'main' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
pacocoursey authored Mar 13, 2024
2 parents c169b88 + 19e5225 commit cf30df1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: E2E - Test

on: push
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Unit - Test

on: push
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
Expand Down
17 changes: 6 additions & 11 deletions next-themes/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ export const script = (
enableColorScheme
) => {
const el = document.documentElement
const media = `(prefers-color-scheme: dark)`
const systemThemes = ['light', 'dark']
const isClass = attribute === 'class'
const classes =
isClass && !!value
? themes.map(t => {
return value[t] || t
})
isClass && value
? themes.map(t => value[t] || t)
: themes

function updateDOM(theme: string) {
Expand All @@ -37,19 +34,17 @@ export const script = (
}

function getSystemTheme() {
return window.matchMedia(media).matches ? 'dark' : 'light'
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

;(function () {
if (forcedTheme) {
updateDOM(forcedTheme)
} else {
try {
const e = localStorage.getItem(storageKey)
const themeName = e || defaultTheme
const isSystem = enableSystem && themeName === 'system' ? true : false

const theme = isSystem ? getSystemTheme() : e || defaultTheme
const themeName = localStorage.getItem(storageKey) || defaultTheme
const isSystem = enableSystem && themeName === 'system'
const theme = isSystem ? getSystemTheme() : themeName
updateDOM(theme)
} catch (e) {
//
Expand Down

0 comments on commit cf30df1

Please sign in to comment.