aboutsummaryrefslogtreecommitdiff
path: root/src/components/AttachLink/AttachLink.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/AttachLink/AttachLink.tsx')
-rw-r--r--src/components/AttachLink/AttachLink.tsx42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/components/AttachLink/AttachLink.tsx b/src/components/AttachLink/AttachLink.tsx
new file mode 100644
index 0000000..e73f5c1
--- /dev/null
+++ b/src/components/AttachLink/AttachLink.tsx
@@ -0,0 +1,42 @@
+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<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;