️ feat: create heading component

This commit is contained in:
Wahyu Kurniawan 2024-02-28 08:29:45 +07:00
parent 282001c317
commit 3215a19141
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import { tv, type VariantProps } from 'tailwind-variants';
export const headingTheme = tv({
base: ['text-elements-high-em', 'font-display', 'font-semibold'],
});
export type HeadingVariants = VariantProps<typeof headingTheme>;

View File

@ -0,0 +1,30 @@
import React, { type PropsWithChildren } from 'react';
import { headingTheme, type HeadingVariants } from './Heading.theme';
import { PolymorphicProps } from 'types/common';
export type HeadingElementType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
export type HeadingProps<Element extends HeadingElementType> =
PropsWithChildren<PolymorphicProps<Element, HeadingVariants>>;
export const Heading = <Element extends HeadingElementType>({
children,
as,
className,
...props
}: HeadingProps<Element>) => {
// Component is the element that will be rendered
const Component = as ?? 'h1';
return (
<Component
{...props}
className={headingTheme({
className,
})}
>
{children}
</Component>
);
};

View File

@ -0,0 +1 @@
export * from './Heading';