Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit d48e920

Browse files
committed
Swap time-based script for prefers-color-scheme
1 parent 2badeaa commit d48e920

File tree

5 files changed

+332
-276
lines changed

5 files changed

+332
-276
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins: [
1616

1717
## Usage
1818

19-
Styles generated by this plugin are only used if the `mode-dark` class is applied to the `<html>` element. How you do that is up to you. `dark-mode.js` is provided as an option, which is a simple script that enables dark mode from 6 PM to 6 AM in the user's timezone.
19+
Styles generated by this plugin are only used if the `mode-dark` class is applied to the `<html>` element. How you do that is up to you. `prefers-dark.js` is provided as an option, which is a simple script that enables dark mode based on the user's system theme.
2020

2121
### Available Variants
2222

dark-mode.js

-9
This file was deleted.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tailwindcss-dark-mode",
33
"description": "A Tailwind CSS plugin that adds variants for dark mode",
4-
"version": "1.0.3",
4+
"version": "1.1.1",
55
"author": "Chance Arthur",
66
"license": "MIT",
77
"copyright": "Chance Arthur",
@@ -23,10 +23,10 @@
2323
"javascript"
2424
],
2525
"dependencies": {
26-
"tailwindcss": "^1.0.0-beta.5"
26+
"tailwindcss": "^1.1.4"
2727
},
2828
"devDependencies": {
29-
"eslint": "^5.16.0",
30-
"eslint-config-google": "^0.12.0"
29+
"eslint": "^6.7.2",
30+
"eslint-config-google": "^0.14.0"
3131
}
3232
}

prefers-dark.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function checkDarkMode() {
2+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
3+
return true;
4+
}
5+
return false;
6+
}
7+
8+
if (checkDarkMode()) {
9+
document.documentElement.classList.add('mode-dark');
10+
} else {
11+
document.documentElement.classList.remove('mode-dark');
12+
}

0 commit comments

Comments
 (0)