@doyourjob/gravity-ui-page-constructor 5.31.62 → 5.31.63
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/README.md +1 -1
- package/build/cjs/blocks/Reports/Reports.css +3 -0
- package/build/cjs/blocks/Reports/Reports.d.ts +1 -1
- package/build/cjs/blocks/Reports/Reports.js +18 -3
- package/build/cjs/blocks/Reports/schema.d.ts +32 -0
- package/build/cjs/blocks/Reports/schema.js +10 -1
- package/build/cjs/components/Paginator/Paginator.css +61 -0
- package/build/cjs/components/Paginator/Paginator.d.ts +3 -0
- package/build/cjs/components/Paginator/Paginator.js +87 -0
- package/build/cjs/components/Paginator/components/NavigationButton.d.ts +6 -0
- package/build/cjs/components/Paginator/components/NavigationButton.js +22 -0
- package/build/cjs/components/Paginator/components/PaginatorItem.d.ts +2 -0
- package/build/cjs/components/Paginator/components/PaginatorItem.js +15 -0
- package/build/cjs/components/Paginator/i18n/en.json +4 -0
- package/build/cjs/components/Paginator/i18n/index.d.ts +1 -0
- package/build/cjs/components/Paginator/i18n/index.js +9 -0
- package/build/cjs/components/Paginator/i18n/ru.json +4 -0
- package/build/cjs/components/Paginator/types.d.ts +28 -0
- package/build/cjs/components/Paginator/types.js +8 -0
- package/build/cjs/components/Paginator/utils.d.ts +3 -0
- package/build/cjs/components/Paginator/utils.js +71 -0
- package/build/cjs/components/index.d.ts +1 -0
- package/build/cjs/components/index.js +3 -1
- package/build/cjs/constructor-items.d.ts +1 -1
- package/build/cjs/context/reportsContext/ReportsContext.d.ts +1 -0
- package/build/cjs/icons/ArrowLeftIcon.d.ts +2 -0
- package/build/cjs/icons/ArrowLeftIcon.js +9 -0
- package/build/cjs/icons/ArrowRightIcon.d.ts +2 -0
- package/build/cjs/icons/ArrowRightIcon.js +9 -0
- package/build/cjs/icons/index.d.ts +2 -0
- package/build/cjs/icons/index.js +2 -0
- package/build/cjs/models/constructor-items/blocks.d.ts +1 -0
- package/build/esm/blocks/Reports/Reports.css +3 -0
- package/build/esm/blocks/Reports/Reports.d.ts +1 -1
- package/build/esm/blocks/Reports/Reports.js +19 -4
- package/build/esm/blocks/Reports/schema.d.ts +32 -0
- package/build/esm/blocks/Reports/schema.js +11 -2
- package/build/esm/components/Paginator/Paginator.css +61 -0
- package/build/esm/components/Paginator/Paginator.d.ts +4 -0
- package/build/esm/components/Paginator/Paginator.js +84 -0
- package/build/esm/components/Paginator/components/NavigationButton.d.ts +6 -0
- package/build/esm/components/Paginator/components/NavigationButton.js +17 -0
- package/build/esm/components/Paginator/components/PaginatorItem.d.ts +2 -0
- package/build/esm/components/Paginator/components/PaginatorItem.js +10 -0
- package/build/esm/components/Paginator/i18n/en.json +4 -0
- package/build/esm/components/Paginator/i18n/index.d.ts +1 -0
- package/build/esm/components/Paginator/i18n/index.js +5 -0
- package/build/esm/components/Paginator/i18n/ru.json +4 -0
- package/build/esm/components/Paginator/types.d.ts +28 -0
- package/build/esm/components/Paginator/types.js +5 -0
- package/build/esm/components/Paginator/utils.d.ts +3 -0
- package/build/esm/components/Paginator/utils.js +66 -0
- package/build/esm/components/index.d.ts +1 -0
- package/build/esm/components/index.js +1 -0
- package/build/esm/constructor-items.d.ts +1 -1
- package/build/esm/context/reportsContext/ReportsContext.d.ts +1 -0
- package/build/esm/icons/ArrowLeftIcon.d.ts +2 -0
- package/build/esm/icons/ArrowLeftIcon.js +4 -0
- package/build/esm/icons/ArrowRightIcon.d.ts +2 -0
- package/build/esm/icons/ArrowRightIcon.js +4 -0
- package/build/esm/icons/index.d.ts +2 -0
- package/build/esm/icons/index.js +2 -0
- package/build/esm/models/constructor-items/blocks.d.ts +1 -0
- package/package.json +1 -1
- package/schema/index.js +1 -1
- package/server/models/constructor-items/blocks.d.ts +1 -0
- package/widget/index.js +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @gravity-ui/page-constructor · [](https://www.npmjs.com/package/@gravity-ui/page-constructor) [](https://github.com/gravity-ui/page-constructor/actions/workflows/ci.yml?query=branch:main) [](https://github.com/gravity-ui/page-constructor/actions/workflows/release.yml?query=branch:main) [](https://
|
|
1
|
+
# @gravity-ui/page-constructor · [](https://www.npmjs.com/package/@gravity-ui/page-constructor) [](https://github.com/gravity-ui/page-constructor/actions/workflows/ci.yml?query=branch:main) [](https://github.com/gravity-ui/page-constructor/actions/workflows/release.yml?query=branch:main) [](https://doyourjob-agency.github.io/page-constructor/main/)
|
|
2
2
|
|
|
3
3
|
## Page constructor
|
|
4
4
|
|
|
@@ -8,9 +8,13 @@ const reportsContext_1 = require("../../context/reportsContext");
|
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const ReportsItem_1 = tslib_1.__importDefault(require("./ReportsItem/ReportsItem"));
|
|
10
10
|
const b = (0, utils_1.block)('reports-block');
|
|
11
|
-
const
|
|
11
|
+
const titleColSizes = {
|
|
12
|
+
all: 12,
|
|
13
|
+
};
|
|
14
|
+
const ReportsBlock = ({ title, typeKey, empty }) => {
|
|
12
15
|
const data = (0, react_1.useContext)(reportsContext_1.ReportsContext);
|
|
13
|
-
const
|
|
16
|
+
const [page, setPage] = (0, react_1.useState)(1);
|
|
17
|
+
const { selects, items, itemsPerPage, filesOutline } = (0, react_1.useMemo)(() => data[typeKey], [data, typeKey]);
|
|
14
18
|
const initFilters = (0, react_1.useMemo)(() => (selects === null || selects === void 0 ? void 0 : selects.reduce((acc, select) => (Object.assign(Object.assign({}, acc), { [select.name]: select.init })), {})) || {}, [selects]);
|
|
15
19
|
const [localFilters, setLocalFilters] = (0, react_1.useState)(initFilters);
|
|
16
20
|
const handleChange = (0, react_1.useCallback)((name, value) => setLocalFilters((prev) => (Object.assign(Object.assign({}, prev), { [name]: value }))), []);
|
|
@@ -23,9 +27,20 @@ const ReportsBlock = ({ typeKey, empty }) => {
|
|
|
23
27
|
return acc;
|
|
24
28
|
}, false))
|
|
25
29
|
: items, [items, localFilters]);
|
|
30
|
+
const paginatedItems = (0, react_1.useMemo)(() => {
|
|
31
|
+
if (!itemsPerPage)
|
|
32
|
+
return filteredItems;
|
|
33
|
+
const startIndex = (page - 1) * itemsPerPage;
|
|
34
|
+
return filteredItems.slice(startIndex, startIndex + itemsPerPage);
|
|
35
|
+
}, [filteredItems, itemsPerPage, page]);
|
|
36
|
+
const titleProps = !title || typeof title === 'string'
|
|
37
|
+
? { text: title, textSize: 'm' }
|
|
38
|
+
: title;
|
|
26
39
|
return (react_1.default.createElement("div", { className: b() },
|
|
40
|
+
title && react_1.default.createElement(components_1.Title, { className: b('title'), title: titleProps, colSizes: titleColSizes }),
|
|
27
41
|
(selects === null || selects === void 0 ? void 0 : selects.length) && (react_1.default.createElement("div", { className: b('select') }, selects.map(({ name, options }) => (react_1.default.createElement(components_1.Select, { key: name, name: name, options: options, onChange: handleChange }))))),
|
|
28
|
-
|
|
42
|
+
paginatedItems.length ? (paginatedItems.map((item, index) => (react_1.default.createElement(ReportsItem_1.default, Object.assign({ key: index }, item, { filesOutline: filesOutline }))))) : (react_1.default.createElement("div", { className: b('empty') }, empty)),
|
|
43
|
+
itemsPerPage && (react_1.default.createElement(components_1.Paginator, { page: page, itemsPerPage: itemsPerPage, totalItems: filteredItems.length, maxPages: Infinity, onPageChange: setPage }))));
|
|
29
44
|
};
|
|
30
45
|
exports.ReportsBlock = ReportsBlock;
|
|
31
46
|
exports.default = exports.ReportsBlock;
|
|
@@ -3,6 +3,38 @@ export declare const ReportsBlock: {
|
|
|
3
3
|
additionalProperties: boolean;
|
|
4
4
|
required: string[];
|
|
5
5
|
properties: {
|
|
6
|
+
title: {
|
|
7
|
+
oneOf: ({
|
|
8
|
+
type: string;
|
|
9
|
+
contentType: string;
|
|
10
|
+
optionName: string;
|
|
11
|
+
} | {
|
|
12
|
+
optionName: string;
|
|
13
|
+
type: string;
|
|
14
|
+
additionalProperties: boolean;
|
|
15
|
+
required: string[];
|
|
16
|
+
properties: {
|
|
17
|
+
text: {
|
|
18
|
+
type: string;
|
|
19
|
+
contentType: string;
|
|
20
|
+
};
|
|
21
|
+
textSize: {
|
|
22
|
+
type: string;
|
|
23
|
+
enum: string[];
|
|
24
|
+
};
|
|
25
|
+
url: {
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
urlTitle: {
|
|
29
|
+
type: string;
|
|
30
|
+
};
|
|
31
|
+
resetMargin: {
|
|
32
|
+
type: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
contentType?: undefined;
|
|
36
|
+
})[];
|
|
37
|
+
};
|
|
6
38
|
typeKey: {
|
|
7
39
|
type: string;
|
|
8
40
|
};
|
|
@@ -6,7 +6,16 @@ exports.ReportsBlock = {
|
|
|
6
6
|
'reports-block': {
|
|
7
7
|
additionalProperties: false,
|
|
8
8
|
required: ['typeKey'],
|
|
9
|
-
properties: Object.assign(Object.assign({}, common_1.BaseProps), {
|
|
9
|
+
properties: Object.assign(Object.assign({}, common_1.BaseProps), { title: {
|
|
10
|
+
oneOf: [
|
|
11
|
+
{
|
|
12
|
+
type: 'string',
|
|
13
|
+
contentType: 'text',
|
|
14
|
+
optionName: 'text',
|
|
15
|
+
},
|
|
16
|
+
Object.assign(Object.assign({}, common_1.TitleProps), { optionName: 'options' }),
|
|
17
|
+
],
|
|
18
|
+
}, typeKey: {
|
|
10
19
|
type: 'string',
|
|
11
20
|
}, empty: {
|
|
12
21
|
type: 'string',
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* use this for style redefinitions to awoid problems with
|
|
2
|
+
unpredictable css rules order in build */
|
|
3
|
+
.pc-paginator {
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: 0;
|
|
6
|
+
list-style: none;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
}
|
|
12
|
+
.pc-paginator__item {
|
|
13
|
+
font-size: var(--g-text-body-2-font-size, var(--pc-text-body-2-font-size));
|
|
14
|
+
line-height: var(--g-text-body-2-line-height, var(--pc-text-body-2-line-height));
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
min-width: 52px;
|
|
19
|
+
min-height: 52px;
|
|
20
|
+
margin: 0 4px;
|
|
21
|
+
padding: 16px 20px;
|
|
22
|
+
border: none;
|
|
23
|
+
border-radius: 8px;
|
|
24
|
+
background: transparent;
|
|
25
|
+
color: var(--g-color-text-primary);
|
|
26
|
+
}
|
|
27
|
+
.pc-paginator__item:hover {
|
|
28
|
+
background-color: var(--g-color-private-blue-50);
|
|
29
|
+
}
|
|
30
|
+
.pc-paginator__item_type_page {
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
}
|
|
33
|
+
.pc-paginator__item_type_page.pc-paginator__item_active {
|
|
34
|
+
background-color: var(--g-color-private-blue-200-solid);
|
|
35
|
+
cursor: default;
|
|
36
|
+
}
|
|
37
|
+
.pc-paginator__item_type_prev, .pc-paginator__item_type_next {
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
gap: 8px;
|
|
40
|
+
font-size: 14px;
|
|
41
|
+
}
|
|
42
|
+
.pc-paginator__pagination {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-flow: row wrap;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
align-items: center;
|
|
47
|
+
width: 100%;
|
|
48
|
+
gap: 8px;
|
|
49
|
+
}
|
|
50
|
+
@media (max-width: 577px) {
|
|
51
|
+
.pc-paginator__pagination {
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
.pc-paginator__pagination-block {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: row;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
align-items: center;
|
|
60
|
+
margin-bottom: 4px;
|
|
61
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Paginator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const cn_1 = require("../../utils/cn");
|
|
7
|
+
const NavigationButton_1 = require("./components/NavigationButton");
|
|
8
|
+
const PaginatorItem_1 = require("./components/PaginatorItem");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const b = (0, cn_1.block)('paginator');
|
|
12
|
+
const DEFAULT_PAGE_COUNT_FOR_SHOW_SUPPORT_BUTTONS = 5;
|
|
13
|
+
const Paginator = ({ itemsPerPage, totalItems, maxPages, page, className, onPageChange, pageCountForShowSupportButtons = DEFAULT_PAGE_COUNT_FOR_SHOW_SUPPORT_BUTTONS, }) => {
|
|
14
|
+
const [pagesCount, setPagesCount] = (0, react_1.useState)((0, utils_1.getPagesCount)({ itemsPerPage, totalItems, maxPages }));
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
16
|
+
const count = (0, utils_1.getPagesCount)({ itemsPerPage, totalItems, maxPages });
|
|
17
|
+
setPagesCount(count);
|
|
18
|
+
}, [itemsPerPage, totalItems, maxPages]);
|
|
19
|
+
const handlePageChange = (pageIndex) => onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange(pageIndex);
|
|
20
|
+
const isShowSupportButtons = (0, react_1.useMemo)(() => pagesCount > pageCountForShowSupportButtons, [pageCountForShowSupportButtons, pagesCount]);
|
|
21
|
+
if (pagesCount <= 1) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const handleArrowClick = (type) => {
|
|
25
|
+
let newPage = page;
|
|
26
|
+
if (type === 'prev' && page > 1) {
|
|
27
|
+
newPage = page - 1;
|
|
28
|
+
}
|
|
29
|
+
else if (type === 'next' && page < pagesCount) {
|
|
30
|
+
newPage = page + 1;
|
|
31
|
+
}
|
|
32
|
+
if (newPage !== page) {
|
|
33
|
+
handlePageChange(newPage);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const handlePageClick = (index) => {
|
|
37
|
+
if (index !== page && typeof index === 'number') {
|
|
38
|
+
handlePageChange(index);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const paginatorItems = (0, utils_1.getPageConfigs)({
|
|
42
|
+
page,
|
|
43
|
+
pagesCount,
|
|
44
|
+
handlePageClick,
|
|
45
|
+
});
|
|
46
|
+
if (page > 1 && isShowSupportButtons) {
|
|
47
|
+
paginatorItems.unshift({
|
|
48
|
+
key: types_1.ArrowType.Prev,
|
|
49
|
+
dataKey: types_1.ArrowType.Prev,
|
|
50
|
+
mods: { type: types_1.ArrowType.Prev },
|
|
51
|
+
onClick: handleArrowClick,
|
|
52
|
+
index: 0,
|
|
53
|
+
content: react_1.default.createElement(NavigationButton_1.NavigationButton, { arrowType: types_1.ArrowType.Prev }),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (page < pagesCount && isShowSupportButtons) {
|
|
57
|
+
paginatorItems.push({
|
|
58
|
+
key: types_1.ArrowType.Next,
|
|
59
|
+
dataKey: types_1.ArrowType.Next,
|
|
60
|
+
mods: { type: types_1.ArrowType.Next },
|
|
61
|
+
index: page + 1,
|
|
62
|
+
onClick: handleArrowClick,
|
|
63
|
+
content: react_1.default.createElement(NavigationButton_1.NavigationButton, { arrowType: types_1.ArrowType.Next }),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const renderPaginatorItem = (item) => {
|
|
67
|
+
const { key } = item, rest = tslib_1.__rest(item, ["key"]);
|
|
68
|
+
return react_1.default.createElement(PaginatorItem_1.PaginatorItem, Object.assign({ key: `page_${key}` }, rest));
|
|
69
|
+
};
|
|
70
|
+
return (react_1.default.createElement("div", { className: b('pagination') },
|
|
71
|
+
page > 1 && isShowSupportButtons && (react_1.default.createElement("div", { className: b('pagination-block') },
|
|
72
|
+
react_1.default.createElement("ul", { className: b(null, className) }, paginatorItems.slice(0, 1).map(renderPaginatorItem)))),
|
|
73
|
+
react_1.default.createElement("div", { className: b('pagination-block') },
|
|
74
|
+
react_1.default.createElement("ul", { className: b(null, className) }, isShowSupportButtons
|
|
75
|
+
? paginatorItems
|
|
76
|
+
.slice(page > 1 ? 1 : 0, page < pagesCount
|
|
77
|
+
? paginatorItems.length - 1
|
|
78
|
+
: paginatorItems.length)
|
|
79
|
+
.map(renderPaginatorItem)
|
|
80
|
+
: paginatorItems.map(renderPaginatorItem))),
|
|
81
|
+
page < pagesCount && isShowSupportButtons && (react_1.default.createElement("div", { className: b('pagination-block') },
|
|
82
|
+
react_1.default.createElement("ul", { className: b(null, className) }, paginatorItems
|
|
83
|
+
.slice(paginatorItems.length - 1, paginatorItems.length)
|
|
84
|
+
.map(renderPaginatorItem))))));
|
|
85
|
+
};
|
|
86
|
+
exports.Paginator = Paginator;
|
|
87
|
+
exports.default = exports.Paginator;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NavigationButton = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const icons_1 = require("../../../icons");
|
|
7
|
+
const i18n_1 = require("../i18n");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const NavigationButton = ({ arrowType, disabled }) => {
|
|
10
|
+
if (disabled) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (arrowType === types_1.ArrowType.Prev) {
|
|
14
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
15
|
+
react_1.default.createElement(icons_1.ArrowLeftIcon, null),
|
|
16
|
+
react_1.default.createElement("span", null, (0, i18n_1.i18n)('prev'))));
|
|
17
|
+
}
|
|
18
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
19
|
+
react_1.default.createElement("span", null, (0, i18n_1.i18n)('next')),
|
|
20
|
+
react_1.default.createElement(icons_1.ArrowRightIcon, null)));
|
|
21
|
+
};
|
|
22
|
+
exports.NavigationButton = NavigationButton;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaginatorItem = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const cn_1 = require("../../../utils/cn");
|
|
7
|
+
const b = (0, cn_1.block)('paginator');
|
|
8
|
+
const PaginatorItem = ({ dataKey, mods, content, onClick }) => {
|
|
9
|
+
const itemKey = Number(dataKey) > 0 ? Number(dataKey) : dataKey;
|
|
10
|
+
const handleClick = (0, react_1.useCallback)(() => {
|
|
11
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(itemKey);
|
|
12
|
+
}, [itemKey, onClick]);
|
|
13
|
+
return (react_1.default.createElement("button", { className: b('item', mods), onClick: handleClick }, content));
|
|
14
|
+
};
|
|
15
|
+
exports.PaginatorItem = PaginatorItem;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const i18n: (key: "prev" | "next", params?: import("@gravity-ui/i18n").Params | undefined) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.i18n = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const i18n_1 = require("@gravity-ui/uikit/i18n");
|
|
6
|
+
const cn_1 = require("../../../utils/cn");
|
|
7
|
+
const en_json_1 = tslib_1.__importDefault(require("./en.json"));
|
|
8
|
+
const ru_json_1 = tslib_1.__importDefault(require("./ru.json"));
|
|
9
|
+
exports.i18n = (0, i18n_1.addComponentKeysets)({ en: en_json_1.default, ru: ru_json_1.default }, `${cn_1.NAMESPACE}Paginator`);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { NoStrictEntityMods } from '@bem-react/classname';
|
|
3
|
+
import type { ClassNameProps } from '../../models/common';
|
|
4
|
+
export interface PaginatorItemProps {
|
|
5
|
+
key: string | ArrowType;
|
|
6
|
+
dataKey: string | ArrowType;
|
|
7
|
+
mods: NoStrictEntityMods;
|
|
8
|
+
content: ReactNode;
|
|
9
|
+
onClick?: (key: number | ArrowType) => void;
|
|
10
|
+
index: number;
|
|
11
|
+
}
|
|
12
|
+
export type PaginatorProps = {
|
|
13
|
+
page: number;
|
|
14
|
+
totalItems: number;
|
|
15
|
+
itemsPerPage: number;
|
|
16
|
+
maxPages: number;
|
|
17
|
+
onPageChange: (page: number) => void;
|
|
18
|
+
pageCountForShowSupportButtons?: number;
|
|
19
|
+
} & ClassNameProps;
|
|
20
|
+
export declare enum ArrowType {
|
|
21
|
+
Prev = "prev",
|
|
22
|
+
Next = "next"
|
|
23
|
+
}
|
|
24
|
+
export type GetPageConfigParams = {
|
|
25
|
+
page: number;
|
|
26
|
+
pagesCount: number;
|
|
27
|
+
handlePageClick: (key: number | ArrowType) => void;
|
|
28
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrowType = void 0;
|
|
4
|
+
var ArrowType;
|
|
5
|
+
(function (ArrowType) {
|
|
6
|
+
ArrowType["Prev"] = "prev";
|
|
7
|
+
ArrowType["Next"] = "next";
|
|
8
|
+
})(ArrowType = exports.ArrowType || (exports.ArrowType = {}));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GetPageConfigParams, PaginatorItemProps, PaginatorProps } from './types';
|
|
2
|
+
export declare const getPageConfigs: ({ page, pagesCount, handlePageClick }: GetPageConfigParams) => PaginatorItemProps[];
|
|
3
|
+
export declare const getPagesCount: (props: Pick<PaginatorProps, 'totalItems' | 'itemsPerPage' | 'maxPages'>) => number;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPagesCount = exports.getPageConfigs = void 0;
|
|
4
|
+
const getPageConfigs = ({ page, pagesCount, handlePageClick }) => {
|
|
5
|
+
const paginatorItems = [];
|
|
6
|
+
const showLeftDots = page > 4;
|
|
7
|
+
const showRightDots = page < pagesCount - 3;
|
|
8
|
+
const addPage = (i) => {
|
|
9
|
+
paginatorItems.push({
|
|
10
|
+
key: String(i),
|
|
11
|
+
dataKey: String(i),
|
|
12
|
+
index: i,
|
|
13
|
+
mods: { type: 'page', active: page === i },
|
|
14
|
+
onClick: handlePageClick,
|
|
15
|
+
content: i,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
if (pagesCount <= 5) {
|
|
19
|
+
for (let i = 1; i <= pagesCount; i++) {
|
|
20
|
+
addPage(i);
|
|
21
|
+
}
|
|
22
|
+
return paginatorItems;
|
|
23
|
+
}
|
|
24
|
+
// Всегда добавляем первую
|
|
25
|
+
addPage(1);
|
|
26
|
+
// Левые троеточия
|
|
27
|
+
if (showLeftDots) {
|
|
28
|
+
paginatorItems.push({
|
|
29
|
+
key: 'ellipsis',
|
|
30
|
+
dataKey: 'ellipsis',
|
|
31
|
+
index: -1,
|
|
32
|
+
mods: { type: 'ellipsis' },
|
|
33
|
+
content: '…',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// Центральный блок
|
|
37
|
+
let start = Math.max(2, page - 1);
|
|
38
|
+
let end = Math.min(pagesCount - 1, page + 1);
|
|
39
|
+
if (!showLeftDots) {
|
|
40
|
+
start = 2;
|
|
41
|
+
end = 5;
|
|
42
|
+
}
|
|
43
|
+
else if (!showRightDots) {
|
|
44
|
+
start = pagesCount - 4;
|
|
45
|
+
end = pagesCount - 1;
|
|
46
|
+
}
|
|
47
|
+
for (let i = start; i <= end; i++) {
|
|
48
|
+
addPage(i);
|
|
49
|
+
}
|
|
50
|
+
// Правые троеточия
|
|
51
|
+
if (showRightDots) {
|
|
52
|
+
paginatorItems.push({
|
|
53
|
+
key: 'ellipsis',
|
|
54
|
+
dataKey: 'ellipsis',
|
|
55
|
+
index: -2,
|
|
56
|
+
mods: { type: 'ellipsis' },
|
|
57
|
+
content: '…',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Последняя страница
|
|
61
|
+
if (pagesCount > 1) {
|
|
62
|
+
addPage(pagesCount);
|
|
63
|
+
}
|
|
64
|
+
return paginatorItems;
|
|
65
|
+
};
|
|
66
|
+
exports.getPageConfigs = getPageConfigs;
|
|
67
|
+
const getPagesCount = (props) => {
|
|
68
|
+
const totalPages = Math.ceil(props.totalItems / props.itemsPerPage);
|
|
69
|
+
return Number.isFinite(props.maxPages) ? Math.min(totalPages, props.maxPages) : totalPages;
|
|
70
|
+
};
|
|
71
|
+
exports.getPagesCount = getPagesCount;
|
|
@@ -43,5 +43,6 @@ export { default as InfiniteScroll } from './InfiniteScroll/InfiniteScroll';
|
|
|
43
43
|
export { default as Tag } from './Tag/Tag';
|
|
44
44
|
export { default as ReportFile } from './ReportFile/ReportFile';
|
|
45
45
|
export { default as Select } from './Select/Select';
|
|
46
|
+
export { default as Paginator } from './Paginator/Paginator';
|
|
46
47
|
export type { RouterLinkProps } from './RouterLink/RouterLink';
|
|
47
48
|
export type { ImageBaseProps } from './ImageBase/ImageBase';
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Select = exports.ReportFile = exports.Tag = exports.InfiniteScroll = exports.YandexForm = exports.YFMWrapper = exports.VideoBlock = exports.UnpublishedLabel = exports.ToggleArrow = exports.Title = exports.Table = exports.RouterLink = exports.ReactPlayer = exports.OverflowScroller = exports.OutsideClick = exports.MetaInfo = exports.Media = exports.Links = exports.Link = exports.InnerForm = exports.ImageBase = exports.Image = exports.IconWrapper = exports.HTML = exports.HeaderBreadcrumbs = exports.FullWidthBackground = exports.FullscreenMedia = exports.FullscreenImage = exports.Foldable = exports.FileLink = exports.ErrorWrapper = exports.Control = exports.ContentList = exports.CardBase = exports.BrandFooter = exports.Buttons = exports.Button = exports.BlockBase = exports.BalancedMasonry = exports.BackLink = exports.BackgroundMedia = exports.BackgroundImage = exports.Author = exports.AnimateBlock = exports.Anchor = void 0;
|
|
6
|
+
exports.Paginator = exports.Select = exports.ReportFile = exports.Tag = exports.InfiniteScroll = exports.YandexForm = exports.YFMWrapper = exports.VideoBlock = exports.UnpublishedLabel = exports.ToggleArrow = exports.Title = exports.Table = exports.RouterLink = exports.ReactPlayer = exports.OverflowScroller = exports.OutsideClick = exports.MetaInfo = exports.Media = exports.Links = exports.Link = exports.InnerForm = exports.ImageBase = exports.Image = exports.IconWrapper = exports.HTML = exports.HeaderBreadcrumbs = exports.FullWidthBackground = exports.FullscreenMedia = exports.FullscreenImage = exports.Foldable = exports.FileLink = exports.ErrorWrapper = exports.Control = exports.ContentList = exports.CardBase = exports.BrandFooter = exports.Buttons = exports.Button = exports.BlockBase = exports.BalancedMasonry = exports.BackLink = exports.BackgroundMedia = exports.BackgroundImage = exports.Author = exports.AnimateBlock = exports.Anchor = void 0;
|
|
7
7
|
var Anchor_1 = require("./Anchor/Anchor");
|
|
8
8
|
Object.defineProperty(exports, "Anchor", { enumerable: true, get: function () { return __importDefault(Anchor_1).default; } });
|
|
9
9
|
var AnimateBlock_1 = require("./AnimateBlock/AnimateBlock");
|
|
@@ -94,3 +94,5 @@ var ReportFile_1 = require("./ReportFile/ReportFile");
|
|
|
94
94
|
Object.defineProperty(exports, "ReportFile", { enumerable: true, get: function () { return __importDefault(ReportFile_1).default; } });
|
|
95
95
|
var Select_1 = require("./Select/Select");
|
|
96
96
|
Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return __importDefault(Select_1).default; } });
|
|
97
|
+
var Paginator_1 = require("./Paginator/Paginator");
|
|
98
|
+
Object.defineProperty(exports, "Paginator", { enumerable: true, get: function () { return __importDefault(Paginator_1).default; } });
|
|
@@ -28,7 +28,7 @@ export declare const blockMap: {
|
|
|
28
28
|
"link-table-block": ({ title, items }: import("./models").LinkTableBlockProps) => JSX.Element;
|
|
29
29
|
"services-block": ({ title, serviceLinkType }: import("./models").ServicesBlockProps) => JSX.Element;
|
|
30
30
|
"quotes-block": ({ theme: localTheme, items, background, backgroundColor, }: import("./models").QuotesBlockProps) => JSX.Element;
|
|
31
|
-
"reports-block": ({ typeKey, empty }: import("./models").ReportsBlockProps) => JSX.Element;
|
|
31
|
+
"reports-block": ({ title, typeKey, empty }: import("./models").ReportsBlockProps) => JSX.Element;
|
|
32
32
|
"form-wall-block": (props: import("./models").FormWallBlockProps) => JSX.Element;
|
|
33
33
|
"slider-new-block": ({ animated, title, description, type, anchorId, arrows, adaptive, autoplay: autoplayMs, dots, className, dotsClassName, disclaimer, children, blockClassName, arrowSize, slidesToShow, onSlideChange, onSlideChangeTransitionStart, onSlideChangeTransitionEnd, onActiveIndexChange, onBreakpoint, }: import("react").PropsWithChildren<import("./blocks/SliderNew/Slider").SliderNewProps>) => JSX.Element;
|
|
34
34
|
};
|
|
@@ -9,6 +9,7 @@ interface Select extends SelectProps {
|
|
|
9
9
|
type ReportsData = {
|
|
10
10
|
selects?: Select[];
|
|
11
11
|
items: Item[];
|
|
12
|
+
itemsPerPage?: number;
|
|
12
13
|
} & Pick<ReportsItemProps, 'filesOutline'>;
|
|
13
14
|
export type ReportsContextProps = Record<string, ReportsData>;
|
|
14
15
|
export declare const ReportsContext: React.Context<ReportsContextProps>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrowLeftIcon = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const svg_1 = require("../utils/svg");
|
|
7
|
+
const ArrowLeftIcon = (props) => (react_1.default.createElement("svg", Object.assign({ height: "12", width: "12", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 12 12", fill: "currentColor" }, svg_1.a11yHiddenSvgProps, props),
|
|
8
|
+
react_1.default.createElement("path", { fill: "none", stroke: "currentColor", fillRule: "evenodd", d: "M8 10L4 6l4-4" })));
|
|
9
|
+
exports.ArrowLeftIcon = ArrowLeftIcon;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrowRightIcon = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const svg_1 = require("../utils/svg");
|
|
7
|
+
const ArrowRightIcon = (props) => (react_1.default.createElement("svg", Object.assign({ height: "12", width: "12", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 12 12", fill: "currentColor" }, svg_1.a11yHiddenSvgProps, props),
|
|
8
|
+
react_1.default.createElement("path", { fill: "none", stroke: "currentColor", fillRule: "evenodd", d: "M4 2l4 4-4 4" })));
|
|
9
|
+
exports.ArrowRightIcon = ArrowRightIcon;
|
package/build/cjs/icons/index.js
CHANGED
|
@@ -5,3 +5,5 @@ tslib_1.__exportStar(require("./Chevron"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./Github"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./NavigationChevron"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./NavigationArrow"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./ArrowLeftIcon"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./ArrowRightIcon"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ReportsBlockProps } from '../../models';
|
|
2
2
|
import './Reports.css';
|
|
3
|
-
export declare const ReportsBlock: ({ typeKey, empty }: ReportsBlockProps) => JSX.Element;
|
|
3
|
+
export declare const ReportsBlock: ({ title, typeKey, empty }: ReportsBlockProps) => JSX.Element;
|
|
4
4
|
export default ReportsBlock;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import React, { useCallback, useContext, useMemo, useState } from 'react';
|
|
2
|
-
import { Select } from '../../components';
|
|
2
|
+
import { Paginator, Select, Title } from '../../components';
|
|
3
3
|
import { ReportsContext } from '../../context/reportsContext';
|
|
4
4
|
import { block } from '../../utils';
|
|
5
5
|
import ReportsItem from './ReportsItem/ReportsItem';
|
|
6
6
|
import './Reports.css';
|
|
7
7
|
const b = block('reports-block');
|
|
8
|
-
|
|
8
|
+
const titleColSizes = {
|
|
9
|
+
all: 12,
|
|
10
|
+
};
|
|
11
|
+
export const ReportsBlock = ({ title, typeKey, empty }) => {
|
|
9
12
|
const data = useContext(ReportsContext);
|
|
10
|
-
const
|
|
13
|
+
const [page, setPage] = useState(1);
|
|
14
|
+
const { selects, items, itemsPerPage, filesOutline } = useMemo(() => data[typeKey], [data, typeKey]);
|
|
11
15
|
const initFilters = useMemo(() => (selects === null || selects === void 0 ? void 0 : selects.reduce((acc, select) => (Object.assign(Object.assign({}, acc), { [select.name]: select.init })), {})) || {}, [selects]);
|
|
12
16
|
const [localFilters, setLocalFilters] = useState(initFilters);
|
|
13
17
|
const handleChange = useCallback((name, value) => setLocalFilters((prev) => (Object.assign(Object.assign({}, prev), { [name]: value }))), []);
|
|
@@ -20,8 +24,19 @@ export const ReportsBlock = ({ typeKey, empty }) => {
|
|
|
20
24
|
return acc;
|
|
21
25
|
}, false))
|
|
22
26
|
: items, [items, localFilters]);
|
|
27
|
+
const paginatedItems = useMemo(() => {
|
|
28
|
+
if (!itemsPerPage)
|
|
29
|
+
return filteredItems;
|
|
30
|
+
const startIndex = (page - 1) * itemsPerPage;
|
|
31
|
+
return filteredItems.slice(startIndex, startIndex + itemsPerPage);
|
|
32
|
+
}, [filteredItems, itemsPerPage, page]);
|
|
33
|
+
const titleProps = !title || typeof title === 'string'
|
|
34
|
+
? { text: title, textSize: 'm' }
|
|
35
|
+
: title;
|
|
23
36
|
return (React.createElement("div", { className: b() },
|
|
37
|
+
title && React.createElement(Title, { className: b('title'), title: titleProps, colSizes: titleColSizes }),
|
|
24
38
|
(selects === null || selects === void 0 ? void 0 : selects.length) && (React.createElement("div", { className: b('select') }, selects.map(({ name, options }) => (React.createElement(Select, { key: name, name: name, options: options, onChange: handleChange }))))),
|
|
25
|
-
|
|
39
|
+
paginatedItems.length ? (paginatedItems.map((item, index) => (React.createElement(ReportsItem, Object.assign({ key: index }, item, { filesOutline: filesOutline }))))) : (React.createElement("div", { className: b('empty') }, empty)),
|
|
40
|
+
itemsPerPage && (React.createElement(Paginator, { page: page, itemsPerPage: itemsPerPage, totalItems: filteredItems.length, maxPages: Infinity, onPageChange: setPage }))));
|
|
26
41
|
};
|
|
27
42
|
export default ReportsBlock;
|