Add dark mode toggle
Finally, it won't be all dark all the time!
This commit is contained in:
parent
553e393ba4
commit
27c0d64122
4 changed files with 39 additions and 3 deletions
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -9,7 +9,8 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^6.1.1",
|
"@fortawesome/fontawesome-free": "^6.1.1",
|
||||||
"bulma": "^0.9.4"
|
"bulma": "^0.9.4",
|
||||||
|
"darkmode-js": "^1.5.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "^0.14.43",
|
"esbuild": "^0.14.43",
|
||||||
|
@ -184,6 +185,11 @@
|
||||||
"node": ">=4.8"
|
"node": ">=4.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/darkmode-js": {
|
||||||
|
"version": "1.5.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/darkmode-js/-/darkmode-js-1.5.7.tgz",
|
||||||
|
"integrity": "sha512-gM1KhV/yy/84ZUpES9/oeOn0CVtuOi2HBd+Kccr4CJz+rFccQo2gUuPbjfyPXUx7t800Zf408G6kZb5rkTgjFA=="
|
||||||
|
},
|
||||||
"node_modules/define-properties": {
|
"node_modules/define-properties": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz",
|
||||||
|
@ -1694,6 +1700,11 @@
|
||||||
"which": "^1.2.9"
|
"which": "^1.2.9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"darkmode-js": {
|
||||||
|
"version": "1.5.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/darkmode-js/-/darkmode-js-1.5.7.tgz",
|
||||||
|
"integrity": "sha512-gM1KhV/yy/84ZUpES9/oeOn0CVtuOi2HBd+Kccr4CJz+rFccQo2gUuPbjfyPXUx7t800Zf408G6kZb5rkTgjFA=="
|
||||||
|
},
|
||||||
"define-properties": {
|
"define-properties": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz",
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^6.1.1",
|
"@fortawesome/fontawesome-free": "^6.1.1",
|
||||||
"bulma": "^0.9.4"
|
"bulma": "^0.9.4",
|
||||||
|
"darkmode-js": "^1.5.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
static/src/js/darkmode.js
Normal file
23
static/src/js/darkmode.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import Darkmode from 'darkmode-js';
|
||||||
|
|
||||||
|
const DARKMODE_OPTIONS = {
|
||||||
|
left: '32px',
|
||||||
|
right: 'unset',
|
||||||
|
time: '0.7s',
|
||||||
|
saveInCookies: false,
|
||||||
|
label: '🌓',
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
const darkmode = new Darkmode(DARKMODE_OPTIONS);
|
||||||
|
darkmode.showWidget();
|
||||||
|
window.darkmodejs = darkmode;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also listen to native theme changes
|
||||||
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", e => {
|
||||||
|
if (e.matches !== window.darkmodejs.isActivated()) {
|
||||||
|
// HACK: .toggle doesn't work quite right
|
||||||
|
window.darkmodejs.button.click();
|
||||||
|
}
|
||||||
|
});
|
|
@ -27,7 +27,8 @@
|
||||||
|
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|
||||||
<script type="text/javascript" src="{% static 'js/base.js' %}"></script>
|
<script async defer type="text/javascript" src="{% static 'js/base.js' %}"></script>
|
||||||
|
<script async defer type="text/javascript" src="{% static 'js/darkmode.js' %}"></script>
|
||||||
|
|
||||||
{% block extra_js %}{% endblock %}
|
{% block extra_js %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue