Skip to content

Commit

Permalink
Add position config for List pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
zheeeng committed May 19, 2018
1 parent f3545cc commit 473779d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 17 deletions.
11 changes: 11 additions & 0 deletions components/list/__tests__/pagination.test.js
Expand Up @@ -126,4 +126,15 @@ describe('List.pagination', () => {
.hasClass('ant-pagination-item-active')
).toBe(true);
});

it('specify the position of pagination', () => {
const wrapper = mount(createList({ pagination: { position: 'top' } }));
expect(wrapper.find('.ant-list').childAt(0).find('.ant-pagination')).toHaveLength(1);
wrapper.setProps({ pagination: { position: 'bottom' } });
expect(wrapper.find('.ant-list').children().last().find('.ant-pagination')).toHaveLength(1);
wrapper.setProps({ pagination: { position: 'both' } });
expect(wrapper.find('.ant-pagination')).toHaveLength(2);
expect(wrapper.find('.ant-list').childAt(0).find('.ant-pagination')).toHaveLength(1);
expect(wrapper.find('.ant-list').children().last().find('.ant-pagination')).toHaveLength(1);
});
});
12 changes: 11 additions & 1 deletion components/list/index.en-US.md
@@ -1,7 +1,7 @@
---
category: Components
type: Data Display
title: List
title: List
cols: 1
---

Expand All @@ -28,6 +28,16 @@ A list can be used to display content related to a single subject. The content c
| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean \| object | false |
| split | Toggles rendering of the split under the list item | boolean | true |

### pagination

Properties for pagination.

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| position | specify the position of `Pagination` | 'top' \| 'bottom' \| 'both' | 'bottom' |

More about pagination, please check [`Pagination`](/components/pagination/).

### List grid props

| Property | Description | Type | Default |
Expand Down
12 changes: 8 additions & 4 deletions components/list/index.tsx
Expand Up @@ -6,7 +6,7 @@ import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default';

import Spin from '../spin';
import Pagination from '../pagination';
import Pagination, { PaginationConfig } from '../pagination';
import { Row } from '../grid';

import Item from './Item';
Expand Down Expand Up @@ -49,7 +49,7 @@ export interface ListProps {
itemLayout?: string;
loading?: boolean | SpinProps;
loadMore?: React.ReactNode;
pagination?: any;
pagination?: PaginationConfig;
prefixCls?: string;
rowKey?: any;
renderItem: any;
Expand Down Expand Up @@ -200,8 +200,9 @@ export default class List extends React.Component<ListProps> {
...this.defaultPaginationProps,
total: dataSource.length,
current: paginationCurrent,
...pagination,
...pagination || {},
};

const largestPage = Math.ceil(
paginationProps.total / paginationProps.pageSize,
);
Expand Down Expand Up @@ -258,15 +259,18 @@ export default class List extends React.Component<ListProps> {
);
}

const paginationPosition = paginationProps.position || 'bottom';

return (
<div className={classString} {...rest}>
{(paginationPosition === 'top' || paginationPosition === 'both') && paginationContent}
{header && <div className={`${prefixCls}-header`}>{header}</div>}
<Spin {...loadingProp}>
{childrenContent}
{children}
</Spin>
{footer && <div className={`${prefixCls}-footer`}>{footer}</div>}
{loadMore || paginationContent}
{loadMore || (paginationPosition === 'bottom' || paginationPosition === 'both') && paginationContent}
</div>
);
}
Expand Down
12 changes: 11 additions & 1 deletion components/list/index.zh-CN.md
@@ -1,7 +1,7 @@
---
category: Components
type: Data Display
title: List
title: List
subtitle: 列表
cols: 1
---
Expand Down Expand Up @@ -30,6 +30,16 @@ cols: 1
| size | list 的尺寸 | `default` \| `middle` \| `small` | `default` |
| split | 是否展示分割线 | boolean | true |

### pagination

分页的配置项。

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| position | 指定分页显示的位置 | 'top' \| 'bottom' \| 'both' | 'bottom' |

更多配置项,请查看 [`Pagination`](/components/pagination/)

### List grid props

| 参数 | 说明 | 类型 | 默认值 |
Expand Down
4 changes: 4 additions & 0 deletions components/pagination/Pagination.tsx
Expand Up @@ -29,6 +29,10 @@ export interface PaginationProps {
itemRender?: (page: number, type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next') => React.ReactNode;
}

export interface PaginationConfig extends PaginationProps {
position?: 'top' | 'bottom' | 'both';
}

export type PaginationLocale = any;

export default class Pagination extends React.Component<PaginationProps, {}> {
Expand Down
2 changes: 1 addition & 1 deletion components/pagination/index.tsx
@@ -1,4 +1,4 @@
import Pagination from './Pagination';

export { PaginationProps } from './Pagination';
export { PaginationProps, PaginationConfig } from './Pagination';
export default Pagination;
4 changes: 2 additions & 2 deletions components/table/Table.tsx
Expand Up @@ -29,9 +29,9 @@ import {
TableStateFilters,
SelectionItemSelectFn,
SelectionInfo,
TablePaginationConfig,
TableSelectWay,
TableRowSelection,
PaginationConfig,
} from './interface';
import { RadioChangeEvent } from '../radio';
import { CheckboxChangeEvent } from '../checkbox';
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
}

getDefaultPagination(props: TableProps<T>) {
const pagination: TablePaginationConfig = props.pagination || {};
const pagination: PaginationConfig = props.pagination || {};
return this.hasPagination(props) ?
{
...defaultPagination,
Expand Down
13 changes: 5 additions & 8 deletions components/table/interface.tsx
@@ -1,9 +1,10 @@
import * as React from 'react';
import { PaginationProps } from '../pagination';
import { SpinProps } from '../spin';
import { Store } from './createStore';
import { RadioChangeEvent } from '../radio';
import { CheckboxChangeEvent } from '../checkbox';
import { PaginationConfig } from '../pagination';
export { PaginationConfig } from '../pagination';

export type CompareFn<T> = ((a: T, b: T, sortOrder?: 'ascend' | 'descend') => number);
export type ColumnFilterItem = { text: string; value: string, children?: ColumnFilterItem[] };
Expand Down Expand Up @@ -61,10 +62,6 @@ export interface TableLocale {
export type RowSelectionType = 'checkbox' | 'radio';
export type SelectionSelectFn<T> = (record: T, selected: boolean, selectedRows: Object[], nativeEvent: Event) => any;

export interface TablePaginationConfig extends PaginationProps {
position?: 'top' | 'bottom' | 'both';
}

export type TableSelectWay = 'onSelect' | 'onSelectAll' | 'onSelectInvert';

export interface TableRowSelection<T> {
Expand All @@ -85,7 +82,7 @@ export interface TableProps<T> {
prefixCls?: string;
dropdownPrefixCls?: string;
rowSelection?: TableRowSelection<T>;
pagination?: TablePaginationConfig | false;
pagination?: PaginationConfig | false;
size?: 'default' | 'middle' | 'small';
dataSource?: T[];
components?: TableComponents;
Expand All @@ -101,7 +98,7 @@ export interface TableProps<T> {
expandRowByClick?: boolean;
onExpandedRowsChange?: (expandedRowKeys: string[] | number[]) => void;
onExpand?: (expanded: boolean, record: T) => void;
onChange?: (pagination: TablePaginationConfig | boolean, filters: string[], sorter: Object) => any;
onChange?: (pagination: PaginationConfig | boolean, filters: string[], sorter: Object) => any;
loading?: boolean | SpinProps;
locale?: Object;
indentSize?: number;
Expand All @@ -126,7 +123,7 @@ export interface TableStateFilters {
}

export interface TableState<T> {
pagination: TablePaginationConfig;
pagination: PaginationConfig;
filters: TableStateFilters;
sortColumn: ColumnProps<T> | null;
sortOrder: 'ascend' | 'descend' | undefined;
Expand Down

0 comments on commit 473779d

Please sign in to comment.