Skip to content

Commit 486ebff

Browse files
maurerleskorpy2009
authored andcommitted
basic dark mode
1 parent 1fc580e commit 486ebff

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

lib/map.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,20 @@ export const Map = function (linkScale: (t: any) => any, sidebar: ReturnType<typ
146146
map.setZoom(map.options.maxZoom);
147147
}
148148

149-
let style: Element & { media?: string } = document.querySelector('.css-mode:not([media="not"])');
150-
if (style && e.layer.options.mode !== "" && !style.classList.contains(e.layer.options.mode)) {
151-
style.media = "not";
152-
labelLayer.updateLayer();
153-
}
154-
if (e.layer.options.mode) {
155-
let newStyle: Element & { media?: string } = document.querySelector(".css-mode." + e.layer.options.mode);
156-
newStyle.media = "";
157-
newStyle.appendChild(document.createTextNode(""));
149+
let html_tag: Element = document.querySelector("html");
150+
let class_list = html_tag.classList;
151+
class_list.forEach(function (item) {
152+
if (item.startsWith("theme_")) {
153+
class_list.remove(item);
154+
}
155+
});
156+
if (
157+
html_tag &&
158+
e.layer.options.mode &&
159+
e.layer.options.mode !== "" &&
160+
!html_tag.classList.contains(e.layer.options.mode)
161+
) {
162+
class_list.add("theme_" + e.layer.options.mode);
158163
labelLayer.updateLayer();
159164
}
160165
});

scss/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727

2828
// Make adjustments in custom scss
2929
@import "custom/custom";
30+
@import "night";

scss/night.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $color-map-background: #0d151c;
88

99
$color-online: lighten($color-online, 25%);
1010

11-
html {
11+
.theme_night {
1212
//@import 'modules/base';
1313
body,
1414
textarea,
@@ -89,10 +89,6 @@ html {
8989
border-right: 1px solid darken($color-white, 10%);
9090
}
9191

92-
img {
93-
filter: invert(100%);
94-
}
95-
9692
@media screen and (max-width: map-get($grid-breakpoints, xl) - 1) {
9793
background: $color-white;
9894
}

0 commit comments

Comments
 (0)