pleroma/app/soapbox/reducers/theme.js

31 lines
818 B
JavaScript
Raw Normal View History

2020-05-30 17:05:01 -07:00
import {
SET_THEME,
} from '../actions/theme';
import { Map as ImmutableMap } from 'immutable';
2020-05-30 19:48:37 -07:00
import { brightness, hue, convert } from 'chromatism';
2020-05-30 17:05:01 -07:00
const initialState = ImmutableMap();
2020-05-30 19:48:37 -07:00
const cssrgba = (color, a) => {
const { r, g, b } = convert(color).rgb;
return `rgba(${[r, g, b, a].join(',')})`;
};
2020-05-30 18:11:08 -07:00
const populate = themeData => {
const { 'brand-color': brandColor } = themeData.toObject();
return ImmutableMap({
'nav-ui-highlight-color': brightness(10, hue(-3, brandColor).hex).hex,
2020-05-30 19:48:37 -07:00
'brand-color-faint': cssrgba(brandColor, 0.1),
'highlight-text-color': brandColor,
2020-05-30 18:11:08 -07:00
}).merge(themeData);
};
2020-05-30 17:05:01 -07:00
export default function theme(state = initialState, action) {
switch(action.type) {
case SET_THEME:
2020-05-30 18:11:08 -07:00
return populate(ImmutableMap(action.themeData));
2020-05-30 17:05:01 -07:00
default:
return state;
}
};