返回 presentation-ai
resize-handle.tsx
根目录 / src / components / plate / ui / resize-handle.tsx
1 "use client";
2
3 import {
4 Resizable as ResizablePrimitive,
5 useResizeHandle,
6 useResizeHandleState,
7 type ResizeHandle as ResizeHandlePrimitive,
8 } from "@platejs/resizable";
9 import { cva, type VariantProps } from "class-variance-authority";
10 import type * as React from "react";
11
12 import { cn } from "@/lib/utils";
13
14 export const mediaResizeHandleVariants = cva(
15 cn(
16 "top-0 flex w-6 flex-col justify-center select-none",
17 "after:flex after:h-16 after:w-0.75 after:rounded-[6px] after:bg-ring after:opacity-0 after:content-['_'] group-hover:after:opacity-100",
18 ),
19 {
20 variants: {
21 direction: {
22 left: "-left-3 -ml-3 cursor-e-resize pl-3",
23 right: "-right-3 -mr-3 cursor-w-resize items-end pr-3",
24 },
25 },
26 },
27 );
28
29 const resizeHandleVariants = cva("absolute z-40", {
30 variants: {
31 direction: {
32 bottom: "w-full cursor-row-resize",
33 left: "h-full cursor-col-resize",
34 right: "h-full cursor-col-resize",
35 top: "w-full cursor-row-resize",
36 },
37 },
38 });
39
40 export function ResizeHandle({
41 className,
42 options,
43 ...props
44 }: React.ComponentProps<typeof ResizeHandlePrimitive> &
45 VariantProps<typeof resizeHandleVariants>) {
46 const state = useResizeHandleState(options ?? {});
47 const resizeHandle = useResizeHandle(state);
48
49 if (state.readOnly) return null;
50
51 return (
52 <div
53 className={cn(
54 resizeHandleVariants({ direction: options?.direction }),
55 className,
56 )}
57 data-resizing={state.isResizing}
58 {...resizeHandle.props}
59 {...props}
60 />
61 );
62 }
63
64 const resizableVariants = cva("flex w-full", {
65 variants: {
66 align: {
67 center: "mx-auto",
68 left: "ml-0",
69 right: "ml-auto",
70 },
71 },
72 });
73
74 export function Resizable({
75 align,
76 className,
77 ...props
78 }: React.ComponentProps<typeof ResizablePrimitive> &
79 VariantProps<typeof resizableVariants>) {
80 return (
81 <ResizablePrimitive
82 {...props}
83 className={cn(resizableVariants({ align }), className)}
84 />
85 );
86 }
87
87 lines Plain Text