This repository has been archived on 2025-05-09. You can view files and clone it, but cannot push or open issues or pull requests.
EvoCalculator/src/client/UIKit/lib/typographyStyle.js

46 lines
951 B
JavaScript

import { css } from 'styled-components';
import mq from 'client/UIKit/mq';
const TYPOGRAPHY_BPS = [
320,
'tablet',
'desktop1280',
'desktop1440',
'desktop1680',
];
const getTypographyStyle = fontSize => `font-size: ${fontSize}px;`;
const typographyArray = arr =>
arr
.map((v, i) => {
return v === arr[i - 1] ? null : v;
})
.map(fSize => (fSize ? getTypographyStyle(fSize) : null));
const typographyArrayToCSS = (arr, lh) =>
arr.reduce(
(acc, curr, i) => {
if (curr === null) {
return acc;
}
const addition =
i > 0
? css`
${mq[TYPOGRAPHY_BPS[i]]`${curr}`};
`
: curr;
return css`
${acc} ${addition};
`;
},
css`
line-height: ${lh};
`,
);
const typographyStyle = (fontSizeArray, lineHeight) =>
typographyArrayToCSS(typographyArray(fontSizeArray), lineHeight);
export default typographyStyle;