You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.4 KiB

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';
7 years ago
import { Row } from '../grid';
import Item from './Item';
7 years ago
export interface ListGridType {
7 years ago
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<any>;
pagination?: any;
prefixCls?: string;
7 years ago
grid?: ListGridType;
style?: React.CSSProperties;
}
export default class List extends Component<ListProps> {
static Item: typeof Item = Item;
render() {
const {
bordered = true,
className,
children,
loading = false,
itemLayout,
showLoadMore = false,
loadingMore = false,
onLoadMore = (() => {
}),
pagination = false,
prefixCls = 'ant-list',
7 years ago
grid,
} = this.props;
const classString = classNames(prefixCls, className, {
[`${prefixCls}-vertical`]: itemLayout === 'vertical',
[`${prefixCls}-bordered`]: bordered,
[`${prefixCls}-loading`]: loading,
7 years ago
[`${prefixCls}-grid`]: grid,
});
const moreButton = (
<Button onClick={onLoadMore}>
<Icon type="loading"/>
...
</Button>
);
const moreContent = (
<div className={`${prefixCls}-more`}>
{loadingMore ? moreButton : <Button onClick={onLoadMore}>...</Button>}
</div>
);
const paginationContent = (
<div className={`${prefixCls}-pagination`}>
<Pagination {...pagination} />
</div>
);
const loadingContent = (
<div className={`${prefixCls}-spin`}>
<Spin />
</div>
);
7 years ago
const childrenContent = grid ? (
<Row gutter={grid.gutter}>
{React.Children.map(children, (element: React.ReactElement<any>) => React.cloneElement(element, { grid }))}
</Row>
) : children;
return (
<div className={classString}>
{loading && loadingContent}
7 years ago
{!loading && childrenContent}
{showLoadMore && moreContent}
{(!showLoadMore && pagination) && paginationContent}
</div>
);
}
}