@true-engineering/true-react-common-ui-kit 3.0.0-alpha.15 → 3.0.0-alpha.16

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": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.0.0-alpha.15",
3
+ "version": "3.0.0-alpha.16",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -17,7 +17,7 @@ export interface IFlexibleTableProps<Values extends Record<string, any>>
17
17
  headerContent?: Partial<Record<keyof Values, any>>;
18
18
  enabledColumns?: Array<keyof Values>;
19
19
  activeRows?: number[];
20
- config?: IFlexibleTableConfigType<Values>;
20
+ config: IFlexibleTableConfigType<Values>;
21
21
  isHorizontallyScrollable?: boolean;
22
22
  isFirstColumnSticky?: boolean;
23
23
  infinityScrollConfig?: IInfinityScrollConfig;
@@ -1,8 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import clsx from 'clsx';
3
- import { format } from 'date-fns';
3
+ import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
4
4
  import type { ICommonProps } from '../../../../types';
5
- import { DEFAULT_DATE_FORMAT } from '../../constants';
5
+ import { formatCellContent } from '../../helpers';
6
6
  import type { IFlexibleTableConfigType } from '../../types';
7
7
  import { useStyles, IFlexibleTableCellStyles } from './FlexibleTableCell.styles';
8
8
 
@@ -10,7 +10,7 @@ export interface IFlexibleTableCellProps<Values extends Record<string, any>>
10
10
  extends Pick<ICommonProps<IFlexibleTableCellStyles>, 'tweakStyles'> {
11
11
  item: Values;
12
12
  columnName: keyof Values;
13
- config?: IFlexibleTableConfigType<Values>;
13
+ config: IFlexibleTableConfigType<Values>;
14
14
  isFocusedRow?: boolean;
15
15
  isSecond?: boolean;
16
16
  isSticky?: boolean;
@@ -33,39 +33,37 @@ function FlexibleTableCell<Values extends Record<string, any>>({
33
33
  }: IFlexibleTableCellProps<Values>): JSX.Element {
34
34
  const classes = useStyles({ theme: tweakStyles });
35
35
 
36
- const itemConfig = config?.[columnName];
37
- const value = item[columnName];
38
- let content = null;
36
+ const { component, cellAlign, position, right, left, cellVerticalAlign } =
37
+ config[columnName] ?? {};
39
38
 
40
- if (itemConfig?.component) {
41
- const ValueComponent = itemConfig?.component;
42
- content = ValueComponent({
43
- value,
44
- row: item,
45
- isFocusedRow,
46
- isNestedComponentExpanded,
47
- isRowNestedComponentExpanded,
48
- onSetNestedComponent,
49
- });
50
- } else if (typeof value === 'string' || typeof value === 'number') {
51
- content = value;
52
- } else if ((value as any) instanceof Date) {
53
- content = format(value, itemConfig?.dateFormat || DEFAULT_DATE_FORMAT);
54
- }
39
+ const value = item[columnName];
55
40
 
56
41
  return (
57
42
  <td
58
43
  key={columnName as string}
59
44
  className={clsx(classes.root, { [classes.sticky]: isSticky, [classes.second]: isSecond })}
60
45
  style={{
61
- textAlign: itemConfig?.cellAlign,
62
- position: isSticky ? 'sticky' : itemConfig?.position,
63
- right: itemConfig?.right,
64
- left: isSticky ? 0 : itemConfig?.left,
65
- verticalAlign: itemConfig?.cellVerticalAlign,
46
+ textAlign: cellAlign,
47
+ position: isSticky ? 'sticky' : position,
48
+ right,
49
+ left: isSticky ? 0 : left,
50
+ verticalAlign: cellVerticalAlign,
66
51
  }}
67
52
  >
68
- {content}
53
+ {isNotEmpty(value) && (
54
+ <>
55
+ {isNotEmpty(component)
56
+ ? component({
57
+ value,
58
+ row: item,
59
+ isFocusedRow,
60
+ isNestedComponentExpanded,
61
+ isRowNestedComponentExpanded,
62
+ onSetNestedComponent,
63
+ })
64
+ : formatCellContent(value, config[columnName])}
65
+ </>
66
+ )}
69
67
  </td>
70
68
  );
71
69
  }
@@ -15,7 +15,7 @@ export interface IFlexibleTableRowProps<Values extends Record<string, any>>
15
15
  uniqueField?: keyof Values;
16
16
  isFirstColumnSticky?: boolean;
17
17
  isActive: boolean;
18
- config?: IFlexibleTableConfigType<Values>;
18
+ config: IFlexibleTableConfigType<Values>;
19
19
  enabledColumns?: Array<keyof Values>;
20
20
  rowAttributes?: Array<keyof Values>;
21
21
  expandableRowComponent?(item: Values, isOpen: boolean, close: () => void): ReactNode;
@@ -1,4 +1,15 @@
1
+ import { format } from 'date-fns';
1
2
  import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
3
+ import { DEFAULT_DATE_FORMAT } from './constants';
4
+ import { IFlexibleTableConfigType } from './types';
2
5
 
3
6
  export const hasHorizontalScrollBar = (el: HTMLElement | null | undefined): boolean =>
4
7
  isNotEmpty(el) && el.scrollWidth !== el.clientWidth;
8
+
9
+ export const formatCellContent = <Values>(
10
+ value: unknown,
11
+ config?: IFlexibleTableConfigType<Values>[keyof Values],
12
+ ): string =>
13
+ value instanceof Date
14
+ ? format(value as Date, config?.dateFormat ?? DEFAULT_DATE_FORMAT)
15
+ : String(value);
@@ -23,7 +23,7 @@ export type IFlexibleTableConfigType<Values> = {
23
23
  [Key in keyof Values]?: {
24
24
  title?: ReactNode;
25
25
  titleComponent?: ITitleComponent<unknown>;
26
- component?: IValueComponent<Values, Values[Key]>;
26
+ component?: IValueComponent<NonNullable<Values>, Values[Key]>;
27
27
  dateFormat?: string;
28
28
  minWidth?: string | number;
29
29
  width?: string | number;