| 1 | "use client"; |
| 2 | |
| 3 | import { cva, type VariantProps } from "class-variance-authority"; |
| 4 | import { PlateElement, type PlateElementProps } from "platejs/react"; |
| 5 | |
| 6 | const headingVariants = cva("relative mb-1", { |
| 7 | variants: { |
| 8 | variant: { |
| 9 | h1: "font-heading mt-[1.6em] pb-1 text-4xl font-bold", |
| 10 | h2: "font-heading mt-[1.4em] pb-px text-2xl font-semibold tracking-tight", |
| 11 | h3: "font-heading mt-[1em] pb-px text-xl font-semibold tracking-tight", |
| 12 | h4: "font-heading mt-[0.75em] text-lg font-semibold tracking-tight", |
| 13 | h5: "mt-[0.75em] text-lg font-semibold tracking-tight", |
| 14 | h6: "mt-[0.75em] text-base font-semibold tracking-tight", |
| 15 | }, |
| 16 | }, |
| 17 | }); |
| 18 | |
| 19 | function HeadingElement({ |
| 20 | variant = "h1", |
| 21 | ...props |
| 22 | }: PlateElementProps & VariantProps<typeof headingVariants>) { |
| 23 | return ( |
| 24 | <PlateElement |
| 25 | as={variant!} |
| 26 | className={headingVariants({ variant })} |
| 27 | {...props} |
| 28 | > |
| 29 | {props.children} |
| 30 | </PlateElement> |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | export function H1Element(props: PlateElementProps) { |
| 35 | return <HeadingElement variant="h1" {...props} />; |
| 36 | } |
| 37 | |
| 38 | export function H2Element(props: PlateElementProps) { |
| 39 | return <HeadingElement variant="h2" {...props} />; |
| 40 | } |
| 41 | |
| 42 | export function H3Element(props: PlateElementProps) { |
| 43 | return <HeadingElement variant="h3" {...props} />; |
| 44 | } |
| 45 | |
| 46 | export function H4Element(props: PlateElementProps) { |
| 47 | return <HeadingElement variant="h4" {...props} />; |
| 48 | } |
| 49 | |
| 50 | export function H5Element(props: PlateElementProps) { |
| 51 | return <HeadingElement variant="h5" {...props} />; |
| 52 | } |
| 53 | |
| 54 | export function H6Element(props: PlateElementProps) { |
| 55 | return <HeadingElement variant="h6" {...props} />; |
| 56 | } |
| 57 |