Files
js/tw-components/utils/typography.ts
T
Jonas Daniels 3b647fccc1 react 18 upgrade (#80)
* react 18 upgrade (WIP)

* fix typography logic

* fix lots of lint issues
2022-05-12 18:03:53 -07:00

56 lines
1.5 KiB
TypeScript

import chakraTheme from "../../theme";
import {
TypographyBase,
TypographyFontSize,
TypographySize,
baseFontSizes,
mdFontSizes,
} from "theme/typography";
const FONT_SIZE_CSS_VAR_PREFIX = "--tw-font-size-" as const;
function createCssVariable(size: TypographyFontSize) {
return `${FONT_SIZE_CSS_VAR_PREFIX}${size.replace(/\./g, "-")}`;
}
export function convertFontSizeToCSSVar(fontSize: TypographyFontSize) {
return `var(${createCssVariable(fontSize)})`;
}
export function generateBreakpointTypographyCssVars() {
const baseCSSVars = Object.entries(baseFontSizes)
.flatMap(([typographyBase, typographySizeMap]) => {
return Object.entries(typographySizeMap).map(
([typographySize, fontSizeValue]) => {
return `${createCssVariable(
`${typographyBase as TypographyBase}.${
typographySize as TypographySize
}`,
)}: ${fontSizeValue};`;
},
);
})
.join("\n");
const mdCSSVars = Object.entries(mdFontSizes)
.flatMap(([typographyBase, typographySizeMap]) => {
return Object.entries(typographySizeMap).map(
([typographySize, fontSizeValue]) => {
return `${createCssVariable(
`${typographyBase as TypographyBase}.${
typographySize as TypographySize
}`,
)}: ${fontSizeValue};`;
},
);
})
.join("\n");
return `:root {
${baseCSSVars}
@media screen and (min-width: ${chakraTheme.breakpoints.md}) {
${mdCSSVars}
}
}`;
}