import { useState } from "react"; import { TransitionDialogue } from "~/components/TransitionDialogue"; import { Button, ButtonPropsI } from "~/components/Button"; type UnionedButtonProps = { label?: string } & ButtonPropsI; interface ButtonDialoguePropsI { buttonProps?: UnionedButtonProps; confirmButtonProps?: UnionedButtonProps; closeButtonProps?: UnionedButtonProps; dialogProps?: { className?: string; }; title?: string; children: React.ReactNode; showClose?: boolean; } export const ButtonDialogue = ({ dialogProps = {}, buttonProps: unionedButtonProps, confirmButtonProps, closeButtonProps: unionedCloseButtonProps, title, children, showClose = true, }: ButtonDialoguePropsI) => { const [isOpen, setIsOpen] = useState(false); const closeModal = () => setIsOpen(false); const openModal = () => setIsOpen(true); const { label: buttonLabel, ...buttonProps } = unionedButtonProps || { label: "Open", }; const { label: closeButtonLabel, ...closeButtonProps } = unionedCloseButtonProps || { label: "Close" }; return ( <> {buttonLabel} {children} {showClose && ( {closeButtonLabel} )} {confirmButtonProps && ( { if (confirmButtonProps.onClick) { confirmButtonProps.onClick(e); } closeModal(); }}> {confirmButtonProps.label ? confirmButtonProps.label : "Confirm"} )} > ); };