Files
js/tw-components/text.tsx
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

36 lines
833 B
TypeScript

import { convertFontSizeToCSSVar } from "./utils/typography";
import {
Text as ChakraText,
TextProps as ChakraTextProps,
} from "@chakra-ui/react";
import {
TextBase,
TextSizes,
TypographySize,
fontWeights,
letterSpacings,
lineHeights,
} from "theme/typography";
import { ComponentWithChildren } from "types/component-with-children";
export interface TextProps extends Omit<ChakraTextProps, "size"> {
size?: TextSizes;
}
export const Text: ComponentWithChildren<TextProps> = ({
size = "body.md",
...restProps
}) => {
const [base] = size.split(".") as [TextBase, TypographySize];
return (
<ChakraText
fontSize={convertFontSizeToCSSVar(size)}
fontWeight={fontWeights[base]}
lineHeight={lineHeights[base]}
letterSpacing={letterSpacings[base]}
{...restProps}
/>
);
};