diff --git a/components/list/Item.tsx b/components/list/Item.tsx index e13d00ea31..e7f84a1704 100644 --- a/components/list/Item.tsx +++ b/components/list/Item.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Col } from '../grid'; -import { ListGridType } from './index'; +import { ListGridType, ColumnType } from './index'; export interface ListItemProps { className?: string; @@ -51,8 +51,8 @@ export const Meta = (props: ListItemMetaProps) => { ); }; -function getGrid(grid, t) { - return grid[t] && Math.floor(24 / grid[t]); +function getGrid(grid: ListGridType, t: ColumnType) { + return grid[t] && Math.floor(24 / grid[t]!); } const GridColumns = ['', 1, 2, 3, 4, 6, 8, 12, 24]; @@ -99,7 +99,7 @@ export default class Item extends React.Component { let actionsContent; if (actions && actions.length > 0) { - const actionsContentItem = (action, i) => ( + const actionsContentItem = (action: React.ReactNode, i: number) => (
  • {action} {i !== (actions.length - 1) && } diff --git a/components/list/index.tsx b/components/list/index.tsx index 1ea6180c14..2e4dbc672a 100644 --- a/components/list/index.tsx +++ b/components/list/index.tsx @@ -12,16 +12,18 @@ import Item from './Item'; export { ListItemProps, ListItemMetaProps } from './Item'; -export type ColumnType = 1 | 2 | 3 | 4 | 6 | 8 | 12 | 24; +export type ColumnCount = 1 | 2 | 3 | 4 | 6 | 8 | 12 | 24; + +export type ColumnType = 'gutter' | 'column' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'; export interface ListGridType { gutter?: number; - column?: ColumnType; - xs?: ColumnType; - sm?: ColumnType; - md?: ColumnType; - lg?: ColumnType; - xl?: ColumnType; + column?: ColumnCount; + xs?: ColumnCount; + sm?: ColumnCount; + md?: ColumnCount; + lg?: ColumnCount; + xl?: ColumnCount; } export type ListSize = 'small' | 'default' | 'large'; @@ -48,6 +50,10 @@ export interface ListProps { locale?: Object; } +export interface ListLocale { + emptyText: string; +} + export default class List extends React.Component { static Item: typeof Item = Item; @@ -64,7 +70,7 @@ export default class List extends React.Component { pagination: false, }; - private keys = {}; + private keys: {[key: string]: string} = {}; getChildContext() { return { @@ -72,7 +78,7 @@ export default class List extends React.Component { }; } - renderItem = (item, index) => { + renderItem = (item: React.ReactElement, index: number) => { const { dataSource, renderItem, rowKey } = this.props; let key; @@ -98,7 +104,7 @@ export default class List extends React.Component { return !!(loadMore || pagination || footer); } - renderEmpty = (contextLocale) => { + renderEmpty = (contextLocale: ListLocale) => { const locale = { ...contextLocale, ...this.props.locale }; return
    {locale.emptyText}
    ; } @@ -155,8 +161,8 @@ export default class List extends React.Component { let childrenContent; if (dataSource.length > 0) { - const childrenList = React.Children.map(dataSource.map((item: any, index) => this.renderItem(item, index)), - (child: any, index) => React.cloneElement(child, { + const items = dataSource.map((item: any, index: number) => this.renderItem(item, index)); + const childrenList = React.Children.map(items, (child: any, index) => React.cloneElement(child, { key: this.keys[index], }), );