mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
docs(theme): use Theme
component from library (#1700)
This commit is contained in:
parent
14f23962c3
commit
aa2e97f110
2 changed files with 3 additions and 32 deletions
|
@ -1,30 +0,0 @@
|
||||||
<script>
|
|
||||||
export let persist = false;
|
|
||||||
export let persistKey = "carbon-theme";
|
|
||||||
export const themes = ["white", "g10", "g80", "g90", "g100"];
|
|
||||||
|
|
||||||
import { onMount, afterUpdate } from "svelte";
|
|
||||||
import { theme } from "../store";
|
|
||||||
|
|
||||||
const isValidTheme = (value) => themes.includes(value);
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
try {
|
|
||||||
const persisted_theme = localStorage.getItem(persistKey);
|
|
||||||
if (isValidTheme(persisted_theme)) theme.set(persisted_theme);
|
|
||||||
} catch (e) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
afterUpdate(() => {
|
|
||||||
if (isValidTheme($theme)) {
|
|
||||||
document.documentElement.setAttribute("theme", $theme);
|
|
||||||
if (persist) {
|
|
||||||
try {
|
|
||||||
localStorage.setItem(persistKey, $theme);
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<slot />
|
|
|
@ -12,10 +12,11 @@
|
||||||
SideNav,
|
SideNav,
|
||||||
SideNavItems,
|
SideNavItems,
|
||||||
SideNavMenuItem,
|
SideNavMenuItem,
|
||||||
|
Theme,
|
||||||
Tag,
|
Tag,
|
||||||
} from "carbon-components-svelte";
|
} from "carbon-components-svelte";
|
||||||
import LogoGithub from "carbon-icons-svelte/lib/LogoGithub.svelte";
|
import LogoGithub from "carbon-icons-svelte/lib/LogoGithub.svelte";
|
||||||
import Theme from "../components/Theme.svelte";
|
import { theme } from "../store";
|
||||||
|
|
||||||
const deprecated = [];
|
const deprecated = [];
|
||||||
const new_components = [];
|
const new_components = [];
|
||||||
|
@ -38,7 +39,7 @@
|
||||||
<!-- routify:options bundle=true -->
|
<!-- routify:options bundle=true -->
|
||||||
<svelte:window bind:innerWidth />
|
<svelte:window bind:innerWidth />
|
||||||
|
|
||||||
<Theme persist>
|
<Theme persist bind:theme="{$theme}">
|
||||||
<Header
|
<Header
|
||||||
aria-label="Navigation"
|
aria-label="Navigation"
|
||||||
href="{$url('/')}"
|
href="{$url('/')}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue