feat: actually add theme switching :mind_blown:
This commit is contained in:
parent
1066822dd5
commit
441dc0c15c
4 changed files with 31 additions and 4 deletions
|
@ -5,7 +5,11 @@
|
||||||
<p class="subtitle">THEMES</p>
|
<p class="subtitle">THEMES</p>
|
||||||
<div class="themes">
|
<div class="themes">
|
||||||
<div v-for="theme of themes" class="theme-preview-container">
|
<div v-for="theme of themes" class="theme-preview-container">
|
||||||
<span class="theme-preview" :title="theme.displayName" :style="{background:`linear-gradient(${theme.previewGradient})`}">
|
<span class="theme-preview"
|
||||||
|
:title="theme.displayName"
|
||||||
|
:style="{background:`linear-gradient(${theme.previewGradient})`}"
|
||||||
|
@click="changeTheme(theme.ID, theme.themeURL)"
|
||||||
|
>
|
||||||
<span class="theme-title" :style="{color:`${theme.complementaryColor}`}">
|
<span class="theme-title" :style="{color:`${theme.complementaryColor}`}">
|
||||||
{{ theme.displayName }}
|
{{ theme.displayName }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -25,23 +29,45 @@
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
const defaultThemes = runtimeConfig.public.defaultThemes
|
const defaultThemes = runtimeConfig.public.defaultThemes
|
||||||
const baseURL = runtimeConfig.app.baseURL;
|
const baseURL = runtimeConfig.app.baseURL;
|
||||||
|
let themeLinkElement: HTMLLinkElement | null = null;
|
||||||
|
|
||||||
const themes: Array<Theme> = []
|
const themes: Array<Theme> = []
|
||||||
|
|
||||||
interface Theme {
|
interface Theme {
|
||||||
|
ID: string
|
||||||
displayName: string
|
displayName: string
|
||||||
previewGradient: string
|
previewGradient: string
|
||||||
complementaryColor: string
|
complementaryColor: string
|
||||||
themeURL: string
|
themeURL: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeTheme(ID: string, URL: string) {
|
||||||
|
if (themeLinkElement && themeLinkElement.getAttribute('href') === `${baseURL}themes/${URL}`) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem("selectedTheme", ID);
|
||||||
|
|
||||||
|
// if the theme didn't originally load for some reason, create it
|
||||||
|
if (!themeLinkElement) {
|
||||||
|
themeLinkElement = document.createElement('link');
|
||||||
|
themeLinkElement.rel = 'stylesheet';
|
||||||
|
document.head.appendChild(themeLinkElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
themeLinkElement.href = `${baseURL}themes/${URL}`;
|
||||||
|
}
|
||||||
|
|
||||||
const fetchThemes = async () => {
|
const fetchThemes = async () => {
|
||||||
for (const theme of defaultThemes) {
|
for (const theme of defaultThemes) {
|
||||||
const themeConfig = await fetch(`${baseURL}themes/${theme}.json`)
|
const themeConfig = await fetch(`${baseURL}themes/${theme}.json`)
|
||||||
const themeConfigJson = await themeConfig.json() as Theme
|
const themeConfigJson = await themeConfig.json() as Theme
|
||||||
|
themeConfigJson.ID = theme
|
||||||
|
|
||||||
themes.push(themeConfigJson)
|
themes.push(themeConfigJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(themes)
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchThemes()
|
await fetchThemes()
|
||||||
|
@ -67,6 +93,7 @@ await fetchThemes()
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.theme-title {
|
.theme-title {
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
"displayName": "Ash",
|
"displayName": "Ash",
|
||||||
"previewGradient": "45deg, #2f2e2d, #46423b",
|
"previewGradient": "45deg, #2f2e2d, #46423b",
|
||||||
"complementaryColor": "white",
|
"complementaryColor": "white",
|
||||||
"themeData": "ash.css"
|
"themeURL": "ash.css"
|
||||||
}
|
}
|
|
@ -2,5 +2,5 @@
|
||||||
"displayName": "Dark",
|
"displayName": "Dark",
|
||||||
"previewGradient": "45deg, #1f1e1d, #36322b",
|
"previewGradient": "45deg, #1f1e1d, #36322b",
|
||||||
"complementaryColor": "white",
|
"complementaryColor": "white",
|
||||||
"themeData": "dark.css"
|
"themeURL": "dark.css"
|
||||||
}
|
}
|
|
@ -2,5 +2,5 @@
|
||||||
"displayName": "Light",
|
"displayName": "Light",
|
||||||
"previewGradient": "45deg, #f0ebe8, #d4d0ca",
|
"previewGradient": "45deg, #f0ebe8, #d4d0ca",
|
||||||
"complementaryColor": "black",
|
"complementaryColor": "black",
|
||||||
"themeData": "light.css"
|
"themeURL": "light.css"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue