@true-engineering/true-react-common-ui-kit 4.0.0-alpha26 → 4.0.0-alpha27

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": "4.0.0-alpha26",
3
+ "version": "4.0.0-alpha27",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -1,8 +1,14 @@
1
1
  import { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import { debounce } from 'ts-debounce';
4
- import { isReactNodeNotEmpty } from '@true-engineering/true-react-platform-helpers';
5
- import { addDataAttributes } from '../../../../helpers';
4
+ import {
5
+ addDataTestId,
6
+ getTestId,
7
+ isReactNodeNotEmpty,
8
+ addDataAttributes,
9
+ isArrayNotEmpty,
10
+ isNotEmpty,
11
+ } from '@true-engineering/true-react-platform-helpers';
6
12
  import { useIsMounted, useTweakStyles } from '../../../../hooks';
7
13
  import { ICommonProps } from '../../../../types';
8
14
  import { Button } from '../../../Button';
@@ -227,7 +233,7 @@ export function FilterSelect<Value>({
227
233
  }, []);
228
234
 
229
235
  return (
230
- <div className={classes.root} {...addDataAttributes(data)}>
236
+ <div className={classes.root} {...addDataAttributes(data, testId)}>
231
237
  {isSearchEnabled && (
232
238
  <div className={classes.dropdownInput}>
233
239
  <SearchInput
@@ -235,7 +241,7 @@ export function FilterSelect<Value>({
235
241
  placeholder={translates.searchPlaceholder}
236
242
  onChange={handleOnChange}
237
243
  tweakStyles={tweakSearchInputStyles}
238
- testId={testId !== undefined ? `${testId}-search` : undefined}
244
+ testId={getTestId(testId, 'search')}
239
245
  shouldFocusOnMount
240
246
  />
241
247
  </div>
@@ -243,19 +249,17 @@ export function FilterSelect<Value>({
243
249
 
244
250
  {!isLoading && (
245
251
  <>
246
- {allOptions.length !== 0 && (
252
+ {isArrayNotEmpty(allOptions) && (
247
253
  <div
248
- className={clsx(classes.list, hasClearButton && classes.withClearButton)}
249
- data-testid={testId !== undefined ? `${testId}-list` : undefined}
254
+ className={clsx(classes.list, { [classes.withClearButton]: hasClearButton })}
255
+ {...addDataTestId(testId, 'list')}
250
256
  >
251
- {isGroupingEnabled && value !== undefined && (
257
+ {isGroupingEnabled && isNotEmpty(value) && (
252
258
  <>
253
259
  <div
254
- className={clsx(
255
- classes.label,
256
- classes.labelChosen,
257
- !isSearchEnabled && classes.withoutTopGap,
258
- )}
260
+ className={clsx(classes.label, classes.labelChosen, {
261
+ [classes.withoutTopGap]: !isSearchEnabled,
262
+ })}
259
263
  >
260
264
  {translates.chosen}
261
265
  </div>
@@ -269,7 +273,7 @@ export function FilterSelect<Value>({
269
273
  </>
270
274
  )}
271
275
  {allOptions.map((item, index) => {
272
- const isActive = value !== undefined && getValueId(value) === getValueId(item);
276
+ const isActive = isNotEmpty(value) && getValueId(value) === getValueId(item);
273
277
  if (isGroupingEnabled && isActive) {
274
278
  return null;
275
279
  }
@@ -287,8 +291,7 @@ export function FilterSelect<Value>({
287
291
  }
288
292
  onClick={() => handleChange(item)}
289
293
  >
290
- {/* data нужно ли? */}
291
- <div className={classes.option} data-option={id}>
294
+ <div className={classes.option} {...addDataAttributes({ id, option: id })}>
292
295
  {view}
293
296
  </div>
294
297
  {isActive && (
@@ -320,17 +323,13 @@ export function FilterSelect<Value>({
320
323
  )}
321
324
 
322
325
  {/* Nothing found */}
323
- {allOptions.length === 0 && (
326
+ {!isArrayNotEmpty(allOptions) && (
324
327
  <div className={classes.nothingFound}>{translates.nothingFound}</div>
325
328
  )}
326
329
 
327
330
  {/* Controls and footer */}
328
331
  {(hasClearButton || hasFooter) && (
329
- <div
330
- className={clsx(classes.panel, {
331
- [classes.panelWithFooter]: hasFooter,
332
- })}
333
- >
332
+ <div className={clsx(classes.panel, { [classes.panelWithFooter]: hasFooter })}>
334
333
  {hasFooter && <div className={classes.footer}>{footer}</div>}
335
334
 
336
335
  {hasClearButton && (
@@ -339,7 +338,7 @@ export function FilterSelect<Value>({
339
338
  onClick={handleClear}
340
339
  size="s"
341
340
  view="text"
342
- testId={testId !== undefined ? `${testId}-clear-button` : undefined}
341
+ testId={getTestId(testId, 'clear-button')}
343
342
  tweakStyles={tweakClearButtonStyles}
344
343
  >
345
344
  {translates.clear}
@@ -119,8 +119,9 @@ export function SelectList<Value>({
119
119
  )}
120
120
  {listOptions.map((opt, i) => {
121
121
  const optionValue = options[i];
122
+ const id = convertValueToId(optionValue);
122
123
  const isFocused = focusedIndex === i;
123
- const isActive = activeOptionsIds.has(convertValueToId(optionValue));
124
+ const isActive = activeOptionsIds.has(id);
124
125
  // проверяем, что опция задизейблена
125
126
  const isDisabled = optionsDisableMap[i];
126
127
 
@@ -135,6 +136,7 @@ export function SelectList<Value>({
135
136
  isMultiSelect={isMultiSelect}
136
137
  onOptionSelect={onOptionSelect}
137
138
  onToggleCheckbox={onToggleCheckbox}
139
+ data={{ id }}
138
140
  >
139
141
  {opt}
140
142
  </SelectListItem>
@@ -7,12 +7,13 @@ import {
7
7
  } from 'react';
8
8
  import clsx from 'clsx';
9
9
  import { type Classes } from 'jss';
10
- import { addDataAttributes } from '../../../../helpers';
10
+ import { addDataAttributes } from '@true-engineering/true-react-platform-helpers';
11
+ import { IDataAttributesProps } from '../../../../types';
11
12
  import { Checkbox } from '../../../Checkbox';
12
13
  import { ScrollIntoViewIfNeeded } from '../../../ScrollIntoViewIfNeeded';
13
14
  import { checkboxStyles } from './SelectListItem.styles';
14
15
 
15
- export interface ISelectListItemProps {
16
+ export interface ISelectListItemProps extends IDataAttributesProps {
16
17
  index: number;
17
18
  isSemiChecked?: boolean;
18
19
  isDisabled?: boolean;
@@ -38,6 +39,7 @@ export const SelectListItem: FC<ISelectListItemProps> = ({
38
39
  children,
39
40
  isFocused,
40
41
  isMultiSelect,
42
+ data,
41
43
  onOptionSelect,
42
44
  onToggleCheckbox,
43
45
  }) => {
@@ -67,6 +69,7 @@ export const SelectListItem: FC<ISelectListItemProps> = ({
67
69
  disabled: isDisabled,
68
70
  active: isActive,
69
71
  focused: isFocused,
72
+ ...data,
70
73
  })}
71
74
  onClick={!isDisabled && !isMultiSelect ? (event) => onOptionSelect(index, event) : undefined}
72
75
  >