Skip to content

Commit 2ce3249

Browse files
committed
Refactor pagination for readability and maintainability
--- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/react-component/pagination?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 8f26e36 commit 2ce3249

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

src/Options.tsx renamed to src/components/Options.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { OptionProps } from 'rc-select/es/Option';
33
import KEYCODE from 'rc-util/lib/KeyCode';
44
import classNames from 'classnames';
55
import React from 'react';
6-
import type { PaginationLocale, PaginationProps } from './interface';
6+
import type { PaginationLocale, PaginationProps } from '../interface';
77

88
interface InternalSelectProps extends SelectProps {
99
/**

src/Pager.tsx renamed to src/components/Pager.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/* eslint react/prop-types: 0 */
21
import classNames from 'classnames';
32
import React from 'react';
4-
import type { PaginationProps } from './interface';
3+
import type { PaginationProps } from '../interface';
54

65
export interface PagerProps extends Pick<PaginationProps, 'itemRender'> {
76
rootPrefixCls: string;

src/Pagination.tsx renamed to src/components/Pagination.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import KeyCode from 'rc-util/lib/KeyCode';
44
import pickAttrs from 'rc-util/lib/pickAttrs';
55
import warning from 'rc-util/lib/warning';
66
import React, { useEffect } from 'react';
7-
import type { PaginationProps } from './interface';
8-
import zhCN from './locale/zh_CN';
7+
import type { PaginationProps } from '../interface';
8+
import zhCN from '../locale/zh_CN';
99
import Options from './Options';
1010
import type { PagerProps } from './Pager';
1111
import Pager from './Pager';

src/components/Simple.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react';
2+
import type { PaginationProps } from '../interface';
3+
4+
const Simple: React.FC<PaginationProps> = ({
5+
locale,
6+
prefixCls,
7+
current,
8+
allPages,
9+
disabled,
10+
internalInputVal,
11+
handleKeyDown,
12+
handleKeyUp,
13+
handleBlur,
14+
handleGoTO,
15+
goButton,
16+
showTitle,
17+
}) => {
18+
const isReadOnly = typeof simple === 'object' ? simple.readOnly : !simple;
19+
let gotoButton: any = goButton;
20+
21+
if (goButton) {
22+
if (typeof goButton === 'boolean') {
23+
gotoButton = (
24+
<button type="button" onClick={handleGoTO} onKeyUp={handleGoTO}>
25+
{locale.jump_to_confirm}
26+
</button>
27+
);
28+
} else {
29+
gotoButton = (
30+
<span onClick={handleGoTO} onKeyUp={handleGoTO}>
31+
{goButton}
32+
</span>
33+
);
34+
}
35+
36+
gotoButton = (
37+
<li
38+
title={showTitle ? `${locale.jump_to}${current}/${allPages}` : null}
39+
className={`${prefixCls}-simple-pager`}
40+
>
41+
{gotoButton}
42+
</li>
43+
);
44+
}
45+
46+
return (
47+
<li
48+
title={showTitle ? `${current}/${allPages}` : null}
49+
className={`${prefixCls}-simple-pager`}
50+
>
51+
{isReadOnly ? (
52+
internalInputVal
53+
) : (
54+
<input
55+
type="text"
56+
value={internalInputVal}
57+
disabled={disabled}
58+
onKeyDown={handleKeyDown}
59+
onKeyUp={handleKeyUp}
60+
onChange={handleKeyUp}
61+
onBlur={handleBlur}
62+
size={3}
63+
/>
64+
)}
65+
<span className={`${prefixCls}-slash`}>/</span>
66+
{allPages}
67+
</li>
68+
);
69+
};
70+
71+
export default Simple;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default } from './Pagination';
1+
export { default } from './components/Pagination';
22
export type { PaginationLocale, PaginationProps } from './interface';

0 commit comments

Comments
 (0)