"use client"; /** * CommentMenu — the kebab (⋮) overflow menu on a comment: Pin / Report / * Delete (each shown only when permitted). Rendered in a portal with a * transparent full-screen backdrop that swallows the dismiss click, so it * can't reach (and accidentally close) the surrounding vaul comments drawer. */ import { useRef, useState } from "react"; import { createPortal } from "react-dom"; import { Flag, MoreVertical, Pin, PinOff, Trash2 } from "lucide-react"; import { cn } from "@/lib/utils"; export function CommentMenu({ canPin, isPinned, canDelete, canReport, onPin, onDelete, onReport, }: { canPin: boolean; isPinned: boolean; canDelete: boolean; canReport: boolean; onPin: () => void; onDelete: () => void; onReport: () => void; }) { const [open, setOpen] = useState(false); const [pos, setPos] = useState<{ top: number; right: number } | null>(null); const btnRef = useRef(null); // Nothing actionable → no kebab at all. if (!canPin && !canDelete && !canReport) return null; function openMenu() { const r = btnRef.current?.getBoundingClientRect(); if (r) setPos({ top: r.bottom + 4, right: window.innerWidth - r.right }); setOpen(true); } return ( <> {open && pos && typeof document !== "undefined" ? createPortal( <>
{ e.stopPropagation(); setOpen(false); }} />
{canPin ? ( : } onClick={() => { setOpen(false); onPin(); }} > {isPinned ? "Unpin" : "Pin"} ) : null} {canReport ? ( } onClick={() => { setOpen(false); onReport(); }} > Report ) : null} {canDelete ? ( } danger onClick={() => { setOpen(false); onDelete(); }} > Delete ) : null}
, document.body, ) : null} ); } function MenuItem({ icon, children, onClick, danger = false, }: { icon: React.ReactNode; children: React.ReactNode; onClick: () => void; danger?: boolean; }) { return ( ); }