@mailstep/design-system 0.11.1 → 0.12.0-beta.2

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.11.1",
3
+ "version": "0.12.0-beta.2",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./ui/index.js",
@@ -5,8 +5,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
5
5
  //#region packages/ui/Blocks/CommonGrid/components/Filters/ActionsFilter/ActionsFilter.tsx
6
6
  const ActionsFilter = ({ actionColumn, rowsData, uxState, handleUxChange }) => {
7
7
  const [allChecked, toggleCheckbox] = useToggleAllCheckbox(rowsData, uxState, handleUxChange);
8
- const displayRowNumberLabel = actionColumn?.addRowNumbers;
9
- const rowsNumberLabel = actionColumn?.addRowNumbersLabel ?? "#";
8
+ const rowsNumberLabel = actionColumn?.addRowNumbersLabel;
10
9
  const displayCheckbox = actionColumn?.actionOptions?.length || actionColumn?.forceCheckboxes;
11
10
  return /* @__PURE__ */ jsxs(x.div, {
12
11
  display: "flex",
@@ -21,7 +20,7 @@ const ActionsFilter = ({ actionColumn, rowsData, uxState, handleUxChange }) => {
21
20
  onChange: toggleCheckbox,
22
21
  label: ""
23
22
  }, "check-all")
24
- }), displayRowNumberLabel && /* @__PURE__ */ jsx(x.div, {
23
+ }), actionColumn?.addRowNumbersLabel && /* @__PURE__ */ jsx(x.div, {
25
24
  w: "100%",
26
25
  pr: "12px",
27
26
  display: "flex",
@@ -19,7 +19,6 @@ const IconButtonInCell = ({ icon, isLoading, onClick, linkTo }) => {
19
19
  "data-cy": `${icon ?? ""}IconBtn`,
20
20
  cursor: "pointer",
21
21
  h: "100%",
22
- w: "100%",
23
22
  display: "flex",
24
23
  alignItems: "center",
25
24
  justifyContent: "center",
@@ -5,6 +5,7 @@ type Props = DataCellProps<{
5
5
  }> & {
6
6
  addRowNumbers?: boolean;
7
7
  rowIndex?: number;
8
+ rowNumberWidth?: number;
8
9
  actionColumnDefinition?: ActionColumn;
9
10
  checkedRows?: UxState['checkedRows'];
10
11
  onUxChange?: GridActionsType['handleUxChange'];
@@ -3,9 +3,9 @@ import { IconButtonInCell } from "./IconButtonInCell.js";
3
3
  import { useCallback, useMemo } from "react";
4
4
  import { x } from "@xstyled/styled-components";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { isFunction } from "lodash/fp";
6
+ import { isFunction, omit } from "lodash/fp";
7
7
  //#region packages/ui/Blocks/CommonGrid/components/gridCells/RowActionsCell.tsx
8
- const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowIndex, checkedRows, withCheckboxes, onUxChange, onRowAction }) => {
8
+ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowIndex, rowNumberWidth = 0, checkedRows, withCheckboxes, onUxChange, onRowAction }) => {
9
9
  const rowDataId = rowData?.id;
10
10
  const canEdit = isFunction(actionColumnDefinition?.canRowEdit) ? actionColumnDefinition?.canRowEdit(rowData) : actionColumnDefinition?.canRowEdit;
11
11
  const canRead = isFunction(actionColumnDefinition?.canRowRead) ? actionColumnDefinition?.canRowRead(rowData) : actionColumnDefinition?.canRowRead;
@@ -26,9 +26,10 @@ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowInd
26
26
  }, [canEdit, rowData?.id]);
27
27
  const isChecked = !!checkedRows?.[rowDataId];
28
28
  const onCheckboxChange = useCallback(() => {
29
- const newCheckedRows = { ...checkedRows || {} };
30
- if (!isChecked) newCheckedRows[rowDataId] = true;
31
- else delete newCheckedRows[rowDataId];
29
+ const newCheckedRows = isChecked ? omit(rowDataId, checkedRows || {}) : {
30
+ ...checkedRows || {},
31
+ [rowDataId]: true
32
+ };
32
33
  onUxChange?.("checkedRows", newCheckedRows);
33
34
  }, [
34
35
  onUxChange,
@@ -40,14 +41,13 @@ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowInd
40
41
  if (isFunction(onClick)) onClick();
41
42
  }, [onClick]);
42
43
  return /* @__PURE__ */ jsxs(x.div, {
43
- w: "100%",
44
44
  display: "flex",
45
- gap: "16px",
45
+ gap: addRowNumbers ? "12px" : "18px",
46
46
  pl: "4px",
47
47
  pr: "4px",
48
48
  children: [
49
49
  withCheckboxes && /* @__PURE__ */ jsx(x.div, {
50
- w: "100%",
50
+ w: "18px",
51
51
  children: /* @__PURE__ */ jsx(Checkbox_default, {
52
52
  checked: isChecked,
53
53
  onChange: onCheckboxChange,
@@ -58,8 +58,8 @@ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowInd
58
58
  display: "flex",
59
59
  alignItems: "center",
60
60
  justifyContent: "center",
61
- pr: "8px",
62
- w: "100%",
61
+ w: `${rowNumberWidth}px`,
62
+ flexShrink: 0,
63
63
  children: rowIndex
64
64
  }),
65
65
  canEdit && /* @__PURE__ */ jsx(IconButtonInCell, {
@@ -1,3 +1,4 @@
1
+ import { getActionsColumnExtraWidth, getRowNumbersExtraWidth } from "../utils/index.js";
1
2
  import "../types.js";
2
3
  import withProps from "../HoC/withProps.js";
3
4
  import { RowActionsCell } from "../components/gridCells/RowActionsCell.js";
@@ -5,25 +6,35 @@ import "../components/gridCells/index.js";
5
6
  import { useCallback, useMemo } from "react";
6
7
  //#region packages/ui/Blocks/CommonGrid/hooks/useEditReadAsColumn.tsx
7
8
  const useEditReadAsColumn = (props) => {
8
- const { onRowAction, actionColumnDefinition, columnsDefinitions, gridSelectors, gridActions, onRowEditClick, onRowReadClick } = props;
9
+ const { onRowAction, actionColumnDefinition, columnsDefinitions, gridSelectors, gridActions, onRowEditClick, onRowReadClick, rowsData } = props;
9
10
  const modifiedOnRowAction = useCallback((id, field, value, rowData) => {
10
11
  if (field === "row_edit" || field === "row_read") {
11
12
  if (field === "row_edit" && onRowEditClick) onRowEditClick(id, value);
12
13
  if (field === "row_read" && onRowReadClick) onRowReadClick(id, value);
13
- } else if (onRowAction) return onRowAction(id, field, value, rowData);
14
+ } else if (onRowAction) onRowAction(id, field, value, rowData);
14
15
  }, [
15
16
  onRowAction,
16
17
  onRowEditClick,
17
18
  onRowReadClick
18
19
  ]);
19
- const { canRowEdit, canRowRead, addRowNumbers, stickTo = "left", flexBasis = 20 } = actionColumnDefinition || {};
20
+ const { canRowEdit, canRowRead, addRowNumbers, stickTo = "left", flexBasis = 0 } = actionColumnDefinition || {};
20
21
  const withCheckboxes = !!actionColumnDefinition?.actionOptions?.length || actionColumnDefinition?.forceCheckboxes;
21
22
  const hasActions = canRowEdit || canRowRead || withCheckboxes || addRowNumbers;
23
+ const page = gridSelectors?.page || 1;
24
+ const maxRowNumber = (gridSelectors?.rowsPerPage || 10) * (page - 1) + (rowsData?.length || 0);
25
+ const actionColumnFlexBasis = flexBasis + getActionsColumnExtraWidth({
26
+ addRowNumbers,
27
+ withCheckboxes,
28
+ canRowEdit,
29
+ canRowRead,
30
+ maxRowNumber
31
+ });
32
+ const rowNumberWidth = getRowNumbersExtraWidth(maxRowNumber);
22
33
  return {
23
34
  columnsDefinitions: useMemo(() => {
24
35
  const editReadColumnDefinition = {
25
36
  name: "actions-cell-cg",
26
- flexBasis,
37
+ flexBasis: actionColumnFlexBasis,
27
38
  filtering: withCheckboxes || addRowNumbers,
28
39
  filteringType: "actions",
29
40
  sorting: false,
@@ -34,6 +45,7 @@ const useEditReadAsColumn = (props) => {
34
45
  actionColumnDefinition,
35
46
  withCheckboxes,
36
47
  addRowNumbers: actionColumnDefinition?.addRowNumbers,
48
+ rowNumberWidth,
37
49
  checkedRows: gridSelectors?.uxState?.checkedRows,
38
50
  onUxChange: gridActions?.handleUxChange
39
51
  })(RowActionsCell)
@@ -42,7 +54,8 @@ const useEditReadAsColumn = (props) => {
42
54
  else return [...columnsDefinitions, editReadColumnDefinition];
43
55
  }, [
44
56
  addRowNumbers,
45
- flexBasis,
57
+ actionColumnFlexBasis,
58
+ rowNumberWidth,
46
59
  stickTo,
47
60
  hasActions,
48
61
  columnsDefinitions,
@@ -86,11 +86,9 @@ export type RowProps = {
86
86
  id: string;
87
87
  [rowClassSymbol]?: string;
88
88
  };
89
- type ColumnBaseProps = {
90
- flexBasis: number;
91
- };
92
89
  export type RowValueType = string | React.ReactNode | number | void;
93
- export type ColumnDefinition<ColumnName extends string = string> = ColumnBaseProps & {
90
+ export type ColumnDefinition<ColumnName extends string = string> = {
91
+ flexBasis: number;
94
92
  asyncLoadKey?: string;
95
93
  name: ColumnName;
96
94
  group?: Group['name'];
@@ -140,7 +138,8 @@ type batchAction = {
140
138
  isEnabled?: (checkedRows: any[]) => boolean;
141
139
  };
142
140
  export type OnBatchActionFn<T = RowProps> = (action: batchAction, affectedRows: T[]) => void;
143
- export type ActionColumn = ColumnBaseProps & {
141
+ export type ActionColumn = {
142
+ flexBasis?: number;
144
143
  actionOptions?: batchAction[];
145
144
  canRowEdit?: boolean | ((row: any) => boolean);
146
145
  canRowRead?: boolean | ((row: any) => boolean);
@@ -1,4 +1,4 @@
1
- import type { ColumnDefinition, ColumnConfig, FilterProps, Group, StickTo, FiltersConfig } from '../types';
1
+ import type { ColumnDefinition, ColumnConfig, FilterProps, Group, StickTo, FiltersConfig, ActionColumn } from '../types';
2
2
  type CellSizePropsResult = {
3
3
  flexBasis?: number;
4
4
  flexGrow?: number;
@@ -13,6 +13,15 @@ export declare const calculatePaginator: (page: number, rowsPerPage: number) =>
13
13
  offset: number;
14
14
  limit: number;
15
15
  };
16
+ export declare const getRowNumbersExtraWidth: (maxRowNumber?: number) => number;
17
+ type ActionsColumnExtraWidthParams = {
18
+ addRowNumbers?: boolean;
19
+ withCheckboxes?: boolean;
20
+ canRowEdit?: ActionColumn['canRowEdit'];
21
+ canRowRead?: ActionColumn['canRowRead'];
22
+ maxRowNumber?: number;
23
+ };
24
+ export declare const getActionsColumnExtraWidth: ({ addRowNumbers, withCheckboxes, canRowEdit, canRowRead, maxRowNumber }: ActionsColumnExtraWidthParams) => number;
16
25
  export declare const createFilterType: (columnDefinition: ColumnDefinition) => FilterProps["type"];
17
26
  export declare const getGroups: (columns: ColumnDefinition[]) => Group[];
18
27
  export declare const getGroupClassNames: (group?: Group) => string;
@@ -4,6 +4,7 @@ import BooleanSelect_default from "../components/Filters/BooleanSelect/index.js"
4
4
  import DatePickerRange_default from "../components/Filters/DatePickerRange/index.js";
5
5
  import NumberRange_default from "../components/Filters/NumberRange/index.js";
6
6
  import TextRange_default from "../components/Filters/TextRange/index.js";
7
+ import sum from "lodash/sum";
7
8
  //#region packages/ui/Blocks/CommonGrid/utils/index.ts
8
9
  const isDefined = (val) => typeof val !== "undefined";
9
10
  const getCellSizeProps = (column, columnWidth) => {
@@ -34,6 +35,27 @@ const calculatePaginator = (page, rowsPerPage) => ({
34
35
  offset: rowsPerPage ? rowsPerPage * (page - 1) : rowsPerPage,
35
36
  limit: rowsPerPage
36
37
  });
38
+ const ROW_NUMBER_DIGIT_WIDTH = 8;
39
+ const CHECKBOX_WIDTH = 18;
40
+ const ICON_BUTTON_WIDTH = 20;
41
+ const ACTIONS_CELL_GAP_WITH_ROW_NUMBERS = 12;
42
+ const ACTIONS_CELL_GAP = 18;
43
+ const ACTIONS_CELL_PADDING = 16;
44
+ const getRowNumbersExtraWidth = (maxRowNumber = 0) => {
45
+ return String(maxRowNumber).length * ROW_NUMBER_DIGIT_WIDTH;
46
+ };
47
+ const getActionsColumnExtraWidth = ({ addRowNumbers, withCheckboxes, canRowEdit, canRowRead, maxRowNumber = 0 }) => {
48
+ const hasActionIcon = !!canRowEdit || !!canRowRead;
49
+ const parts = [];
50
+ if (withCheckboxes) parts.push(CHECKBOX_WIDTH);
51
+ if (addRowNumbers) parts.push(getRowNumbersExtraWidth(maxRowNumber));
52
+ if (hasActionIcon) parts.push(ICON_BUTTON_WIDTH);
53
+ if (!parts.length) return 0;
54
+ const gap = addRowNumbers ? ACTIONS_CELL_GAP_WITH_ROW_NUMBERS : ACTIONS_CELL_GAP;
55
+ const gaps = (parts.length - 1) * gap;
56
+ parts.push(ACTIONS_CELL_PADDING);
57
+ return sum(parts) + gaps;
58
+ };
37
59
  const createFilterType = (columnDefinition) => {
38
60
  if (columnDefinition.filterOptions || columnDefinition.asyncLoadKey) return "options";
39
61
  else return columnDefinition.filteringType || "text";
@@ -75,4 +97,4 @@ const checksColumnsOrder = (colsOrder, columnsDefinitions) => {
75
97
  if (stickyRightColls.length && colsOrder.indexOf(stickyRightColls[0].name) !== colsOrder.length - 1 && stickyRightColls[0].name !== "actions-cell-cg") console.error("The Right sticky column should be the last one in a row");
76
98
  };
77
99
  //#endregion
78
- export { calculatePaginator, checksColumnsOrder, createFilterType, getCellSizeProps, getFilterName, getFilters, getGroupClassNames, getGroups, getSortName, getStickyCollClassNames, isColumnOn, isFilterActive };
100
+ export { calculatePaginator, checksColumnsOrder, createFilterType, getActionsColumnExtraWidth, getCellSizeProps, getFilterName, getFilters, getGroupClassNames, getGroups, getRowNumbersExtraWidth, getSortName, getStickyCollClassNames, isColumnOn, isFilterActive };
@@ -12,7 +12,7 @@ const ChevronOption = (props) => {
12
12
  ...props,
13
13
  children: [(showCheckbox || showToggle) && /* @__PURE__ */ jsxs(SelectedIndicator, { children: [showCheckbox && /* @__PURE__ */ jsx(Checkbox_default, {
14
14
  checked: isSelected,
15
- size: 2,
15
+ size: "14px",
16
16
  readOnly: true
17
17
  }), showToggle && /* @__PURE__ */ jsx(Toggle, {
18
18
  name: "",
@@ -66,7 +66,7 @@ const SelectAll = ({ onCustomSelectAll, onCustomDeselectAll, value, options, max
66
66
  children: [
67
67
  (showCheckbox || showToggle) && /* @__PURE__ */ jsxs(SelectedIndicator, { children: [showCheckbox && /* @__PURE__ */ jsx(Checkbox_default, {
68
68
  checked: isSelected,
69
- size: 2,
69
+ size: "14px",
70
70
  readOnly: true
71
71
  }), showToggle && /* @__PURE__ */ jsx(Toggle, {
72
72
  name: "",
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { type CheckboxProps } from './types';
3
- declare const _default: React.NamedExoticComponent<CheckboxProps>;
2
+ declare const _default: import("react").NamedExoticComponent<CheckboxProps>;
4
3
  export default _default;
@@ -1,14 +1,11 @@
1
1
  import { CheckIcon, CheckboxWrap, FakeInput, Label } from "./styles.js";
2
2
  import { memo, useId } from "react";
3
- import { th, useTheme } from "@xstyled/styled-components";
4
3
  import { jsx, jsxs } from "react/jsx-runtime";
5
4
  //#region packages/ui/Forms/Checkbox/Checkbox.tsx
6
- const Checkbox = ({ name, label, onChange, checked, defaultChecked, size = 4, className, disabled, inputRef, readOnly, minusIcon = false }) => {
7
- const theme = useTheme();
8
- const themeSize = th.fontSize(size)({ theme });
5
+ const Checkbox = ({ name, label, onChange, checked, defaultChecked, size = "18px", className, disabled, inputRef, readOnly, minusIcon = false }) => {
9
6
  const id = useId();
10
7
  return /* @__PURE__ */ jsxs(CheckboxWrap, {
11
- size: themeSize,
8
+ size,
12
9
  className,
13
10
  children: [
14
11
  /* @__PURE__ */ jsx("input", {
@@ -26,10 +23,10 @@ const Checkbox = ({ name, label, onChange, checked, defaultChecked, size = 4, cl
26
23
  id
27
24
  }),
28
25
  /* @__PURE__ */ jsx(FakeInput, {
29
- size: themeSize,
26
+ size,
30
27
  children: /* @__PURE__ */ jsx(CheckIcon, {
31
28
  icon: minusIcon ? "minus" : "check",
32
- size: themeSize
29
+ size
33
30
  })
34
31
  }),
35
32
  label && /* @__PURE__ */ jsx(Label, {
@@ -8,7 +8,7 @@ export type CheckboxProps = {
8
8
  disabled?: boolean;
9
9
  color?: string;
10
10
  unsetColor?: string;
11
- size?: number;
11
+ size?: string;
12
12
  className?: string;
13
13
  inputRef?: RefObject<HTMLInputElement>;
14
14
  readOnly?: boolean;