bigbuffet-rw/app/soapbox/utils/theme.js
Alex Gleason cbdcccb8b2
Fix RGB->HSL precision issues
Moved back to chromatism. Well worth it for the accuracy.
2020-06-12 10:48:04 -05:00

22 lines
588 B
JavaScript

import { Map as ImmutableMap } from 'immutable';
import { convert } from 'chromatism';
export const generateThemeCss = brandColor => {
if (!brandColor) return null;
return themeDataToCss(brandColorToThemeData(brandColor));
};
export const brandColorToThemeData = brandColor => {
const { h, s, l } = convert(brandColor).hsl;
return ImmutableMap({
'brand-color_h': h,
'brand-color_s': `${s}%`,
'brand-color_l': `${l}%`,
});
};
export const themeDataToCss = themeData => (
themeData
.entrySeq()
.reduce((acc, cur) => acc + `--${cur[0]}:${cur[1]};`, '')
);