SurfSense/surfsense_web/components/ui/block-selection.tsx

39 lines
948 B
TypeScript
Raw Normal View History

2026-02-17 12:47:39 +05:30
"use client";
2026-02-17 12:47:39 +05:30
import { DndPlugin } from "@platejs/dnd";
import { useBlockSelected } from "@platejs/selection/react";
import { cva } from "class-variance-authority";
import { type PlateElementProps, usePluginOption } from "platejs/react";
2026-02-20 22:44:56 -08:00
import * as React from "react";
export const blockSelectionVariants = cva(
2026-02-17 12:47:39 +05:30
"pointer-events-none absolute inset-0 z-1 bg-brand/[.13] transition-opacity",
{
defaultVariants: {
active: true,
},
variants: {
active: {
false: "opacity-0",
true: "opacity-100",
},
},
}
);
export function BlockSelection(props: PlateElementProps) {
2026-02-17 12:47:39 +05:30
const isBlockSelected = useBlockSelected();
const isDragging = usePluginOption(DndPlugin, "isDragging");
2026-02-17 12:47:39 +05:30
if (!isBlockSelected || props.plugin.key === "tr" || props.plugin.key === "table") return null;
2026-02-17 12:47:39 +05:30
return (
<div
className={blockSelectionVariants({
active: isBlockSelected && !isDragging,
})}
data-slot="block-selection"
/>
);
}