SurfSense/surfsense_web/components/ui/resize-handle.tsx

79 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-02-17 12:47:39 +05:30
"use client";
import {
2026-02-17 12:47:39 +05:30
Resizable as ResizablePrimitive,
2026-02-20 22:44:56 -08:00
type ResizeHandle as ResizeHandlePrimitive,
2026-02-17 12:47:39 +05:30
useResizeHandle,
useResizeHandleState,
} from "@platejs/resizable";
2026-02-20 22:44:56 -08:00
import type { VariantProps } from "class-variance-authority";
2026-02-17 12:47:39 +05:30
import { cva } from "class-variance-authority";
2026-02-20 22:44:56 -08:00
import type * as React from "react";
2026-02-17 12:47:39 +05:30
import { cn } from "@/lib/utils";
export const mediaResizeHandleVariants = cva(
2026-02-17 12:47:39 +05:30
cn(
"top-0 flex w-6 select-none flex-col justify-center",
"after:flex after:h-16 after:w-[3px] after:rounded-[6px] after:bg-ring after:opacity-0 after:content-['_'] group-hover:after:opacity-100"
),
{
variants: {
direction: {
left: "-left-3 -ml-3 pl-3",
right: "-right-3 -mr-3 items-end pr-3",
},
},
}
);
2026-02-17 12:47:39 +05:30
const resizeHandleVariants = cva("absolute z-40", {
variants: {
direction: {
bottom: "w-full cursor-row-resize",
left: "h-full cursor-col-resize",
right: "h-full cursor-col-resize",
top: "w-full cursor-row-resize",
},
},
});
export function ResizeHandle({
2026-02-17 12:47:39 +05:30
className,
options,
...props
}: React.ComponentProps<typeof ResizeHandlePrimitive> & VariantProps<typeof resizeHandleVariants>) {
const state = useResizeHandleState(options ?? {});
const resizeHandle = useResizeHandle(state);
2026-02-17 12:47:39 +05:30
if (state.readOnly) return null;
2026-02-17 12:47:39 +05:30
return (
<div
className={cn(resizeHandleVariants({ direction: options?.direction }), className)}
data-resizing={state.isResizing}
{...resizeHandle.props}
{...props}
/>
);
}
2026-02-17 12:47:39 +05:30
const resizableVariants = cva("", {
variants: {
align: {
center: "mx-auto",
left: "mr-auto",
right: "ml-auto",
},
},
});
export function Resizable({
2026-02-17 12:47:39 +05:30
align,
className,
...props
}: React.ComponentProps<typeof ResizablePrimitive> & VariantProps<typeof resizableVariants>) {
return <ResizablePrimitive {...props} className={cn(resizableVariants({ align }), className)} />;
}