mirror of
https://github.com/jakejarvis/dark-mode.git
synced 2025-04-26 01:45:24 -04:00
remove unnecessary deps (now zero 😎)
This commit is contained in:
parent
4881b908e9
commit
e4d7e4f61b
@ -4,7 +4,7 @@
|
||||
[](https://www.npmjs.com/package/@jakejarvis/dark-mode)
|
||||
[](LICENSE)
|
||||
|
||||
Very simple CSS dark/light mode toggler with saved preference via local storage & dynamic OS setting detection. Only ~700 bytes gzipped!
|
||||
Very simple CSS dark/light mode toggler with saved preference via local storage & dynamic OS setting detection. Zero dependencies and only ~700 bytes gzipped!
|
||||
|
||||
- [View the example.](https://jakejarvis.github.io/dark-mode-example/)
|
||||
- [Read the blog post.](https://jarv.is/notes/dark-mode/)
|
||||
@ -64,6 +64,11 @@ darkMode.init({
|
||||
});
|
||||
```
|
||||
|
||||
## To-Do
|
||||
|
||||
- [ ] Support more than two themes
|
||||
- [ ] Add callback function `onChange` (or `onToggle` etc.) passed in as an option
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
@ -19,9 +19,7 @@
|
||||
"lint": "eslint src/**/*.js",
|
||||
"prepublishOnly": "run-s lint build"
|
||||
},
|
||||
"dependencies": {
|
||||
"storage-available": "^1.1.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"eslint": "^7.32.0",
|
||||
|
16
src/index.js
16
src/index.js
@ -1,4 +1,4 @@
|
||||
const storageAvailable = require("storage-available");
|
||||
"use strict";
|
||||
|
||||
const initializeDarkMode = function (options) {
|
||||
// { toggle, classes: { light, dark }, default, storageKey }
|
||||
@ -88,4 +88,18 @@ const initializeDarkMode = function (options) {
|
||||
}
|
||||
};
|
||||
|
||||
// recommended method (by MDN) to detect localStorage availability:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage
|
||||
const storageAvailable = function (type) {
|
||||
try {
|
||||
var storage = window[type];
|
||||
var x = "__storage_test__";
|
||||
storage.setItem(x, x);
|
||||
storage.removeItem(x);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.init = initializeDarkMode;
|
||||
|
Loading…
x
Reference in New Issue
Block a user