64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
import { type ReactNode, createElement } from "react";
|
|
|
|
type HeadingLevel = "h1" | "h2" | "h3";
|
|
|
|
interface HeadingProps {
|
|
children: ReactNode;
|
|
level?: HeadingLevel;
|
|
underline?: boolean;
|
|
underlineColor?: string;
|
|
color?: string;
|
|
uppercase?: boolean;
|
|
fontFamily?: string;
|
|
className?: string;
|
|
}
|
|
|
|
const SIZE_CLASSES: Record<HeadingLevel, string> = {
|
|
h1: "text-h1",
|
|
h2: "text-h2",
|
|
h3: "text-h3",
|
|
};
|
|
|
|
const DEFAULT_FONT: Record<HeadingLevel, string> = {
|
|
h1: "font-lato-black",
|
|
h2: "font-lato-bold",
|
|
h3: "font-lato-bold",
|
|
};
|
|
|
|
export default function Heading({
|
|
children,
|
|
level = "h2",
|
|
underline = true,
|
|
underlineColor = "#E00A1E",
|
|
color = "text-bleu",
|
|
className = "",
|
|
uppercase = true,
|
|
fontFamily,
|
|
}: Readonly<HeadingProps>) {
|
|
const font = fontFamily ?? DEFAULT_FONT[level];
|
|
|
|
return createElement(
|
|
level,
|
|
{
|
|
className: `inline-block ${uppercase ? "uppercase" : ""} ${font} ${SIZE_CLASSES[level]} ${color} ${className}`,
|
|
},
|
|
<>
|
|
{children}
|
|
{underline && (
|
|
<svg
|
|
viewBox="0 0 243 15"
|
|
preserveAspectRatio="none"
|
|
className="mt-1 block h-[15px] w-full"
|
|
>
|
|
<path
|
|
d="M2,7 C40,2 80,11 121,6 C160,2 200,11 241,6"
|
|
fill="none"
|
|
stroke={underlineColor}
|
|
strokeWidth="7"
|
|
strokeLinecap="round"
|
|
/>
|
|
</svg>
|
|
)}
|
|
</>,
|
|
);
|
|
}
|