Skip to content

Commit d41e27f

Browse files
authored
feat(ui): use temporary overlay during light/dark theme switching
1 parent bd54307 commit d41e27f

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

shkeeper/static/css/common.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ dialog::backdrop {
1616
opacity: .9;
1717
}
1818

19+
.theme-transition-overlay {
20+
position: fixed;
21+
inset: 0;
22+
background: var(--theme-transition-color, #000);
23+
opacity: 0;
24+
pointer-events: none;
25+
transition: opacity .35s ease;
26+
z-index: 9999;
27+
}
28+
29+
html[data-theme="light"] .theme-transition-overlay {
30+
--theme-transition-color: #ffffff;
31+
}
32+
33+
html[data-theme="dark"] .theme-transition-overlay {
34+
--theme-transition-color: #000000;
35+
}
1936

2037
.htmx-indicator{
2138
display:none;

shkeeper/templates/base.j2

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<link rel="stylesheet" href="{{ url_for('static', filename='css/tooltips.css') }}">
2525
</head>
2626
<body>
27+
<div class="theme-transition-overlay"></div>
2728

2829
{% block body %}{% endblock %}
2930

@@ -59,13 +60,26 @@
5960
document.querySelectorAll('img.big-logo, img.menu-logo, img.htmx-indicator').forEach((e, i) => { e.src = e.src.replace('.dark.', '.light.'); });
6061
}
6162
62-
function forceColorScheme(is_dark) {
63-
if (is_dark) {
64-
setDark();
65-
} else {
66-
setLight();
67-
}
68-
}
63+
function forceColorScheme(is_dark) {
64+
const overlay = document.querySelector('.theme-transition-overlay');
65+
66+
overlay.style.opacity = '1';
67+
68+
setTimeout(() => {
69+
if (is_dark) {
70+
setDark();
71+
document.documentElement.setAttribute("data-theme", "dark");
72+
} else {
73+
setLight();
74+
document.documentElement.setAttribute("data-theme", "light");
75+
}
76+
}, 150);
77+
78+
setTimeout(() => {
79+
overlay.style.opacity = '0';
80+
}, 350);
81+
}
82+
6983
7084
function useMediaRequestColorScheme() {
7185
if (document.cookie.match(/theme=(dark|light)/)) return;

0 commit comments

Comments
 (0)