From 625ae3280bdf83b66a66873344acad4103d30006 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 13 Aug 2020 21:33:03 +0300 Subject: feat: create FileUpload component --- src/components/AttachLink/AttachLink.tsx | 6 +- src/components/FileUpload/FileUpload.tsx | 46 ++++++++++++++ src/containers/PollCreation/PollCreation.tsx | 4 +- src/containers/PollCreation/PollCreationImage.tsx | 77 +++++++---------------- 4 files changed, 73 insertions(+), 60 deletions(-) create mode 100644 src/components/FileUpload/FileUpload.tsx diff --git a/src/components/AttachLink/AttachLink.tsx b/src/components/AttachLink/AttachLink.tsx index b8742a2..eb7aebd 100644 --- a/src/components/AttachLink/AttachLink.tsx +++ b/src/components/AttachLink/AttachLink.tsx @@ -13,9 +13,9 @@ const AttachLink: React.FC = ({ callback, children }) => { const handleOpen = (): void => { setIsOpen(true); }; - + const defaultButton = ( - + ); + + return ( + <> + + {React.isValidElement(child) + ? React.cloneElement(child, { onClick }) + : defaultButton + } + + ); +}; + +export default FileUpload; diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index 1286c6f..34fc7c3 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -79,8 +79,8 @@ const PollCreation: React.FC = () => { {user && }
- - + +
+
+ or - - + +
); const Media = ( - - {isMediaHover && } - + + + + + ); - return ( -
- {file ? (url && Media) : Upload} -
- ); + return url ? Media : Upload; }; export default PollCreationImage; -- cgit v1.2.3