2022-01-13 19:44:37 +00:00
|
|
|
import {createContext} from 'preact';
|
|
|
|
|
|
|
|
type Theme = {
|
|
|
|
cssClass: string;
|
|
|
|
name: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const themes: Theme[] = [
|
|
|
|
{
|
|
|
|
cssClass: 'love-dark',
|
|
|
|
name: 'Love Dark',
|
|
|
|
},
|
2022-01-14 19:11:12 +00:00
|
|
|
{
|
|
|
|
cssClass: 'love-light',
|
|
|
|
name: 'Love Light',
|
|
|
|
},
|
2022-01-13 19:44:37 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export const themeContext = createContext<Theme>(themes[0]);
|
2022-01-14 19:17:52 +00:00
|
|
|
|
|
|
|
export function getThemeByCssClass(cssClass: string): Theme {
|
|
|
|
return themes.find((theme) => theme.cssClass === cssClass) ?? themes[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setTheme(theme: Theme): void {
|
|
|
|
document.body.classList.value = theme.cssClass;
|
|
|
|
window.localStorage.setItem('theme', theme.cssClass);
|
|
|
|
}
|