import * as React from 'react'; import * as _ from 'lodash'; import * as DefaultStyles from './style'; import Scroller from '../Scroller' import LoadingSpinner from "../LoadingSpinner"; export namespace List { export interface Props { /** * Number of items to show per 'jump' or section, when the component * does not show all the elements at once in the list */ showLoadMoreButton?: boolean; handleItemClick?: any; handleShowMore?: () => void; customLoadingAnimation?: any; status?: string; children?: any; id?: string; name?: string; onScroll?: (e) => void; styles?: Styles; } export interface Styles { ListItemsContainer?: any, ItemsStyles?: any, ListBottom?: any, LoadMoreButton?: any, LoadMoreButtonContainer?: any, ScrollWrapper?: any, MemberList?: any } } export default class List extends React.Component { constructor(props: List.Props) { super(props); } handleShowMore = () => { this.props.handleShowMore && this.props.handleShowMore(); }; handleOnFocus = () => { this.handleShowMore(); } loadMore = (Styles) => { if (this.props.showLoadMoreButton && this.props.handleShowMore) { return ( LOAD MORE ); } else { return ( ); } } selectLoadingAnimation = (Custom): JSX.Element => { if (Custom) { return ; } else { return } } render() { const Styles: List.Styles = _.merge(DefaultStyles, this.props.styles); const children = React.Children.map(this.props.children, (child: any, index: number) => { return React.cloneElement(child, { styles: (Styles && Styles.ItemsStyles) ? Styles.ItemsStyles : {}, onClick: () => this.props.handleItemClick && this.props.handleItemClick(index) }); }) return ( {this.props.status === 'LOADING' ? this.selectLoadingAnimation(this.props.customLoadingAnimation) : {children} { this.loadMore(Styles) } } ); } }