@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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/build/cjs/blocks/Reports/Reports.css +3 -0
  3. package/build/cjs/blocks/Reports/Reports.d.ts +1 -1
  4. package/build/cjs/blocks/Reports/Reports.js +18 -3
  5. package/build/cjs/blocks/Reports/schema.d.ts +32 -0
  6. package/build/cjs/blocks/Reports/schema.js +10 -1
  7. package/build/cjs/components/Paginator/Paginator.css +61 -0
  8. package/build/cjs/components/Paginator/Paginator.d.ts +3 -0
  9. package/build/cjs/components/Paginator/Paginator.js +87 -0
  10. package/build/cjs/components/Paginator/components/NavigationButton.d.ts +6 -0
  11. package/build/cjs/components/Paginator/components/NavigationButton.js +22 -0
  12. package/build/cjs/components/Paginator/components/PaginatorItem.d.ts +2 -0
  13. package/build/cjs/components/Paginator/components/PaginatorItem.js +15 -0
  14. package/build/cjs/components/Paginator/i18n/en.json +4 -0
  15. package/build/cjs/components/Paginator/i18n/index.d.ts +1 -0
  16. package/build/cjs/components/Paginator/i18n/index.js +9 -0
  17. package/build/cjs/components/Paginator/i18n/ru.json +4 -0
  18. package/build/cjs/components/Paginator/types.d.ts +28 -0
  19. package/build/cjs/components/Paginator/types.js +8 -0
  20. package/build/cjs/components/Paginator/utils.d.ts +3 -0
  21. package/build/cjs/components/Paginator/utils.js +71 -0
  22. package/build/cjs/components/index.d.ts +1 -0
  23. package/build/cjs/components/index.js +3 -1
  24. package/build/cjs/constructor-items.d.ts +1 -1
  25. package/build/cjs/context/reportsContext/ReportsContext.d.ts +1 -0
  26. package/build/cjs/icons/ArrowLeftIcon.d.ts +2 -0
  27. package/build/cjs/icons/ArrowLeftIcon.js +9 -0
  28. package/build/cjs/icons/ArrowRightIcon.d.ts +2 -0
  29. package/build/cjs/icons/ArrowRightIcon.js +9 -0
  30. package/build/cjs/icons/index.d.ts +2 -0
  31. package/build/cjs/icons/index.js +2 -0
  32. package/build/cjs/models/constructor-items/blocks.d.ts +1 -0
  33. package/build/esm/blocks/Reports/Reports.css +3 -0
  34. package/build/esm/blocks/Reports/Reports.d.ts +1 -1
  35. package/build/esm/blocks/Reports/Reports.js +19 -4
  36. package/build/esm/blocks/Reports/schema.d.ts +32 -0
  37. package/build/esm/blocks/Reports/schema.js +11 -2
  38. package/build/esm/components/Paginator/Paginator.css +61 -0
  39. package/build/esm/components/Paginator/Paginator.d.ts +4 -0
  40. package/build/esm/components/Paginator/Paginator.js +84 -0
  41. package/build/esm/components/Paginator/components/NavigationButton.d.ts +6 -0
  42. package/build/esm/components/Paginator/components/NavigationButton.js +17 -0
  43. package/build/esm/components/Paginator/components/PaginatorItem.d.ts +2 -0
  44. package/build/esm/components/Paginator/components/PaginatorItem.js +10 -0
  45. package/build/esm/components/Paginator/i18n/en.json +4 -0
  46. package/build/esm/components/Paginator/i18n/index.d.ts +1 -0
  47. package/build/esm/components/Paginator/i18n/index.js +5 -0
  48. package/build/esm/components/Paginator/i18n/ru.json +4 -0
  49. package/build/esm/components/Paginator/types.d.ts +28 -0
  50. package/build/esm/components/Paginator/types.js +5 -0
  51. package/build/esm/components/Paginator/utils.d.ts +3 -0
  52. package/build/esm/components/Paginator/utils.js +66 -0
  53. package/build/esm/components/index.d.ts +1 -0
  54. package/build/esm/components/index.js +1 -0
  55. package/build/esm/constructor-items.d.ts +1 -1
  56. package/build/esm/context/reportsContext/ReportsContext.d.ts +1 -0
  57. package/build/esm/icons/ArrowLeftIcon.d.ts +2 -0
  58. package/build/esm/icons/ArrowLeftIcon.js +4 -0
  59. package/build/esm/icons/ArrowRightIcon.d.ts +2 -0
  60. package/build/esm/icons/ArrowRightIcon.js +4 -0
  61. package/build/esm/icons/index.d.ts +2 -0
  62. package/build/esm/icons/index.js +2 -0
  63. package/build/esm/models/constructor-items/blocks.d.ts +1 -0
  64. package/package.json +1 -1
  65. package/schema/index.js +1 -1
  66. package/server/models/constructor-items/blocks.d.ts +1 -0
  67. package/widget/index.js +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @gravity-ui/page-constructor · [![npm package](https://img.shields.io/npm/v/@gravity-ui/page-constructor)](https://www.npmjs.com/package/@gravity-ui/page-constructor) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/page-constructor/ci.yml?branch=main&label=CI)](https://github.com/gravity-ui/page-constructor/actions/workflows/ci.yml?query=branch:main) [![Release](https://img.shields.io/github/actions/workflow/status/gravity-ui/page-constructor/release.yml?branch=main&label=Release)](https://github.com/gravity-ui/page-constructor/actions/workflows/release.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.gravity-ui.com/page-constructor/)
1
+ # @gravity-ui/page-constructor · [![npm package](https://img.shields.io/npm/v/@gravity-ui/page-constructor)](https://www.npmjs.com/package/@gravity-ui/page-constructor) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/page-constructor/ci.yml?branch=main&label=CI)](https://github.com/gravity-ui/page-constructor/actions/workflows/ci.yml?query=branch:main) [![Release](https://img.shields.io/github/actions/workflow/status/gravity-ui/page-constructor/release.yml?branch=main&label=Release)](https://github.com/gravity-ui/page-constructor/actions/workflows/release.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://doyourjob-agency.github.io/page-constructor/main/)
2
2
 
3
3
  ## Page constructor
4
4
 
@@ -1,5 +1,8 @@
1
1
  /* use this for style redefinitions to awoid problems with
2
2
  unpredictable css rules order in build */
3
+ .pc-reports-block__title {
4
+ margin-bottom: 24px;
5
+ }
3
6
  .pc-reports-block__select {
4
7
  margin-bottom: 32px;
5
8
  }
@@ -1,3 +1,3 @@
1
1
  import { ReportsBlockProps } from '../../models';
2
- export declare const ReportsBlock: ({ typeKey, empty }: ReportsBlockProps) => JSX.Element;
2
+ export declare const ReportsBlock: ({ title, typeKey, empty }: ReportsBlockProps) => JSX.Element;
3
3
  export default ReportsBlock;
@@ -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 ReportsBlock = ({ typeKey, empty }) => {
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 { selects, items, filesOutline } = (0, react_1.useMemo)(() => data[typeKey], [data, typeKey]);
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
- filteredItems.length ? (filteredItems === null || filteredItems === void 0 ? void 0 : filteredItems.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))));
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), { typeKey: {
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,3 @@
1
+ import { PaginatorProps } from './types';
2
+ export declare const Paginator: ({ itemsPerPage, totalItems, maxPages, page, className, onPageChange, pageCountForShowSupportButtons, }: PaginatorProps) => JSX.Element | null;
3
+ export default Paginator;
@@ -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,6 @@
1
+ import { ArrowType } from '../types';
2
+ export type NavigationButtonProps = {
3
+ arrowType: ArrowType;
4
+ disabled?: boolean;
5
+ };
6
+ export declare const NavigationButton: ({ arrowType, disabled }: NavigationButtonProps) => JSX.Element | null;
@@ -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,2 @@
1
+ import { PaginatorItemProps } from '../types';
2
+ export declare const PaginatorItem: ({ dataKey, mods, content, onClick }: PaginatorItemProps) => JSX.Element;
@@ -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,4 @@
1
+ {
2
+ "prev": "Previous",
3
+ "next": "Next"
4
+ }
@@ -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,4 @@
1
+ {
2
+ "prev": "Предыдущая",
3
+ "next": "Следующая"
4
+ }
@@ -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,2 @@
1
+ import React from 'react';
2
+ export declare const ArrowLeftIcon: (props: React.SVGProps<SVGSVGElement>) => JSX.Element;
@@ -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,2 @@
1
+ import React from 'react';
2
+ export declare const ArrowRightIcon: (props: React.SVGProps<SVGSVGElement>) => JSX.Element;
@@ -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;
@@ -2,3 +2,5 @@ export * from './Chevron';
2
2
  export * from './Github';
3
3
  export * from './NavigationChevron';
4
4
  export * from './NavigationArrow';
5
+ export * from './ArrowLeftIcon';
6
+ export * from './ArrowRightIcon';
@@ -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);
@@ -389,6 +389,7 @@ export interface ReportsItemProps extends ReportsItem {
389
389
  filesOutline?: boolean;
390
390
  }
391
391
  export interface ReportsBlockProps {
392
+ title?: TitleItemBaseProps | string;
392
393
  typeKey: string;
393
394
  empty?: string;
394
395
  }
@@ -1,5 +1,8 @@
1
1
  /* use this for style redefinitions to awoid problems with
2
2
  unpredictable css rules order in build */
3
+ .pc-reports-block__title {
4
+ margin-bottom: 24px;
5
+ }
3
6
  .pc-reports-block__select {
4
7
  margin-bottom: 32px;
5
8
  }
@@ -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
- export const ReportsBlock = ({ typeKey, empty }) => {
8
+ const titleColSizes = {
9
+ all: 12,
10
+ };
11
+ export const ReportsBlock = ({ title, typeKey, empty }) => {
9
12
  const data = useContext(ReportsContext);
10
- const { selects, items, filesOutline } = useMemo(() => data[typeKey], [data, typeKey]);
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
- filteredItems.length ? (filteredItems === null || filteredItems === void 0 ? void 0 : filteredItems.map((item, index) => (React.createElement(ReportsItem, Object.assign({ key: index }, item, { filesOutline: filesOutline }))))) : (React.createElement("div", { className: b('empty') }, empty))));
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;