Skip to content

chore: use rc-component/util #635

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

Merged
merged 7 commits into from
Feb 7, 2025
Merged
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
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-pagination",
"version": "5.1.0",
"name": "@rc-component/pagination",
"version": "1.0.0",
"description": "pagination ui component for react",
"keywords": [
"react",
Expand Down Expand Up @@ -43,17 +43,17 @@
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"classnames": "^2.3.2",
"rc-util": "^5.38.0"
"@rc-component/util": "^1.2.0",
"classnames": "^2.3.2"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.2.2",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@umijs/fabric": "^4.0.1",
"coveralls": "^3.0.6",
"cross-env": "^7.0.0",
Expand All @@ -72,8 +72,8 @@
"prettier": "^3.1.0",
"rc-select": "^14.16.4",
"rc-test": "^7.0.15",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"peerDependencies": {
"react": ">=16.9.0",
Expand Down
14 changes: 7 additions & 7 deletions src/Options.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import KEYCODE from 'rc-util/lib/KeyCode';
import KEYCODE from '@rc-component/util/lib/KeyCode';
import React from 'react';
import type { PaginationLocale } from './interface';

Expand Down Expand Up @@ -48,11 +48,11 @@ const Options: React.FC<OptionsProps> = (props) => {

const [goInputText, setGoInputText] = React.useState('');

const getValidValue = () => {
const getValidValue = React.useMemo<number>(() => {
return !goInputText || Number.isNaN(goInputText)
? undefined
: Number(goInputText);
};
}, [goInputText]);

const mergeBuildOptionText =
typeof buildOptionText === 'function'
Expand All @@ -70,12 +70,12 @@ const Options: React.FC<OptionsProps> = (props) => {
setGoInputText('');
if (
e.relatedTarget &&
(e.relatedTarget.className.indexOf(`${rootPrefixCls}-item-link`) >= 0 ||
e.relatedTarget.className.indexOf(`${rootPrefixCls}-item`) >= 0)
(e.relatedTarget.className.includes(`${rootPrefixCls}-item-link`) ||
e.relatedTarget.className.includes(`${rootPrefixCls}-item`))
) {
return;
}
quickGo?.(getValidValue());
quickGo?.(getValidValue);
};

const go = (e: any) => {
Expand All @@ -84,7 +84,7 @@ const Options: React.FC<OptionsProps> = (props) => {
}
if (e.keyCode === KEYCODE.ENTER || e.type === 'click') {
setGoInputText('');
quickGo?.(getValidValue());
quickGo?.(getValidValue);
}
};

Expand Down
23 changes: 10 additions & 13 deletions src/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import KeyCode from 'rc-util/lib/KeyCode';
import pickAttrs from 'rc-util/lib/pickAttrs';
import warning from 'rc-util/lib/warning';
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
import KeyCode from '@rc-component/util/lib/KeyCode';
import pickAttrs from '@rc-component/util/lib/pickAttrs';
import warning from '@rc-component/util/lib/warning';
import React, { useEffect } from 'react';
import type { PaginationProps } from './interface';
import zhCN from './locale/zh_CN';
import Options from './Options';
import type { PagerProps } from './Pager';
import Pager from './Pager';

const defaultItemRender: PaginationProps['itemRender'] = (
page,
type,
element,
) => element;
const defaultItemRender: PaginationProps['itemRender'] = (_, __, element) =>
element;

function noop() {}

Expand Down Expand Up @@ -244,8 +241,8 @@ const Pagination: React.FC<PaginationProps> = (props) => {

function runIfEnter(
event: React.KeyboardEvent<HTMLLIElement>,
callback,
...restParams
callback: (...args: any[]) => void,
...restParams: any[]
) {
if (
event.key === 'Enter' ||
Expand Down Expand Up @@ -300,7 +297,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
}
}

let jumpPrev: React.ReactElement = null;
let jumpPrev: React.ReactElement<PagerProps> = null;

const dataOrAriaAttributeProps = pickAttrs(props, {
aria: true,
Expand All @@ -316,7 +313,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
</li>
);

let jumpNext: React.ReactElement = null;
let jumpNext: React.ReactElement<PagerProps> = null;

const allPages = calculatePage(undefined, pageSize, total);

Expand Down
3 changes: 1 addition & 2 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { RenderResult } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import Select from 'rc-select';
import React from 'react';
import Pagination from '../src';
import { resetWarned } from 'rc-util/lib/warning';
import { resetWarned } from '@rc-component/util/lib/warning';
import { sizeChangerRender } from './commonUtil';

describe('Default Pagination', () => {
Expand Down
Loading