@true-engineering/true-react-common-ui-kit 3.37.0 → 3.39.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.37.0",
3
+ "version": "3.39.0",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -34,6 +34,10 @@ export const useStyles = createThemedStyles('FlexibleTableCell', {
34
34
  skeleton: {
35
35
  height: 21,
36
36
  },
37
+
38
+ clickable: {
39
+ cursor: 'pointer',
40
+ },
37
41
  });
38
42
 
39
43
  export type IFlexibleTableCellStyles = ITweakStyles<typeof useStyles>;
@@ -65,9 +65,17 @@ export function FlexibleTableCell<
65
65
  cellVerticalAlign,
66
66
  shouldRenderDataId,
67
67
  shouldRenderComponent = isNotEmpty,
68
+ onCellClick,
68
69
  } = config[columnName] ?? {};
69
70
 
70
71
  const isSticky = isOldSticky || position === 'sticky';
72
+ const isClickable = !isLoading && isNotEmpty(onCellClick);
73
+
74
+ const cellComponentProps: IValueComponentProps<Row, Row[keyof Row]> = {
75
+ ...valueComponentProps,
76
+ value,
77
+ row,
78
+ };
71
79
 
72
80
  const Table = TableRenders[renderMode];
73
81
 
@@ -77,6 +85,7 @@ export function FlexibleTableCell<
77
85
  [classes.sticky]: isSticky,
78
86
  [classes.second]: isSecond,
79
87
  [classes.loading]: isLoading,
88
+ [classes.clickable]: isClickable,
80
89
  })}
81
90
  style={{
82
91
  textAlign: cellAlign,
@@ -88,6 +97,7 @@ export function FlexibleTableCell<
88
97
  left,
89
98
  verticalAlign: cellVerticalAlign,
90
99
  }}
100
+ onClick={isClickable ? (event) => onCellClick?.(event, cellComponentProps) : undefined}
91
101
  {...addDataAttributes({ id: shouldRenderDataId ? columnName : undefined })}
92
102
  >
93
103
  {isLoading ? (
@@ -96,7 +106,7 @@ export function FlexibleTableCell<
96
106
  </div>
97
107
  ) : (
98
108
  applyAction(shouldRenderComponent, value, row, columnName) &&
99
- applyAction(component, { ...valueComponentProps, value, row })
109
+ applyAction(component, cellComponentProps)
100
110
  )}
101
111
  </Table.Cell>
102
112
  );
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ReactNode } from 'react';
1
+ import { CSSProperties, MouseEvent, ReactNode } from 'react';
2
2
  import { IRenderNode } from '../../types';
3
3
 
4
4
  export type IFlexibleTableRenderMode = 'table' | 'divs';
@@ -27,6 +27,11 @@ export interface IValueComponentProps<Values, Value> {
27
27
  onSetNestedComponent: (component?: ReactNode) => void;
28
28
  }
29
29
 
30
+ export type ICellClickHandler<Values, Value> = (
31
+ event: MouseEvent,
32
+ cellComponentProps: IValueComponentProps<Values, Value>,
33
+ ) => void;
34
+
30
35
  export interface IFlexibleTableRowConfig<
31
36
  Values extends ITableRow,
32
37
  Key extends keyof Values,
@@ -52,6 +57,7 @@ export interface IFlexibleTableRowConfig<
52
57
  * @default isNotEmpty
53
58
  */
54
59
  shouldRenderComponent?: boolean | ((value: Values[Key], values: Values, key: Key) => boolean);
60
+ onCellClick?: ICellClickHandler<Values, Values[Key]>;
55
61
  }
56
62
 
57
63
  export type IFlexibleTableConfigType<
@@ -216,6 +216,7 @@ Default.args = {
216
216
  hasFloatingLabel: true,
217
217
  hasRequiredLabel: true,
218
218
  isDisabled: false,
219
+ isReadonly: false,
219
220
  isRequired: false,
220
221
  isClearable: false,
221
222
  isLoading: false,
@@ -276,6 +276,10 @@ export function Select<Value>(
276
276
  );
277
277
 
278
278
  const handleListOpen = () => {
279
+ if (isReadonly) {
280
+ return;
281
+ }
282
+
279
283
  if (!isListOpen) {
280
284
  setIsListOpen(true);
281
285
 
@@ -612,7 +616,7 @@ export function Select<Value>(
612
616
  <div className={classes.root} onKeyDown={handleKeyDown} ref={root}>
613
617
  <div
614
618
  className={clsx(classes.inputWrapper, isDisabled && classes.disabled)}
615
- onClick={isDisabled ? undefined : handleOnClick}
619
+ onClick={isDisabled || isReadonly ? undefined : handleOnClick}
616
620
  ref={inputWrapper}
617
621
  >
618
622
  <Input