1- import type { HTMLAttributes } from "react" ;
1+ import type { ElementType , HTMLAttributes } from "react" ;
22import { type VariantProps , cva } from "class-variance-authority" ;
33import { cn } from "@/lib/utils" ;
44
55const typographyVariants = cva ( "font-head" , {
66 variants : {
77 variant : {
8+ p : "font-sans text-base" ,
89 h1 : "text-5xl lg:text-6xl font-bold" ,
910 h2 : "text-3xl lg:text-4xl font-semibold" ,
1011 h3 : "text-2xl font-medium" ,
@@ -14,28 +15,26 @@ const typographyVariants = cva("font-head", {
1415 } ,
1516 } ,
1617 defaultVariants : {
17- variant : "h1 " ,
18+ variant : "p " ,
1819 } ,
1920} ) ;
2021
21- interface TypographyProps
22- extends HTMLAttributes < HTMLHeadingElement > ,
22+ type ComponentsMap = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" ;
23+ interface TypographyProps < T extends ComponentsMap = "p" >
24+ extends Omit < HTMLAttributes < HTMLElement > , "className" > ,
2325 VariantProps < typeof typographyVariants > {
2426 className ?: string ;
25- component ?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" ;
27+ component ?: T ;
2628}
2729
28- export const Typography = ( {
29- className,
30- component,
31- variant,
32- ...props
33- } : TypographyProps ) => {
34- const Component = component || "h1" ;
30+ export const Typography = ( props : TypographyProps ) => {
31+ const { className, component = "p" , variant, ...otherProps } = props ;
32+ const Tag : ElementType = component ;
33+
3534 return (
36- < Component
35+ < Tag
3736 className = { cn ( typographyVariants ( { variant } ) , className ) }
38- { ...props }
37+ { ...otherProps }
3938 />
4039 ) ;
4140} ;
0 commit comments