@true-engineering/true-react-common-ui-kit 3.0.0-alpha.2 → 3.0.0-alpha.4

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.2",
3
+ "version": "3.0.0-alpha.4",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -5,6 +5,7 @@ import clsx from 'clsx';
5
5
  import { isAfter, isBefore, isValid } from 'date-fns';
6
6
  import {
7
7
  addDataTestId,
8
+ getTestId,
8
9
  isEmpty,
9
10
  isNotEmpty,
10
11
  isStringNotEmpty,
@@ -125,6 +126,7 @@ export const DatePicker = forwardRef<ReactDatePicker, IDatePickerProps>(
125
126
  iconType: isClearable && hasDateInputValue ? undefined : 'calendar',
126
127
  tweakStyles: tweakDateInputStyles,
127
128
  ...(isRange ? { startDate: startDateValue, endDate: endDateValue } : { date: dateValue }),
129
+ testId: getTestId(testId, 'input'),
128
130
  };
129
131
 
130
132
  const handleChangeDate = (value: Date | null, event?: SyntheticEvent) => {
@@ -315,18 +315,20 @@ const tweak: IFlexibleTableStyles = {
315
315
  };
316
316
 
317
317
  const Template: ComponentStory<typeof FlexibleTable<ITableContent>> = (args) => (
318
- <FlexibleTable<ITableContent>
319
- {...args}
320
- uniqueField="contractCode"
321
- expandableRowComponent={(item, _, close) =>
322
- item.contractCode === 'OB_UT_M119' ? (
323
- <div onClick={close}>всем привет :) {item.contractCode}</div>
324
- ) : null
325
- }
326
- tweakStyles={tweak}
327
- content={content}
328
- config={config}
329
- />
318
+ <div style={{ width: 500, overflow: 'auto' }}>
319
+ <FlexibleTable<ITableContent>
320
+ {...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
+ config={config}
330
+ />
331
+ </div>
330
332
  );
331
333
 
332
334
  export const Default = Template.bind({});
@@ -22,16 +22,6 @@ export const useStyles = createThemedStyles('FlexibleTable', {
22
22
  maxHeight: '100%',
23
23
  },
24
24
 
25
- horizontallyScrolled: {
26
- '& $cellSticky': {
27
- boxShadow: '4px 0 4px rgba(0, 0, 0, 0.05)',
28
- },
29
-
30
- '& $headerSticky::before': {
31
- boxShadow: '4px 0 4px rgba(0, 0, 0, 0.05)',
32
- },
33
- },
34
-
35
25
  loader: {
36
26
  position: 'sticky',
37
27
  left: 0,
@@ -75,6 +65,10 @@ export const useStyles = createThemedStyles('FlexibleTable', {
75
65
  pointerEvents: 'none',
76
66
  zIndex: 1,
77
67
  transition: ['box-shadow', '0.25s', 'ease-in-out'],
68
+
69
+ '[data-scrolled] &': {
70
+ boxShadow: '4px 0 4px rgba(0, 0, 0, 0.05)',
71
+ },
78
72
  },
79
73
 
80
74
  '&::after': {
@@ -1,5 +1,6 @@
1
1
  import { ReactNode, RefObject, useCallback, useEffect, useRef, useState } from 'react';
2
2
  import clsx from 'clsx';
3
+ import { addDataTestId } from '@true-engineering/true-react-platform-helpers';
3
4
  import { addDataAttributes } from '../../helpers';
4
5
  import { useTweakStyles } from '../../hooks';
5
6
  import { ICommonProps } from '../../types';
@@ -41,7 +42,7 @@ export function FlexibleTable<Values extends Record<string, any>>({
41
42
  isHorizontallyScrollable,
42
43
  isFirstColumnSticky,
43
44
  infinityScrollConfig,
44
- uniqueField,
45
+ uniqueField = 'id',
45
46
  onHeadClick,
46
47
  onRowHover,
47
48
  onRowClick,
@@ -111,12 +112,10 @@ export function FlexibleTable<Values extends Record<string, any>>({
111
112
  return (
112
113
  <div
113
114
  ref={refForScroll ?? scrollRef}
114
- className={clsx(
115
- isHorizontallyScrollable && classes.scroll,
116
- isHorizontallyScrolled && classes.horizontallyScrolled,
117
- )}
115
+ className={clsx({ [classes.scroll]: isHorizontallyScrollable })}
116
+ data-scrolled={isHorizontallyScrolled ? true : undefined}
118
117
  >
119
- <table className={classes.root} data-testid={testId} {...addDataAttributes(data)}>
118
+ <table className={classes.root} {...addDataTestId(testId)} {...addDataAttributes(data)}>
120
119
  <thead>
121
120
  <tr className={classes.headerRow}>
122
121
  {(enabledColumns || Object.keys(content[0])).map((key, idx) => {
@@ -131,11 +130,10 @@ export function FlexibleTable<Values extends Record<string, any>>({
131
130
 
132
131
  return (
133
132
  <th
134
- className={clsx(
135
- classes.header,
136
- isFirstColumnSticky && idx === 0 && classes.headerSticky,
137
- isFirstColumnSticky && idx === 1 && classes.headerSecond,
138
- )}
133
+ className={clsx(classes.header, {
134
+ [classes.headerSticky]: isFirstColumnSticky && idx === 0,
135
+ [classes.headerSecond]: isFirstColumnSticky && idx === 1,
136
+ })}
139
137
  style={{
140
138
  minWidth: itemConfig?.minWidth,
141
139
  width: itemConfig?.width,
@@ -163,17 +161,17 @@ export function FlexibleTable<Values extends Record<string, any>>({
163
161
  </tr>
164
162
  )}
165
163
 
166
- {content.map((item, idx) => (
164
+ {content.map((item, i) => (
167
165
  <FlexibleTableRow
168
166
  item={item}
169
167
  uniqueField={uniqueField}
170
- isActive={activeRows?.includes(idx) ?? false}
168
+ isActive={activeRows?.includes(i) ?? false}
171
169
  isFirstColumnSticky={isFirstColumnSticky}
172
170
  onRowClick={onRowClick}
173
171
  onRowHover={onRowHover}
174
172
  enabledColumns={enabledColumns}
175
173
  config={config}
176
- key={uniqueField ? item[uniqueField] : idx}
174
+ key={item[uniqueField] ?? i}
177
175
  rowAttributes={rowAttributes}
178
176
  tweakStyles={tweakTableRowStyles}
179
177
  expandableRowComponent={expandableRowComponent}
@@ -18,6 +18,10 @@ export const useStyles = createThemedStyles('FlexibleTableCell', {
18
18
  paddingLeft: 24,
19
19
  paddingRight: 12,
20
20
  ...getTransition(['box-shadow']),
21
+
22
+ '[data-scrolled] &': {
23
+ boxShadow: '4px 0 4px rgba(0, 0, 0, 0.05)',
24
+ },
21
25
  },
22
26
 
23
27
  second: {