mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
style(docs): color-scheme
reflects theme (#1874)
This commit is contained in:
parent
fe0b0c2b18
commit
1600775968
4 changed files with 34 additions and 7 deletions
|
@ -5,6 +5,16 @@
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="/favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Carbon Components Svelte</title>
|
<title>Carbon Components Svelte</title>
|
||||||
|
<script>
|
||||||
|
try {
|
||||||
|
const theme = localStorage.getItem("theme");
|
||||||
|
|
||||||
|
if (["white", "g10", "g80", "g90", "g100"].includes(theme)) {
|
||||||
|
document.documentElement.setAttribute("theme", theme);
|
||||||
|
document.documentElement.style.setProperty("color-scheme", ["white", "g10"].includes(theme) ? "light" : "dark");
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module" src="/src/index.js"></script>
|
<script type="module" src="/src/index.js"></script>
|
||||||
|
|
|
@ -34,10 +34,11 @@
|
||||||
$: multiple = api_components.length > 1;
|
$: multiple = api_components.length > 1;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const currentTheme = window.location.search.split("?theme=")[1];
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
|
const current_theme = searchParams.get("theme");
|
||||||
|
|
||||||
if (["white", "g10", "g80", "g90", "g100"].includes(currentTheme)) {
|
if (["white", "g10", "g80", "g90", "g100"].includes(current_theme)) {
|
||||||
theme.set(currentTheme);
|
theme.set(current_theme);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,14 @@
|
||||||
}
|
}
|
||||||
}}" />
|
}}" />
|
||||||
|
|
||||||
<Theme persist bind:theme="{$theme}">
|
<Theme
|
||||||
|
persist
|
||||||
|
bind:theme="{$theme}"
|
||||||
|
on:update="{(e) => {
|
||||||
|
const theme = e.detail.theme;
|
||||||
|
document.documentElement.style.setProperty("color-scheme", ["white", "g10"].includes(theme) ? "light" : "dark");
|
||||||
|
}}"
|
||||||
|
>
|
||||||
<Header
|
<Header
|
||||||
aria-label="Navigation"
|
aria-label="Navigation"
|
||||||
href="{$url('/')}"
|
href="{$url('/')}"
|
||||||
|
|
|
@ -8,9 +8,18 @@
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: [refactor] parse search parameters more reliably
|
$: {
|
||||||
$: currentTheme = window.location.search.split("?theme=")[1];
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
$: document.documentElement.setAttribute("theme", currentTheme);
|
const current_theme = searchParams.get("theme");
|
||||||
|
|
||||||
|
// NOTE: we *do not* want to persist the theme as this can
|
||||||
|
// conflict with how the iframe is displayed in the docs.
|
||||||
|
// Instead, we want the theme to be overridden in the standalone page.
|
||||||
|
if ([ "white", "g10", "g80", "g90", "g100" ].includes(current_theme)) {
|
||||||
|
document.documentElement.setAttribute("theme", current_theme)
|
||||||
|
document.documentElement.style.setProperty("color-scheme", ["white", "g10"].includes(current_theme) ? "light" : "dark");
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot />
|
<slot />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue