"use client";
import { createPortal } from "react-dom";
import { cn } from "@/lib/utils";
import { type Position, type ToolbarAction } from "./shared";
export function FloatingToolbar({
position,
actions,
isMobile,
}: {
position: Position;
actions: ToolbarAction[];
isMobile: boolean;
}) {
if (isMobile) {
// Mobile: fixed bottom bar
return createPortal(
e.preventDefault()}
>
{actions.map((action) => (
))}
,
document.body,
);
}
// Desktop: floating above the selection
const toolbarWidth = actions.length * 44 + 8;
const left = Math.max(
8,
Math.min(
position.x - toolbarWidth / 2,
window.innerWidth - toolbarWidth - 8,
),
);
const top = Math.max(8, position.y - 48);
return createPortal(
e.preventDefault()}
>
{actions.map((action) => (
))}
,
document.body,
);
}