1
Fork 0
href-plus/source/ts/utilities/themes.ts

29 lines
608 B
TypeScript
Raw Normal View History

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',
},
];
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);
}