@mailstep/design-system 0.6.3 → 0.6.5-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailstep/design-system",
3
- "version": "0.6.3",
3
+ "version": "0.6.5-beta.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./ui/index.js",
@@ -61,6 +61,6 @@ var StyledCommonGrid = function (props) {
61
61
  gridSelectors: gridSelectors,
62
62
  onClose: onClose,
63
63
  }), columnsConfigValues = _d.columnsConfigValues, setColumnsConfigOptions = _d.setColumnsConfigOptions, onConfirmForm = _d.onConfirmForm, resetColumnConfig = _d.resetColumnConfig;
64
- return (_jsxs(ContentContainer, { children: [_jsxs(CommonGridWrap, { children: [_jsx(HidePrint, { children: _jsxs(StyledButtonStrip, { className: "buttonsStrip", children: [!hideControlButtons && (_jsx(ControlButtons, { extraControlButtons: extraControlButtons, gridActions: gridActions, gridSelectors: gridSelectors, eshopSelect: eshopSelect })), _jsx(StyledColumnButton, { type: "button", sizing: "iconLg", appearance: "ghost", icon: _jsx(Settings2, {}), onClick: openManageColumnForm, children: _jsx(H6, { variant: "semiBold", children: _jsx(Trans, { id: "manageColumn.title", message: "Manage column" }) }) })] }) }), _jsx(CommonGridWithStyles, __assign({}, passDownProps, modifiedPassDownProps, { filters: filters, gridRef: gridRef, height: gridHeight, floatingButtonProps: floatingButtonProps, hasColouredRows: true }))] }), _jsx(HidePrint, { children: _jsxs(BottomWrapper, { ref: paginationRef, isFixed: !!gridHeight, children: [processCheckedValues && (_jsx(ActionHead, { rowsData: rowsData, onBatchAction: onBatchAction, gridActions: gridActions, gridSelectors: gridSelectors, actionColumn: actionColumnDefinition, processCheckedValues: processCheckedValues, processCheckedValuesTitle: processCheckedValuesTitle })), _jsxs(x.div, { display: "flex", justifyContent: "center", alignItems: "center", className: "paginatorWrapper", w: "100%", h: window.innerWidth > 1204 ? '60px' : '32px', children: [_jsx(Pagination, { page: gridSelectors === null || gridSelectors === void 0 ? void 0 : gridSelectors.page, itemCount: passDownProps === null || passDownProps === void 0 ? void 0 : passDownProps.totalRowsCount, itemPerPage: (gridSelectors === null || gridSelectors === void 0 ? void 0 : gridSelectors.rowsPerPage) || 10, onPageChange: gridActions === null || gridActions === void 0 ? void 0 : gridActions.setPage, customPaginationHandler: customPaginationHandler }), _jsx(TablePagination, { gridActions: gridActions, gridSelectors: gridSelectors, customPaginationHandler: customPaginationHandler })] })] }) }), manageColumnFormVisible && (_jsx(Modal, { title: _jsx(Trans, { id: "manageColumn.title", message: "Manage columns" }), onClose: onClose, onCancel: onClose, onExtraAction: resetColumnConfig, onConfirm: onConfirmForm, width: "auto", minWidth: "350px", hasFooter: true, extraActionLabel: _jsx(Trans, { id: "dataGrid.buttonClearConfig", message: "Reset config" }), cancelLabel: _jsx(Trans, { id: "form.buttonCancel", message: "Cancel" }), confirmLabel: _jsx(Trans, { id: "form.buttonConfirm", message: "Confirm" }), children: _jsx(ManageColumnForm, { columns: columns, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions }) }))] }));
64
+ return (_jsxs(ContentContainer, { children: [_jsxs(CommonGridWrap, { children: [_jsx(HidePrint, { children: _jsxs(StyledButtonStrip, { className: "buttonsStrip", children: [!hideControlButtons && (_jsx(ControlButtons, { extraControlButtons: extraControlButtons, gridActions: gridActions, gridSelectors: gridSelectors, eshopSelect: eshopSelect })), _jsx(StyledColumnButton, { type: "button", sizing: "iconLg", appearance: "ghost", icon: _jsx(Settings2, {}), onClick: openManageColumnForm, children: _jsx(H6, { variant: "semiBold", children: _jsx(Trans, { id: "manageColumn.title", message: "Manage column" }) }) })] }) }), _jsx(CommonGridWithStyles, __assign({}, passDownProps, modifiedPassDownProps, { filters: filters, gridRef: gridRef, height: gridHeight, floatingButtonProps: floatingButtonProps, hasColouredRows: true }))] }), _jsx(HidePrint, { children: _jsxs(BottomWrapper, { ref: paginationRef, isFixed: !!gridHeight, children: [processCheckedValues && (_jsx(ActionHead, { rowsData: rowsData, onBatchAction: onBatchAction, gridActions: gridActions, gridSelectors: gridSelectors, actionColumn: actionColumnDefinition, processCheckedValues: processCheckedValues, processCheckedValuesTitle: processCheckedValuesTitle })), _jsxs(x.div, { display: "flex", justifyContent: "center", alignItems: "center", className: "paginatorWrapper", w: "100%", h: window.innerWidth > 1204 ? '60px' : '32px', children: [_jsx(Pagination, { page: gridSelectors === null || gridSelectors === void 0 ? void 0 : gridSelectors.page, itemCount: passDownProps === null || passDownProps === void 0 ? void 0 : passDownProps.totalRowsCount, itemPerPage: (gridSelectors === null || gridSelectors === void 0 ? void 0 : gridSelectors.rowsPerPage) || 10, onPageChange: gridActions === null || gridActions === void 0 ? void 0 : gridActions.setPage, customPaginationHandler: customPaginationHandler, radius: window.innerWidth < 768 ? 3 : 5, rate: window.innerWidth < 768 ? 1 : 4 }), _jsx(TablePagination, { gridActions: gridActions, gridSelectors: gridSelectors, customPaginationHandler: customPaginationHandler })] })] }) }), manageColumnFormVisible && (_jsx(Modal, { title: _jsx(Trans, { id: "manageColumn.title", message: "Manage columns" }), onClose: onClose, onCancel: onClose, onExtraAction: resetColumnConfig, onConfirm: onConfirmForm, width: "auto", minWidth: "350px", hasFooter: true, extraActionLabel: _jsx(Trans, { id: "dataGrid.buttonClearConfig", message: "Reset config" }), cancelLabel: _jsx(Trans, { id: "form.buttonCancel", message: "Cancel" }), confirmLabel: _jsx(Trans, { id: "form.buttonConfirm", message: "Confirm" }), children: _jsx(ManageColumnForm, { columns: columns, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions }) }))] }));
65
65
  };
66
66
  export default StyledCommonGrid;
@@ -1,9 +1,11 @@
1
- export type Props = {
1
+ export type PaginationProps = {
2
2
  page?: number;
3
3
  itemCount?: number;
4
4
  itemPerPage: number;
5
+ radius?: number;
6
+ rate?: number;
5
7
  onPageChange?: (number: number, rows: number) => void;
6
8
  customPaginationHandler?: (page: number, rows: number) => void;
7
9
  };
8
- declare const Pagination: ({ onPageChange, itemPerPage, itemCount, page, customPaginationHandler }: Props) => JSX.Element;
10
+ declare const Pagination: ({ onPageChange, itemPerPage, itemCount, page, radius, rate, customPaginationHandler, }: PaginationProps) => JSX.Element;
9
11
  export default Pagination;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useMemo } from 'react';
3
3
  import { Btn, GoIcon, Wrapper, PageBtn, DotsWrapper } from './styled';
4
4
  var Pagination = function (_a) {
5
- var onPageChange = _a.onPageChange, itemPerPage = _a.itemPerPage, itemCount = _a.itemCount, page = _a.page, customPaginationHandler = _a.customPaginationHandler;
5
+ var onPageChange = _a.onPageChange, _b = _a.itemPerPage, itemPerPage = _b === void 0 ? 3 : _b, _c = _a.itemCount, itemCount = _c === void 0 ? 0 : _c, page = _a.page, _d = _a.radius, radius = _d === void 0 ? 5 : _d, _e = _a.rate, rate = _e === void 0 ? 4 : _e, customPaginationHandler = _a.customPaginationHandler;
6
6
  var setPage = useCallback(function (number) { return function () {
7
7
  if (customPaginationHandler) {
8
8
  customPaginationHandler(number, itemPerPage);
@@ -13,31 +13,27 @@ var Pagination = function (_a) {
13
13
  }
14
14
  }; }, [itemPerPage, onPageChange, customPaginationHandler]);
15
15
  var pageX = page !== null && page !== void 0 ? page : 1;
16
- var pageCount = Math.max(Math.ceil((itemCount !== null && itemCount !== void 0 ? itemCount : 0) / (itemPerPage !== null && itemPerPage !== void 0 ? itemPerPage : 3)), 1);
16
+ var pageCount = Math.max(Math.ceil(itemCount / itemPerPage), 1);
17
17
  var arrayOfPages = useMemo(function () {
18
18
  var pageNumbers = Array.from({ length: pageCount }, function (_, i) { return i + 1; });
19
19
  // first and last page are still visible
20
20
  // if number of pages is less than 6 (display all pages without dots and duplication of first and last char)
21
- if (pageCount < 6) {
21
+ if (pageCount < radius + 1) {
22
22
  return pageNumbers.slice(1, pageCount - 1);
23
- // if current page is less than 5 (display first 5 pages)
23
+ // if current page is less than radius (display first radius pages)
24
24
  }
25
- else if (pageX < 5) {
26
- return pageNumbers.slice(1, 5);
27
- // display last 5 pages
25
+ else if (pageX < radius) {
26
+ return pageNumbers.slice(1, Math.min(pageX + rate, radius));
27
+ // display last radius pages
28
28
  }
29
- else if (pageX > pageCount - 4) {
30
- return pageNumbers.slice(pageCount - 5, pageCount - 1);
31
- }
32
- else if (window.innerWidth < 768) {
33
- // display dispersion of 1 chars from current page (part between dots)
34
- return pageNumbers.slice(pageX - 2, pageX + 1);
29
+ else if (pageX > pageCount - Math.floor(radius / 2)) {
30
+ return pageNumbers.slice(pageCount - rate - 1, pageCount - 1);
35
31
  }
36
32
  else {
37
33
  // display dispersion of 2 chars from current page (part between dots)
38
- return pageNumbers.slice(pageX - 3, pageX + 2);
34
+ return pageNumbers.slice(pageX - Math.ceil(radius / 2), Math.min(pageX + Math.floor(radius / 2), pageCount - 1));
39
35
  }
40
36
  }, [pageCount, pageX]);
41
- return (_jsxs(Wrapper, { children: [_jsx(Btn, { disabled: pageX <= 1, onClick: setPage(pageX - 1), children: _jsx(GoIcon, { icon: "goLeft", isActive: pageX > 1 }) }), _jsx(PageBtn, { isCurrent: pageX === 1, onClick: setPage(1), children: 1 }), pageX >= 5 && pageCount > 6 && _jsx(DotsWrapper, { children: "..." }), arrayOfPages === null || arrayOfPages === void 0 ? void 0 : arrayOfPages.map(function (number) { return (_jsx(PageBtn, { isCurrent: pageX === number, onClick: setPage(number !== null && number !== void 0 ? number : 1), children: number }, number)); }), pageX < pageCount - 3 && pageCount > 6 && _jsx(DotsWrapper, { children: "..." }), pageCount !== 1 && (_jsx(PageBtn, { isCurrent: pageX === pageCount, onClick: setPage(pageCount), children: pageCount })), _jsx(Btn, { disabled: pageX >= pageCount, onClick: setPage(pageX + 1), children: _jsx(GoIcon, { icon: "goRight", isActive: pageX < pageCount }) })] }));
37
+ return (_jsxs(Wrapper, { children: [_jsx(Btn, { disabled: pageX <= 1, onClick: setPage(pageX - 1), children: _jsx(GoIcon, { icon: "goLeft", isActive: pageX > 1 }) }), _jsx(PageBtn, { isCurrent: pageX === 1, onClick: setPage(1), children: 1 }), arrayOfPages[0] > 2 && _jsx(DotsWrapper, { children: "..." }), arrayOfPages === null || arrayOfPages === void 0 ? void 0 : arrayOfPages.map(function (number) { return (_jsx(PageBtn, { isCurrent: pageX === number, onClick: setPage(number !== null && number !== void 0 ? number : 1), children: number }, number)); }), arrayOfPages[arrayOfPages.length - 1] < pageCount - 1 && _jsx(DotsWrapper, { children: "..." }), pageCount !== 1 && (_jsx(PageBtn, { isCurrent: pageX === pageCount, onClick: setPage(pageCount), children: pageCount })), _jsx(Btn, { disabled: pageX >= pageCount, onClick: setPage(pageX + 1), children: _jsx(GoIcon, { icon: "goRight", isActive: pageX < pageCount }) })] }));
42
38
  };
43
39
  export default Pagination;
@@ -1,3 +1,4 @@
1
1
  import Pagination from './Pagination';
2
+ export type { PaginationProps } from './Pagination';
2
3
  export { Pagination };
3
4
  export default Pagination;
@@ -1,8 +1,8 @@
1
- /// <reference types="react" />
2
1
  import type { StoryObj } from '@storybook/react';
2
+ import { PaginationProps } from '../';
3
3
  declare const meta: {
4
4
  title: string;
5
- component: ({ onPageChange, itemPerPage, itemCount, page, customPaginationHandler }: import("../Pagination").Props) => JSX.Element;
5
+ component: ({ onPageChange, itemPerPage, itemCount, page, radius, rate, customPaginationHandler, }: PaginationProps) => JSX.Element;
6
6
  tags: string[];
7
7
  argTypes: {};
8
8
  };
@@ -10,3 +10,4 @@ export default meta;
10
10
  type Story = StoryObj<typeof meta>;
11
11
  export declare const Default: Story;
12
12
  export declare const ManyPages: Story;
13
+ export declare const Shorter: Story;
@@ -1,3 +1,16 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useState } from 'react';
1
14
  import { Pagination } from '../';
2
15
  var meta = {
3
16
  title: 'Elements/Pagination',
@@ -6,17 +19,30 @@ var meta = {
6
19
  argTypes: {},
7
20
  };
8
21
  export default meta;
22
+ var withSetState = function (arg) {
23
+ var _a = useState(1), page = _a[0], setPage = _a[1];
24
+ return _jsx(Pagination, __assign({}, arg, { page: page, onPageChange: setPage }));
25
+ };
9
26
  export var Default = {
10
27
  args: {
11
28
  itemCount: 100,
12
29
  itemPerPage: 8,
13
- page: 1,
14
30
  },
31
+ render: withSetState,
15
32
  };
16
33
  export var ManyPages = {
17
34
  args: {
18
35
  itemCount: 1000,
19
36
  itemPerPage: 8,
20
- page: 1,
21
37
  },
38
+ render: withSetState,
39
+ };
40
+ export var Shorter = {
41
+ args: {
42
+ itemCount: 100,
43
+ itemPerPage: 8,
44
+ radius: 3,
45
+ rate: 1,
46
+ },
47
+ render: withSetState,
22
48
  };