1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Adds a fancy theme selector

This commit is contained in:
Óscar García Amor 2024-12-02 12:10:01 +01:00
parent ee9cb7a66d
commit 3911da475a
No known key found for this signature in database
GPG Key ID: E18B2370D3D566EE
2 changed files with 46 additions and 13 deletions

View File

@ -22,3 +22,30 @@ document.querySelectorAll('.modal').forEach(function (modal) {
}, { once: true });
});
});
function setTheme(theme) {
if (theme === 'auto') {
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
document.body.setAttribute('data-bs-theme', systemTheme);
} else {
document.body.setAttribute('data-bs-theme', theme);
}
}
const savedTheme = localStorage.getItem('theme') || 'light';
document.querySelector(`input[value="${savedTheme}"]`).checked = true;
setTheme(savedTheme);
document.querySelectorAll('input[name="theme"]').forEach(function (radio) {
radio.addEventListener('change', function () {
const selectedTheme = this.value;
localStorage.setItem('theme', selectedTheme);
setTheme(selectedTheme);
});
});
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function () {
if (localStorage.getItem('theme') === 'auto') {
setTheme('auto');
}
});

View File

@ -57,12 +57,30 @@
<ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="bi bi-person-circle" viewBox="0 0 16 16">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="bi bi-person-circle" aria-label="User settings" viewBox="0 0 16 16">
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0"/>
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1"/>
</svg>
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li class="text-center">
<div class="btn-group w-100 px-3" role="group" aria-label="Toggle theme">
<input type="radio" class="btn-check" name="theme" id="light" value="light" autocomplete="off" checked>
<label class="btn btn-outline-secondary" for="light"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-brightness-high" aria-label="Light" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Light" viewBox="0 0 16 16">
<path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6m0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8M8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0m0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13m8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5M3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8m10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0m-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0m9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707M4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708"/>
</svg></label>
<input type="radio" class="btn-check" name="theme" id="dark" value="dark" autocomplete="off">
<label class="btn btn-outline-secondary" for="dark"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-brightness-high" aria-label="Dark" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Dark" viewBox="0 0 16 16">
<path d="M6 .278a.77.77 0 0 1 .08.858 7.2 7.2 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277q.792-.001 1.533-.16a.79.79 0 0 1 .81.316.73.73 0 0 1-.031.893A8.35 8.35 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.75.75 0 0 1 6 .278M4.858 1.311A7.27 7.27 0 0 0 1.025 7.71c0 4.02 3.279 7.276 7.319 7.276a7.32 7.32 0 0 0 5.205-2.162q-.506.063-1.029.063c-4.61 0-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286"/>
<path d="M10.794 3.148a.217.217 0 0 1 .412 0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217 0 0 1 0 .412l-1.162.387a1.73 1.73 0 0 0-1.097 1.097l-.387 1.162a.217.217 0 0 1-.412 0l-.387-1.162A1.73 1.73 0 0 0 9.31 6.593l-1.162-.387a.217.217 0 0 1 0-.412l1.162-.387a1.73 1.73 0 0 0 1.097-1.097zM13.863.099a.145.145 0 0 1 .274 0l.258.774c.115.346.386.617.732.732l.774.258a.145.145 0 0 1 0 .274l-.774.258a1.16 1.16 0 0 0-.732.732l-.258.774a.145.145 0 0 1-.274 0l-.258-.774a1.16 1.16 0 0 0-.732-.732l-.774-.258a.145.145 0 0 1 0-.274l.774-.258c.346-.115.617-.386.732-.732z"/>
</svg></label>
<input type="radio" class="btn-check" name="theme" id="auto" value="auto" autocomplete="off">
<label class="btn btn-outline-secondary" for="auto"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-brightness-high" aria-label="Auto" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Auto" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 0 8 1zm0 1A8 8 0 1 1 8 0a8 8 0 0 1 0 16"/>
</svg></label>
</div>
</li>
<li><hr class="dropdown-divider"></li>
<li>
{% block navbar_profile %}
<a class="dropdown-item" href="{{ url_for('frontend.user_profile', uid = 'me')}}">{{ request.user.name }}</a>
@ -100,17 +118,5 @@
<script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/supysonic.js') }}"></script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!--
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
-->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!--
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
-->
<!-- Activate tooltips -->
<!--
<script src="{{ url_for('static', filename='js/supysonic.js') }}"></script>
-->
</body>
</html>