docs(palimpsest): support dark mode, local storage for theming

This commit is contained in:
Eric Liu 2020-01-12 12:55:21 -08:00
commit 4ae51209aa

View file

@ -1,9 +1,26 @@
<script>
export let inline = false;
import { onMount, afterUpdate } from 'svelte';
import { Select, SelectItem } from 'carbon-components-svelte';
import { theme } from '../store';
onMount(() => {
let currentTheme = localStorage.getItem('theme');
if (currentTheme) {
theme.set(currentTheme);
} else {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
theme.set('g90');
}
}
});
afterUpdate(() => {
localStorage.setItem('theme', $theme);
});
$: {
document.documentElement.setAttribute('carbon-theme', $theme);
}