Skip to content

Commit 2ba03d3

Browse files
committed
add 'p' tag to typography
1 parent f96da94 commit 2ba03d3

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import type { HTMLAttributes } from "react";
1+
import type { ElementType, HTMLAttributes } from "react";
22
import { type VariantProps, cva } from "class-variance-authority";
33
import { cn } from "@/lib/utils";
44

55
const 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

Comments
 (0)