diff options
Diffstat (limited to 'src/components/AttachLink/AttachLink.tsx')
-rw-r--r-- | src/components/AttachLink/AttachLink.tsx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/components/AttachLink/AttachLink.tsx b/src/components/AttachLink/AttachLink.tsx new file mode 100644 index 0000000..b8742a2 --- /dev/null +++ b/src/components/AttachLink/AttachLink.tsx @@ -0,0 +1,41 @@ +import React, { useState } from 'react'; +import { Button, } from '@material-ui/core'; +import LinkIcon from '@material-ui/icons/Link'; +import Modal from './Modal'; + +interface PropTypes { + callback: (url: string) => void; +} + +const AttachLink: React.FC<PropTypes> = ({ callback, children }) => { + const [isOpen, setIsOpen] = useState<boolean>(false); + + const handleOpen = (): void => { + setIsOpen(true); + }; + + const defaultButton = ( + <Button + onClick={handleOpen} + variant="outlined" + color="primary" + startIcon={<LinkIcon />} + > + Attach a link + </Button> + ); + + const child = children && React.Children.toArray(children)[0]; + + return ( + <> + <Modal callback={callback} isOpen={isOpen} setIsOpen={setIsOpen} /> + {React.isValidElement(child) + ? React.cloneElement(child, { onClick: handleOpen }) + : defaultButton + } + </> + ); +}; + +export default AttachLink; |