1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-24 13:39:35 +02:00
flame/client/src/store/actions/theme.ts

29 lines
784 B
TypeScript
Raw Normal View History

import { Dispatch } from 'redux';
import { themes } from '../../components/Themer/themes.json';
import { Theme } from '../../interfaces/Theme';
import { ActionTypes } from './actionTypes';
export interface SetThemeAction {
type: ActionTypes.setTheme,
payload: Theme
}
export const setTheme = (themeName: string) => (dispatch: Dispatch) => {
const theme = themes.find((theme: Theme) => theme.name === themeName);
if (theme) {
localStorage.setItem('theme', themeName);
loadTheme(theme);
dispatch<SetThemeAction>({
type: ActionTypes.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);
}
}