Skip to content

Commit fce4ca0

Browse files
committed
v2.0.0
1 parent ddcbd43 commit fce4ca0

38 files changed

+17165
-38602
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
/node_modules
2+
/lib
3+
/cjs
4+
/esm
5+
/dist

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

.prettierrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"endOfLine": "auto",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 100,
10+
"proseWrap": "preserve",
11+
"quoteProps": "as-needed",
12+
"requirePragma": false,
13+
"semi": true,
14+
"singleQuote": false,
15+
"tabWidth": 4,
16+
"trailingComma": "es5",
17+
"useTabs": true
18+
}

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 react-widget
3+
Copyright (c) 2018-2020 react-widget-pagination
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+232-58
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,248 @@
1-
# react-widget-pagination
1+
# Pagination
22

3-
## Install
3+
Pagination分页组件
4+
5+
## 安装
46

57
`npm install --save react-widget-pagination`
68

79

8-
## Options
10+
## 使用
11+
12+
```js
13+
import React from "react";
14+
import Pagination from "react-widget-pagination";
15+
import "react-widget-pagination/style";
16+
17+
export default function App() {
18+
return (
19+
<div
20+
className="App"
21+
style={{
22+
padding: 100
23+
}}
24+
>
25+
<Pagination total={1000} showSizeChanger showTotal showQuickJumper />
26+
</div>
27+
);
28+
}
29+
930

1031
```
11-
static propTypes = {
12-
className: PropTypes.string,
13-
prefixCls: PropTypes.string,
14-
small: PropTypes.bool,
15-
total: PropTypes.number.isRequired,
16-
defaultCurrent: PropTypes.number,
17-
current: PropTypes.number,
18-
defaultPageSize: PropTypes.number,
19-
pageSize: PropTypes.number,
20-
pageRange: PropTypes.number,
21-
pageSizeOptions: PropTypes.array,
22-
onPageSizeChange: PropTypes.func,
23-
onChange: PropTypes.func,
24-
layout: PropTypes.array,
25-
totalRender: PropTypes.func,
26-
prevBtnRender: PropTypes.func,
27-
nextBtnRender: PropTypes.func,
28-
itemRender: PropTypes.func,
29-
pageSizeOptionRender: PropTypes.func,
30-
jumperRender: PropTypes.func,
31-
showPrevMore: PropTypes.bool,
32-
showNextMore: PropTypes.bool,
33-
selectComponent: PropTypes.any,
34-
};
3532

36-
static defaultProps = {
37-
prefixCls: 'rw-pagination',
38-
small: false,
39-
total: 0,
40-
showSizeChanger: false,
41-
pageSizeOptions: [10, 20, 30, 40],
42-
pageRange: 5,//必须是奇数,界面上最多显示7页
43-
//total, sizes, prev, pager, next, jumper
44-
layout: ['total', 'sizes', 'prev', 'pager', 'next', 'jumper'],
45-
totalRender: function (total, pn, ps) {
46-
return `共 ${total} 条`;
47-
},
48-
pageSizeOptionRender: function (v) {
49-
return `${v} 条/页`;
50-
},
51-
jumperRender: null,
52-
prevBtnRender: () => '上一页',
53-
nextBtnRender: () => '下一页',
54-
itemRender: null,
55-
showPrevMore: true,
56-
showNextMore: true,
57-
selectComponent: Select,
33+
34+
### Interfaces
35+
36+
```ts
37+
import React from "react";
38+
export declare type PaginationLayout = "total" | "sizeChanger" | "prev" | "pager" | "next" | "jumper";
39+
export declare type ItemType = "page" | "prev" | "next" | "prevMore" | "nextMore";
40+
export interface TotalRenderProps {
41+
page: number;
42+
total: number;
43+
pageSize: number;
44+
disabled: boolean;
45+
range: [number, number];
46+
}
47+
export interface SizeChangerProps {
48+
options: Array<number>;
49+
setPageSize: (pageSize: number) => void;
50+
pageSize: number;
51+
page: number;
52+
total: number;
53+
disabled: boolean;
54+
}
55+
export interface JumperProps {
56+
page: number;
57+
pageSize: number;
58+
total: number;
59+
setPage: (page: number) => void;
60+
disabled: boolean;
61+
}
62+
export declare function SizeChanger(props: SizeChangerProps): JSX.Element;
63+
export declare function Jumper(props: JumperProps): JSX.Element;
64+
export interface PaginationProps {
65+
/** 样式前缀 */
66+
prefixCls?: string;
67+
/** 样式名称 */
68+
className?: string;
69+
/** 样式属性 */
70+
style?: React.CSSProperties;
71+
/** 数据总数:默认为:0 */
72+
total?: number;
73+
/** 当前页数(受控) */
74+
current?: number;
75+
/** 默认的当前页数 */
76+
defaultCurrent?: number;
77+
/** 每页条数(受控) */
78+
pageSize?: number;
79+
/** 默认的每页条数 */
80+
defaultPageSize?: number;
81+
/** 指定每页可以显示多少条 */
82+
pageSizeOptions?: Array<number>;
83+
/** 禁用分页 */
84+
disabled?: boolean;
85+
/** 只有一页时是否隐藏分页器 */
86+
hideOnSinglePage?: boolean;
87+
/** 是否展示 pageSize 选择器 */
88+
showSizeChanger?: boolean;
89+
/** 自定义渲染 pageSize 选择器 */
90+
sizeChangerRender?: (props: SizeChangerProps) => React.ReactNode;
91+
/** 是否显示快速跳转至某页输入框 */
92+
showQuickJumper?: boolean;
93+
/** 自定义渲染快速跳转至某页输入框 */
94+
quickJumperRender?: (props: JumperProps) => React.ReactNode;
95+
/** 是否显示总条数信息,默认:共 x 条,每页 y 条 */
96+
showTotal?: boolean;
97+
/** 自定义显示总条数信息 */
98+
totalRender?: (props: TotalRenderProps) => React.ReactNode;
99+
/** 显示页码数,默认为:5,该数值为奇数 */
100+
pageRange?: number;
101+
/** 自定义显示布局顺序及内置模块 */
102+
layout?: PaginationLayout[];
103+
/** 自定义渲染页码的内容 */
104+
itemRender?: (page: number, type: ItemType, originalElement: React.ReactNode) => React.ReactNode;
105+
/** 页数改变的回调 */
106+
onChange?: (page: number, pageSize: number) => void;
107+
/** 每页条数改变的回调 */
108+
onPageSizeChange?: (pageSize: number, page: number) => void;
109+
}
110+
export interface PaginationState {
111+
pageSize: number;
112+
current: number;
113+
}
114+
export declare class Pagination extends React.Component<PaginationProps, PaginationState> {
115+
static defaultProps: PaginationProps;
116+
static getDerivedStateFromProps(props: PaginationProps, state: PaginationState): {
117+
current: number;
118+
pageSize: number;
58119
};
120+
state: Readonly<PaginationState>;
121+
setPage(page: number): void;
122+
prev: () => void;
123+
next: () => void;
124+
protected onItemEnter(callback: () => void, e: React.KeyboardEvent): void;
125+
getTotalPages(pageSize?: number): number;
126+
getPageItemClassName(page: number): any;
127+
setPageSize: (pageSize: number) => void;
128+
protected renderPager(): JSX.Element[];
129+
getCurrentRange(): [number, number];
130+
protected renderLayoutTotal(): JSX.Element | null;
131+
protected renderLayoutSizeChanger(): JSX.Element | null;
132+
protected renderLayoutPrev(): JSX.Element;
133+
protected renderLayoutPager(): JSX.Element[];
134+
protected renderLayoutNext(): JSX.Element;
135+
protected renderLayoutJumper(): JSX.Element | null;
136+
render(): JSX.Element | null;
137+
}
138+
export default Pagination;
59139

60140
```
61141

62-
## Useage
142+
### defaultProps
143+
```js
144+
{
145+
prefixCls: "rw-pagination",
146+
total: 0,
147+
hideOnSinglePage: false,
148+
showSizeChanger: false,
149+
pageSizeOptions: [10, 20, 50, 100],
150+
pageRange: 5,
151+
layout: ["total", "prev", "pager", "next", "sizeChanger", "jumper"],
152+
totalRender: function (props: TotalRenderProps) {
153+
return `${props.total} 条,每页 ${props.pageSize}`;
154+
},
63155

156+
}
64157
```
65158

66-
<Pagination
67-
total={1000}
68-
style={{
69-
width: 260,
70-
height: 300
71-
}}
72-
/>
159+
### 基础样式
160+
161+
```css
162+
.rw-pagination {
163+
display: flex;
164+
align-items: center;
165+
}
166+
167+
.rw-pagination > div:not(:last-child) {
168+
margin-right: 6px;
169+
}
170+
171+
.rw-pagination-item {
172+
padding: 5px 10px;
173+
user-select: none;
174+
background: #fff;
175+
border: 1px solid #d9d9d9;
176+
outline: 0;
177+
border-radius: 2px;
178+
cursor: pointer;
179+
line-height: 20px;
180+
}
181+
182+
.rw-pagination-item-next-more,
183+
.rw-pagination-item-prev-more {
184+
font-size: 12px;
185+
}
186+
187+
.rw-pagination-icon-left,
188+
.rw-pagination-icon-right {
189+
display: none;
190+
}
73191

74-
```
192+
.rw-pagination-item:focus,
193+
.rw-pagination-item:hover {
194+
border-color: #40a9ff;
195+
}
196+
197+
.rw-pagination-item:active {
198+
background-color: #eaeaea;
199+
border-color: #dcdee0;
200+
}
201+
202+
.rw-pagination-item-disabled,
203+
.rw-pagination-item-disabled:active {
204+
color: rgba(0, 0, 0, 0.25);
205+
border-color: #d9d9d9;
206+
background-color: #fff;
207+
cursor: not-allowed;
208+
}
209+
210+
.rw-pagination-item-disabled:hover {
211+
border-color: #d9d9d9;
212+
}
213+
214+
.rw-pagination-item-active,
215+
.rw-pagination-item-active:active {
216+
background: #40a9ff;
217+
color: #fff;
218+
border-color: #40a9ff;
219+
cursor: default;
220+
}
221+
222+
.rw-pagination-quick-jumper input {
223+
width: 45px;
224+
margin: 0 6px;
225+
padding: 5px 10px;
226+
border-radius: 2px;
227+
border: 1px solid #d9d9d9;
228+
}
229+
230+
.rw-pagination-size-changer select {
231+
padding: 5px 10px;
232+
border-radius: 2px;
233+
border: 1px solid #d9d9d9;
234+
}
235+
236+
.rw-pagination-disabled .rw-pagination-item {
237+
background: #f5f5f5;
238+
border-color: #d9d9d9;
239+
cursor: not-allowed;
240+
}
241+
242+
.rw-pagination-disabled .rw-pagination-item-active {
243+
background: #dbdbdb;
244+
border-color: transparent;
245+
}
246+
247+
248+
```

babel.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = api => {
2+
const isTest = api.env("test");
3+
if (!isTest) return {};
4+
5+
return {
6+
presets: [
7+
[
8+
"babel-preset-packez",
9+
{
10+
modules: "cjs",
11+
},
12+
],
13+
],
14+
};
15+
};

docs/asset-manifest.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"index.css": "static/css/index.1f18a912.chunk.css",
3+
"index.js": "static/js/index.1f18a912.chunk.js",
4+
"runtime-index.js": "static/js/runtime-index.92eae014.js",
5+
"static/js/2.68d5c405.chunk.js": "static/js/2.68d5c405.chunk.js",
6+
"index.html": "index.html"
7+
}

docs/index.html

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1 @@
1-
<!DOCTYPE html>
2-
<html style="width:100%; height:100%; overflow:hidden;">
3-
4-
<head>
5-
<meta charset="utf-8">
6-
<title>scrollview</title>
7-
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1">
8-
<style type="text/css">
9-
.demo {
10-
width: 1200px;
11-
height: 500px;
12-
margin: 100px auto;
13-
background: #FFF;
14-
font-size: 12px;
15-
overflow: auto;
16-
}
17-
</style>
18-
<link href="static\css\index.a46d9cf2.css" rel="stylesheet"></head>
19-
20-
<body style="background:#F5F5F5">
21-
<div class="demo" id="demo">
22-
</div>
23-
<script src="static\js\vendors.226cb6a9.chunk.js"></script><script src="static\js\index.0853f3d2.js"></script></body>
24-
25-
</html>
1+
<!doctype html><html s><head><meta charset="utf-8"/><title>Pagination</title><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1"/><style></style><link href="static/css/index.1f18a912.chunk.css" rel="stylesheet"></head><body><div class="demo" id="demo"></div><script src="static/js/runtime-index.92eae014.js"></script><script src="static/js/2.68d5c405.chunk.js"></script><script src="static/js/index.1f18a912.chunk.js"></script></body></html>

0 commit comments

Comments
 (0)