@mailstep/design-system 0.7.8-beta.1 → 0.7.8-beta.5

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.7.8-beta.1",
3
+ "version": "0.7.8-beta.5",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./ui/index.js",
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
24
- import { useEffect, useMemo, useState } from 'react';
24
+ import { useMemo, useState } from 'react';
25
25
  import { Pagination } from '../../Elements/Pagination';
26
26
  import HidePrint from '../HidePrint/HidePrint';
27
27
  import { useModal } from '../Modal/hooks/useModal';
@@ -36,23 +36,14 @@ import { usePresetState } from './hooks/usePresetsState';
36
36
  import { x } from '@xstyled/styled-components';
37
37
  import { CommonGridWithStyles, BottomWrapper, CommonGridWrap, ContentContainer, StyledButtonStrip } from './styles';
38
38
  import { getFilters } from './utils';
39
+ import { useGridAutoHeight } from './hooks/useGridAutoHeight';
39
40
  var CommonGridContainer = function (props) {
40
41
  var _a;
41
42
  var _b = props.optimizeFilters, optimizeFilters = _b === void 0 ? false : _b, extraControlButtons = props.extraControlButtons, onBatchAction = props.onBatchAction, processCheckedValues = props.processCheckedValues, processCheckedValuesTitle = props.processCheckedValuesTitle, hideControlButtons = props.hideControlButtons, quickFilter = props.quickFilter, floatingButtonProps = props.floatingButtonProps, queryRowsParam = props.queryRowsParam, customPaginationHandler = props.customPaginationHandler, _c = props.autoHeight, autoHeight = _c === void 0 ? true : _c, gridName = props.gridName, _d = props.withPresets, withPresets = _d === void 0 ? true : _d, getRowsPerPage = props.getRowsPerPage, passDownProps = __rest(props, ["optimizeFilters", "extraControlButtons", "onBatchAction", "processCheckedValues", "processCheckedValuesTitle", "hideControlButtons", "quickFilter", "floatingButtonProps", "queryRowsParam", "customPaginationHandler", "autoHeight", "gridName", "withPresets", "getRowsPerPage"]);
42
43
  var gridActions = passDownProps.gridActions, gridSelectors = passDownProps.gridSelectors, rowsData = passDownProps.rowsData, actionColumnDefinition = passDownProps.actionColumnDefinition;
43
44
  var _e = useState(false), displayManageColumnButton = _e[0], setDisplayManageColumnButton = _e[1];
44
45
  var _f = useGetGridHeight(), gridHeight = _f.gridHeight, gridRef = _f.gridRef, paginationRef = _f.paginationRef;
45
- useEffect(function () {
46
- var _a;
47
- if (!queryRowsParam && gridHeight && gridHeight > 0) {
48
- // @TODO this move to mailship
49
- // const numberOfRows = Math.max(Math.floor(gridHeight / rowHeight - 2), GRID_MIN_ROWS)
50
- var numberOfRows = getRowsPerPage === null || getRowsPerPage === void 0 ? void 0 : getRowsPerPage(gridHeight);
51
- if (autoHeight && numberOfRows) {
52
- (_a = gridActions.setRowsPerPage) === null || _a === void 0 ? void 0 : _a.call(gridActions, numberOfRows);
53
- }
54
- }
55
- }, [gridHeight, gridActions, queryRowsParam]);
46
+ useGridAutoHeight({ gridHeight: gridHeight, autoHeight: autoHeight, gridActions: gridActions, queryRowsParam: queryRowsParam, rowsPerPage: gridSelectors.rowsPerPage, getRowsPerPage: getRowsPerPage });
56
47
  var modifiedPassDownProps = useEditReadAsColumn(passDownProps);
57
48
  var filters = useMemo(function () { return getFilters(optimizeFilters); }, [optimizeFilters]);
58
49
  var columns = modifiedPassDownProps.columnsDefinitions;
@@ -2,33 +2,42 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
2
2
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
3
  return cooked;
4
4
  };
5
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
6
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
7
+ if (ar || !(i in from)) {
8
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
9
+ ar[i] = from[i];
10
+ }
11
+ }
12
+ return to.concat(ar || Array.prototype.slice.call(from));
13
+ };
5
14
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- import { useCallback } from 'react';
15
+ import { useCallback, useMemo } from 'react';
7
16
  import Select from '../../../../Elements/Select/Select';
8
17
  import { Paragraph4 } from '../../../../Elements/Typography/Typography';
18
+ import { rowsPerPageOptions } from '../../utils/constants';
9
19
  import { Trans } from '@lingui/react';
10
20
  import styled, { x } from '@xstyled/styled-components';
11
21
  var Wrapper = styled.span(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n & > :nth-child(2) {\n display: none;\n @media (min-width: 1024px) {\n display: block;\n }\n }\n"], ["\n display: flex;\n align-items: center;\n & > :nth-child(2) {\n display: none;\n @media (min-width: 1024px) {\n display: block;\n }\n }\n"])));
12
22
  var StyledSelect = styled(x.div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-right: 15px;\n @media (min-width: 1024px) {\n margin-right: 8px;\n }\n"], ["\n margin-right: 15px;\n @media (min-width: 1024px) {\n margin-right: 8px;\n }\n"])));
13
- var rowsPerPageOptions = [
14
- { value: 10, label: 10 },
15
- { value: 20, label: 20 },
16
- { value: 50, label: 50 },
17
- { value: 100, label: 100 },
18
- { value: 'auto', label: 'auto' },
19
- ];
20
23
  var TablePagination = function (_a) {
21
24
  var gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, getRowsPerPage = _a.getRowsPerPage, gridHeight = _a.gridHeight, customPaginationHandler = _a.customPaginationHandler;
22
25
  var setRowsPerPage = gridActions.setRowsPerPage;
23
26
  var page = gridSelectors.page;
27
+ var rowsPerPage = gridSelectors.rowsPerPage;
28
+ var rowsPerPageAuto = useMemo(function () { return getRowsPerPage && getRowsPerPage(gridHeight); }, [getRowsPerPage, gridHeight]);
24
29
  var onSetRowsPerPage = useCallback(function (option) {
25
30
  if (option && 'value' in option) {
26
- var value = option.value !== 'auto' ? Number(option.value) : ((getRowsPerPage === null || getRowsPerPage === void 0 ? void 0 : getRowsPerPage(gridHeight)) || 10); // @TODO use 10 from constants
27
- setRowsPerPage === null || setRowsPerPage === void 0 ? void 0 : setRowsPerPage(Number(option.value));
28
- customPaginationHandler === null || customPaginationHandler === void 0 ? void 0 : customPaginationHandler(page !== null && page !== void 0 ? page : 1, Number(option.value));
31
+ var value = Number(option.value);
32
+ if (option.value === 'auto') {
33
+ value = (getRowsPerPage === null || getRowsPerPage === void 0 ? void 0 : getRowsPerPage(gridHeight)) || 10; // @TODO use 10 from constants
34
+ }
35
+ setRowsPerPage === null || setRowsPerPage === void 0 ? void 0 : setRowsPerPage(value);
36
+ customPaginationHandler === null || customPaginationHandler === void 0 ? void 0 : customPaginationHandler(page !== null && page !== void 0 ? page : 1, value);
29
37
  }
30
38
  }, [setRowsPerPage, page, customPaginationHandler]);
31
- return (_jsxs(Wrapper, { children: [_jsx(StyledSelect, { minWidth: "80px", children: _jsx(Select, { name: "rowsPerPage", menuPlacement: "top", style: "gridFilter", placeholder: "".concat(gridSelectors.rowsPerPage), options: rowsPerPageOptions, value: gridSelectors.rowsPerPage, isDarkPlaceholderText: true, onChange: onSetRowsPerPage }) }), _jsx(Paragraph4, { variant: "normal", mr: "20px", children: _jsx(Trans, { id: "dataGrid.resultsPerPage", message: "Results per page" }) })] }));
39
+ var options = useMemo(function () { return (rowsPerPageAuto ? __spreadArray(__spreadArray([], rowsPerPageOptions, true), [{ value: rowsPerPageAuto, label: rowsPerPageAuto }], false) : rowsPerPageOptions); }, [rowsPerPageAuto, rowsPerPageAuto]);
40
+ return (_jsxs(Wrapper, { children: [_jsx(StyledSelect, { minWidth: "80px", children: _jsx(Select, { name: "rowsPerPage", menuPlacement: "top", style: "gridFilter", placeholder: "".concat(rowsPerPage), options: options, value: rowsPerPage, isDarkPlaceholderText: true, onChange: onSetRowsPerPage }) }), _jsx(Paragraph4, { variant: "normal", mr: "20px", children: _jsx(Trans, { id: "dataGrid.resultsPerPage", message: "Results per page" }) })] }));
32
41
  };
33
42
  export default TablePagination;
34
43
  var templateObject_1, templateObject_2;
@@ -0,0 +1,12 @@
1
+ import { GridActionsType } from '../types';
2
+ type Props = {
3
+ gridHeight?: number;
4
+ gridActions: GridActionsType;
5
+ queryRowsParam?: number | string;
6
+ getRowsPerPage?: (height?: number) => number;
7
+ autoHeight: boolean;
8
+ rowsPerPage?: number;
9
+ };
10
+ type HookType = (props: Props) => void;
11
+ export declare const useGridAutoHeight: HookType;
12
+ export {};
@@ -0,0 +1,21 @@
1
+ import { useEffect } from 'react';
2
+ // import { GRID_MIN_ROWS, rowHeight } from './utils'
3
+ import { rowsPerPageOptions } from '../utils/constants';
4
+ export var useGridAutoHeight = function (_a) {
5
+ var gridHeight = _a.gridHeight, gridActions = _a.gridActions, queryRowsParam = _a.queryRowsParam, rowsPerPage = _a.rowsPerPage, getRowsPerPage = _a.getRowsPerPage, autoHeight = _a.autoHeight;
6
+ useEffect(function () {
7
+ var _a;
8
+ if (!autoHeight || queryRowsParam || !gridHeight || gridHeight <= 0) {
9
+ return;
10
+ }
11
+ var selectedOption = rowsPerPageOptions.find(function (option) { return option.value === rowsPerPage; });
12
+ if (!selectedOption) {
13
+ // @TODO this move to mailship
14
+ // const numberOfRows = Math.max(Math.floor(gridHeight / rowHeight - 2), GRID_MIN_ROWS)
15
+ var numberOfRows = getRowsPerPage === null || getRowsPerPage === void 0 ? void 0 : getRowsPerPage(gridHeight);
16
+ if (numberOfRows) {
17
+ (_a = gridActions.setRowsPerPage) === null || _a === void 0 ? void 0 : _a.call(gridActions, numberOfRows);
18
+ }
19
+ }
20
+ }, [gridHeight, gridActions, queryRowsParam]);
21
+ };
@@ -22,6 +22,7 @@ var FilterSetter = function (_a) {
22
22
  }, []);
23
23
  return null;
24
24
  };
25
+ var getRowsPerPage = function (height) { return 13; };
25
26
  var ConnectedFilterSetter = withReduxActions('testGrid')(FilterSetter);
26
27
  var extraControlButtons = [
27
28
  {
@@ -45,7 +46,7 @@ export default {
45
46
  title: 'Blocks/CommonGrid',
46
47
  decorators: [withRedux]
47
48
  };
48
- export var ComplexWithPaginationAndRedux = function () { return (_jsxs(LinguiContainer, { children: [_jsx(ConnectedFilterSetter, { gridActions: gridDummyActions }), _jsx(ReduxGrid, { columnsDefinitions: columnDefinitions, actionColumnDefinition: ActionColumnButtons, rowsData: createRandomData(10), onRowAction: onRowAction, onRowReadClick: onRowReadClick, onRowEditClick: onRowEditClick, totalRowsCount: 200, onBatchAction: onBatchAction, quickFilter: "productSku", extraControlButtons: extraControlButtons, comparators: comparators, gridName: "gridName" })] })); };
49
+ export var ComplexWithPaginationAndRedux = function () { return (_jsxs(LinguiContainer, { children: [_jsx(ConnectedFilterSetter, { gridActions: gridDummyActions }), _jsx(ReduxGrid, { columnsDefinitions: columnDefinitions, actionColumnDefinition: ActionColumnButtons, rowsData: createRandomData(10), onRowAction: onRowAction, onRowReadClick: onRowReadClick, onRowEditClick: onRowEditClick, totalRowsCount: 200, onBatchAction: onBatchAction, getRowsPerPage: getRowsPerPage, quickFilter: "productSku", extraControlButtons: extraControlButtons, comparators: comparators, gridName: "gridName" })] })); };
49
50
  ComplexWithPaginationAndRedux.story = {
50
51
  name: 'Complex, with pagination and redux'
51
52
  };
@@ -1 +1,5 @@
1
1
  export declare const presetsLocalStorageKey = "commonGridPresets";
2
+ export declare const rowsPerPageOptions: {
3
+ value: number;
4
+ label: number;
5
+ }[];
@@ -1 +1,7 @@
1
1
  export var presetsLocalStorageKey = 'commonGridPresets';
2
+ export var rowsPerPageOptions = [
3
+ { value: 10, label: 10 },
4
+ { value: 20, label: 20 },
5
+ { value: 50, label: 50 },
6
+ { value: 100, label: 100 }
7
+ ];