bigbuffet-rw/app/soapbox/utils/theme.js

23 lines
582 B
JavaScript
Raw Normal View History

2020-06-02 13:48:27 -07:00
import { Map as ImmutableMap } from 'immutable';
2020-06-06 20:55:00 -07:00
import hexToHsl from 'hex-to-hsl';
2020-06-02 13:48:27 -07:00
export const generateThemeCss = brandColor => {
if (!brandColor) return null;
return themeDataToCss(brandColorToThemeData(brandColor));
};
export const brandColorToThemeData = brandColor => {
2020-06-06 20:55:00 -07:00
const [ h, s, l ] = hexToHsl(brandColor);
2020-06-02 13:48:27 -07:00
return ImmutableMap({
2020-06-06 20:55:00 -07:00
'brand-color_h': h,
'brand-color_s': `${s}%`,
'brand-color_l': `${l}%`,
2020-06-02 13:48:27 -07:00
});
};
2020-05-30 17:05:01 -07:00
export const themeDataToCss = themeData => (
themeData
.entrySeq()
.reduce((acc, cur) => acc + `--${cur[0]}:${cur[1]};`, '')
);