| 1 | "use client"; |
| 2 | |
| 3 | import { cva, type VariantProps } from "class-variance-authority"; |
| 4 | import { type PlateElementProps } from "platejs/react"; |
| 5 | |
| 6 | import { cn } from "@/lib/utils"; |
| 7 | import { PresentationElement } from "./presentation-element"; |
| 8 | |
| 9 | const headingVariants = cva("relative mb-1", { |
| 10 | variants: { |
| 11 | variant: { |
| 12 | h1: "pb-1 [font-size:var(--presentation-h1-size)] font-bold", |
| 13 | h2: "pb-px [font-size:var(--presentation-h2-size)] font-semibold tracking-tight", |
| 14 | h3: "pb-px [font-size:var(--presentation-h3-size)] font-semibold tracking-tight", |
| 15 | h4: "[font-size:var(--presentation-h4-size)] font-semibold tracking-tight", |
| 16 | h5: "[font-size:var(--presentation-h5-size)] font-semibold tracking-tight", |
| 17 | h6: "[font-size:var(--presentation-h6-size)] font-semibold tracking-tight", |
| 18 | }, |
| 19 | }, |
| 20 | }); |
| 21 | |
| 22 | const PresentationHeadingElement = ({ |
| 23 | children, |
| 24 | variant, |
| 25 | ref, |
| 26 | ...props |
| 27 | }: PlateElementProps & VariantProps<typeof headingVariants>) => { |
| 28 | return ( |
| 29 | <PresentationElement |
| 30 | ref={ref} |
| 31 | className={cn( |
| 32 | "[font-family:var(--presentation-heading-font)] font-bold", |
| 33 | "text-(--presentation-heading)", |
| 34 | "caret-primary", |
| 35 | headingVariants({ variant }), |
| 36 | )} |
| 37 | {...props} |
| 38 | > |
| 39 | {children} |
| 40 | </PresentationElement> |
| 41 | ); |
| 42 | }; |
| 43 | |
| 44 | export function H1Element(props: PlateElementProps) { |
| 45 | return <PresentationHeadingElement variant="h1" {...props} />; |
| 46 | } |
| 47 | |
| 48 | export function H2Element(props: PlateElementProps) { |
| 49 | return <PresentationHeadingElement variant="h2" {...props} />; |
| 50 | } |
| 51 | |
| 52 | export function H3Element(props: PlateElementProps) { |
| 53 | return <PresentationHeadingElement variant="h3" {...props} />; |
| 54 | } |
| 55 | |
| 56 | export function H4Element(props: PlateElementProps) { |
| 57 | return <PresentationHeadingElement variant="h4" {...props} />; |
| 58 | } |
| 59 | |
| 60 | export function H5Element(props: PlateElementProps) { |
| 61 | return <PresentationHeadingElement variant="h5" {...props} />; |
| 62 | } |
| 63 | |
| 64 | export function H6Element(props: PlateElementProps) { |
| 65 | return <PresentationHeadingElement variant="h6" {...props} />; |
| 66 | } |
| 67 |