Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor pagination for readability and maintainability #616

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Options.tsx → src/components/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { OptionProps } from 'rc-select/es/Option';
import KEYCODE from 'rc-util/lib/KeyCode';
import classNames from 'classnames';
import React from 'react';
import type { PaginationLocale, PaginationProps } from './interface';
import type { PaginationLocale, PaginationProps } from '../interface';

interface InternalSelectProps extends SelectProps {
/**
Expand Down
3 changes: 1 addition & 2 deletions src/Pager.tsx → src/components/Pager.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint react/prop-types: 0 */
import classNames from 'classnames';
import React from 'react';
import type { PaginationProps } from './interface';
import type { PaginationProps } from '../interface';

export interface PagerProps extends Pick<PaginationProps, 'itemRender'> {
rootPrefixCls: string;
Expand Down
4 changes: 2 additions & 2 deletions src/Pagination.tsx → src/components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import KeyCode from 'rc-util/lib/KeyCode';
import pickAttrs from 'rc-util/lib/pickAttrs';
import warning from 'rc-util/lib/warning';
import React, { useEffect } from 'react';
import type { PaginationProps } from './interface';
import zhCN from './locale/zh_CN';
import type { PaginationProps } from '../interface';
import zhCN from '../locale/zh_CN';
import Options from './Options';
import type { PagerProps } from './Pager';
import Pager from './Pager';
Expand Down
71 changes: 71 additions & 0 deletions src/components/Simple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import type { PaginationProps } from '../interface';

const Simple: React.FC<PaginationProps> = ({
locale,
prefixCls,
current,
allPages,
disabled,
internalInputVal,
handleKeyDown,
handleKeyUp,
handleBlur,
handleGoTO,
goButton,
showTitle,
}) => {
const isReadOnly = typeof simple === 'object' ? simple.readOnly : !simple;
let gotoButton: any = goButton;

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

The initial value of gotoButton is unused, since it is always overwritten.

if (goButton) {
if (typeof goButton === 'boolean') {
gotoButton = (
<button type="button" onClick={handleGoTO} onKeyUp={handleGoTO}>
{locale.jump_to_confirm}
</button>
);
} else {
gotoButton = (
<span onClick={handleGoTO} onKeyUp={handleGoTO}>
{goButton}
</span>
);
}

gotoButton = (
<li
title={showTitle ? `${locale.jump_to}${current}/${allPages}` : null}
className={`${prefixCls}-simple-pager`}
>
{gotoButton}
</li>
);
Comment on lines +36 to +43

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

The value assigned to gotoButton here is unused.
}

return (
<li
title={showTitle ? `${current}/${allPages}` : null}
className={`${prefixCls}-simple-pager`}
>
{isReadOnly ? (
internalInputVal
) : (
<input
type="text"
value={internalInputVal}
disabled={disabled}
onKeyDown={handleKeyDown}
onKeyUp={handleKeyUp}
onChange={handleKeyUp}
onBlur={handleBlur}
size={3}
/>
)}
<span className={`${prefixCls}-slash`}>/</span>
{allPages}
</li>
);
};

export default Simple;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './Pagination';
export { default } from './components/Pagination';
export type { PaginationLocale, PaginationProps } from './interface';
Loading