Skip to content

Commit 7071568

Browse files
add dark mode functionality with toggle switch; update CSS for dark mode styles
1 parent b20dde1 commit 7071568

4 files changed

Lines changed: 89 additions & 3 deletions

File tree

sources/src/main/resources/web/templates/dynamical/static/css/dynamical.css

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ li.title-menu a span {
200200
--bs-modal-border-width: var(--bs-border-width);
201201
--bs-modal-border-radius: var(--bs-border-radius-lg);
202202
--bs-modal-box-shadow: var(--bs-box-shadow-sm);
203-
--bs-modal-inner-border-radius: calc(var(--bs-border-radius-lg) -(var(--bs-border-width)));
203+
--bs-modal-inner-border-radius: calc(var(--bs-border-radius-lg) - (var(--bs-border-width)));
204204
--bs-modal-header-padding-x: 1rem;
205205
--bs-modal-header-padding-y: 1rem;
206206
--bs-modal-header-padding: 1rem 1rem;
@@ -313,6 +313,13 @@ input[type=checkbox] {
313313
text-align: center;
314314
}
315315

316+
.dark-mode .actiontb-a.z-toolbarbutton {
317+
background: var(--dt-background-dark-hover);
318+
height: 30px !important;
319+
min-width: 30px;
320+
text-align: center;
321+
}
322+
316323
.actiontb-a.btn {
317324
padding: 2px 7px;
318325
height: 30px;
@@ -703,7 +710,30 @@ input[type=checkbox] {
703710
border-color: transparent;
704711
}
705712

713+
714+
706715
.z-listheader-content,
707716
.z-treecol-content {
708717
color: #2d3238;
709718
}
719+
720+
body.dark-mode img[src="/static/dynamia-tools/images/no-photo.jpg"] {
721+
filter: brightness(0.7) invert(1);
722+
}
723+
724+
.dark-mode .z-listbox-footer .z-listfooter {
725+
background: var(--dt-background-dark);
726+
border-color: transparent;
727+
}
728+
729+
.dark-mode .dark-mode-switch .dark-icon {
730+
display: none;
731+
}
732+
733+
.dark-mode-switch .light-icon{
734+
display: none;
735+
}
736+
737+
.dark-mode .dark-mode-switch .light-icon{
738+
display: inline;
739+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function initDarkMode(toggleSelector) {
2+
const body = document.body;
3+
const toggleBtn = document.querySelector(toggleSelector);
4+
5+
// Función para aplicar modo según preferencia
6+
function applyTheme(theme) {
7+
if (theme === "dark") {
8+
body.classList.add("dark-mode");
9+
body.classList.remove("light-mode");
10+
} else {
11+
body.classList.add("light-mode");
12+
body.classList.remove("dark-mode");
13+
}
14+
localStorage.setItem("theme", theme);
15+
}
16+
17+
// Inicializar: leer localStorage o usar default "light"
18+
const savedTheme = localStorage.getItem("theme") || "light";
19+
applyTheme(savedTheme);
20+
21+
// Toggle al dar clic
22+
toggleBtn.addEventListener("click", () => {
23+
const newTheme = body.classList.contains("dark-mode") ? "light" : "dark";
24+
applyTheme(newTheme);
25+
});
26+
}
27+
28+
function detectDevice() {
29+
const body = document.body;
30+
body.classList.remove("device-smartphone", "device-tablet", "device-desktop");
31+
32+
const width = window.innerWidth;
33+
34+
if (width <= 767) {
35+
body.classList.add("device-smartphone");
36+
} else if (width <= 1024) {
37+
body.classList.add("device-tablet");
38+
} else {
39+
body.classList.add("device-desktop");
40+
}
41+
}
42+
43+
44+
zk.afterMount(function () {
45+
initDarkMode(".dark-mode-switch");
46+
detectDevice();
47+
window.addEventListener("resize", detectDevice);
48+
});

sources/src/main/resources/web/templates/dynamical/views/index.zul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<?script src="${contextPath}/static/js/bootstrap.min.js?v=5.4.12"?>
4747
<?script src="${contextPath}/static/js/adminlte.min.js?v=5.4.12"?>
4848
<?script src="${contextPath}/static/js/dynamical.js?v=5.4.12"?>
49+
<?script src="${contextPath}/static/js/dark-mode.js?v=5.4.12"?>
4950

5051
<zk >
5152
<import src="classpath:/zk/dynamical/index-main.zul"/>

sources/src/main/resources/zk/dynamical/index-main.zul

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
</li>
3636
</z:zk>
3737

38+
<li class="nav-item">
39+
<a class="nav-link dark-mode-switch" href="#">
40+
<i class="fa fa-moon dark-icon"/>
41+
<i class="fa fa-sun light-icon"/>
42+
</a>
43+
</li>
3844

3945
<li class="nav-item">
4046
<a class="nav-link" data-lte-toggle="fullscreen" href="#">
@@ -46,7 +52,8 @@
4652
<!-- User Account: style can be found in dropdown.less -->
4753
<z:zk if="${userInfo.enabled}">
4854
<li class="nav-item dropdown user-menu">
49-
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
55+
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown"
56+
aria-expanded="false">
5057
<img src="${userInfo.image}" class="user-image shadow"/>
5158
<span class="d-none d-md-inline">${userInfo.fullName}</span>
5259
</a>
@@ -66,7 +73,7 @@
6673
<li class="user-footer">
6774
<div class="pull-left">
6875
<z:a zclass="btn btn-primary btn-flat" label=" ${labels.profile}"
69-
iconSclass="fa fa-user"
76+
iconSclass="fa fa-user" if="${userInfo.profilePath != null}"
7077
onClick='navManager.navigateTo(userInfo.profilePath)'/>
7178

7279
</div>

0 commit comments

Comments
 (0)