forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPagination.tsx
168 lines (157 loc) · 5.73 KB
/
Pagination.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import type { ExtractPropTypes } from 'vue';
import { computed, toRef, defineComponent } from 'vue';
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
import DoubleLeftOutlined from '@ant-design/icons-vue/DoubleLeftOutlined';
import DoubleRightOutlined from '@ant-design/icons-vue/DoubleRightOutlined';
import MiniSelect, { MiddleSelect } from './Select';
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
import VcPagination from '../vc-pagination';
import enUS from '../vc-pagination/locale/en_US';
import classNames from '../_util/classNames';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import useBreakpoint from '../_util/hooks/useBreakpoint';
import { booleanType, arrayType, stringType, functionType, someType } from '../_util/type';
// CSSINJS
import useStyle from './style';
export const paginationProps = () => ({
total: Number,
defaultCurrent: Number,
disabled: booleanType(),
current: Number,
defaultPageSize: Number,
pageSize: Number,
hideOnSinglePage: booleanType(),
showSizeChanger: booleanType(),
pageSizeOptions: arrayType<(string | number)[]>(),
buildOptionText: functionType<(opt: { value: any }) => any>(),
showQuickJumper: someType<boolean | { goButton?: any }>([Boolean, Object]),
showTotal: functionType<(total: number, range: [number, number]) => any>(),
size: stringType<'default' | 'small'>(),
simple: booleanType(),
locale: Object,
prefixCls: String,
selectPrefixCls: String,
totalBoundaryShowSizeChanger: Number,
selectComponentClass: String,
itemRender:
functionType<
(opt: {
page: number;
type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next';
originalElement: any;
}) => any
>(),
role: String,
responsive: Boolean,
showLessItems: booleanType(),
onChange: functionType<(page: number, pageSize: number) => void>(),
onShowSizeChange: functionType<(current: number, size: number) => void>(),
'onUpdate:current': functionType<(current: number) => void>(),
'onUpdate:pageSize': functionType<(size: number) => void>(),
});
export type PaginationPosition = 'top' | 'bottom' | 'both';
export const paginationConfig = () => ({
...paginationProps(),
position: stringType<PaginationPosition>(),
});
export type PaginationProps = Partial<ExtractPropTypes<ReturnType<typeof paginationProps>>>;
export type PaginationConfig = Partial<ExtractPropTypes<ReturnType<typeof paginationConfig>>>;
export interface PaginationLocale {
items_per_page?: string;
jump_to?: string;
jump_to_confirm?: string;
page?: string;
prev_page?: string;
next_page?: string;
prev_5?: string;
next_5?: string;
prev_3?: string;
next_3?: string;
}
export default defineComponent({
compatConfig: { MODE: 3 },
name: 'APagination',
inheritAttrs: false,
props: paginationProps(),
// emits: ['change', 'showSizeChange', 'update:current', 'update:pageSize'],
setup(props, { slots, attrs }) {
const { prefixCls, configProvider, direction, size } = useConfigInject('pagination', props);
// style
const [wrapSSR, hashId] = useStyle(prefixCls);
const selectPrefixCls = computed(() =>
configProvider.getPrefixCls('select', props.selectPrefixCls),
);
const breakpoint = useBreakpoint();
const [locale] = useLocaleReceiver('Pagination', enUS, toRef(props, 'locale'));
const getIconsProps = (pre: string) => {
const ellipsis = <span class={`${pre}-item-ellipsis`}>•••</span>;
const prevIcon = (
<button class={`${pre}-item-link`} type="button" tabindex={-1}>
{direction.value === 'rtl' ? <RightOutlined /> : <LeftOutlined />}
</button>
);
const nextIcon = (
<button class={`${pre}-item-link`} type="button" tabindex={-1}>
{direction.value === 'rtl' ? <LeftOutlined /> : <RightOutlined />}
</button>
);
const jumpPrevIcon = (
<a rel="nofollow" class={`${pre}-item-link`}>
<div class={`${pre}-item-container`}>
{direction.value === 'rtl' ? (
<DoubleRightOutlined class={`${pre}-item-link-icon`} />
) : (
<DoubleLeftOutlined class={`${pre}-item-link-icon`} />
)}
{ellipsis}
</div>
</a>
);
const jumpNextIcon = (
<a rel="nofollow" class={`${pre}-item-link`}>
<div class={`${pre}-item-container`}>
{direction.value === 'rtl' ? (
<DoubleLeftOutlined class={`${pre}-item-link-icon`} />
) : (
<DoubleRightOutlined class={`${pre}-item-link-icon`} />
)}
{ellipsis}
</div>
</a>
);
return { prevIcon, nextIcon, jumpPrevIcon, jumpNextIcon };
};
return () => {
const {
itemRender = slots.itemRender,
buildOptionText = slots.buildOptionText,
selectComponentClass,
responsive,
...restProps
} = props;
const isSmall =
size.value === 'small' || !!(breakpoint.value?.xs && !size.value && responsive);
const paginationProps = {
...restProps,
...getIconsProps(prefixCls.value),
prefixCls: prefixCls.value,
selectPrefixCls: selectPrefixCls.value,
selectComponentClass: selectComponentClass || (isSmall ? MiniSelect : MiddleSelect),
locale: locale.value,
buildOptionText,
...attrs,
class: classNames(
{
[`${prefixCls.value}-mini`]: isSmall,
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
},
attrs.class,
hashId.value,
),
itemRender,
};
return wrapSSR(<VcPagination {...paginationProps} />);
};
},
});