feat(web): add theme definition system with 5 built-in themes (#493)
All checks were successful
ci/woodpecker/push/web Pipeline was successful
All checks were successful
ci/woodpecker/push/web Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #493.
This commit is contained in:
50
apps/web/src/themes/registry.ts
Normal file
50
apps/web/src/themes/registry.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { darkTheme } from "./dark";
|
||||
import { draculaTheme } from "./dracula";
|
||||
import { lightTheme } from "./light";
|
||||
import { nordTheme } from "./nord";
|
||||
import { solarizedDarkTheme } from "./solarized-dark";
|
||||
import type { ThemeDefinition } from "./types";
|
||||
|
||||
/** All built-in themes, ordered for display */
|
||||
const builtInThemes: ThemeDefinition[] = [
|
||||
darkTheme,
|
||||
lightTheme,
|
||||
nordTheme,
|
||||
draculaTheme,
|
||||
solarizedDarkTheme,
|
||||
];
|
||||
|
||||
const themeMap = new Map<string, ThemeDefinition>(builtInThemes.map((t) => [t.id, t]));
|
||||
|
||||
/** Default theme when no preference is set */
|
||||
export const DEFAULT_THEME_ID = "dark";
|
||||
|
||||
/** Get all registered themes */
|
||||
export function getAllThemes(): ThemeDefinition[] {
|
||||
return [...builtInThemes];
|
||||
}
|
||||
|
||||
/** Get a theme by ID, or undefined if not found */
|
||||
export function getTheme(id: string): ThemeDefinition | undefined {
|
||||
return themeMap.get(id);
|
||||
}
|
||||
|
||||
/** Get a theme by ID, falling back to the default dark theme */
|
||||
export function getThemeOrDefault(id: string): ThemeDefinition {
|
||||
return themeMap.get(id) ?? darkTheme;
|
||||
}
|
||||
|
||||
/** Get only dark themes */
|
||||
export function getDarkThemes(): ThemeDefinition[] {
|
||||
return builtInThemes.filter((t) => t.isDark);
|
||||
}
|
||||
|
||||
/** Get only light themes */
|
||||
export function getLightThemes(): ThemeDefinition[] {
|
||||
return builtInThemes.filter((t) => !t.isDark);
|
||||
}
|
||||
|
||||
/** Check if a theme ID is valid */
|
||||
export function isValidThemeId(id: string): boolean {
|
||||
return themeMap.has(id);
|
||||
}
|
||||
Reference in New Issue
Block a user