@true-engineering/true-react-common-ui-kit 3.8.1 → 3.9.1

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/README.md CHANGED
@@ -10,6 +10,22 @@
10
10
 
11
11
  # Release Notes
12
12
 
13
+ ## v3.9.1
14
+
15
+ ### Changes
16
+
17
+ - **WithPopup** для `trigger` добавлен `testId`
18
+
19
+ ## v3.9.0
20
+
21
+ ### Changes
22
+
23
+ - **Select**:
24
+ 1. Добавлена поддержка для `readonly` опций
25
+ 2. Добавлена типизация для `event` в `onChange`
26
+ - **WithPopup**: добавлен `z-index: 5` для дропдауна
27
+ - **NewMoreMenu**: добавлены твикстайлс для **List** и **WithPopup**
28
+
13
29
  ## v3.8.1
14
30
 
15
31
  ### Changes
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import { ReactNode, ChangeEvent, KeyboardEvent } from 'react';
2
2
  import { ICommonProps } from '../../types';
3
3
  import { ICheckboxStyles } from './Checkbox.styles';
4
4
  export interface ICheckboxProps<V> extends ICommonProps<ICheckboxStyles> {
@@ -18,6 +18,6 @@ export interface ICheckboxProps<V> extends ICommonProps<ICheckboxStyles> {
18
18
  onSelect: (value: {
19
19
  value: V;
20
20
  isSelected: boolean;
21
- }) => void;
21
+ }, event: ChangeEvent<HTMLInputElement> | KeyboardEvent) => void;
22
22
  }
23
23
  export declare function Checkbox<V>({ children, isDisabled, isReadonly, isChecked, value, data, testId, isSemiChecked, labelPosition, tweakStyles, onSelect, }: ICheckboxProps<V>): JSX.Element;
@@ -1,6 +1,8 @@
1
1
  import { ITweakStyles } from '../../theme';
2
2
  import { IListStyles } from '../List';
3
- export declare const useStyles: import("../../theme").IUseStyles<"root" | "button" | "icon" | "menu" | "active" | "disabled" | "hasCircle", unknown>;
3
+ import { IWithPopupStyles } from '../WithPopup';
4
+ export declare const useStyles: import("../../theme").IUseStyles<"button" | "icon" | "active" | "disabled" | "hasCircle", unknown>;
4
5
  export type INewMoreMenuStyles = ITweakStyles<typeof useStyles, {
5
6
  tweakList: IListStyles;
7
+ tweakWithPopup: IWithPopupStyles;
6
8
  }>;
@@ -175,7 +175,7 @@ export declare class ScrollIntoViewIfNeeded extends PureComponent<IScrollIntoVie
175
175
  'aria-describedby'?: string | undefined;
176
176
  'aria-details'?: string | undefined;
177
177
  'aria-disabled'?: (boolean | "false" | "true") | undefined;
178
- 'aria-dropeffect'?: "copy" | "none" | "link" | "move" | "execute" | "popup" | undefined;
178
+ 'aria-dropeffect'?: "copy" | "none" | "link" | "move" | "popup" | "execute" | undefined;
179
179
  'aria-errormessage'?: string | undefined;
180
180
  'aria-expanded'?: (boolean | "false" | "true") | undefined;
181
181
  'aria-flowto'?: string | undefined;
@@ -1,4 +1,4 @@
1
- import { ReactNode, SyntheticEvent } from 'react';
1
+ import { ReactNode, KeyboardEvent, MouseEvent, SyntheticEvent, ChangeEvent, FormEvent } from 'react';
2
2
  import { ICommonProps, IDropdownWithPopperOptions } from '../../types';
3
3
  import { IIcon } from '../Icon';
4
4
  import { IInputProps } from '../Input';
@@ -19,7 +19,7 @@ export interface ISelectProps<Value> extends Omit<IInputProps, 'value' | 'onChan
19
19
  dropdownOptions?: IDropdownWithPopperOptions;
20
20
  /** @default 'chevron-down' */
21
21
  dropdownIcon?: IIcon;
22
- options: Value[];
22
+ options: Value[] | Readonly<Value[]>;
23
23
  value: Value | undefined;
24
24
  /** @default true */
25
25
  shouldScrollToList?: boolean;
@@ -28,7 +28,7 @@ export interface ISelectProps<Value> extends Omit<IInputProps, 'value' | 'onChan
28
28
  shouldRenderInList: true;
29
29
  } & Pick<ISearchInputProps, 'placeholder'>;
30
30
  isOptionDisabled?: (option: Value) => boolean;
31
- onChange: (value?: Value) => void;
31
+ onChange: (value: Value | undefined, event: MouseEvent<HTMLElement> | KeyboardEvent | ChangeEvent<HTMLElement> | FormEvent<HTMLElement>) => void;
32
32
  onBlur?: (event: Event | SyntheticEvent) => void;
33
33
  onType?: (value: string) => Promise<void>;
34
34
  optionsFilter?: (options: Value[], query: string) => Value[];
@@ -41,7 +41,7 @@ export interface ISelectProps<Value> extends Omit<IInputProps, 'value' | 'onChan
41
41
  export interface IMultipleSelectProps<Value> extends Omit<ISelectProps<Value>, 'value' | 'onChange' | 'compareValuesOnChange'> {
42
42
  isMultiSelect: true;
43
43
  value: IMultipleSelectValue<Value> | undefined;
44
- onChange: (value?: IMultipleSelectValue<Value>) => void;
44
+ onChange: (value: IMultipleSelectValue<Value> | undefined, event: MouseEvent<HTMLElement> | KeyboardEvent | ChangeEvent<HTMLElement> | FormEvent<HTMLElement>) => void;
45
45
  compareValuesOnChange?: (v1?: IMultipleSelectValue<Value>, v2?: IMultipleSelectValue<Value>) => boolean;
46
46
  }
47
47
  export declare function Select<Value>(props: ISelectProps<Value> | IMultipleSelectProps<Value>): JSX.Element;
@@ -1,20 +1,19 @@
1
- import { ReactNode, MouseEvent } from 'react';
1
+ import { ReactNode } from 'react';
2
2
  import { ICommonProps } from '../../../../types';
3
+ import { ISelectListItemProps } from '../SelectListItem';
3
4
  import { ISelectListStyles } from './SelectList.styles';
4
- export interface ISelectListProps<Value> extends ICommonProps<ISelectListStyles> {
5
- options: Value[];
5
+ export interface ISelectListProps<Value> extends ICommonProps<ISelectListStyles>, Pick<ISelectListItemProps, 'onToggleCheckbox' | 'onOptionSelect'> {
6
+ options: Value[] | Readonly<Value[]>;
6
7
  focusedIndex?: number;
7
8
  activeValue?: Value | Value[];
8
9
  noMatchesLabel?: string;
9
10
  isLoading?: boolean;
10
11
  loadingLabel?: ReactNode;
11
12
  defaultOptionLabel?: ReactNode;
12
- allOptionsLabel?: string;
13
+ allOptionsLabel?: ReactNode;
13
14
  areAllOptionsSelected?: boolean;
14
15
  shouldScrollToList?: boolean;
15
16
  customListHeader?: ReactNode;
16
- onOptionSelect: (index: number, event: MouseEvent<HTMLElement>) => void;
17
- onToggleCheckbox?: (index: number, isSelected: boolean) => void;
18
17
  isOptionDisabled: (value: Value) => boolean;
19
18
  convertValueToString: (value: Value) => string | undefined;
20
19
  convertValueToReactNode?: (value: Value, isDisabled: boolean) => ReactNode;
@@ -1,4 +1,4 @@
1
- import { ReactNode, MouseEvent, FC } from 'react';
1
+ import { ReactNode, MouseEvent, FC, KeyboardEvent, ChangeEvent } from 'react';
2
2
  import { Classes } from 'jss';
3
3
  export interface ISelectListItemProps {
4
4
  index: number;
@@ -9,6 +9,6 @@ export interface ISelectListItemProps {
9
9
  children: ReactNode;
10
10
  classes: Classes<'cellWithCheckbox' | 'cell' | 'focused' | 'active' | 'disabled'>;
11
11
  onOptionSelect: (index: number, event: MouseEvent<HTMLElement>) => void;
12
- onToggleCheckbox?: (index: number, isSelected: boolean) => void;
12
+ onToggleCheckbox?: (index: number, isSelected: boolean, event: ChangeEvent<HTMLElement> | KeyboardEvent) => void;
13
13
  }
14
14
  export declare const SelectListItem: FC<ISelectListItemProps>;
@@ -1,3 +1,3 @@
1
1
  import { ITweakStyles } from '../../theme';
2
- export declare const useStyles: import("../../theme").IUseStyles<"root" | "disabled" | "trigger", unknown>;
2
+ export declare const useStyles: import("../../theme").IUseStyles<"root" | "disabled" | "trigger" | "popup", unknown>;
3
3
  export type IWithPopupStyles = ITweakStyles<typeof useStyles>;
@@ -9110,12 +9110,12 @@ function Checkbox(param) {
9110
9110
  });
9111
9111
  var _useState = _sliced_to_array$o(useState(false), 2), isSelected = _useState[0], setIsSelected = _useState[1];
9112
9112
  var hasAction = !isDisabled && !isReadonly;
9113
- var onToggle = function() {
9113
+ var onToggle = function(event) {
9114
9114
  var isSelectedNext = !isSelected;
9115
9115
  onSelect({
9116
9116
  value,
9117
9117
  isSelected: isSelectedNext
9118
- });
9118
+ }, event);
9119
9119
  setIsSelected(isSelectedNext);
9120
9120
  };
9121
9121
  useEffect(function() {
@@ -10851,8 +10851,8 @@ var SelectListItem = function(param) {
10851
10851
  isSemiChecked,
10852
10852
  isDisabled,
10853
10853
  tweakStyles: checkboxStyles$1,
10854
- onSelect: function(v) {
10855
- return onToggleCheckbox(index, v.isSelected);
10854
+ onSelect: function(v, event) {
10855
+ return onToggleCheckbox(index, v.isSelected, event);
10856
10856
  },
10857
10857
  children
10858
10858
  }) : children
@@ -10974,7 +10974,7 @@ function SelectList(param) {
10974
10974
  },
10975
10975
  children: defaultOptionLabel
10976
10976
  }),
10977
- isStringNotEmpty(allOptionsLabel) && /* @__PURE__ */ jsx(SelectListItem, {
10977
+ isReactNodeNotEmpty(allOptionsLabel) && /* @__PURE__ */ jsx(SelectListItem, {
10978
10978
  classes,
10979
10979
  index: ALL_OPTION_INDEX,
10980
10980
  isSemiChecked: selectedOptionsCount > 0 && !areAllOptionsSelected,
@@ -11455,7 +11455,9 @@ function Select(props) {
11455
11455
  var classes = useStyles$B({
11456
11456
  theme: tweakStyles
11457
11457
  });
11458
- var shouldRenderSearchInputInList = (searchInput === null || searchInput === void 0 ? void 0 : searchInput.shouldRenderInList) === true;
11458
+ var _ref = searchInput !== null && searchInput !== void 0 ? searchInput : {}, tmp = _ref.shouldRenderInList, shouldRenderSearchInputInList = tmp === void 0 ? false : tmp, searchInputProps = _object_without_properties$9(_ref, [
11459
+ "shouldRenderInList"
11460
+ ]);
11459
11461
  var hasSearchInputInList = optionsMode !== "normal" && shouldRenderSearchInputInList;
11460
11462
  var isMultiSelect = isMultiSelectValue(props);
11461
11463
  var hasReadonlyInput = isReadonly || optionsMode === "normal" || shouldRenderSearchInputInList;
@@ -11534,7 +11536,11 @@ function Select(props) {
11534
11536
  return acc;
11535
11537
  }, []));
11536
11538
  }, [
11537
- filteredOptions
11539
+ filteredOptions,
11540
+ hasDefaultOption,
11541
+ isOptionDisabled,
11542
+ shouldShowAllOption,
11543
+ shouldShowDefaultOption
11538
11544
  ]);
11539
11545
  var stringValue = isNotEmpty(strValue) ? convertValueToString(strValue) : void 0;
11540
11546
  var showedStringValue = areAllOptionsSelected && isNotEmpty(allOptionsLabel) ? allOptionsLabel : stringValue;
@@ -11577,9 +11583,9 @@ function Select(props) {
11577
11583
  handleListClose(event);
11578
11584
  }
11579
11585
  };
11580
- var handleOnChange = useCallback(function(newValue) {
11586
+ var handleOnChange = useCallback(function(newValue, event) {
11581
11587
  if (!compareValuesOnChange(value, newValue)) {
11582
- onChange(newValue);
11588
+ onChange(newValue, event);
11583
11589
  }
11584
11590
  }, [
11585
11591
  value,
@@ -11588,7 +11594,7 @@ function Select(props) {
11588
11594
  ]);
11589
11595
  var handleOptionSelect = useCallback(function(index, event) {
11590
11596
  var _input_current;
11591
- handleOnChange(index === DEFAULT_OPTION_INDEX ? void 0 : filteredOptions[index]);
11597
+ handleOnChange(index === DEFAULT_OPTION_INDEX ? void 0 : filteredOptions[index], event);
11592
11598
  handleListClose(event);
11593
11599
  (_input_current = input.current) === null || _input_current === void 0 ? void 0 : _input_current.blur();
11594
11600
  }, [
@@ -11596,16 +11602,16 @@ function Select(props) {
11596
11602
  handleListClose,
11597
11603
  filteredOptions
11598
11604
  ]);
11599
- var handleToggleOptionCheckbox = useCallback(function(index, isSelected) {
11605
+ var handleToggleOptionCheckbox = useCallback(function(index, isSelected, event) {
11600
11606
  if (!isMultiSelect) {
11601
11607
  return;
11602
11608
  }
11603
11609
  if (index === DEFAULT_OPTION_INDEX || index === ALL_OPTION_INDEX && !isSelected) {
11604
- handleOnChange(void 0);
11610
+ handleOnChange(void 0, event);
11605
11611
  return;
11606
11612
  }
11607
11613
  if (index === ALL_OPTION_INDEX && isSelected) {
11608
- handleOnChange(availableOptions);
11614
+ handleOnChange(availableOptions, event);
11609
11615
  return;
11610
11616
  }
11611
11617
  var option = filteredOptions[index];
@@ -11619,12 +11625,14 @@ function Select(props) {
11619
11625
  value === null || value === void 0 ? void 0 : value.filter(function(o) {
11620
11626
  return convertToId(o) !== convertToId(option);
11621
11627
  })
11622
- ));
11628
+ ), event);
11623
11629
  }, [
11624
- handleOnChange,
11625
- filteredOptions,
11626
11630
  isMultiSelect,
11627
- value
11631
+ filteredOptions,
11632
+ handleOnChange,
11633
+ value,
11634
+ availableOptions,
11635
+ convertToId
11628
11636
  ]);
11629
11637
  var handleOnType = useCallback(function() {
11630
11638
  var _ref2 = _async_to_generator$4(function(v) {
@@ -11661,14 +11669,17 @@ function Select(props) {
11661
11669
  return _ref2.apply(this, arguments);
11662
11670
  };
11663
11671
  }(), [
11672
+ isMounted,
11664
11673
  onType,
11665
11674
  optionsMode
11666
11675
  ]);
11667
- var debounceHandleOnType = useCallback(debounce$1(handleOnType, debounceTime), [
11676
+ var debounceHandleOnType = useMemo(function() {
11677
+ return debounce$1(handleOnType, debounceTime);
11678
+ }, [
11668
11679
  handleOnType,
11669
11680
  debounceTime
11670
11681
  ]);
11671
- var handleInputChange = function(v) {
11682
+ var handleInputChange = function(v, event) {
11672
11683
  if (onType !== void 0) {
11673
11684
  debounceHandleOnType(v);
11674
11685
  }
@@ -11676,7 +11687,7 @@ function Select(props) {
11676
11687
  setShouldShowDefaultOption(v === "");
11677
11688
  }
11678
11689
  if (v === "" && !hasSearchInputInList) {
11679
- handleOnChange(void 0);
11690
+ handleOnChange(void 0, event);
11680
11691
  }
11681
11692
  setSearchValue(v);
11682
11693
  };
@@ -11706,7 +11717,7 @@ function Select(props) {
11706
11717
  return convertToId(opt) === valueIdToSelect;
11707
11718
  })) !== null && _value_some !== void 0 ? _value_some : false;
11708
11719
  }
11709
- handleToggleOptionCheckbox(indexToSelect, !isThisValueAlreadySelected);
11720
+ handleToggleOptionCheckbox(indexToSelect, !isThisValueAlreadySelected, event);
11710
11721
  } else {
11711
11722
  handleOptionSelect(indexToSelect, event);
11712
11723
  }
@@ -11748,7 +11759,7 @@ function Select(props) {
11748
11759
  hasSearchInputInList) && // Последняя проверка на случай, если мы че то ищем в опциях
11749
11760
  (optionsMode === "normal" || hasEnoughSymbolsToSearch)
11750
11761
  );
11751
- var _ref = dropdownOptions !== null && dropdownOptions !== void 0 ? dropdownOptions : {}, _ref_shouldUsePopper = _ref.shouldUsePopper, shouldUsePopper = _ref_shouldUsePopper === void 0 ? false : _ref_shouldUsePopper, _ref_shouldRenderInBody = _ref.shouldRenderInBody, shouldRenderInBody = _ref_shouldRenderInBody === void 0 ? false : _ref_shouldRenderInBody, _ref_shouldHideOnScroll = _ref.shouldHideOnScroll, shouldHideOnScroll = _ref_shouldHideOnScroll === void 0 ? false : _ref_shouldHideOnScroll;
11762
+ var _ref1 = dropdownOptions !== null && dropdownOptions !== void 0 ? dropdownOptions : {}, _ref_shouldUsePopper = _ref1.shouldUsePopper, shouldUsePopper = _ref_shouldUsePopper === void 0 ? false : _ref_shouldUsePopper, _ref_shouldRenderInBody = _ref1.shouldRenderInBody, shouldRenderInBody = _ref_shouldRenderInBody === void 0 ? false : _ref_shouldRenderInBody, _ref_shouldHideOnScroll = _ref1.shouldHideOnScroll, shouldHideOnScroll = _ref_shouldHideOnScroll === void 0 ? false : _ref_shouldHideOnScroll;
11752
11763
  var popperData = useDropdown({
11753
11764
  isOpen,
11754
11765
  onDropdownClose: handleListClose,
@@ -11787,15 +11798,15 @@ function Select(props) {
11787
11798
  }, popperData === null || popperData === void 0 ? void 0 : popperData.attributes.popper), {
11788
11799
  children: isOpen && /* @__PURE__ */ jsx(SelectList, {
11789
11800
  options: filteredOptions,
11790
- defaultOptionLabel: hasDefaultOption && shouldShowDefaultOption ? defaultOptionLabel : void 0,
11791
- allOptionsLabel: shouldShowAllOption ? allOptionsLabel : void 0,
11801
+ defaultOptionLabel: hasDefaultOption && shouldShowDefaultOption && defaultOptionLabel,
11802
+ allOptionsLabel: shouldShowAllOption && allOptionsLabel,
11792
11803
  areAllOptionsSelected,
11793
- customListHeader: hasSearchInputInList ? /* @__PURE__ */ jsx(SearchInput, _object_spread$D({
11804
+ customListHeader: hasSearchInputInList && /* @__PURE__ */ jsx(SearchInput, _object_spread$D({
11794
11805
  value: searchValue,
11795
11806
  onChange: handleInputChange,
11796
11807
  tweakStyles: tweakSearchInputStyles,
11797
11808
  placeholder: "Поиск"
11798
- }, searchInput)) : void 0,
11809
+ }, searchInputProps)),
11799
11810
  noMatchesLabel,
11800
11811
  focusedIndex: focusedListCellIndex,
11801
11812
  activeValue: value,
@@ -30086,6 +30097,9 @@ var useStyles$1 = createThemedStyles("WithPopup", {
30086
30097
  },
30087
30098
  trigger: {
30088
30099
  cursor: "pointer"
30100
+ },
30101
+ popup: {
30102
+ zIndex: 5
30089
30103
  }
30090
30104
  });
30091
30105
  function _array_like_to_array(arr, len) {
@@ -30264,19 +30278,21 @@ var WithPopup = function(param) {
30264
30278
  className: clsx(classes.root, _define_property$1({}, classes.disabled, isDisabled))
30265
30279
  }), addDataTestId(testId), addDataAttributes(data)), {
30266
30280
  children: [
30267
- /* @__PURE__ */ jsx("div", {
30281
+ /* @__PURE__ */ jsx("div", _object_spread_props$1(_object_spread$1({
30268
30282
  className: classes.trigger,
30269
30283
  onClick: eventType === "click" ? function(e) {
30270
30284
  return handleToggle(!isOpen, e);
30271
- } : void 0,
30285
+ } : void 0
30286
+ }, addDataTestId(testId, "trigger")), {
30272
30287
  children: isFunction$1(Trigger) ? /* @__PURE__ */ jsx(Trigger, {
30273
30288
  isActive: isOpen
30274
30289
  }) : Trigger
30275
- }),
30290
+ })),
30276
30291
  isOpen && /* @__PURE__ */ jsx(FloatingPortal, {
30277
30292
  root: !shouldRenderInBody ? refs.reference.current : void 0,
30278
30293
  children: /* @__PURE__ */ jsx("div", _object_spread_props$1(_object_spread$1({
30279
30294
  style: floatingStyles,
30295
+ className: classes.popup,
30280
30296
  ref: refs.setFloating
30281
30297
  }, getFloatingProps()), {
30282
30298
  children: isFunction$1(Popup) ? /* @__PURE__ */ jsx(Popup, {
@@ -30288,7 +30304,6 @@ var WithPopup = function(param) {
30288
30304
  }));
30289
30305
  };
30290
30306
  var useStyles = createThemedStyles("NewMoreMenu", {
30291
- root: {},
30292
30307
  hasCircle: {},
30293
30308
  button: {
30294
30309
  display: "flex",
@@ -30311,8 +30326,7 @@ var useStyles = createThemedStyles("NewMoreMenu", {
30311
30326
  active: {},
30312
30327
  disabled: {
30313
30328
  cursor: "default"
30314
- },
30315
- menu: {}
30329
+ }
30316
30330
  });
30317
30331
  function _define_property(obj, key, value) {
30318
30332
  if (key in obj) {
@@ -30371,6 +30385,16 @@ var NewMoreMenu = function(param) {
30371
30385
  var classes = useStyles({
30372
30386
  theme: tweakStyles
30373
30387
  });
30388
+ var tweakWithPopupStyles = useTweakStyles({
30389
+ tweakStyles,
30390
+ className: "tweakWithPopup",
30391
+ currentComponentName: "NewMoreMenu"
30392
+ });
30393
+ var tweakListStyles = useTweakStyles({
30394
+ tweakStyles,
30395
+ className: "tweakList",
30396
+ currentComponentName: "NewMoreMenu"
30397
+ });
30374
30398
  var isButtonDisabled = isDisabled || !isArrayNotEmpty(items);
30375
30399
  return /* @__PURE__ */ jsx(WithPopup, {
30376
30400
  placement,
@@ -30378,6 +30402,7 @@ var NewMoreMenu = function(param) {
30378
30402
  shouldHideOnScroll,
30379
30403
  shouldRenderInBody,
30380
30404
  isDisabled: isButtonDisabled,
30405
+ tweakStyles: tweakWithPopupStyles,
30381
30406
  trigger: function(param2) {
30382
30407
  var isActive = param2.isActive;
30383
30408
  var _obj;
@@ -30397,6 +30422,7 @@ var NewMoreMenu = function(param) {
30397
30422
  var onClose = param2.onClose;
30398
30423
  return /* @__PURE__ */ jsx(List, {
30399
30424
  items,
30425
+ tweakStyles: tweakListStyles,
30400
30426
  onClick: onClose
30401
30427
  });
30402
30428
  }