generateTheme function, refactor
This commit is contained in:
parent
d5632851fe
commit
2c0ee3f29d
4 changed files with 28 additions and 17 deletions
|
@ -1,8 +1,17 @@
|
|||
export const SET_THEME = 'SET_THEME';
|
||||
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: SET_THEME,
|
||||
type: THEME_SET,
|
||||
themeData,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@ import { fetchMe } from 'soapbox/actions/me';
|
|||
import PublicLayout from 'soapbox/features/public_layout';
|
||||
import { getSettings } from 'soapbox/actions/settings';
|
||||
import { themeDataToCss } from 'soapbox/utils/theme';
|
||||
import { setTheme } from 'soapbox/actions/theme';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { generateTheme } from 'soapbox/actions/theme';
|
||||
|
||||
export const store = configureStore();
|
||||
const hydrateAction = hydrateStore(initialState);
|
||||
|
@ -77,10 +76,7 @@ class SoapboxMount extends React.PureComponent {
|
|||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.props.dispatch(setTheme(ImmutableMap({
|
||||
// 'brand-color': '#0482d8',
|
||||
'brand-color': '#1ca82b',
|
||||
})));
|
||||
this.props.dispatch(generateTheme('#1ca82b', 'light'));
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
SET_THEME,
|
||||
THEME_SET,
|
||||
THEME_GENERATE,
|
||||
} from '../actions/theme';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { brightness, hue, convert } from 'chromatism';
|
||||
|
@ -11,19 +12,26 @@ const cssrgba = (color, a) => {
|
|||
return `rgba(${[r, g, b, a].join(',')})`;
|
||||
};
|
||||
|
||||
const populate = themeData => {
|
||||
const { 'brand-color': brandColor } = themeData.toObject();
|
||||
export const generateTheme = (brandColor, mode) => {
|
||||
return ImmutableMap({
|
||||
'brand-color': brandColor,
|
||||
'accent-color': brightness(10, hue(-3, brandColor).hex).hex,
|
||||
'brand-color-faint': cssrgba(brandColor, 0.1),
|
||||
'highlight-text-color': brandColor,
|
||||
}).merge(themeData);
|
||||
});
|
||||
};
|
||||
|
||||
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 SET_THEME:
|
||||
return populate(ImmutableMap(action.themeData));
|
||||
case THEME_GENERATE:
|
||||
return generateTheme(action.brandColor, action.mode);
|
||||
case THEME_SET:
|
||||
return setTheme(ImmutableMap(action.brandColor));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
$nav-ui-background-color: var(--brand-color) !default;
|
||||
|
||||
.tabs-bar {
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
background: $nav-ui-background-color;
|
||||
background: var(--brand-color);
|
||||
flex: 0 0 auto;
|
||||
overflow-y: auto;
|
||||
height: 50px;
|
||||
|
|
Loading…
Reference in a new issue