返回 presentation-ai
caption.tsx
根目录 / src / components / plate / ui / caption.tsx
1 "use client";
2
3 import {
4 Caption as CaptionPrimitive,
5 CaptionTextarea as CaptionTextareaPrimitive,
6 useCaptionButton,
7 useCaptionButtonState,
8 } from "@platejs/caption/react";
9 import { cva, type VariantProps } from "class-variance-authority";
10 import { createPrimitiveComponent } from "platejs/react";
11 import type * as React from "react";
12
13 import { Button } from "@/components/plate/ui/button";
14 import { cn } from "@/lib/utils";
15
16 const captionVariants = cva("max-w-full", {
17 defaultVariants: {
18 align: "center",
19 },
20 variants: {
21 align: {
22 center: "mx-auto",
23 left: "mr-auto",
24 right: "ml-auto",
25 },
26 },
27 });
28
29 export function Caption({
30 align,
31 className,
32 ...props
33 }: React.ComponentProps<typeof CaptionPrimitive> &
34 VariantProps<typeof captionVariants>) {
35 return (
36 <CaptionPrimitive
37 {...props}
38 className={cn(captionVariants({ align }), className)}
39 />
40 );
41 }
42
43 export function CaptionTextarea(
44 props: React.ComponentProps<typeof CaptionTextareaPrimitive>,
45 ) {
46 return (
47 <CaptionTextareaPrimitive
48 {...props}
49 className={cn(
50 "mt-2 w-full resize-none border-none bg-inherit p-0 font-[inherit] text-inherit",
51 "focus:outline-hidden focus:placeholder:opacity-0",
52 "text-center print:placeholder:text-transparent",
53 props.className,
54 )}
55 />
56 );
57 }
58
59 const CaptionButtonPrimitive = createPrimitiveComponent(Button)({
60 propsHook: useCaptionButton,
61 stateHook: useCaptionButtonState,
62 });
63
64 export function CaptionButton(
65 props: React.ComponentProps<typeof CaptionButtonPrimitive>,
66 ) {
67 return <CaptionButtonPrimitive {...props} />;
68 }
69
69 lines Plain Text