返回 presentation-ai
presentation-title.tsx
根目录 / src / components / notebook / presentation / editor / custom-elements / presentation-title.tsx
1 "use client";
2
3 import { cva } from "class-variance-authority";
4 import { PlateElement, type PlateElementProps } from "platejs/react";
5
6 import { cn } from "@/lib/utils";
7 import { type TPresentationTitleElement } from "../lib";
8
9 function getTextAlignClass(alignment: TPresentationTitleElement["alignment"]) {
10 if (alignment === "left") return "text-left";
11 if (alignment === "right") return "text-right";
12 return "text-center";
13 }
14
15 const titleVariants = cva(
16 "my-2 font-black leading-[0.95] tracking-normal text-(--presentation-heading) caret-primary",
17 {
18 variants: {
19 variant: {
20 display: "text-[4.75rem]",
21 humongous: "text-[6.5rem]",
22 title: "text-[3.5rem]",
23 },
24 },
25 },
26 );
27
28 export default function PresentationTitleElement(
29 props: PlateElementProps<TPresentationTitleElement>,
30 ) {
31 const variant = props.element.variant ?? "title";
32 const alignment = props.element.alignment ?? "left";
33 const color =
34 props.element.textColor ??
35 props.element.color ??
36 "var(--presentation-heading)";
37
38 return (
39 <PlateElement
40 {...props}
41 className={cn(
42 titleVariants({ variant }),
43 getTextAlignClass(alignment),
44 "[font-family:var(--presentation-heading-font)]",
45 )}
46 style={{
47 backgroundColor: props.element.backgroundColor,
48 color,
49 }}
50 >
51 {props.children}
52 </PlateElement>
53 );
54 }
55
55 lines Plain Text