@ebay/ui-core-react 3.7.0 → 3.8.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/ebay-pagination/const.d.ts +3 -0
- package/ebay-pagination/const.d.ts.map +1 -1
- package/ebay-pagination/const.js +4 -1
- package/ebay-pagination/helpers.d.ts +1 -1
- package/ebay-pagination/helpers.d.ts.map +1 -1
- package/ebay-pagination/helpers.js +37 -9
- package/ebay-pagination/pagination.d.ts.map +1 -1
- package/ebay-pagination/pagination.js +46 -5
- package/ebay-pagination/types.d.ts +1 -1
- package/ebay-pagination/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,IAAI,CAAA;AAC1B,eAAO,MAAM,SAAS,IAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,IAAI,CAAA;AAC1B,eAAO,MAAM,SAAS,IAAI,CAAA;AAC1B,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAClC,eAAO,MAAM,sBAAsB,IAAI,CAAA;AACvC,eAAO,MAAM,uBAAuB,QAAqC,CAAA"}
|
package/ebay-pagination/const.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_PAGES = exports.MIN_PAGES = void 0;
|
|
3
|
+
exports.TRAILING_SPACE_WITH_DOT = exports.LEADING_SPACE_WITH_DOT = exports.MIN_VISIBLE_ITEMS = exports.MAX_PAGES = exports.MIN_PAGES = void 0;
|
|
4
4
|
exports.MIN_PAGES = 1;
|
|
5
5
|
exports.MAX_PAGES = 9;
|
|
6
|
+
exports.MIN_VISIBLE_ITEMS = 4;
|
|
7
|
+
exports.LEADING_SPACE_WITH_DOT = 2;
|
|
8
|
+
exports.TRAILING_SPACE_WITH_DOT = exports.MAX_PAGES - exports.LEADING_SPACE_WITH_DOT;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ItemState, PaginationVariant } from './types';
|
|
2
|
-
export declare function pageNumbersAround(totalPages: number, selectedPage: number, maxVisiblePages?: number,
|
|
2
|
+
export declare function pageNumbersAround(totalPages: number, selectedPage: number, maxVisiblePages?: number, variant?: PaginationVariant): ItemState[];
|
|
3
3
|
export declare function calcPageState(selectedPage: number, visiblePages: number, totalPages: number, variant?: PaginationVariant): ItemState[];
|
|
4
4
|
/**
|
|
5
5
|
* Calculates the maximum width for an element within its container.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEtD,wBAAgB,iBAAiB,CAC7B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,eAAe,GAAE,MAAmB,EACpC,OAAO,GAAE,iBAAwB,GAClC,SAAS,EAAE,CA4Db;AAED,wBAAgB,aAAa,CACzB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,iBAAgC,GAC1C,SAAS,EAAE,CASb;AAaD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,MAAM,CASpD"}
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMaxWidth = exports.calcPageState = exports.pageNumbersAround = void 0;
|
|
4
4
|
var const_1 = require("./const");
|
|
5
|
-
function pageNumbersAround(totalPages, selectedPage, maxVisiblePages,
|
|
5
|
+
function pageNumbersAround(totalPages, selectedPage, maxVisiblePages, variant) {
|
|
6
6
|
if (maxVisiblePages === void 0) { maxVisiblePages = totalPages; }
|
|
7
|
-
if (
|
|
7
|
+
if (variant === void 0) { variant = null; }
|
|
8
|
+
var withDots = variant === 'show-last' || (variant === 'overflow' && totalPages > const_1.MAX_PAGES);
|
|
9
|
+
var hasLeadingDots = variant === 'overflow' && totalPages > const_1.MAX_PAGES;
|
|
8
10
|
var visibleItems = Math.min(maxVisiblePages, totalPages);
|
|
9
11
|
var startIndexWithoutDots = Math.max(0, selectedPage - Math.ceil((visibleItems - 1) / 2));
|
|
10
|
-
var startIndexWithDots = visibleItems <
|
|
12
|
+
var startIndexWithDots = visibleItems < const_1.MIN_VISIBLE_ITEMS ? selectedPage :
|
|
11
13
|
Math.max(0, selectedPage - Math.floor((visibleItems - 1) / 2));
|
|
12
14
|
var endIndex = (withDots ? startIndexWithDots : startIndexWithoutDots) + visibleItems;
|
|
13
15
|
var closeToEnd = endIndex >= totalPages;
|
|
16
|
+
var closeToFront = selectedPage <= const_1.MIN_VISIBLE_ITEMS;
|
|
14
17
|
var visibleRangeWithDots = function (start, end) {
|
|
15
18
|
var items = visibleRange(totalPages, start, end);
|
|
16
19
|
if (visibleItems > 2) {
|
|
@@ -23,12 +26,36 @@ function pageNumbersAround(totalPages, selectedPage, maxVisiblePages, withDots)
|
|
|
23
26
|
}
|
|
24
27
|
return items;
|
|
25
28
|
};
|
|
26
|
-
|
|
29
|
+
// middle show item[1] (...) and item[item.length - 1] (...)
|
|
30
|
+
var visibleRangeWithOverflowDots = function (start, end) {
|
|
31
|
+
// Following Dot
|
|
32
|
+
if (closeToFront) {
|
|
33
|
+
return visibleRangeWithDots(0, end);
|
|
34
|
+
// Leading Dot
|
|
35
|
+
}
|
|
36
|
+
else if (closeToEnd) {
|
|
37
|
+
var items_1 = visibleRange(totalPages, totalPages - const_1.TRAILING_SPACE_WITH_DOT, totalPages);
|
|
38
|
+
items_1[0] = 'visible';
|
|
39
|
+
items_1[1] = 'dots';
|
|
40
|
+
return items_1;
|
|
41
|
+
}
|
|
42
|
+
// Middle case with Leading & Following Dots
|
|
43
|
+
var items = visibleRange(totalPages, selectedPage - const_1.LEADING_SPACE_WITH_DOT, selectedPage + const_1.LEADING_SPACE_WITH_DOT + 1);
|
|
44
|
+
items[0] = 'visible';
|
|
45
|
+
items[1] = closeToFront ? 'visible' : 'dots';
|
|
46
|
+
items[totalPages - 2] = 'dots';
|
|
47
|
+
items[totalPages - 1] = 'visible';
|
|
48
|
+
return items;
|
|
49
|
+
};
|
|
50
|
+
if (closeToEnd && totalPages <= const_1.MAX_PAGES) {
|
|
27
51
|
return visibleRange(totalPages, totalPages - visibleItems);
|
|
28
52
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
53
|
+
if (withDots) {
|
|
54
|
+
return hasLeadingDots ?
|
|
55
|
+
visibleRangeWithOverflowDots(startIndexWithDots, endIndex) :
|
|
56
|
+
visibleRangeWithDots(startIndexWithDots, endIndex);
|
|
57
|
+
}
|
|
58
|
+
return visibleRange(totalPages, startIndexWithoutDots, endIndex);
|
|
32
59
|
}
|
|
33
60
|
exports.pageNumbersAround = pageNumbersAround;
|
|
34
61
|
function calcPageState(selectedPage, visiblePages, totalPages, variant) {
|
|
@@ -36,8 +63,9 @@ function calcPageState(selectedPage, visiblePages, totalPages, variant) {
|
|
|
36
63
|
if (selectedPage === -1) {
|
|
37
64
|
return [];
|
|
38
65
|
}
|
|
39
|
-
var adjustedNumPages =
|
|
40
|
-
|
|
66
|
+
var adjustedNumPages = variant === 'overflow' ? const_1.MAX_PAGES :
|
|
67
|
+
clamp(Math.min(totalPages, visiblePages), const_1.MIN_PAGES, const_1.MAX_PAGES);
|
|
68
|
+
return pageNumbersAround(totalPages, selectedPage - 1, adjustedNumPages, variant);
|
|
41
69
|
}
|
|
42
70
|
exports.calcPageState = calcPageState;
|
|
43
71
|
function clamp(n, min, max) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/pagination.tsx"],"names":[],"mappings":"AAAA,OAAc,EACA,cAAc,EAAE,EAAE,EAE/B,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/pagination.tsx"],"names":[],"mappings":"AAAA,OAAc,EACA,cAAc,EAAE,EAAE,EAE/B,MAAM,OAAO,CAAA;AAUd,OAAO,EAAa,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEtD,aAAK,kBAAkB,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAC9D,aAAK,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,GAAG;IAC7D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/D,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,eAAe,CA+JvC,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -52,6 +52,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
var react_1 = __importStar(require("react"));
|
|
55
|
+
var ebay_fake_menu_button_1 = require("../ebay-fake-menu-button");
|
|
55
56
|
var classnames_1 = __importDefault(require("classnames"));
|
|
56
57
|
var debounce_1 = require("../common/debounce");
|
|
57
58
|
var helpers_1 = require("./helpers");
|
|
@@ -78,10 +79,13 @@ var EbayPagination = function (_a) {
|
|
|
78
79
|
0;
|
|
79
80
|
};
|
|
80
81
|
var _l = react_1.useState([]), page = _l[0], setPage = _l[1];
|
|
81
|
-
var
|
|
82
|
-
|
|
82
|
+
var _m = react_1.useState(0), selectedIndex = _m[0], setSelectedIndex = _m[1];
|
|
83
|
+
// selectedPageIndexFromDotMenu: override pageIndex on pagination with dot menu value
|
|
84
|
+
var updatePages = function (selectedPageIndexFromDotMenu) {
|
|
85
|
+
var selectedPageIndex = selectedPageIndexFromDotMenu || childPageRefs.current.findIndex(function (pageRef) { var _a; return ((_a = pageRef.current) === null || _a === void 0 ? void 0 : _a.getAttribute('aria-current')) === 'page'; });
|
|
83
86
|
var visiblePageItems = getNumOfVisiblePageItems();
|
|
84
87
|
var pageState = helpers_1.calcPageState(selectedPageIndex, visiblePageItems, totalPages, variant);
|
|
88
|
+
setSelectedIndex(selectedPageIndex);
|
|
85
89
|
setPage(__spreadArrays(['hidden'], pageState));
|
|
86
90
|
};
|
|
87
91
|
react_1.useEffect(function () {
|
|
@@ -94,17 +98,54 @@ var EbayPagination = function (_a) {
|
|
|
94
98
|
}, [children]);
|
|
95
99
|
var createChildItems = function (itemType) {
|
|
96
100
|
var pageIndex = 0;
|
|
101
|
+
var firstDotItems = [];
|
|
102
|
+
var secondDotItems = [];
|
|
103
|
+
var allDotItems = [];
|
|
104
|
+
var firstDot = page.indexOf('dots');
|
|
105
|
+
var lastDot = page.lastIndexOf('dots');
|
|
97
106
|
return react_1.Children.map(children, function (item, index) {
|
|
98
107
|
var _a = item.props, _b = _a.type, type = _b === void 0 ? 'page' : _b, current = _a.current, disabled = _a.disabled, href = _a.href, text = _a.children;
|
|
108
|
+
var isDot = page[index] === 'dots';
|
|
109
|
+
var key = id + "-item-" + index;
|
|
110
|
+
var hide = page[index] === 'hidden';
|
|
99
111
|
var newProps = {
|
|
100
112
|
type: type, current: current, disabled: disabled, href: href,
|
|
101
|
-
children:
|
|
113
|
+
children: isDot ? '…' : text,
|
|
102
114
|
pageIndex: type === 'page' ? pageIndex++ : undefined,
|
|
103
|
-
key:
|
|
104
|
-
hide:
|
|
115
|
+
key: key,
|
|
116
|
+
hide: hide,
|
|
105
117
|
onPrevious: onPrevious, onNext: onNext, onSelect: onSelect, a11yPreviousText: a11yPreviousText, a11yNextText: a11yNextText,
|
|
106
118
|
ref: childPageRefs.current[index]
|
|
107
119
|
};
|
|
120
|
+
// include hidden numbers & number of (...)itself
|
|
121
|
+
if ((hide || isDot) && type === 'page') {
|
|
122
|
+
var itemComponent = (react_1.default.createElement(ebay_fake_menu_button_1.EbayFakeMenuButtonItem, { key: key, href: href, onClick: function (event) {
|
|
123
|
+
if (!href) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
}
|
|
126
|
+
var currentTarget = event.currentTarget;
|
|
127
|
+
onSelect(event, currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.innerText, pageIndex);
|
|
128
|
+
updatePages(Number(currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.innerText));
|
|
129
|
+
} }, text));
|
|
130
|
+
if (firstDot === lastDot) {
|
|
131
|
+
allDotItems.push(itemComponent);
|
|
132
|
+
}
|
|
133
|
+
if (selectedIndex - 2 > firstDot && index < selectedIndex) {
|
|
134
|
+
firstDotItems.push(itemComponent);
|
|
135
|
+
}
|
|
136
|
+
if (selectedIndex + 2 < lastDot && index > selectedIndex) {
|
|
137
|
+
secondDotItems.push(itemComponent);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (itemType === 'page' && isDot && variant === 'overflow') {
|
|
141
|
+
var childComponent = allDotItems;
|
|
142
|
+
if (firstDot !== lastDot) {
|
|
143
|
+
childComponent = index === 2 ? firstDotItems : secondDotItems;
|
|
144
|
+
}
|
|
145
|
+
return (react_1.default.createElement("li", { key: key },
|
|
146
|
+
react_1.default.createElement("span", { className: "pagination__item", role: "separator" },
|
|
147
|
+
react_1.default.createElement(ebay_fake_menu_button_1.EbayFakeMenuButton, { a11yText: "Menu", borderless: true, variant: "overflow", noToggleIcon: true }, childComponent))));
|
|
148
|
+
}
|
|
108
149
|
return itemType === type ? react_1.cloneElement(item, newProps) : null;
|
|
109
150
|
});
|
|
110
151
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/types.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;AACrD,oBAAY,iBAAiB,GAAG,WAAW,GAAG,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ebay-pagination/types.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;AACrD,oBAAY,iBAAiB,GAAG,WAAW,GAAG,YAAY,GAAG,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebay/ui-core-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Skin components build off React",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"author": "tmanyanov@ebay.com",
|
|
42
42
|
"license": "ISC",
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@ebay/skin": "^15.
|
|
44
|
+
"@ebay/skin": "^15.2.0",
|
|
45
45
|
"react": "^16.0.0",
|
|
46
46
|
"react-dom": "^16.0.0"
|
|
47
47
|
},
|