mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
ui: Implement a toggle menu for setting dark mode
- Add a toggle menu for selecting the color scheme. JS code largely taken from Bootstrap documentation and slightly customized. - Use local storage to store the setting for dark/light/auto. Default to auto which means browser level preference is picked up (which could be system level preference). Tests: - Appearance of the toggle menu is consistent. Check box is shown on the currently selected value. - Deleting the local storage value reverts the preference to browser set value. - Menu is collapsed at smaller screen sizes. Appearance and functionality as expected. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
0419eb02cf
commit
00a69108dd
5 files changed
+156
No files matched your search
@@ -58,6 +58,9 @@
|
||||
<link rel="stylesheet" href="{% static user_css %}"/>
|
||||
{% endif %}
|
||||
|
||||
<!-- This script is not loaded in defer mode because it needs to run before
|
||||
page is rendered -->
|
||||
<script type="text/javascript" src="{% static 'theme/js/color-modes.js' %}"></script>
|
||||
<!-- Local link to system Bootstrap JS -->
|
||||
<script type="text/javascript" src="{% static '/javascript/popperjs2/popper.min.js' %}" defer></script>
|
||||
<script type="text/javascript" src="{% static '/javascript/bootstrap5/js/bootstrap.bundle.min.js' %}" defer></script>
|
||||
@@ -148,6 +151,8 @@
|
||||
|
||||
{% include "notifications-dropdown.html" %}
|
||||
|
||||
{% include "theme-menu.html" %}
|
||||
|
||||
{% include "help-menu.html" %}
|
||||
|
||||
<li id="id_user_menu" class="nav-item dropdown">
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
{% comment %}
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
{% endcomment %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
<li id="id_theme_menu" class="dropdown nav-item">
|
||||
<a href="#" title="{% trans "Toggle theme (auto)" %}"
|
||||
class="nav-link dropdown-toggle" data-bs-toggle="dropdown"
|
||||
role="button" aria-expanded="false" aria-haspopup="true"
|
||||
id="id_theme_menu_link">
|
||||
<span class="fa fa-adjust nav-icon" id="id_active_theme_icon"></span>
|
||||
<span class="nav-text d-md-none" id="id_toggle_theme_text">
|
||||
{% trans "Toggle theme" %}
|
||||
</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="id_theme_menu_link">
|
||||
<li>
|
||||
<button type="button" class="dropdown-item d-flex align-items-center"
|
||||
data-bs-theme-value="light" data-bs-icon-value="fa-sun"
|
||||
aria-pressed="false">
|
||||
<span class="fa fa-sun nav-icon me-2"></span>
|
||||
{% trans "Light" %}
|
||||
<span class="fa fa-check nav-icon ms-auto d-none"></span>
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="button" class="dropdown-item d-flex align-items-center"
|
||||
data-bs-theme-value="dark" data-bs-icon-value="fa-moon"
|
||||
aria-pressed="false">
|
||||
<span class="fa fa-moon nav-icon me-2"></span>
|
||||
{% trans "Dark" %}
|
||||
<span class="fa fa-check nav-icon ms-auto d-none"></span>
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="button" class="dropdown-item d-flex align-items-center"
|
||||
data-bs-theme-value="auto" data-bs-icon-value="fa-adjust"
|
||||
aria-pressed="true">
|
||||
<span class="fa fa-adjust nav-icon me-2"></span>
|
||||
{% trans "Auto" %}
|
||||
<span class="fa fa-check nav-icon ms-auto d-none"></span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
Reference in new issue
Block a user