supermemory/apps/web/app/components/plate-ui/block-selection.tsx
2025-01-20 17:50:45 -07:00

42 lines
888 B
TypeScript

'use client';
import { cn } from '@udecode/cn';
import { useBlockSelected } from '@udecode/plate-selection/react';
import { type VariantProps, cva } from 'class-variance-authority';
export const blockSelectionVariants = cva(
'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({
className,
...props
}: React.HTMLAttributes<HTMLDivElement> &
VariantProps<typeof blockSelectionVariants>) {
const isBlockSelected = useBlockSelected();
if (!isBlockSelected) return null;
return (
<div
className={cn(
blockSelectionVariants({
active: isBlockSelected,
}),
className
)}
{...props}
/>
);
}