@true-engineering/true-react-common-ui-kit 3.5.0 → 3.7.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.
Files changed (35) hide show
  1. package/README.md +28 -0
  2. package/dist/components/FiltersPane/FiltersPane.stories.d.ts +1 -2
  3. package/dist/components/FlexibleTable/FlexibleTable.d.ts +13 -21
  4. package/dist/components/FlexibleTable/FlexibleTable.stories.d.ts +3 -6
  5. package/dist/components/FlexibleTable/FlexibleTable.styles.d.ts +1 -1
  6. package/dist/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.d.ts +10 -14
  7. package/dist/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.d.ts +1 -1
  8. package/dist/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.d.ts +19 -12
  9. package/dist/components/FlexibleTable/types.d.ts +8 -8
  10. package/dist/components/Icon/Icon.stories.d.ts +2 -2
  11. package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +60 -56
  12. package/dist/components/Select/CustomSelect.stories.d.ts +13 -0
  13. package/dist/components/Select/MultiSelect.stories.d.ts +1 -2
  14. package/dist/components/Select/Select.d.ts +1 -1
  15. package/dist/components/Select/Select.stories.d.ts +1 -2
  16. package/dist/components/Select/components/SelectList/SelectList.d.ts +1 -1
  17. package/dist/true-react-common-ui-kit.js +485 -358
  18. package/dist/true-react-common-ui-kit.js.map +1 -1
  19. package/dist/true-react-common-ui-kit.umd.cjs +484 -357
  20. package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
  21. package/package.json +2 -1
  22. package/src/components/FiltersPane/components/Filter/Filter.tsx +1 -1
  23. package/src/components/FiltersPane/components/FilterValueView/FilterValueView.tsx +10 -9
  24. package/src/components/FlexibleTable/FlexibleTable.stories.tsx +28 -114
  25. package/src/components/FlexibleTable/FlexibleTable.styles.ts +1 -8
  26. package/src/components/FlexibleTable/FlexibleTable.tsx +89 -98
  27. package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.ts +6 -0
  28. package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.tsx +48 -39
  29. package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.tsx +89 -57
  30. package/src/components/FlexibleTable/helpers.ts +1 -3
  31. package/src/components/FlexibleTable/types.ts +9 -9
  32. package/src/components/Select/CustomSelect.stories.tsx +217 -0
  33. package/src/components/Select/Select.tsx +3 -2
  34. package/src/components/Select/components/SelectList/SelectList.tsx +2 -2
  35. package/src/hooks/use-dropdown.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.5.0",
3
+ "version": "3.7.0",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -84,6 +84,7 @@
84
84
  "eslint-config-prettier": "8.7.0",
85
85
  "eslint-plugin-import": "2.29.0",
86
86
  "eslint-plugin-react": "7.32.2",
87
+ "eslint-plugin-react-hooks": "4.6.0",
87
88
  "prettier": "2.8.3",
88
89
  "rollup-plugin-swc3": "0.3.0",
89
90
  "typescript": "4.9.3",
@@ -39,7 +39,7 @@ export function Filter<Values, Key extends keyof Values>({
39
39
  const translatesLocaleKey = filter.localeKey ?? localeKey;
40
40
  const translates = useMemo(
41
41
  () => getLocale(translatesLocaleKey, locale, filter.locale),
42
- [localeKey, locale, filter.locale],
42
+ [translatesLocaleKey, locale, filter.locale],
43
43
  );
44
44
 
45
45
  useOnClickOutsideWithRef(
@@ -1,5 +1,6 @@
1
1
  import { useMemo } from 'react';
2
2
  import { format } from 'date-fns';
3
+ import { isEmpty, isNotEmpty } from '@true-engineering/true-react-platform-helpers';
3
4
  import { ICommonProps } from '../../../../types';
4
5
  import { IMultiSelectListValues } from '../../../MultiSelectList';
5
6
  import { DEFAULT_DATE_FORMAT } from '../../constants';
@@ -18,16 +19,16 @@ export function FilterValueView<Values, Key extends keyof Values>({
18
19
  ICommonProps<IFilterValueViewStyles>): JSX.Element {
19
20
  const classes = useStyles({ theme: tweakStyles });
20
21
 
21
- if (value === undefined || value === null) {
22
- return <></>;
23
- }
24
-
25
22
  const translatesLocaleKey = filter.localeKey ?? localeKey;
26
23
  const translates = useMemo(
27
24
  () => getLocale(translatesLocaleKey, locale, filter.locale),
28
- [localeKey, locale, filter.locale],
25
+ [translatesLocaleKey, locale, filter.locale],
29
26
  );
30
27
 
28
+ if (isEmpty(value)) {
29
+ return <></>;
30
+ }
31
+
31
32
  if (filter.getSelectedValueView !== undefined) {
32
33
  return <span className={classes.text}>{filter.getSelectedValueView(value)}</span>;
33
34
  }
@@ -36,8 +37,8 @@ export function FilterValueView<Values, Key extends keyof Values>({
36
37
  const isRange = filter.type === 'custom' && filter.valueViewType === 'range';
37
38
  const isDate = filter.type === 'dateRange' || filter.type === 'dateRangeWithoutPeriod';
38
39
 
39
- const displayValue = (v: any): string => {
40
- if (v === undefined || v === null) {
40
+ const displayValue = (v: unknown): string => {
41
+ if (!isNotEmpty(v)) {
41
42
  return '';
42
43
  }
43
44
 
@@ -48,7 +49,7 @@ export function FilterValueView<Values, Key extends keyof Values>({
48
49
  );
49
50
  }
50
51
 
51
- if (typeof v === 'object' && v.value !== undefined) {
52
+ if (typeof v === 'object' && 'value' in v && isNotEmpty(v.value)) {
52
53
  return String(v.value);
53
54
  }
54
55
 
@@ -70,7 +71,7 @@ export function FilterValueView<Values, Key extends keyof Values>({
70
71
  }
71
72
 
72
73
  if (filter.type === 'multiSelect') {
73
- const multiSelectValue = value as unknown as IMultiSelectListValues<any>;
74
+ const multiSelectValue = value as IMultiSelectListValues<any>;
74
75
  const getView = filter.getValueView ?? defaultConvertFunction;
75
76
  const { include } = multiSelectValue;
76
77
 
@@ -1,13 +1,11 @@
1
- import { FC } from 'react';
2
- import { ComponentStory } from '@storybook/react';
1
+ import { ComponentMeta, ComponentStory } from '@storybook/react';
3
2
  import { FlexibleTable } from './FlexibleTable';
4
- import { IFlexibleTableConfigType } from './types';
5
- import { IFlexibleTableStyles } from './FlexibleTable.styles';
3
+ import { IFlexibleTableConfigType, IValueComponent } from './types';
6
4
 
7
5
  export default {
8
6
  title: 'Table/FlexibleTable',
9
7
  component: FlexibleTable,
10
- };
8
+ } as ComponentMeta<typeof FlexibleTable>;
11
9
 
12
10
  interface ITableContent {
13
11
  contractCode: string;
@@ -22,8 +20,7 @@ interface ITableContent {
22
20
  status: string;
23
21
  }
24
22
 
25
- const Temp: FC<{ value: string | undefined }> = ({ value }) => <>{value}</>;
26
- const Temp1: FC<{ value: string }> = ({ value }) => <>{value}</>;
23
+ const Temp: IValueComponent<ITableContent, string> = ({ value }) => <>{value}</>;
27
24
 
28
25
  const config: IFlexibleTableConfigType<ITableContent> = {
29
26
  contractCode: {
@@ -44,12 +41,12 @@ const config: IFlexibleTableConfigType<ITableContent> = {
44
41
  title: 'Sign Date',
45
42
  },
46
43
  partner: {
47
- component: Temp1,
44
+ component: Temp,
48
45
  title: 'Partner',
49
46
  },
50
47
  };
51
48
 
52
- const content = [
49
+ const content: ITableContent[] = [
53
50
  {
54
51
  contractCode: 'SOME_CODE',
55
52
  validFrom: new Date('2015-05-18'),
@@ -59,13 +56,7 @@ const content = [
59
56
  partner: 'SE_00206_CR',
60
57
  partnerDescription: 'TEST PARTNER DESCRIPTION',
61
58
  parentContract: '',
62
- childContracts: [],
63
- parentContractWrongAssignment: 'N',
64
59
  currency: 'RUR',
65
- entityCode: 'TEST_ENITY_CODE',
66
- contractCode1C: '2000632',
67
- taxCode: '20%',
68
- taxPercentage: 20,
69
60
  status: 'Active',
70
61
  },
71
62
  {
@@ -77,13 +68,7 @@ const content = [
77
68
  partner: 'SE_00168_CR',
78
69
  partnerDescription: 'TEST PARTNER DESCRIPTION',
79
70
  parentContract: '',
80
- childContracts: [],
81
- parentContractWrongAssignment: 'N',
82
71
  currency: 'RUR',
83
- entityCode: 'TEST_ENITY_CODE',
84
- contractCode1C: '2000262',
85
- taxCode: '20%',
86
- taxPercentage: 20,
87
72
  status: 'Active',
88
73
  },
89
74
  {
@@ -95,13 +80,7 @@ const content = [
95
80
  partner: 'SE_00206_CR',
96
81
  partnerDescription: 'TEST PARTNER DESCRIPTION',
97
82
  parentContract: '',
98
- childContracts: ['SOME_CODE_1'],
99
- parentContractWrongAssignment: 'N',
100
83
  currency: 'U00',
101
- entityCode: 'TEST_ENITY_CODE',
102
- contractCode1C: '2000392',
103
- taxCode: '20%',
104
- taxPercentage: 20,
105
84
  status: 'Active',
106
85
  },
107
86
  {
@@ -113,13 +92,7 @@ const content = [
113
92
  partner: 'SE_00168_CR',
114
93
  partnerDescription: 'TEST PARTNER DESCRIPTION',
115
94
  parentContract: 'PARENT/CONTRACT',
116
- childContracts: [],
117
- parentContractWrongAssignment: 'N',
118
95
  currency: 'RUR',
119
- entityCode: 'TEST_ENITY_CODE',
120
- contractCode1C: '2001199',
121
- taxCode: '20%',
122
- taxPercentage: 20,
123
96
  status: 'Active',
124
97
  },
125
98
  {
@@ -131,13 +104,7 @@ const content = [
131
104
  partner: 'SE_00206_CR',
132
105
  partnerDescription: 'TEST PARTNER DESCRIPTION',
133
106
  parentContract: 'PARENT/CONTRACT',
134
- childContracts: [],
135
- parentContractWrongAssignment: 'N',
136
107
  currency: 'RUR',
137
- entityCode: 'TEST_ENITY_CODE',
138
- contractCode1C: '2000632',
139
- taxCode: '20%',
140
- taxPercentage: 20,
141
108
  status: 'Active',
142
109
  },
143
110
  {
@@ -149,13 +116,7 @@ const content = [
149
116
  partner: 'SE_00168_CR',
150
117
  partnerDescription: 'TEST PARTNER DESCRIPTION',
151
118
  parentContract: 'PARENT/CONTRACT',
152
- childContracts: [],
153
- parentContractWrongAssignment: 'N',
154
119
  currency: 'RUR',
155
- entityCode: 'TEST_ENITY_CODE',
156
- contractCode1C: '2000262',
157
- taxCode: '20%',
158
- taxPercentage: 20,
159
120
  status: 'Active',
160
121
  },
161
122
  {
@@ -167,13 +128,7 @@ const content = [
167
128
  partner: 'SE_00206_CR',
168
129
  partnerDescription: 'TEST PARTNER DESCRIPTION',
169
130
  parentContract: '',
170
- childContracts: ['1-073-СТ/2010'],
171
- parentContractWrongAssignment: 'N',
172
131
  currency: 'U00',
173
- entityCode: 'TEST_ENITY_CODE',
174
- contractCode1C: '2000392',
175
- taxCode: '20%',
176
- taxPercentage: 20,
177
132
  status: 'Active',
178
133
  },
179
134
  {
@@ -185,13 +140,7 @@ const content = [
185
140
  partner: 'SE_00168_CR',
186
141
  partnerDescription: 'TEST PARTNER DESCRIPTION',
187
142
  parentContract: 'PARENT/CONTRACT',
188
- childContracts: [],
189
- parentContractWrongAssignment: 'N',
190
143
  currency: 'RUR',
191
- entityCode: 'TEST_ENITY_CODE',
192
- contractCode1C: '2001199',
193
- taxCode: '20%',
194
- taxPercentage: 20,
195
144
  status: 'Active',
196
145
  },
197
146
  {
@@ -203,13 +152,7 @@ const content = [
203
152
  partner: 'SE_00206_CR',
204
153
  partnerDescription: 'TEST PARTNER DESCRIPTION',
205
154
  parentContract: '',
206
- childContracts: ['1', '2', '3', '4', '5', '6'],
207
- parentContractWrongAssignment: 'N',
208
155
  currency: 'U00',
209
- entityCode: 'TEST_ENITY_CODE',
210
- contractCode1C: '2001199',
211
- taxCode: '20%',
212
- taxPercentage: 20,
213
156
  status: 'Active',
214
157
  },
215
158
  {
@@ -221,13 +164,7 @@ const content = [
221
164
  partner: 'SE_00206_CR',
222
165
  partnerDescription: 'TEST PARTNER DESCRIPTION',
223
166
  parentContract: '',
224
- childContracts: ['1', '2', '3', '4', '5', '6'],
225
- parentContractWrongAssignment: 'N',
226
167
  currency: 'U00',
227
- entityCode: 'TEST_ENITY_CODE',
228
- contractCode1C: '2001199',
229
- taxCode: '20%',
230
- taxPercentage: 20,
231
168
  status: 'Active',
232
169
  },
233
170
  {
@@ -239,13 +176,7 @@ const content = [
239
176
  partner: 'SE_00206_CR',
240
177
  partnerDescription: 'TEST PARTNER DESCRIPTION',
241
178
  parentContract: '',
242
- childContracts: ['1', '2', '3', '4', '5', '6'],
243
- parentContractWrongAssignment: 'N',
244
179
  currency: 'U00',
245
- entityCode: 'TEST_ENITY_CODE',
246
- contractCode1C: '2001199',
247
- taxCode: '20%',
248
- taxPercentage: 20,
249
180
  status: 'Active',
250
181
  },
251
182
  {
@@ -257,17 +188,11 @@ const content = [
257
188
  partner: 'SE_00206_CR',
258
189
  partnerDescription: 'TEST PARTNER DESCRIPTION',
259
190
  parentContract: '',
260
- childContracts: ['1', '2', '3', '4', '5', '6'],
261
- parentContractWrongAssignment: 'N',
262
191
  currency: 'U00',
263
- entityCode: 'TEST_ENITY_CODE',
264
- contractCode1C: '2001199',
265
- taxCode: '20%',
266
- taxPercentage: 20,
267
192
  status: 'Active',
268
193
  },
269
194
  {
270
- contractCode: 'SOME_CODE',
195
+ contractCode: 'OB_UT_M119',
271
196
  validFrom: new Date('2015-05-18'),
272
197
  validTo: new Date('2020-05-18'),
273
198
  title: 'Название',
@@ -275,13 +200,7 @@ const content = [
275
200
  partner: 'SE_00206_CR',
276
201
  partnerDescription: 'TEST PARTNER DESCRIPTION',
277
202
  parentContract: '',
278
- childContracts: ['1', '2', '3', '4', '5', '6'],
279
- parentContractWrongAssignment: 'N',
280
203
  currency: 'U00',
281
- entityCode: 'TEST_ENITY_CODE',
282
- contractCode1C: '2001199',
283
- taxCode: '20%',
284
- taxPercentage: 20,
285
204
  status: 'Active',
286
205
  },
287
206
  {
@@ -293,40 +212,25 @@ const content = [
293
212
  partner: 'SE_00206_CR',
294
213
  partnerDescription: 'TEST PARTNER DESCRIPTION',
295
214
  parentContract: '',
296
- childContracts: ['1', '2', '3', '4', '5', '6'],
297
- parentContractWrongAssignment: 'N',
298
215
  currency: 'U00',
299
- entityCode: 'TEST_ENITY_CODE',
300
- contractCode1C: '2001199',
301
- taxCode: '20%',
302
- taxPercentage: 20,
303
216
  status: 'Active',
304
217
  },
305
218
  ];
306
219
 
307
- const tweak: IFlexibleTableStyles = {
308
- tweakTableRow: {
309
- tweakTableCell: {
310
- root: {
311
- color: 'red',
312
- },
313
- },
314
- },
315
- };
316
-
317
220
  const Template: ComponentStory<typeof FlexibleTable<ITableContent>> = (args) => (
318
221
  <div style={{ width: 500, overflow: 'auto' }}>
319
222
  <FlexibleTable<ITableContent>
320
223
  {...args}
321
- uniqueField="contractCode"
322
- expandableRowComponent={(item, _, close) =>
323
- item.contractCode === 'OB_UT_M119' ? (
324
- <div onClick={close}>всем привет :) {item.contractCode}</div>
325
- ) : null
326
- }
327
- tweakStyles={tweak}
328
- content={content}
329
224
  config={config}
225
+ content={content}
226
+ rowAttributes={['contractCode']}
227
+ expandableRowComponent={(_0, _1, close) => (
228
+ <div onClick={close}>
229
+ всем привет :)
230
+ <br />
231
+ Нажми на меня, чтобы закрыть
232
+ </div>
233
+ )}
330
234
  />
331
235
  </div>
332
236
  );
@@ -334,9 +238,14 @@ const Template: ComponentStory<typeof FlexibleTable<ITableContent>> = (args) =>
334
238
  export const Default = Template.bind({});
335
239
 
336
240
  Default.args = {
337
- isHorizontallyScrollable: true,
338
- isFirstColumnSticky: true,
339
241
  isLoading: false,
242
+ isFirstColumnSticky: true,
243
+ isHorizontallyScrollable: true,
244
+ isExpandableRowComponentInitiallyOpen: false,
245
+ };
246
+
247
+ Default.argTypes = {
248
+ isExpandableRowComponentInitiallyOpen: { control: 'boolean' },
340
249
  };
341
250
 
342
251
  Default.parameters = {
@@ -344,6 +253,11 @@ Default.parameters = {
344
253
  exclude: [
345
254
  'data',
346
255
  'testId',
256
+ 'content',
257
+ 'config',
258
+ 'rowAttributes',
259
+ 'headerContent',
260
+ 'tweakStyles',
347
261
  'onHeadClick',
348
262
  'onRowClick',
349
263
  'onRowHover',
@@ -6,8 +6,8 @@ export const STICKY_SHADOW_PADDING = 12;
6
6
 
7
7
  export const useStyles = createThemedStyles('FlexibleTable', {
8
8
  root: {
9
- position: 'relative',
10
9
  width: '100%',
10
+ position: 'relative',
11
11
  borderCollapse: 'separate',
12
12
  borderSpacing: 0,
13
13
  },
@@ -102,13 +102,6 @@ export const useStyles = createThemedStyles('FlexibleTable', {
102
102
  nothingFoundRow: {},
103
103
 
104
104
  nothingFound: {},
105
-
106
- skeletonRow: {},
107
-
108
- skeleton: {
109
- height: 21,
110
- padding: [14, 7],
111
- },
112
105
  });
113
106
 
114
107
  export type IFlexibleTableStyles = ITweakStyles<