From a7b51742bb8253e6cf3e7dc0ac2cc026575bcc11 Mon Sep 17 00:00:00 2001 From: bqxbqx <132878537+BQXBQX@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:58:34 +0800 Subject: [PATCH] fix(pagination): fix update bug * fix(pagination): fix update bug --- .../lib/Checkbox/Checkbox.stories.tsx | 5 ++ .../ui-react/lib/Pagination/Pagination.tsx | 84 ++++++++++++------- .../lib/Pagination/PaginationItem.tsx | 4 +- packages/ui-react/package.json | 2 +- 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/packages/ui-react/lib/Checkbox/Checkbox.stories.tsx b/packages/ui-react/lib/Checkbox/Checkbox.stories.tsx index 51f6661..a9c49f6 100644 --- a/packages/ui-react/lib/Checkbox/Checkbox.stories.tsx +++ b/packages/ui-react/lib/Checkbox/Checkbox.stories.tsx @@ -3,6 +3,10 @@ import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; import { Checkbox, type CheckboxProps } from './Checkbox'; +const test = (value) => { + console.log(value); +}; + const meta = { title: 'Components/Checkbox', component: Checkbox, @@ -20,6 +24,7 @@ type Story = StoryObj; const defaultProps: CheckboxProps = { label: 'SAST', disabled: false, + onChecked: test, }; export const DefaultCheckbox: Story = { diff --git a/packages/ui-react/lib/Pagination/Pagination.tsx b/packages/ui-react/lib/Pagination/Pagination.tsx index 807a106..645cf5a 100644 --- a/packages/ui-react/lib/Pagination/Pagination.tsx +++ b/packages/ui-react/lib/Pagination/Pagination.tsx @@ -66,11 +66,8 @@ export const Pagination = React.forwardRef( useEffect(() => { onChange(currentPage); - }, [currentPage, onChange]); - - useEffect(() => { - if (activePage) changeCurrentPage(activePage); - }, [activePage, changeCurrentPage]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [currentPage]); useEffect(() => { const newItems: ReactNode[] = []; @@ -83,6 +80,7 @@ export const Pagination = React.forwardRef( key={i} index={i} disabled={disabled} + activePage={activePage} > {i + 1} , @@ -95,15 +93,20 @@ export const Pagination = React.forwardRef( newItems.push( {i + 1} , ); } newItems.push( - + ... , ); @@ -112,7 +115,9 @@ export const Pagination = React.forwardRef( {i + 1} , @@ -126,14 +131,19 @@ export const Pagination = React.forwardRef( {i + 1} , ); } newItems.push( - + ... , ); @@ -142,7 +152,9 @@ export const Pagination = React.forwardRef( {i + 1} , @@ -155,13 +167,18 @@ export const Pagination = React.forwardRef( {1} , ); newItems.push( - + ... , ); @@ -170,14 +187,19 @@ export const Pagination = React.forwardRef( {i + 1} , ); } newItems.push( - + ... , ); @@ -186,6 +208,8 @@ export const Pagination = React.forwardRef( type="select" index={pageNumber - 1} disabled={disabled} + key={pageNumber - 1} + activePage={activePage} > {pageNumber} , @@ -193,32 +217,32 @@ export const Pagination = React.forwardRef( } } setItemList(newItems); - }, [pageNumber, currentPage, disabled]); + }, [pageNumber, currentPage, disabled, activePage]); const PaginationClass = classNames(`${styles['base']} ${styles[disabled ? 'disabled' : '']}`); return ( - <> -
+ + + + {itemList} + - - - - {itemList} - - - -
- + +
+ ); }, ); diff --git a/packages/ui-react/lib/Pagination/PaginationItem.tsx b/packages/ui-react/lib/Pagination/PaginationItem.tsx index 3890a5f..b65a55f 100644 --- a/packages/ui-react/lib/Pagination/PaginationItem.tsx +++ b/packages/ui-react/lib/Pagination/PaginationItem.tsx @@ -8,6 +8,7 @@ export interface PaginationItemProps { disabled?: boolean; type: 'select' | 'add' | 'delete' | 'none'; index?: number; + activePage?: number; } export const PaginationItem = ({ @@ -15,6 +16,7 @@ export const PaginationItem = ({ disabled = false, index, type, + activePage, }: PaginationItemProps) => { const [currentPage, increaseCurrentPage, decreaseCurrentPage, changeCurrentPage] = useCurrentPageStore((state) => [ @@ -33,7 +35,7 @@ export const PaginationItem = ({ return (