mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-07 14:15:34 +00:00
Add support for system theme (#987)
Add support for system theme --------- Co-authored-by: Juan Mora <juan@nimble.gt> Co-authored-by: Pēteris Caune <cuu508@gmail.com>
This commit is contained in:
parent
8ba75475bb
commit
3718ff57c7
4 changed files with 35 additions and 8 deletions
|
@ -940,7 +940,7 @@ def appearance(request: AuthenticatedHttpRequest) -> HttpResponse:
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
theme = request.POST.get("theme", "")
|
theme = request.POST.get("theme", "")
|
||||||
if theme in ("", "dark"):
|
if theme in ("", "dark", "system"):
|
||||||
profile.theme = theme
|
profile.theme = theme
|
||||||
profile.save()
|
profile.save()
|
||||||
ctx["status"] = "info"
|
ctx["status"] = "info"
|
||||||
|
|
BIN
static/img/theme-system.png
Normal file
BIN
static/img/theme-system.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 8.7 KiB |
|
@ -33,7 +33,7 @@
|
||||||
<h2>Theme</h2>
|
<h2>Theme</h2>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6 theme">
|
<div class="col-sm-4 theme">
|
||||||
<label for="theme-light">
|
<label for="theme-light">
|
||||||
<img
|
<img
|
||||||
src="{% static 'img/theme-light.png' %}"
|
src="{% static 'img/theme-light.png' %}"
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
Light
|
Light
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6 theme">
|
<div class="col-sm-4 theme">
|
||||||
<label for="theme-dark">
|
<label for="theme-dark">
|
||||||
<img
|
<img
|
||||||
src="{% static 'img/theme-dark.png' %}"
|
src="{% static 'img/theme-dark.png' %}"
|
||||||
|
@ -69,7 +69,24 @@
|
||||||
Dark
|
Dark
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="col-sm-4 theme">
|
||||||
|
<label for="theme-system">
|
||||||
|
<img
|
||||||
|
src="{% static 'img/theme-system.png' %}"
|
||||||
|
alt="System theme preview">
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="radio-container">
|
||||||
|
<input
|
||||||
|
id="theme-system"
|
||||||
|
type="radio"
|
||||||
|
name="theme"
|
||||||
|
value="system"
|
||||||
|
{% if profile.theme == "system" %} checked {% endif %}>
|
||||||
|
<span class="radiomark"></span>
|
||||||
|
System
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% if status == "info" %}
|
{% if status == "info" %}
|
||||||
|
|
|
@ -12,9 +12,6 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="apple-mobile-web-app-title" content="{{ site_name }}">
|
<meta name="apple-mobile-web-app-title" content="{{ site_name }}">
|
||||||
<meta name="application-name" content="{{ site_name }}">
|
<meta name="application-name" content="{{ site_name }}">
|
||||||
{% if request.user.is_authenticated and request.profile.theme == 'dark' %}
|
|
||||||
<meta name="theme-color" content="#18181b">
|
|
||||||
{% endif %}
|
|
||||||
{% block favicon %}
|
{% block favicon %}
|
||||||
<link rel="icon" type="image/svg+xml" href="{% static 'img/favicon.svg' %}">
|
<link rel="icon" type="image/svg+xml" href="{% static 'img/favicon.svg' %}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -224,9 +221,22 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
{% block base_modals %}{% endblock %}
|
{% block base_modals %}{% endblock %}
|
||||||
|
|
||||||
|
{% if request.user.is_authenticated and request.profile.theme == 'system' %}
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
|
function switchColors() {
|
||||||
|
document.body.classList.toggle("dark", prefersDark.matches);
|
||||||
|
}
|
||||||
|
switchColors();
|
||||||
|
prefersDark.addEventListener("change", switchColors);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% block base_scripts %}
|
{% block base_scripts %}
|
||||||
{% compress js %}
|
{% compress js %}
|
||||||
<script src="{% static 'js/jquery-3.6.0.min.js' %}"></script>
|
<script src="{% static 'js/jquery-3.6.0.min.js' %}"></script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue