2022-01-13 19:44:37 +00:00
|
|
|
import {createContext} from 'preact';
|
|
|
|
|
|
|
|
type Theme = {
|
|
|
|
cssClass: string;
|
|
|
|
name: string;
|
|
|
|
};
|
|
|
|
|
2022-01-28 12:10:05 +00:00
|
|
|
export const defaultTheme: Theme = {
|
|
|
|
cssClass: 'love-dark',
|
|
|
|
name: 'Love Dark',
|
|
|
|
};
|
|
|
|
|
2022-01-13 19:44:37 +00:00
|
|
|
export const themes: Theme[] = [
|
2022-01-28 12:10:05 +00:00
|
|
|
defaultTheme,
|
2022-01-14 19:11:12 +00:00
|
|
|
{
|
|
|
|
cssClass: 'love-light',
|
|
|
|
name: 'Love Light',
|
|
|
|
},
|
2022-01-25 10:43:41 +00:00
|
|
|
{
|
|
|
|
cssClass: 'solarized-dark',
|
|
|
|
name: 'Solarized Dark',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cssClass: 'solarized-light',
|
|
|
|
name: 'Solarized Light',
|
|
|
|
},
|
2022-01-26 12:04:03 +00:00
|
|
|
{
|
|
|
|
cssClass: 'dracula',
|
|
|
|
name: 'Dracula',
|
|
|
|
},
|
2022-01-27 10:59:27 +00:00
|
|
|
{
|
|
|
|
cssClass: 'monokai',
|
|
|
|
name: 'Monokai',
|
|
|
|
},
|
2022-01-29 13:21:03 +00:00
|
|
|
{
|
|
|
|
cssClass: 'high-contrast-black',
|
|
|
|
name: 'High Contrast Black',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cssClass: 'high-contrast-white',
|
|
|
|
name: 'High Contrast White',
|
|
|
|
},
|
2022-01-28 12:10:05 +00:00
|
|
|
].sort((a, b) => a.name.localeCompare(b.name));
|
2022-01-13 19:44:37 +00:00
|
|
|
|
2022-01-28 12:10:05 +00:00
|
|
|
export const themeContext = createContext<Theme>(defaultTheme);
|
2022-01-14 19:17:52 +00:00
|
|
|
|
|
|
|
export function getThemeByCssClass(cssClass: string): Theme {
|
2022-01-28 12:10:05 +00:00
|
|
|
return themes.find((theme) => theme.cssClass === cssClass) ?? defaultTheme;
|
2022-01-14 19:17:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setTheme(theme: Theme): void {
|
|
|
|
document.body.classList.value = theme.cssClass;
|
|
|
|
window.localStorage.setItem('theme', theme.cssClass);
|
|
|
|
}
|