/* Copyright 2026 Marimo. All rights reserved. */ import { CopyIcon, PlayIcon } from "lucide-react"; import type { JSX } from "react"; import { Button } from "@/components/ui/button"; import { Tooltip } from "@/components/ui/tooltip"; import type { CellId } from "@/core/cells/ids"; import { useRequestClient } from "@/core/network/requests"; import { copyToClipboard } from "@/utils/copy"; import { Logger } from "@/utils/Logger"; /** * Props for IslandControls component */ export interface IslandControlsProps { /** * ID of the cell this control operates on */ cellId: CellId; /** * Callback to get the current code for the cell */ codeCallback: () => string; /** * Whether the controls should be visible */ visible: boolean; } /** * Props for individual control buttons */ interface IconButtonProps { tooltip: string; icon: JSX.Element; action: () => void; } /** * A single icon button with tooltip */ const IconButton: React.FC = ({ tooltip, icon, action }) => ( ); /** * Controls for interacting with an island cell. * * Provides buttons to: * - Copy the cell's code to clipboard * - Re-run the cell */ export const IslandControls: React.FC = ({ cellId, codeCallback, visible, }) => { const { sendRun } = useRequestClient(); const handleCopy = () => { copyToClipboard(codeCallback()); }; const handleRun = async () => { try { await sendRun({ cellIds: [cellId], codes: [codeCallback()], }); } catch (error) { Logger.error("Failed to run cell:", error); } }; return (
} action={handleCopy} /> } action={handleRun} />
); };