parent
eb9517873d
commit
d21db82247
@ -1,17 +0,0 @@
|
||||
export const THEME_SET = 'THEME_SET';
|
||||
export const THEME_GENERATE = 'THEME_GENERATE';
|
||||
|
||||
export function generateTheme(brandColor, mode) {
|
||||
return {
|
||||
type: THEME_GENERATE,
|
||||
brandColor,
|
||||
mode,
|
||||
};
|
||||
}
|
||||
|
||||
export function setTheme(themeData) {
|
||||
return {
|
||||
type: THEME_SET,
|
||||
themeData,
|
||||
};
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
import {
|
||||
THEME_SET,
|
||||
THEME_GENERATE,
|
||||
} from '../actions/theme';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
const hex2rgb = c => c.substr(1).match(/../g).map(x => + `0x${x}`);
|
||||
|
||||
export const generateTheme = (brandColor, mode = 'light') => {
|
||||
if (!brandColor) return false;
|
||||
const [ r, g, b ] = hex2rgb(brandColor);
|
||||
return ImmutableMap({
|
||||
'brand-color-r': r,
|
||||
'brand-color-g': g,
|
||||
'brand-color-b': b,
|
||||
});
|
||||
};
|
||||
|
||||
export const setTheme = themeData => {
|
||||
const { 'brand-color': brandColor } = themeData.toObject();
|
||||
return ImmutableMap(generateTheme(brandColor, 'light')).merge(themeData);
|
||||
};
|
||||
|
||||
export default function theme(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case THEME_GENERATE:
|
||||
return generateTheme(action.brandColor, action.mode);
|
||||
case THEME_SET:
|
||||
return setTheme(ImmutableMap(action.brandColor));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
Loading…
Reference in new issue