@v-c/pagination 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Pager.d.ts +2 -0
- package/dist/Pager.js +16 -3
- package/dist/Pagination.js +39 -22
- package/dist/index.d.ts +1 -1
- package/dist/interface.d.ts +4 -1
- package/dist/isEnterOrSpaceKey.d.ts +7 -0
- package/dist/isEnterOrSpaceKey.js +7 -0
- package/package.json +8 -2
package/dist/Pager.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { PaginationProps } from './interface';
|
|
|
3
3
|
export interface PagerProps extends Pick<PaginationProps, 'itemRender'> {
|
|
4
4
|
rootPrefixCls: string;
|
|
5
5
|
page: number;
|
|
6
|
+
/** Localized word for "page", prefixed to the number in the accessible name. */
|
|
7
|
+
pageLabel?: string;
|
|
6
8
|
active?: boolean;
|
|
7
9
|
className?: string;
|
|
8
10
|
style?: CSSProperties;
|
package/dist/Pager.js
CHANGED
|
@@ -9,20 +9,28 @@ var Pager = /* @__PURE__ */ defineComponent((props) => {
|
|
|
9
9
|
props.onKeyPress?.(e, props.onClick, props.page);
|
|
10
10
|
};
|
|
11
11
|
return () => {
|
|
12
|
-
const { rootPrefixCls, page, active, className, showTitle, itemRender, style } = props;
|
|
12
|
+
const { rootPrefixCls, page, pageLabel, active, className, showTitle, itemRender, style } = props;
|
|
13
13
|
const prefixCls = `${rootPrefixCls}-item`;
|
|
14
14
|
const cls = classNames(prefixCls, `${prefixCls}-${page}`, {
|
|
15
15
|
[`${prefixCls}-active`]: active,
|
|
16
16
|
[`${prefixCls}-disabled`]: !page
|
|
17
17
|
}, className);
|
|
18
|
-
const pager = itemRender?.(page, "page", createVNode("a", {
|
|
18
|
+
const pager = itemRender?.(page, "page", createVNode("a", {
|
|
19
|
+
"tabindex": -1,
|
|
20
|
+
"aria-hidden": "true",
|
|
21
|
+
"rel": "nofollow"
|
|
22
|
+
}, [page]));
|
|
23
|
+
const pagerLabel = `${pageLabel ?? ""} ${page}`.trim();
|
|
19
24
|
return pager ? createVNode("li", {
|
|
20
25
|
"title": showTitle ? String(page) : void 0,
|
|
21
26
|
"class": cls,
|
|
22
27
|
"style": style,
|
|
23
28
|
"onClick": handleClick,
|
|
24
29
|
"onKeydown": handleKeyPress,
|
|
25
|
-
"tabindex": 0
|
|
30
|
+
"tabindex": 0,
|
|
31
|
+
"role": "button",
|
|
32
|
+
"aria-label": pagerLabel,
|
|
33
|
+
"aria-current": active ? "page" : void 0
|
|
26
34
|
}, [pager]) : null;
|
|
27
35
|
};
|
|
28
36
|
}, { props: {
|
|
@@ -34,6 +42,11 @@ var Pager = /* @__PURE__ */ defineComponent((props) => {
|
|
|
34
42
|
type: Number,
|
|
35
43
|
required: true
|
|
36
44
|
},
|
|
45
|
+
pageLabel: {
|
|
46
|
+
type: String,
|
|
47
|
+
required: false,
|
|
48
|
+
default: void 0
|
|
49
|
+
},
|
|
37
50
|
active: {
|
|
38
51
|
type: Boolean,
|
|
39
52
|
required: false,
|
package/dist/Pagination.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Options from "./Options.js";
|
|
2
2
|
import Pager from "./Pager.js";
|
|
3
|
+
import isEnterOrSpaceKey from "./isEnterOrSpaceKey.js";
|
|
3
4
|
import locale from "./locale/zh_CN.js";
|
|
4
5
|
import { computed, createTextVNode, createVNode, defineComponent, h, isVNode, mergeProps, ref, toRef, watchEffect } from "vue";
|
|
5
6
|
import KeyCode from "@v-c/util/dist/KeyCode";
|
|
@@ -71,11 +72,13 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
71
72
|
function isValid(page) {
|
|
72
73
|
return isInteger(page) && page !== current.value && isInteger(mergedTotal.value) && mergedTotal.value > 0;
|
|
73
74
|
}
|
|
74
|
-
function getItemIcon(icon,
|
|
75
|
+
function getItemIcon(icon, _label, title) {
|
|
75
76
|
const prefixCls = mergedPrefixCls.value;
|
|
76
77
|
let iconNode = icon || createVNode("button", {
|
|
77
78
|
"type": "button",
|
|
78
|
-
"
|
|
79
|
+
"tabindex": -1,
|
|
80
|
+
"aria-hidden": "true",
|
|
81
|
+
"title": title,
|
|
79
82
|
"class": `${prefixCls}-item-link`
|
|
80
83
|
}, null);
|
|
81
84
|
if (typeof icon === "function") iconNode = h(icon, { ...props });
|
|
@@ -113,29 +116,36 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
113
116
|
function jumpNextHandle() {
|
|
114
117
|
handleChange(jumpNextPage.value);
|
|
115
118
|
}
|
|
116
|
-
function
|
|
117
|
-
if (event
|
|
119
|
+
function runIfEnterOrSpace(event, callback, ...restParams) {
|
|
120
|
+
if (isEnterOrSpaceKey(event)) {
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
callback(...restParams);
|
|
123
|
+
}
|
|
118
124
|
}
|
|
119
125
|
function runIfEnterPrev(event) {
|
|
120
|
-
|
|
126
|
+
runIfEnterOrSpace(event, prevHandle);
|
|
121
127
|
}
|
|
122
128
|
function runIfEnterNext(event) {
|
|
123
|
-
|
|
129
|
+
runIfEnterOrSpace(event, nextHandle);
|
|
124
130
|
}
|
|
125
131
|
function runIfEnterJumpPrev(event) {
|
|
126
|
-
|
|
132
|
+
runIfEnterOrSpace(event, jumpPrevHandle);
|
|
127
133
|
}
|
|
128
134
|
function runIfEnterJumpNext(event) {
|
|
129
|
-
|
|
135
|
+
runIfEnterOrSpace(event, jumpNextHandle);
|
|
130
136
|
}
|
|
131
137
|
function renderPrev(prevPage) {
|
|
132
|
-
const
|
|
138
|
+
const itemRender = props.itemRender || defaultItemRender;
|
|
139
|
+
const prevPageTitle = mergedLocale.value.prev_page || "prev page";
|
|
140
|
+
const prevButton = itemRender?.(prevPage, "prev", getItemIcon(props.prevIcon, prevPageTitle, mergedShowTitle.value ? prevPageTitle : void 0));
|
|
133
141
|
const nextProps = {};
|
|
134
142
|
if (!hasPrev.value) nextProps.disabled = true;
|
|
135
143
|
return isVNode(prevButton) ? cloneElement(prevButton, nextProps) : prevButton;
|
|
136
144
|
}
|
|
137
145
|
function renderNext(nextPage) {
|
|
138
|
-
const
|
|
146
|
+
const itemRender = props.itemRender || defaultItemRender;
|
|
147
|
+
const nextPageTitle = mergedLocale.value.next_page || "next page";
|
|
148
|
+
const nextButton = itemRender?.(nextPage, "next", getItemIcon(props.nextIcon, nextPageTitle, mergedShowTitle.value ? nextPageTitle : void 0));
|
|
139
149
|
const nextProps = {};
|
|
140
150
|
if (!hasNext.value) nextProps.disabled = true;
|
|
141
151
|
return isVNode(nextButton) ? cloneElement(nextButton, nextProps) : nextButton;
|
|
@@ -170,13 +180,15 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
170
180
|
handleChange(getValidValue(event));
|
|
171
181
|
}
|
|
172
182
|
function changePageSize(size) {
|
|
183
|
+
const preservedPage = Math.floor((current.value - 1) * pageSize.value / size) + 1;
|
|
173
184
|
const newCurrent = calculatePage(size, pageSize.value, mergedTotal.value);
|
|
185
|
+
const recommendPage = newCurrent === 0 ? 1 : Math.min(preservedPage, newCurrent);
|
|
174
186
|
const nextCurrent = current.value > newCurrent && newCurrent !== 0 ? newCurrent : current.value;
|
|
175
187
|
setPageSize(size);
|
|
176
188
|
internalInputVal.value = nextCurrent;
|
|
177
189
|
props.onShowSizeChange?.(current.value, size);
|
|
178
190
|
setCurrent(nextCurrent);
|
|
179
|
-
props.onChange?.(nextCurrent, size);
|
|
191
|
+
props.onChange?.(nextCurrent, size, { recommendPage });
|
|
180
192
|
}
|
|
181
193
|
const shouldDisplayQuickJumper = computed(() => mergedTotal.value > pageSize.value ? props.showQuickJumper : false);
|
|
182
194
|
return () => {
|
|
@@ -205,13 +217,14 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
205
217
|
return prev;
|
|
206
218
|
})();
|
|
207
219
|
prev = createVNode("li", {
|
|
208
|
-
"title": showTitle ? locale?.prev_page : void 0,
|
|
209
220
|
"onClick": prevHandle,
|
|
210
221
|
"tabindex": prevDisabled ? void 0 : 0,
|
|
211
222
|
"onKeydown": runIfEnterPrev,
|
|
212
223
|
"class": classNames(`${prefixCls}-prev`, itemClassName, { [`${prefixCls}-disabled`]: prevDisabled }),
|
|
213
224
|
"style": itemStyle,
|
|
214
|
-
"aria-disabled": prevDisabled
|
|
225
|
+
"aria-disabled": prevDisabled,
|
|
226
|
+
"role": "button",
|
|
227
|
+
"aria-label": locale?.prev_page
|
|
215
228
|
}, [prev]);
|
|
216
229
|
}
|
|
217
230
|
let next = renderNext(nextPage.value);
|
|
@@ -228,13 +241,14 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
228
241
|
return next;
|
|
229
242
|
})();
|
|
230
243
|
next = createVNode("li", {
|
|
231
|
-
"title": showTitle ? locale?.next_page : void 0,
|
|
232
244
|
"onClick": nextHandle,
|
|
233
245
|
"tabindex": nextTabIndex ?? void 0,
|
|
234
246
|
"onKeydown": runIfEnterNext,
|
|
235
247
|
"class": classNames(`${prefixCls}-next`, itemClassName, { [`${prefixCls}-disabled`]: nextDisabled }),
|
|
236
248
|
"style": itemStyle,
|
|
237
|
-
"aria-disabled": nextDisabled
|
|
249
|
+
"aria-disabled": nextDisabled,
|
|
250
|
+
"role": "button",
|
|
251
|
+
"aria-label": locale?.next_page
|
|
238
252
|
}, [next]);
|
|
239
253
|
}
|
|
240
254
|
const totalText = showTotal && createVNode("li", { "class": `${prefixCls}-total-text` }, [showTotal(total, [total === 0 ? 0 : (current.value - 1) * pageSize.value + 1, current.value * pageSize.value > total ? total : current.value * pageSize.value])]);
|
|
@@ -283,9 +297,10 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
283
297
|
const pagerProps = {
|
|
284
298
|
rootPrefixCls: prefixCls,
|
|
285
299
|
onClick: handleChange,
|
|
286
|
-
onKeyPress:
|
|
300
|
+
onKeyPress: runIfEnterOrSpace,
|
|
287
301
|
showTitle,
|
|
288
302
|
itemRender: mergedItemRender,
|
|
303
|
+
pageLabel: locale?.page,
|
|
289
304
|
page: -1,
|
|
290
305
|
className: itemClassName,
|
|
291
306
|
style: itemStyle
|
|
@@ -306,26 +321,28 @@ var Pagination = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
306
321
|
} else {
|
|
307
322
|
const prevItemTitle = showLessItems ? locale?.prev_3 : locale?.prev_5;
|
|
308
323
|
const nextItemTitle = showLessItems ? locale?.next_3 : locale?.next_5;
|
|
309
|
-
const jumpPrevContent = mergedItemRender(jumpPrevPage.value, "jump-prev", getItemIcon(jumpPrevIcon,
|
|
310
|
-
const jumpNextContent = mergedItemRender(jumpNextPage.value, "jump-next", getItemIcon(jumpNextIcon,
|
|
324
|
+
const jumpPrevContent = mergedItemRender(jumpPrevPage.value, "jump-prev", getItemIcon(jumpPrevIcon, prevItemTitle, showTitle ? prevItemTitle : void 0));
|
|
325
|
+
const jumpNextContent = mergedItemRender(jumpNextPage.value, "jump-next", getItemIcon(jumpNextIcon, nextItemTitle, showTitle ? nextItemTitle : void 0));
|
|
311
326
|
let jumpPrev = null;
|
|
312
327
|
let jumpNext = null;
|
|
313
328
|
if (showPrevNextJumpers) {
|
|
314
329
|
jumpPrev = jumpPrevContent ? createVNode("li", {
|
|
315
|
-
"title": showTitle ? prevItemTitle : void 0,
|
|
316
330
|
"key": "prev",
|
|
317
331
|
"onClick": jumpPrevHandle,
|
|
318
332
|
"tabindex": 0,
|
|
319
333
|
"onKeydown": runIfEnterJumpPrev,
|
|
320
|
-
"class": classNames(`${prefixCls}-jump-prev`, { [`${prefixCls}-jump-prev-custom-icon`]: !!jumpPrevIcon })
|
|
334
|
+
"class": classNames(`${prefixCls}-jump-prev`, { [`${prefixCls}-jump-prev-custom-icon`]: !!jumpPrevIcon }),
|
|
335
|
+
"role": "button",
|
|
336
|
+
"aria-label": prevItemTitle
|
|
321
337
|
}, [jumpPrevContent]) : null;
|
|
322
338
|
jumpNext = jumpNextContent ? createVNode("li", {
|
|
323
|
-
"title": showTitle ? nextItemTitle : void 0,
|
|
324
339
|
"key": "next",
|
|
325
340
|
"onClick": jumpNextHandle,
|
|
326
341
|
"tabindex": 0,
|
|
327
342
|
"onKeydown": runIfEnterJumpNext,
|
|
328
|
-
"class": classNames(`${prefixCls}-jump-next`, { [`${prefixCls}-jump-next-custom-icon`]: !!jumpNextIcon })
|
|
343
|
+
"class": classNames(`${prefixCls}-jump-next`, { [`${prefixCls}-jump-next-custom-icon`]: !!jumpNextIcon }),
|
|
344
|
+
"role": "button",
|
|
345
|
+
"aria-label": nextItemTitle
|
|
329
346
|
}, [jumpNextContent]) : null;
|
|
330
347
|
}
|
|
331
348
|
let left = Math.max(1, current.value - pageBufferSize);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { PaginationData, PaginationLocale, PaginationProps } from './interface';
|
|
1
|
+
export type { PaginationData, PaginationLocale, PaginationOnChangeInfo, PaginationProps } from './interface';
|
|
2
2
|
export { default } from './Pagination';
|
package/dist/interface.d.ts
CHANGED
|
@@ -45,8 +45,11 @@ export interface PaginationData {
|
|
|
45
45
|
jumpPrevIcon: VueNode;
|
|
46
46
|
jumpNextIcon: VueNode;
|
|
47
47
|
}
|
|
48
|
+
export interface PaginationOnChangeInfo {
|
|
49
|
+
recommendPage?: number;
|
|
50
|
+
}
|
|
48
51
|
export interface PaginationProps extends Partial<PaginationData> {
|
|
49
|
-
onChange?: (page: number, pageSize: number) => void;
|
|
52
|
+
onChange?: (page: number, pageSize: number, info?: PaginationOnChangeInfo) => void;
|
|
50
53
|
onShowSizeChange?: (current: number, size: number) => void;
|
|
51
54
|
itemRender?: (page: number, type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next', element: VueNode) => VueNode;
|
|
52
55
|
showTotal?: (total: number, range: [number, number]) => VueNode;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import KeyCode from "@v-c/util/dist/KeyCode";
|
|
2
|
+
//#region src/isEnterOrSpaceKey.ts
|
|
3
|
+
function isEnterOrSpaceKey(event) {
|
|
4
|
+
return event.key === "Enter" || event.key === " " || event.key === "Spacebar" || event.charCode === KeyCode.ENTER || event.keyCode === KeyCode.ENTER;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isEnterOrSpaceKey as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/pagination",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/antdv-next/vue-components/tree/next/packages/pagination",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/antdv-next/vue-components.git"
|
|
10
|
+
},
|
|
5
11
|
"exports": {
|
|
6
12
|
".": {
|
|
7
13
|
"types": "./dist/index.d.ts",
|
|
@@ -43,7 +49,7 @@
|
|
|
43
49
|
"vue": "^3.0.0"
|
|
44
50
|
},
|
|
45
51
|
"dependencies": {
|
|
46
|
-
"@v-c/util": "^1.0
|
|
52
|
+
"@v-c/util": "^1.1.0"
|
|
47
53
|
},
|
|
48
54
|
"scripts": {
|
|
49
55
|
"build": "vite build",
|