mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-01-27 12:18:37 -06:00
This is only to avoid accidentally leaking any secrets from early development especially in the light of short-sha attacks.
25 lines
735 B
TypeScript
25 lines
735 B
TypeScript
import { createSignal, onCleanup, onMount } from "solid-js";
|
|
import type { Accessor } from "solid-js";
|
|
|
|
export function createDarkMode(): Accessor<boolean> {
|
|
const isDark = () => document.documentElement.dataset["theme"] === "dark";
|
|
|
|
const [darkMode, setDarkMode] = createSignal<boolean>(isDark());
|
|
|
|
let observer: MutationObserver | undefined;
|
|
|
|
onMount(() => {
|
|
observer = new MutationObserver((mutations) => {
|
|
mutations.forEach((mu) => {
|
|
if (mu.type === "attributes" && mu.attributeName === "data-theme") {
|
|
setDarkMode(isDark());
|
|
}
|
|
});
|
|
});
|
|
observer.observe(document.documentElement, { attributes: true });
|
|
});
|
|
onCleanup(() => observer?.disconnect());
|
|
|
|
return darkMode;
|
|
}
|