From e70c7a455a9f2ad6138b56bbfaaf3c638e356fe4 Mon Sep 17 00:00:00 2001 From: Rodrigo Antinarelli Date: Thu, 25 Jun 2020 13:46:24 -0300 Subject: [PATCH] split dropdown item into a separated render component --- .../ui/src/components/Dropdown/Dropdown.jsx | 77 +++++++++++-------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/platform/ui/src/components/Dropdown/Dropdown.jsx b/platform/ui/src/components/Dropdown/Dropdown.jsx index 149c55ece..b25240458 100644 --- a/platform/ui/src/components/Dropdown/Dropdown.jsx +++ b/platform/ui/src/components/Dropdown/Dropdown.jsx @@ -8,6 +8,42 @@ const Dropdown = ({ children, showDropdownIcon, list }) => { const [open, setOpen] = useState(false); const element = useRef(null); + const DropdownItem = ({ title, icon, onClick, index }) => { + const itemsAmount = list.length; + const isLastItem = itemsAmount === index + 1; + + return ( +
{ + setOpen(false); + onClick(); + }} + > + {!!icon && } + {title} +
+ ); + }; + + DropdownItem.defaultProps = { + icon: '', + onClick: () => {}, + }; + + DropdownItem.propTypes = { + title: PropTypes.string.isRequired, + icon: PropTypes.string, + onClick: PropTypes.func, + index: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, + }; + const renderTitleElement = () => { return (
@@ -30,8 +66,6 @@ const Dropdown = ({ children, showDropdownIcon, list }) => { }; const renderList = () => { - const itemsAmount = list.length; - return (
{ } )} > - {list.map( - ( - { - title: itemTitle, - icon: itemIcon, - onClick: itemOnClick = () => {}, - }, - idx - ) => ( -
{ - setOpen(false); - itemOnClick(); - }} - > - {!!itemIcon && ( - - )} - {itemTitle} -
- ) - )} + {list.map((item, idx) => ( + + ))}
); }; @@ -107,7 +121,6 @@ Dropdown.propTypes = { title: PropTypes.string.isRequired, icon: PropTypes.string, onClick: PropTypes.func, - link: PropTypes.string, }) ), };