import React, { Component } from 'react'; import classNames from 'classnames'; import Spin from '../spin'; import Icon from '../icon'; import Pagination from '../pagination'; import Button from '../button'; import { Row } from '../grid'; import Item from './Item'; export interface ListGridType { gutter?: number; column?: number; } export interface ListProps { bordered?: boolean; className?: string; children?: React.ReactNode; extra?: React.ReactNode; id?: string; itemLayout: string; loading?: boolean; showLoadMore?: boolean; loadingMore?: boolean; onLoadMore?: React.FormEventHandler; pagination?: any; prefixCls?: string; grid?: ListGridType; style?: React.CSSProperties; } export default class List extends Component { static Item: typeof Item = Item; render() { const { bordered = true, className, children, loading = false, itemLayout, showLoadMore = false, loadingMore = false, onLoadMore = (() => { }), pagination = false, prefixCls = 'ant-list', grid, } = this.props; const classString = classNames(prefixCls, className, { [`${prefixCls}-vertical`]: itemLayout === 'vertical', [`${prefixCls}-bordered`]: bordered, [`${prefixCls}-loading`]: loading, [`${prefixCls}-grid`]: grid, }); const moreButton = ( ); const moreContent = (
{loadingMore ? moreButton : }
); const paginationContent = (
); const loadingContent = (
); const childrenContent = grid ? ( {React.Children.map(children, (element: React.ReactElement) => React.cloneElement(element, { grid }))} ) : children; return (
{loading && loadingContent} {!loading && childrenContent} {!loading && showLoadMore && moreContent} {(!showLoadMore && pagination) && paginationContent}
); } }