Skip to content

Commit f6afd7f

Browse files
authored
refactor:pagination (#6251)
* refactor:pagination * docs:update & refactor: pagination type
1 parent 7de1be6 commit f6afd7f

File tree

7 files changed

+722
-562
lines changed

7 files changed

+722
-562
lines changed

components/pagination/Pagination.tsx

+37-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ExtractPropTypes, PropType } from 'vue';
1+
import type { ExtractPropTypes } from 'vue';
22
import { computed, toRef, defineComponent } from 'vue';
33
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
44
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
@@ -11,50 +11,55 @@ import enUS from '../vc-pagination/locale/en_US';
1111
import classNames from '../_util/classNames';
1212
import useConfigInject from '../config-provider/hooks/useConfigInject';
1313
import useBreakpoint from '../_util/hooks/useBreakpoint';
14+
import { booleanType, arrayType, stringType, functionType, someType } from '../_util/type';
15+
16+
// CSSINJS
17+
import useStyle from './style';
1418

1519
export const paginationProps = () => ({
1620
total: Number,
1721
defaultCurrent: Number,
18-
disabled: { type: Boolean, default: undefined },
22+
disabled: booleanType(),
1923
current: Number,
2024
defaultPageSize: Number,
2125
pageSize: Number,
22-
hideOnSinglePage: { type: Boolean, default: undefined },
23-
showSizeChanger: { type: Boolean, default: undefined },
24-
pageSizeOptions: Array as PropType<(string | number)[]>,
25-
buildOptionText: Function as PropType<(opt: { value: any }) => any>,
26-
showQuickJumper: {
27-
type: [Boolean, Object] as PropType<boolean | { goButton?: any }>,
28-
default: undefined as boolean | { goButton?: any },
29-
},
30-
showTotal: Function as PropType<(total: number, range: [number, number]) => any>,
31-
size: String as PropType<'default' | 'small'>,
32-
simple: { type: Boolean, default: undefined },
26+
hideOnSinglePage: booleanType(),
27+
showSizeChanger: booleanType(),
28+
pageSizeOptions: arrayType<(string | number)[]>(),
29+
buildOptionText: functionType<(opt: { value: any }) => any>(),
30+
showQuickJumper: someType<boolean | { goButton?: any }>(
31+
[Boolean, Object],
32+
undefined as boolean | { goButton?: any },
33+
),
34+
showTotal: functionType<(total: number, range: [number, number]) => any>(),
35+
size: stringType<'default' | 'small'>(),
36+
simple: booleanType(),
3337
locale: Object,
3438
prefixCls: String,
3539
selectPrefixCls: String,
3640
totalBoundaryShowSizeChanger: Number,
3741
selectComponentClass: String,
38-
itemRender: Function as PropType<
39-
(opt: {
40-
page: number;
41-
type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next';
42-
originalElement: any;
43-
}) => any
44-
>,
42+
itemRender:
43+
functionType<
44+
(opt: {
45+
page: number;
46+
type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next';
47+
originalElement: any;
48+
}) => any
49+
>(),
4550
role: String,
4651
responsive: Boolean,
47-
showLessItems: { type: Boolean, default: undefined },
48-
onChange: Function as PropType<(page: number, pageSize: number) => void>,
49-
onShowSizeChange: Function as PropType<(current: number, size: number) => void>,
50-
'onUpdate:current': Function as PropType<(current: number) => void>,
51-
'onUpdate:pageSize': Function as PropType<(size: number) => void>,
52+
showLessItems: booleanType(),
53+
onChange: functionType<(page: number, pageSize: number) => void>(),
54+
onShowSizeChange: functionType<(current: number, size: number) => void>(),
55+
'onUpdate:current': functionType<(current: number) => void>(),
56+
'onUpdate:pageSize': functionType<(size: number) => void>(),
5257
});
5358

5459
export type PaginationPosition = 'top' | 'bottom' | 'both';
5560
export const paginationConfig = () => ({
5661
...paginationProps(),
57-
position: String as PropType<PaginationPosition>,
62+
position: stringType<PaginationPosition>(),
5863
});
5964

6065
export type PaginationProps = Partial<ExtractPropTypes<ReturnType<typeof paginationProps>>>;
@@ -81,6 +86,10 @@ export default defineComponent({
8186
// emits: ['change', 'showSizeChange', 'update:current', 'update:pageSize'],
8287
setup(props, { slots, attrs }) {
8388
const { prefixCls, configProvider, direction } = useConfigInject('pagination', props);
89+
90+
// style
91+
const [wrapSSR, hashId] = useStyle(prefixCls);
92+
8493
const selectPrefixCls = computed(() =>
8594
configProvider.getPrefixCls('select', props.selectPrefixCls),
8695
);
@@ -152,11 +161,12 @@ export default defineComponent({
152161
class: classNames(
153162
{ mini: isSmall, [`${prefixCls.value}-rtl`]: direction.value === 'rtl' },
154163
attrs.class,
164+
hashId.value,
155165
),
156166
itemRender,
157167
};
158168

159-
return <VcPagination {...paginationProps} />;
169+
return wrapSSR(<VcPagination {...paginationProps} />);
160170
};
161171
},
162172
});

components/pagination/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
type: Navigation
44
title: Pagination
55
cols: 1
6-
cover: https://gw.alipayobjects.com/zos/alicdn/1vqv2bj68/Pagination.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*8y_iTJGY_aUAAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
A long list can be divided into several pages using `Pagination`, and only one page will be loaded at a time.

components/pagination/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ subtitle: 分页
44
type: 导航
55
title: Pagination
66
cols: 1
7-
cover: https://gw.alipayobjects.com/zos/alicdn/1vqv2bj68/Pagination.svg
7+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*8y_iTJGY_aUAAAAAAAAAAAAADrJ8AQ/original
88
---
99

1010
采用分页的形式分隔长列表,每次只加载一个页面。

0 commit comments

Comments
 (0)