Skip to content

Commit

Permalink
fix: πŸ› replace defaultProps with useDefaultProps (#2376)
Browse files Browse the repository at this point in the history
* fix: πŸ› πŸ› replace defaultProps with useDefaultProps

* fix: πŸ› fix
  • Loading branch information
li-jia-nan authored Jul 26, 2023
1 parent ced837e commit 8890e87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import { TdPaginationProps } from './type';
import { StyledProps } from '../common';
import { pageSizeValidator } from './validators';
import { paginationDefaultProps } from './defaultProps';
import useDefaultProps from '../hooks/useDefaultProps';

export type { PageInfo } from './type';

export interface PaginationProps extends TdPaginationProps, StyledProps {}

const { Option } = Select;

const Pagination = forwardRef((props: PaginationProps, ref: React.Ref<HTMLDivElement>) => {
const Pagination = forwardRef<HTMLDivElement, PaginationProps>((originalProps, ref) => {
const props = useDefaultProps<PaginationProps>(originalProps, paginationDefaultProps);
const {
theme,
size,
Expand Down Expand Up @@ -69,7 +71,9 @@ const Pagination = forwardRef((props: PaginationProps, ref: React.Ref<HTMLDivEle

// ε€„η†ζ”Ήε˜ε½“ε‰ι‘΅ηš„ι€»θΎ‘
const changeCurrent = (_nextCurrent: number, _nextPageSize?: number) => {
if (disabled || current === _nextCurrent) return;
if (disabled || current === _nextCurrent) {
return;
}

let nextCurrent = _nextCurrent;
let nextPageSize = _nextPageSize;
Expand Down Expand Up @@ -219,6 +223,5 @@ const Pagination = forwardRef((props: PaginationProps, ref: React.Ref<HTMLDivEle
});

Pagination.displayName = 'Pagination';
Pagination.defaultProps = paginationDefaultProps;

export default Pagination;
32 changes: 25 additions & 7 deletions src/pagination/PaginationMini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { StyledProps } from '../common';
import type { TdPaginationMiniProps } from './type';
import { paginationMiniDefaultProps } from './defaultProps';
import noop from '../_util/noop';
import useDefaultProps from '../hooks/useDefaultProps';

export interface PaginationMiniProps extends TdPaginationMiniProps, StyledProps {}

const PaginationMini = forwardRef((props: PaginationMiniProps, ref: React.Ref<HTMLDivElement>) => {
const PaginationMini = forwardRef<HTMLDivElement, PaginationMiniProps>((props, ref) => {
const { classPrefix } = useConfig();
const { RoundIcon, ChevronUpIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } = useGlobalIcon({
RoundIcon: TdRoundIcon,
Expand All @@ -28,17 +29,35 @@ const PaginationMini = forwardRef((props: PaginationMiniProps, ref: React.Ref<HT
ChevronRightIcon: TdChevronRightIcon,
});

const { variant, tips, showCurrent, disabled, layout, size, onChange = noop, className, style } = props;
const {
variant,
tips,
showCurrent,
disabled,
layout,
size,
onChange = noop,
className,
style,
} = useDefaultProps<PaginationMiniProps>(props, paginationMiniDefaultProps);

const titleConfig = useMemo(() => {
if (isObject(tips)) return tips;
if (tips === true) return { prev: 'δΈŠδΈ€ι‘΅', current: '当前', next: 'δΈ‹δΈ€ι‘΅' };
if (isObject(tips)) {
return tips;
}
if (tips === true) {
return { prev: 'δΈŠδΈ€ι‘΅', current: '当前', next: 'δΈ‹δΈ€ι‘΅' };
}
return {};
}, [tips]);

const disabledConfig = useMemo(() => {
if (isObject(disabled)) return disabled;
if (disabled === true) return { prev: true, current: true, next: true };
if (isObject(disabled)) {
return disabled;
}
if (disabled === true) {
return { prev: true, current: true, next: true };
}
return { prev: false, current: false, next: false };
}, [disabled]);

Expand Down Expand Up @@ -89,6 +108,5 @@ const PaginationMini = forwardRef((props: PaginationMiniProps, ref: React.Ref<HT
});

PaginationMini.displayName = 'PaginationMini';
PaginationMini.defaultProps = paginationMiniDefaultProps;

export default PaginationMini;

0 comments on commit 8890e87

Please sign in to comment.