-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intorduce theme types - refactor as a service object
- Loading branch information
1 parent
51f49f3
commit 07f667f
Showing
13 changed files
with
131 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,90 @@ | ||
import { currentTheme, lightMode } from "$lib/runes"; | ||
import type { IconType } from "$lib/services/models/lo-types"; | ||
import type { IconType, Theme } from "$lib/services/models/lo-types"; | ||
import { FluentIconLib } from "./icons/fluent-icons"; | ||
import { HeroIconLib } from "./icons/hero-icons"; | ||
import { FestiveIcons } from "./icons/festive-icons"; | ||
import { makeItSnow, makeItStopSnowing } from "./events/festive.svelte"; | ||
|
||
export const themes = [ | ||
{ name: "tutors", icons: FluentIconLib }, | ||
{ name: "classic", icons: FluentIconLib }, | ||
{ name: "dyslexia", icons: FluentIconLib }, | ||
{ name: "festive", icons: FestiveIcons }, | ||
{ name: "nouveau", icons: FluentIconLib }, | ||
{ name: "rose", icons: FluentIconLib }, | ||
{ name: "cerberus", icons: FluentIconLib } | ||
]; | ||
export const themeService = { | ||
themes: [ | ||
{ name: "tutors", icons: FluentIconLib }, | ||
{ name: "classic", icons: FluentIconLib }, | ||
{ name: "dyslexia", icons: FluentIconLib }, | ||
{ name: "festive", icons: FestiveIcons }, | ||
{ name: "nouveau", icons: FluentIconLib }, | ||
{ name: "rose", icons: FluentIconLib }, | ||
{ name: "cerberus", icons: FluentIconLib } | ||
] as Theme[], | ||
|
||
export function initDisplay(): void { | ||
if (localStorage.modeCurrent) { | ||
lightMode.value = localStorage.modeCurrent; | ||
} else { | ||
lightMode.value = "light"; | ||
} | ||
setDisplayMode(localStorage.modeCurrent); | ||
setTheme(localStorage.theme); | ||
} | ||
isSnowing: false, | ||
|
||
export function setDisplayMode(mode: string): void { | ||
lightMode.value = mode; | ||
localStorage.modeCurrent = mode; | ||
if (mode === "dark") { | ||
document.body.classList.add("dark"); | ||
} else { | ||
document.body.classList.remove("dark"); | ||
} | ||
} | ||
initDisplay(): void { | ||
if (localStorage.modeCurrent) { | ||
lightMode.value = localStorage.modeCurrent; | ||
} else { | ||
lightMode.value = "light"; | ||
} | ||
this.setDisplayMode(localStorage.modeCurrent); | ||
this.setTheme(localStorage.theme); | ||
}, | ||
|
||
export function setTheme(theme: string): void { | ||
if (!theme) { | ||
theme = "tutors"; | ||
} | ||
if (themes.find((theme) => theme.name === currentTheme.value)) { | ||
currentTheme.value = theme; | ||
} else { | ||
currentTheme.value = "tutors"; | ||
} | ||
document.body.setAttribute("data-theme", currentTheme.value); | ||
localStorage.theme = currentTheme.value; | ||
setDisplayMode(mode: string): void { | ||
lightMode.value = mode; | ||
localStorage.modeCurrent = mode; | ||
if (mode === "dark") { | ||
document.body.classList.add("dark"); | ||
} else { | ||
document.body.classList.remove("dark"); | ||
} | ||
}, | ||
|
||
if (currentTheme.value === "festive") { | ||
makeItSnow(); | ||
} else { | ||
makeItStopSnowing(); | ||
} | ||
} | ||
setTheme(theme: string): void { | ||
if (!theme) { | ||
theme = "tutors"; | ||
} | ||
if (themeService.themes.find((theme) => theme.name === currentTheme.value)) { | ||
currentTheme.value = theme; | ||
} else { | ||
currentTheme.value = "tutors"; | ||
} | ||
document.body.setAttribute("data-theme", currentTheme.value); | ||
localStorage.theme = currentTheme.value; | ||
this.eventTrigger(); | ||
}, | ||
|
||
export function getIcon(type: string): IconType { | ||
const iconLib = themes.find((theme) => theme.name === currentTheme.value)?.icons; | ||
if (iconLib && iconLib[type]) { | ||
return iconLib[type]; | ||
} else { | ||
console.log("No type found for icon", type); | ||
return FluentIconLib.tutors; | ||
} | ||
} | ||
getIcon(type: string): IconType { | ||
const iconLib = themeService.themes.find((theme) => theme.name === currentTheme.value)?.icons; | ||
if (iconLib && iconLib[type]) { | ||
return iconLib[type]; | ||
} else { | ||
console.log("No type found for icon", type); | ||
return FluentIconLib.tutors; | ||
} | ||
}, | ||
|
||
addIcon(type: string, icon: IconType) { | ||
FluentIconLib[type] = icon; | ||
HeroIconLib[type] = icon; | ||
FestiveIcons[type] = icon; | ||
}, | ||
|
||
export function addIcon(type: string, icon: IconType) { | ||
FluentIconLib[type] = icon; | ||
HeroIconLib[type] = icon; | ||
FestiveIcons[type] = icon; | ||
} | ||
getTypeColour(type: string): string { | ||
const iconLib = themeService.themes.find((theme) => theme.name === currentTheme.value)?.icons; | ||
if (iconLib && iconLib[type]) { | ||
return iconLib[type].color; | ||
} | ||
return "primary"; | ||
}, | ||
|
||
export function getTypeColour(type: string): string { | ||
const iconLib = themes.find((theme) => theme.name === currentTheme.value)?.icons; | ||
if (iconLib && iconLib[type]) { | ||
return iconLib[type].color; | ||
eventTrigger(): void { | ||
if (currentTheme.value === "festive") { | ||
makeItSnow(); | ||
this.isSnowing = true; | ||
} else { | ||
if (this.isSnowing) { | ||
this.isSnowing = false; | ||
makeItStopSnowing(); | ||
} | ||
} | ||
} | ||
return "primary"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters