mirror of
https://github.com/Xevion/icons.git
synced 2025-12-08 04:07:28 -06:00
Add internal dark mode switching script
This commit is contained in:
15
public/js/darkmode.js
Normal file
15
public/js/darkmode.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const valid = ['system', 'dark', 'light'];
|
||||||
|
|
||||||
|
console.log(localStorage.theme);
|
||||||
|
// Set the default to system, ignore & delete invalid values
|
||||||
|
if (!('theme' in localStorage) || valid.indexOf(localStorage.theme) === -1)
|
||||||
|
localStorage.theme = 'system';
|
||||||
|
|
||||||
|
if (localStorage.theme === 'system') {
|
||||||
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
document.documentElement.classList.add(preferDark ? 'dark' : 'light');
|
||||||
|
} else if (localStorage.theme === 'dark') {
|
||||||
|
document.documentElement.classList.add('dark')
|
||||||
|
} else if (localStorage.theme === 'light') {
|
||||||
|
document.documentElement.classList.remove('dark')
|
||||||
|
}
|
||||||
15
src/pages/_document.tsx
Normal file
15
src/pages/_document.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import {Html, Head, Main, NextScript} from 'next/document'
|
||||||
|
import Script from 'next/script'
|
||||||
|
|
||||||
|
export default function Document() {
|
||||||
|
return (
|
||||||
|
<Html>
|
||||||
|
<Head />
|
||||||
|
<body>
|
||||||
|
<Main/>
|
||||||
|
<NextScript/>
|
||||||
|
<Script strategy="beforeInteractive" id="automatic-darkmode" src="/js/darkmode.js"/>
|
||||||
|
</body>
|
||||||
|
</Html>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: ["./src/**/*.{js,ts,jsx,tsx}"],
|
content: ["./src/**/*.{js,ts,jsx,tsx}"],
|
||||||
|
darkMode: 'class',
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user