@true-engineering/true-react-common-ui-kit 3.33.0 → 3.33.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": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.33.0",
3
+ "version": "3.33.2",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -1,4 +1,5 @@
1
1
  import { FC } from 'react';
2
+ import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
2
3
  import { ComponentMeta, ComponentStory } from '@storybook/react';
3
4
  import { FlexibleTable } from './FlexibleTable';
4
5
  import { IFlexibleTableConfigType, IValueComponentProps } from './types';
@@ -12,6 +13,8 @@ interface ITableContent {
12
13
  contractCode: string;
13
14
  validFrom: Date;
14
15
  validTo: Date;
16
+ validTo1?: Date;
17
+ validTo2?: Date;
15
18
  title: string;
16
19
  signDate: Date;
17
20
  partner: string;
@@ -19,6 +22,8 @@ interface ITableContent {
19
22
  parentContract: string;
20
23
  currency: string;
21
24
  status: string;
25
+ note?: string;
26
+ publicNote?: string;
22
27
  }
23
28
 
24
29
  const Temp: FC<IValueComponentProps<ITableContent, string>> = ({ value }) => <>{value}</>;
@@ -26,11 +31,16 @@ const Temp: FC<IValueComponentProps<ITableContent, string>> = ({ value }) => <>{
26
31
  const config: IFlexibleTableConfigType<ITableContent> = {
27
32
  contractCode: {
28
33
  title: 'Contract Code',
34
+ minWidth: 150,
35
+ maxWidth: 150,
36
+ position: 'sticky',
29
37
  },
30
38
  title: {
31
- component: Temp,
39
+ component: (props) => <Temp {...props} />,
32
40
  title: 'Title',
33
- minWidth: 320,
41
+ minWidth: 100,
42
+ position: 'sticky',
43
+ left: 186,
34
44
  },
35
45
  validFrom: {
36
46
  title: 'Valid From',
@@ -39,11 +49,28 @@ const config: IFlexibleTableConfigType<ITableContent> = {
39
49
  validTo: {
40
50
  title: 'Valid From',
41
51
  },
52
+ validTo1: {
53
+ title: 'Valid To1',
54
+ },
55
+ validTo2: {
56
+ title: 'Valid To2',
57
+ },
58
+ note: {
59
+ title: 'Notes',
60
+ minWidth: 110,
61
+ shouldRenderComponent: (_, { note, publicNote }) => isNotEmpty(note) || isNotEmpty(publicNote),
62
+ component: ({ row }) => (
63
+ <>
64
+ <div>{row.note ?? '-'}</div>
65
+ <div>{row.publicNote ?? '-'}</div>
66
+ </>
67
+ ),
68
+ },
42
69
  signDate: {
43
70
  title: 'Sign Date',
44
71
  },
45
72
  partner: {
46
- component: Temp,
73
+ component: (props) => <Temp {...props} />,
47
74
  title: 'Partner',
48
75
  },
49
76
  };
@@ -60,6 +87,8 @@ const content: ITableContent[] = [
60
87
  parentContract: '',
61
88
  currency: 'RUR',
62
89
  status: 'Active',
90
+ note: 'Note',
91
+ publicNote: 'Public Note',
63
92
  },
64
93
  {
65
94
  contractCode: 'SOME_CODE',
@@ -72,6 +101,7 @@ const content: ITableContent[] = [
72
101
  parentContract: '',
73
102
  currency: 'RUR',
74
103
  status: 'Active',
104
+ note: 'Only Note',
75
105
  },
76
106
  {
77
107
  contractCode: 'SOME_CODE',
@@ -84,6 +114,7 @@ const content: ITableContent[] = [
84
114
  parentContract: '',
85
115
  currency: 'U00',
86
116
  status: 'Active',
117
+ publicNote: 'Only Public Note',
87
118
  },
88
119
  {
89
120
  contractCode: 'SOME_CODE_1',
@@ -220,7 +251,7 @@ const content: ITableContent[] = [
220
251
  ];
221
252
 
222
253
  const Template: ComponentStory<typeof FlexibleTable<ITableContent>> = (args) => (
223
- <div style={{ width: 500, overflow: 'auto' }}>
254
+ <div style={{ width: 700, overflow: 'auto' }}>
224
255
  <FlexibleTable<ITableContent>
225
256
  {...args}
226
257
  config={config}
@@ -222,27 +222,39 @@ export function FlexibleTable<
222
222
  <Table.Head className={classes.head}>
223
223
  <Table.Row className={classes.headerRow}>
224
224
  {columns.map((key, i) => {
225
- const itemConfig = config?.[key];
225
+ const {
226
+ position,
227
+ minWidth,
228
+ width,
229
+ maxWidth,
230
+ titleAlign = 'left',
231
+ right,
232
+ left,
233
+ title = '',
234
+ shouldRenderDataId,
235
+ } = config?.[key] ?? {};
236
+ const isSticky = position === 'sticky' || (isFirstColumnSticky && i === 0);
226
237
 
227
238
  return (
228
239
  <Table.Header
229
240
  key={key}
230
241
  className={clsx(classes.header, {
231
- [classes.headerSticky]: isFirstColumnSticky && i === 0,
242
+ [classes.headerSticky]: isSticky,
232
243
  [classes.headerSecond]: isFirstColumnSticky && i === 1,
233
244
  })}
234
245
  style={{
235
- minWidth: itemConfig?.minWidth,
236
- width: itemConfig?.width,
237
- maxWidth: itemConfig?.maxWidth,
238
- textAlign: itemConfig?.titleAlign ?? 'left',
246
+ minWidth,
247
+ width,
248
+ maxWidth,
249
+ textAlign: titleAlign,
250
+ position: isSticky ? 'sticky' : position,
251
+ right,
252
+ left,
239
253
  }}
240
254
  onClick={isNotEmpty(onHeadClick) ? () => onHeadClick(key) : undefined}
241
- {...addDataAttributes({ id: itemConfig?.shouldRenderDataId ? key : undefined })}
255
+ {...addDataAttributes({ id: shouldRenderDataId ? key : undefined })}
242
256
  >
243
- {applyAction(itemConfig?.title ?? '', {
244
- value: headerContent?.[key] as HeaderContent[string],
245
- })}
257
+ {applyAction(title, { value: headerContent?.[key] as HeaderContent[string] })}
246
258
  </Table.Header>
247
259
  );
248
260
  })}
@@ -17,6 +17,7 @@ export const useStyles = createThemedStyles('FlexibleTableCell', {
17
17
  zIndex: 19,
18
18
  paddingLeft: 24,
19
19
  paddingRight: 12,
20
+ left: 0,
20
21
  ...getTransition(['box-shadow']),
21
22
 
22
23
  '[data-scrolled] &': {
@@ -44,7 +44,7 @@ export function FlexibleTableCell<
44
44
  config,
45
45
  renderMode,
46
46
  isSecond,
47
- isSticky,
47
+ isSticky: isOldSticky,
48
48
  isLoading,
49
49
  tweakStyles,
50
50
  ...valueComponentProps
@@ -61,8 +61,11 @@ export function FlexibleTableCell<
61
61
  cellAlign,
62
62
  cellVerticalAlign,
63
63
  shouldRenderDataId,
64
+ shouldRenderComponent = isNotEmpty,
64
65
  } = config[columnName] ?? {};
65
66
 
67
+ const isSticky = isOldSticky || position === 'sticky';
68
+
66
69
  const Table = TableRenders[renderMode];
67
70
 
68
71
  return (
@@ -76,7 +79,7 @@ export function FlexibleTableCell<
76
79
  textAlign: cellAlign,
77
80
  position: isSticky ? 'sticky' : position,
78
81
  right,
79
- left: isSticky ? 0 : left,
82
+ left,
80
83
  verticalAlign: cellVerticalAlign,
81
84
  }}
82
85
  {...addDataAttributes({ id: shouldRenderDataId ? columnName : undefined })}
@@ -86,7 +89,8 @@ export function FlexibleTableCell<
86
89
  <Skeleton />
87
90
  </div>
88
91
  ) : (
89
- isNotEmpty(value) && applyAction(component, { ...valueComponentProps, value, row })
92
+ applyAction(shouldRenderComponent, value, row, columnName) &&
93
+ applyAction(component, { ...valueComponentProps, value, row })
90
94
  )}
91
95
  </Table.Cell>
92
96
  );
@@ -28,7 +28,8 @@ export interface IFlexibleTableRowProps<
28
28
  isActive?: boolean;
29
29
  /** @default false */
30
30
  isFocusable?: boolean;
31
- /** @default false */
31
+ /** @deprecated Use {@position}
32
+ * @default false */
32
33
  isFirstColumnSticky?: boolean;
33
34
  /** @default false */
34
35
  isLoading?: boolean;
@@ -46,6 +46,12 @@ export interface IFlexibleTableRowConfig<
46
46
  right?: number;
47
47
  left?: number;
48
48
  shouldRenderDataId?: boolean;
49
+ /**
50
+ * Проверка, нужно ли отрисовать component
51
+ * @description **Не влияет на типизацию `component`, лучше использовать `row`**
52
+ * @default isNotEmpty
53
+ */
54
+ shouldRenderComponent?: boolean | ((value: Values[Key], values: Values, key: Key) => boolean);
49
55
  }
50
56
 
51
57
  export type IFlexibleTableConfigType<