import React, { useState } from 'react'; import Button from '@material-ui/core/Button'; import LinkIcon from '@material-ui/icons/Link'; import Modal from './Modal'; interface PropTypes { callback: (url: string) => void; } const AttachLink: React.FC = ({ callback, children }) => { const [isOpen, setIsOpen] = useState(false); const handleOpen = (): void => { setIsOpen(true); }; const defaultButton = ( ); const child = children && React.Children.toArray(children)[0]; return ( <> { React.isValidElement(child) ? React.cloneElement(child, { onClick: handleOpen }) : defaultButton } ); }; export default AttachLink;