Files
js/tw-components/heading.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
873 B
TypeScript

import { convertFontSizeToCSSVar } from "./utils/typography";
import {
Heading as ChakraHeading,
HeadingProps as ChakraHeadingProps,
} from "@chakra-ui/react";
import {
HeadingBase,
HeadingSizes,
TypographySize,
fontWeights,
letterSpacings,
lineHeights,
} from "theme/typography";
import { ComponentWithChildren } from "types/component-with-children";
export interface HeadingProps extends Omit<ChakraHeadingProps, "size"> {
size?: HeadingSizes;
}
export const Heading: ComponentWithChildren<HeadingProps> = ({
size = "title.lg",
...restProps
}) => {
const [base] = size.split(".") as [HeadingBase, TypographySize];
return (
<ChakraHeading
fontSize={convertFontSizeToCSSVar(size)}
fontWeight={fontWeights[base]}
lineHeight={lineHeights[base]}
letterSpacing={letterSpacings[base]}
{...restProps}
/>
);
};