import { Button, Dialog, DialogRoot } from "@cloudflare/kumo"; import { useCallback, useState } from "react"; import type { BlockInteraction, ButtonElement } from "../types.js"; export function ButtonElementComponent({ element, onAction, }: { element: ButtonElement; onAction: (interaction: BlockInteraction) => void; }) { const [confirmOpen, setConfirmOpen] = useState(false); const fireAction = useCallback(() => { onAction({ type: "block_action", action_id: element.action_id, value: element.value, }); }, [onAction, element.action_id, element.value]); const handleClick = useCallback(() => { if (element.confirm) { setConfirmOpen(true); } else { fireAction(); } }, [element.confirm, fireAction]); const handleConfirm = useCallback(() => { setConfirmOpen(false); fireAction(); }, [fireAction]); const variant = element.style === "primary" ? ("primary" as const) : element.style === "danger" ? ("destructive" as const) : ("secondary" as const); return ( <> {element.confirm && (

{element.confirm.title}

{element.confirm.text}

)} ); }