import React from "react"; import PropTypes from "prop-types"; import { TabletSideInfo, SideContainerWrapper, MainContainer, MainIcons, MainContainerWrapper, StyledRowContent, } from "./styled-row-content"; const getSideInfo = (content, convert) => { let info = ""; let child = null; const lastIndex = content.length - 1; content.map((element, index) => { const delimiter = index === lastIndex ? "" : " | "; if (index > 1) { if (!convert && index === lastIndex) { child = element; } else { info += element.props && element.props.children ? element.props.children + delimiter : ""; } } }); return ( <> {info} {child} ); }; const RowContent = (props) => { const { children, disableSideInfo, id, className, style, sideColor, onClick, sectionWidth, isMobile, convertSideInfo, } = props; const sideInfo = getSideInfo(children, convertSideInfo); const mainContainerWidth = children[0].props && children[0].props.containerWidth; return ( {children[0]} {children[1]} {children.map((element, index) => { if (index > 1) { return ( {element} ); } })} {!disableSideInfo && ( {sideInfo} )} ); }; RowContent.propTypes = { /** Components displayed inside RowContent */ children: PropTypes.node.isRequired, /** Accepts class */ className: PropTypes.string, /** If you do not need SideElements */ disableSideInfo: PropTypes.bool, /** Accepts id */ id: PropTypes.string, onClick: PropTypes.func, /** Need for change side information color */ sideColor: PropTypes.string, /** Accepts css style */ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), sectionWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), isMobile: PropTypes.bool, convertSideInfo: PropTypes.bool, }; RowContent.defaultProps = { disableSideInfo: false, convertSideInfo: true, }; export default RowContent;