mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00

Add support for user themes for mui components
Original-merge: 61976b8101
Merged-by: thornbill <thornbill@users.noreply.github.com>
Backported-by: Joshua M. Boniface <joshua@boniface.me>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { type Theme } from '@mui/material/styles';
|
|
|
|
import appletv from './appletv';
|
|
import blueradiance from './blueradiance';
|
|
import dark from './dark';
|
|
import light from './light';
|
|
import purplehaze from './purplehaze';
|
|
import wmc from './wmc';
|
|
|
|
declare module '@mui/material/styles' {
|
|
interface Palette {
|
|
starIcon: Palette['primary'];
|
|
}
|
|
|
|
interface PaletteOptions {
|
|
starIcon?: PaletteOptions['primary'];
|
|
}
|
|
}
|
|
|
|
const ALL_THEMES = {
|
|
appletv,
|
|
blueradiance,
|
|
dark,
|
|
light,
|
|
purplehaze,
|
|
wmc
|
|
};
|
|
|
|
/** The default theme if a user has not selected a preferred theme. */
|
|
export const DEFAULT_THEME = dark;
|
|
|
|
/**
|
|
* Gets a MUI Theme by its string id. Returns the default theme if no matching theme is found.
|
|
*/
|
|
export function getTheme(id?: string): Theme {
|
|
if (!id) {
|
|
console.info('[getTheme] no theme id; returning default theme');
|
|
return DEFAULT_THEME;
|
|
}
|
|
|
|
console.info('[getTheme] getting theme "%s"', id);
|
|
if (Object.keys(ALL_THEMES).includes(id)) {
|
|
return ALL_THEMES[id as keyof typeof ALL_THEMES];
|
|
}
|
|
|
|
console.warn('[getTheme] theme "%s" not found; returning default theme', id);
|
|
return DEFAULT_THEME;
|
|
}
|