mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-24 13:39:35 +02:00
27 lines
756 B
TypeScript
27 lines
756 B
TypeScript
|
import { Dispatch } from 'redux';
|
||
|
import { SetThemeAction } from '../actions/theme';
|
||
|
import { ActionType } from '../action-types';
|
||
|
import { Theme } from '../../interfaces/Theme';
|
||
|
import { themes } from '../../components/Themer/themes.json';
|
||
|
|
||
|
export const setTheme =
|
||
|
(name: string) => (dispatch: Dispatch<SetThemeAction>) => {
|
||
|
const theme = themes.find((theme) => theme.name === name);
|
||
|
|
||
|
if (theme) {
|
||
|
localStorage.setItem('theme', name);
|
||
|
loadTheme(theme);
|
||
|
|
||
|
dispatch({
|
||
|
type: ActionType.setTheme,
|
||
|
payload: theme,
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export const loadTheme = (theme: Theme): void => {
|
||
|
for (const [key, value] of Object.entries(theme.colors)) {
|
||
|
document.body.style.setProperty(`--color-${key}`, value);
|
||
|
}
|
||
|
};
|