@true-engineering/true-react-common-ui-kit 1.5.0 → 1.5.2

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 (243) hide show
  1. package/LICENSE +201 -201
  2. package/dist/components/FiltersPane/FilterMultiSelect/FilterMultiSelect.d.ts +1 -0
  3. package/dist/components/FiltersPane/FilterValueView/FilterValueView.d.ts +1 -0
  4. package/dist/components/FiltersPane/FiltersPane.d.ts +1 -0
  5. package/dist/components/Flag/augment.d.ts +1 -1
  6. package/dist/components/Icon/complexIcons/augment.d.ts +1 -1
  7. package/dist/components/Input/Input.d.ts +4 -4
  8. package/dist/components/MultiSelect/MultiSelect.d.ts +1 -0
  9. package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +1 -1
  10. package/dist/true-react-common-ui-kit.js +67 -60
  11. package/dist/true-react-common-ui-kit.js.map +1 -1
  12. package/dist/true-react-common-ui-kit.umd.cjs +67 -60
  13. package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
  14. package/dist/vite-env.d.ts +1 -1
  15. package/package.json +91 -91
  16. package/src/components/AccountInfo/AccountInfo.stories.tsx +35 -35
  17. package/src/components/AccountInfo/AccountInfo.styles.ts +55 -55
  18. package/src/components/AccountInfo/AccountInfo.tsx +106 -106
  19. package/src/components/AccountInfo/index.ts +2 -2
  20. package/src/components/AddButton/AddButton.stories.tsx +21 -21
  21. package/src/components/AddButton/AddButton.styles.ts +34 -34
  22. package/src/components/AddButton/AddButton.tsx +49 -49
  23. package/src/components/AddButton/index.ts +2 -2
  24. package/src/components/Button/Button.stories.tsx +61 -61
  25. package/src/components/Button/Button.styles.ts +196 -196
  26. package/src/components/Button/Button.tsx +195 -195
  27. package/src/components/Button/index.ts +2 -2
  28. package/src/components/Checkbox/Checkbox.stories.tsx +35 -35
  29. package/src/components/Checkbox/Checkbox.styles.ts +59 -59
  30. package/src/components/Checkbox/Checkbox.tsx +93 -93
  31. package/src/components/Checkbox/index.ts +2 -2
  32. package/src/components/CloseButton/CloseButton.styles.ts +34 -34
  33. package/src/components/CloseButton/CloseButton.tsx +37 -37
  34. package/src/components/CloseButton/index.ts +2 -2
  35. package/src/components/Colors/Colors.stories.tsx +7 -7
  36. package/src/components/Colors/Colors.styles.ts +38 -38
  37. package/src/components/Colors/Colors.tsx +34 -34
  38. package/src/components/Colors/index.ts +2 -2
  39. package/src/components/CssBaseline/CssBaseline.styles.ts +15 -15
  40. package/src/components/CssBaseline/CssBaseline.tsx +17 -17
  41. package/src/components/CssBaseline/index.ts +2 -2
  42. package/src/components/DateInput/DateInput.stories.tsx +63 -63
  43. package/src/components/DateInput/DateInput.styles.ts +14 -14
  44. package/src/components/DateInput/DateInput.tsx +60 -60
  45. package/src/components/DateInput/index.ts +2 -2
  46. package/src/components/DatePicker/DatePicker.stories.tsx +96 -96
  47. package/src/components/DatePicker/DatePicker.styles.ts +54 -54
  48. package/src/components/DatePicker/DatePicker.tsx +358 -358
  49. package/src/components/DatePicker/DatePickerHeader/DatePickerHeader.styles.ts +84 -84
  50. package/src/components/DatePicker/DatePickerHeader/DatePickerHeader.tsx +94 -94
  51. package/src/components/DatePicker/DatePickerHeader/index.ts +1 -1
  52. package/src/components/DatePicker/DatePickerInput/DatePickerInput.styles.ts +25 -25
  53. package/src/components/DatePicker/DatePickerInput/DatePickerInput.tsx +31 -31
  54. package/src/components/DatePicker/DatePickerInput/index.ts +1 -1
  55. package/src/components/DatePicker/index.ts +4 -4
  56. package/src/components/Description/Description.stories.tsx +29 -29
  57. package/src/components/Description/Description.styles.ts +31 -31
  58. package/src/components/Description/Description.tsx +69 -69
  59. package/src/components/Description/index.ts +2 -2
  60. package/src/components/FiltersPane/FilterInterval/FilterInterval.styles.ts +64 -64
  61. package/src/components/FiltersPane/FilterInterval/FilterInterval.tsx +162 -162
  62. package/src/components/FiltersPane/FilterInterval/index.ts +1 -1
  63. package/src/components/FiltersPane/FilterMultiSelect/FilterMultiSelect.tsx +14 -14
  64. package/src/components/FiltersPane/FilterMultiSelect/index.ts +1 -1
  65. package/src/components/FiltersPane/FilterSelect/FilterSelect.styles.ts +144 -144
  66. package/src/components/FiltersPane/FilterSelect/FilterSelect.tsx +397 -397
  67. package/src/components/FiltersPane/FilterSelect/index.ts +1 -1
  68. package/src/components/FiltersPane/FilterSelect/locales.ts +37 -37
  69. package/src/components/FiltersPane/FilterValueView/FilterValueView.styles.tsx +15 -15
  70. package/src/components/FiltersPane/FilterValueView/FilterValueView.tsx +186 -186
  71. package/src/components/FiltersPane/FilterValueView/index.tsx +1 -1
  72. package/src/components/FiltersPane/FilterWithDates/FilterWithDates.styles.ts +60 -60
  73. package/src/components/FiltersPane/FilterWithDates/FilterWithDates.tsx +222 -222
  74. package/src/components/FiltersPane/FilterWithDates/index.ts +1 -1
  75. package/src/components/FiltersPane/FilterWithPeriod/FilterWithPeriod.styles.ts +17 -17
  76. package/src/components/FiltersPane/FilterWithPeriod/FilterWithPeriod.tsx +231 -231
  77. package/src/components/FiltersPane/FilterWithPeriod/index.ts +1 -1
  78. package/src/components/FiltersPane/FilterWrapper/FilterWrapper.styles.ts +110 -110
  79. package/src/components/FiltersPane/FilterWrapper/FilterWrapper.tsx +360 -360
  80. package/src/components/FiltersPane/FilterWrapper/index.ts +1 -1
  81. package/src/components/FiltersPane/FiltersPane.stories.tsx +308 -308
  82. package/src/components/FiltersPane/FiltersPane.styles.ts +71 -71
  83. package/src/components/FiltersPane/FiltersPane.tsx +193 -193
  84. package/src/components/FiltersPane/FiltersPaneSearch/FiltersPaneSearch.styles.ts +109 -109
  85. package/src/components/FiltersPane/FiltersPaneSearch/FiltersPaneSearch.tsx +175 -175
  86. package/src/components/FiltersPane/FiltersPaneSearch/index.ts +1 -1
  87. package/src/components/FiltersPane/index.ts +20 -20
  88. package/src/components/FiltersPane/locales.ts +107 -107
  89. package/src/components/FiltersPane/types.ts +126 -126
  90. package/src/components/Flag/Flag.stories.tsx +29 -29
  91. package/src/components/Flag/Flag.styles.ts +18 -18
  92. package/src/components/Flag/Flag.tsx +28 -28
  93. package/src/components/Flag/augment.d.ts +1 -1
  94. package/src/components/Flag/index.ts +2 -2
  95. package/src/components/FlexibleTable/FlexibleTable.stories.tsx +80 -80
  96. package/src/components/FlexibleTable/FlexibleTable.styles.ts +131 -131
  97. package/src/components/FlexibleTable/FlexibleTable.tsx +243 -243
  98. package/src/components/FlexibleTable/TableRow.tsx +171 -171
  99. package/src/components/FlexibleTable/TableValue.tsx +83 -83
  100. package/src/components/FlexibleTable/fixture-test.ts +254 -254
  101. package/src/components/FlexibleTable/index.ts +3 -3
  102. package/src/components/FlexibleTable/types.ts +58 -58
  103. package/src/components/Icon/ComplexIconBoilerplate.tsx +17 -17
  104. package/src/components/Icon/Icon.stories.tsx +88 -88
  105. package/src/components/Icon/Icon.styles.ts +10 -10
  106. package/src/components/Icon/Icon.tsx +34 -34
  107. package/src/components/Icon/IconBoilerplate.tsx +42 -42
  108. package/src/components/Icon/complexIcons/augment.d.ts +1 -1
  109. package/src/components/Icon/complexIcons/avatarGreen.svg +57 -57
  110. package/src/components/Icon/complexIcons/icons.ts +7 -7
  111. package/src/components/Icon/complexIcons/index.ts +1 -1
  112. package/src/components/Icon/icons/icons.ts +838 -838
  113. package/src/components/Icon/icons/index.ts +1 -1
  114. package/src/components/Icon/index.ts +4 -4
  115. package/src/components/IncrementInput/ChangeButton.tsx +34 -34
  116. package/src/components/IncrementInput/IncrementInput.stories.tsx +34 -34
  117. package/src/components/IncrementInput/IncrementInput.styles.ts +77 -77
  118. package/src/components/IncrementInput/IncrementInput.tsx +95 -95
  119. package/src/components/IncrementInput/index.ts +2 -2
  120. package/src/components/Input/Input.stories.tsx +92 -92
  121. package/src/components/Input/Input.styles.ts +305 -305
  122. package/src/components/Input/Input.tsx +324 -310
  123. package/src/components/Input/index.ts +2 -2
  124. package/src/components/List/List.stories.tsx +62 -62
  125. package/src/components/List/List.styles.ts +52 -52
  126. package/src/components/List/List.tsx +82 -82
  127. package/src/components/List/index.ts +2 -2
  128. package/src/components/Modal/Modal.stories.tsx +113 -113
  129. package/src/components/Modal/Modal.styles.ts +308 -308
  130. package/src/components/Modal/Modal.tsx +210 -210
  131. package/src/components/Modal/index.ts +2 -2
  132. package/src/components/MoreMenu/MoreMenu.stories.tsx +46 -46
  133. package/src/components/MoreMenu/MoreMenu.styles.ts +70 -70
  134. package/src/components/MoreMenu/MoreMenu.tsx +102 -102
  135. package/src/components/MoreMenu/index.ts +2 -2
  136. package/src/components/MultiSelect/MultiSelect.stories.tsx +46 -46
  137. package/src/components/MultiSelect/MultiSelect.styles.ts +55 -55
  138. package/src/components/MultiSelect/MultiSelect.tsx +98 -98
  139. package/src/components/MultiSelect/MultiSelectInput/MultiSelectInput.styles.ts +73 -73
  140. package/src/components/MultiSelect/MultiSelectInput/MultiSelectInput.tsx +62 -62
  141. package/src/components/MultiSelect/MultiSelectInput/index.ts +1 -1
  142. package/src/components/MultiSelect/index.ts +3 -3
  143. package/src/components/MultiSelectList/MultiSelectList.styles.ts +125 -125
  144. package/src/components/MultiSelectList/MultiSelectList.tsx +519 -519
  145. package/src/components/MultiSelectList/index.ts +2 -2
  146. package/src/components/MultiSelectList/locales.ts +37 -37
  147. package/src/components/Notification/Notification.stories.tsx +51 -51
  148. package/src/components/Notification/Notification.styles.ts +50 -50
  149. package/src/components/Notification/Notification.tsx +84 -84
  150. package/src/components/Notification/index.ts +2 -2
  151. package/src/components/NumberInput/NumberInput.stories.tsx +36 -36
  152. package/src/components/NumberInput/NumberInput.tsx +154 -154
  153. package/src/components/NumberInput/helpers.ts +87 -87
  154. package/src/components/NumberInput/index.ts +1 -1
  155. package/src/components/PhoneInput/PhoneInput.stories.tsx +71 -71
  156. package/src/components/PhoneInput/PhoneInput.styles.ts +84 -84
  157. package/src/components/PhoneInput/PhoneInput.tsx +223 -223
  158. package/src/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.stories.tsx +21 -21
  159. package/src/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.styles.ts +100 -100
  160. package/src/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.tsx +171 -171
  161. package/src/components/PhoneInput/PhoneInputCountryList/index.ts +2 -2
  162. package/src/components/PhoneInput/index.ts +6 -6
  163. package/src/components/PhoneInput/phone-info.ts +2167 -2167
  164. package/src/components/PhoneInput/types.ts +16 -16
  165. package/src/components/RadioButton/RadioButton.stories.tsx +46 -46
  166. package/src/components/RadioButton/RadioButton.styles.ts +37 -37
  167. package/src/components/RadioButton/RadioButton.tsx +56 -56
  168. package/src/components/RadioButton/index.ts +2 -2
  169. package/src/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.ts +66 -66
  170. package/src/components/ScrollIntoViewIfNeeded/index.ts +1 -1
  171. package/src/components/SearchInput/SearchInput.stories.tsx +24 -24
  172. package/src/components/SearchInput/SearchInput.styles.ts +50 -50
  173. package/src/components/SearchInput/SearchInput.tsx +63 -63
  174. package/src/components/SearchInput/index.ts +2 -2
  175. package/src/components/Select/Select.stories.tsx +258 -258
  176. package/src/components/Select/Select.styles.ts +85 -85
  177. package/src/components/Select/Select.tsx +508 -501
  178. package/src/components/Select/SelectList/SelectList.styles.ts +68 -68
  179. package/src/components/Select/SelectList/SelectList.tsx +139 -139
  180. package/src/components/Select/SelectList/index.ts +1 -1
  181. package/src/components/Select/helpers.ts +21 -21
  182. package/src/components/Select/index.ts +3 -3
  183. package/src/components/SmartInput/SmartInput.stories.tsx +63 -63
  184. package/src/components/SmartInput/SmartInput.tsx +180 -180
  185. package/src/components/SmartInput/helpers.ts +85 -85
  186. package/src/components/SmartInput/index.ts +1 -1
  187. package/src/components/Switch/Switch.stories.tsx +40 -40
  188. package/src/components/Switch/Switch.styles.ts +75 -75
  189. package/src/components/Switch/Switch.tsx +89 -89
  190. package/src/components/Switch/index.ts +2 -2
  191. package/src/components/TextArea/TextArea.stories.tsx +35 -35
  192. package/src/components/TextArea/TextArea.styles.ts +153 -153
  193. package/src/components/TextArea/TextArea.tsx +178 -178
  194. package/src/components/TextArea/index.ts +2 -2
  195. package/src/components/TextWithInfo/TextWithInfo.stories.tsx +53 -53
  196. package/src/components/TextWithInfo/TextWithInfo.styles.ts +60 -60
  197. package/src/components/TextWithInfo/TextWithInfo.tsx +67 -67
  198. package/src/components/TextWithInfo/index.ts +2 -2
  199. package/src/components/TextWithTooltip/TextWithTooltip.stories.tsx +58 -58
  200. package/src/components/TextWithTooltip/TextWithTooltip.styles.ts +19 -19
  201. package/src/components/TextWithTooltip/TextWithTooltip.tsx +163 -163
  202. package/src/components/TextWithTooltip/index.ts +2 -2
  203. package/src/components/ThemedPreloader/ThemedPreloader.stories.tsx +41 -41
  204. package/src/components/ThemedPreloader/ThemedPreloader.styles.ts +21 -21
  205. package/src/components/ThemedPreloader/ThemedPreloader.tsx +56 -56
  206. package/src/components/ThemedPreloader/components/DefaultPreloader/DefaultPreloader.tsx +34 -34
  207. package/src/components/ThemedPreloader/components/DefaultPreloader/index.ts +1 -1
  208. package/src/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.styles.ts +54 -54
  209. package/src/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.tsx +18 -18
  210. package/src/components/ThemedPreloader/components/DotsPreloader/index.ts +2 -2
  211. package/src/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.styles.ts +11 -11
  212. package/src/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.tsx +32 -32
  213. package/src/components/ThemedPreloader/components/SvgPreloader/index.ts +2 -2
  214. package/src/components/ThemedPreloader/components/index.ts +2 -2
  215. package/src/components/ThemedPreloader/index.ts +2 -2
  216. package/src/components/Toaster/Toaster.stories.tsx +34 -34
  217. package/src/components/Toaster/Toaster.styles.ts +59 -59
  218. package/src/components/Toaster/Toaster.tsx +113 -113
  219. package/src/components/Toaster/index.ts +2 -2
  220. package/src/components/Tooltip/Tooltip.stories.tsx +21 -21
  221. package/src/components/Tooltip/Tooltip.styles.ts +45 -45
  222. package/src/components/Tooltip/Tooltip.tsx +40 -40
  223. package/src/components/Tooltip/index.ts +3 -3
  224. package/src/components/Tooltip/types.ts +1 -1
  225. package/src/components/index.ts +36 -36
  226. package/src/helpers/colors.ts +2 -2
  227. package/src/helpers/data-attributes.ts +18 -18
  228. package/src/helpers/dateHelpers/date-helpers.ts +9 -9
  229. package/src/helpers/index.ts +5 -5
  230. package/src/helpers/phone.ts +106 -106
  231. package/src/helpers/popper-helpers.ts +17 -17
  232. package/src/helpers/snippets.tsx +5 -5
  233. package/src/helpers/utils.ts +178 -178
  234. package/src/hooks/index.ts +6 -6
  235. package/src/hooks/use-did-mount-effect.ts +21 -21
  236. package/src/hooks/use-dropdown.ts +85 -85
  237. package/src/hooks/use-is-mounted.ts +15 -15
  238. package/src/hooks/use-on-click-outside.ts +92 -92
  239. package/src/hooks/use-theme.ts +36 -36
  240. package/src/hooks/use-tweak-styles.ts +14 -14
  241. package/src/index.ts +6 -6
  242. package/src/theme.ts +155 -155
  243. package/src/vite-env.d.ts +1 -1
@@ -1,501 +1,508 @@
1
- import {
2
- ReactNode,
3
- FocusEvent,
4
- KeyboardEvent,
5
- MouseEvent,
6
- useCallback,
7
- useEffect,
8
- useMemo,
9
- useRef,
10
- useState,
11
- SyntheticEvent,
12
- } from 'react';
13
- import { Styles } from 'jss';
14
- import clsx from 'clsx';
15
- import { merge } from 'lodash';
16
- import { debounce } from 'ts-debounce';
17
- import { Portal } from 'react-overlays';
18
- import { SelectList } from './SelectList';
19
- import { IInputProps, Input } from '../Input';
20
- import { IIconType, Icon } from '../Icon';
21
- import {
22
- useIsMounted,
23
- useTheme,
24
- useOnClickOutsideWithRef,
25
- useDropdown,
26
- useTweakStyles,
27
- } from '../../hooks';
28
- import { IDropdownWithPopperOptions } from '../../types';
29
- import { getTestId, hasExactParent, isNotEmpty } from '../../helpers';
30
- import {
31
- defaultConvertFunction,
32
- defaultCompareFunction,
33
- getActiveValueIndex,
34
- defaultIsOptionDisabled,
35
- } from './helpers';
36
- import { SelectStyles, styles } from './Select.styles';
37
- import { ISearchInputProps, SearchInput } from '../SearchInput';
38
-
39
- export interface ISelectProps<Value>
40
- extends Omit<IInputProps, 'value' | 'onChange' | 'onBlur' | 'type'> {
41
- tweakStyles?: SelectStyles;
42
- defaultOptionLabel?: string;
43
- noMatchesLabel?: string;
44
- loadingLabel?: ReactNode;
45
- optionsMode?: 'search' | 'dynamic' | 'normal';
46
- debounceTime?: number;
47
- minSymbolsCountToOpenList?: number;
48
- dropdownOptions?: IDropdownWithPopperOptions;
49
- dropdownIcon?: IIconType;
50
- options: Value[];
51
- value: Value | undefined;
52
- shouldScrollToList?: boolean;
53
- searchInput?: { shouldRenderInList: true } & Pick<
54
- ISearchInputProps,
55
- 'placeholder'
56
- >;
57
- isOptionDisabled?(option: Value): boolean;
58
- onChange(value: Value | undefined): void; // подумать как возвращать индекс
59
- onBlur?(event: Event | SyntheticEvent): void;
60
- onType?(value: string): Promise<void>;
61
- optionsFilter?(options: Value[], query: string): Value[];
62
- onOpen?(): void;
63
- compareValuesOnChange?(v1: Value | undefined, v2: Value | undefined): boolean;
64
- // Для избежания проблем юзайте useCallback на эти функции
65
- // или выносите их из компонента (чтобы не было сайдэфектов от перерендеринга их)
66
- convertValueToString?(value: Value): string | undefined;
67
- convertValueToReactNode?(value: Value, isDisabled: boolean): ReactNode;
68
- convertValueToId?(value: Value): string | undefined;
69
- }
70
-
71
- export function Select<Value>({
72
- options,
73
- value,
74
- defaultOptionLabel,
75
- debounceTime = 400,
76
- optionsMode = 'normal',
77
- noMatchesLabel,
78
- loadingLabel,
79
- tweakStyles,
80
- testId,
81
- isDisabled,
82
- dropdownOptions,
83
- minSymbolsCountToOpenList = 0,
84
- dropdownIcon = 'chevron-down',
85
- shouldScrollToList = true,
86
- searchInput,
87
- onChange,
88
- onFocus,
89
- onBlur,
90
- onType,
91
- onOpen,
92
- isOptionDisabled = defaultIsOptionDisabled,
93
- compareValuesOnChange = defaultCompareFunction,
94
- convertValueToString = defaultConvertFunction,
95
- convertValueToId,
96
- convertValueToReactNode,
97
- optionsFilter,
98
- ...inputProps
99
- }: ISelectProps<Value>): JSX.Element {
100
- const { classes, componentStyles } = useTheme('Select', styles, tweakStyles);
101
- const isMounted = useIsMounted();
102
- const [isListOpen, setIsListOpen] = useState(false);
103
- const [areOptionsLoading, setAreOptionsLoading] = useState(false);
104
- const hasDefaultOption = defaultOptionLabel !== undefined;
105
-
106
- const [focusedListCellIndex, setFocusedListCellIndex] = useState(-1);
107
- const [searchValue, setSearchValue] = useState('');
108
-
109
- // если мы ввели что то в строку поиска - то этот булеан будет отключаться
110
- // вынесен отдельно, из-за проблем с дебаунсом при динамич. опциях
111
- const [shouldShowDefaultOption, setShouldShowDefaultOption] = useState(true);
112
-
113
- const inputWrapper = useRef<HTMLDivElement>(null);
114
- const list = useRef<HTMLDivElement>(null);
115
- const input = useRef<HTMLInputElement>(null); // TODO ref снаружи?
116
-
117
- const shouldRenderSearchInputInList =
118
- searchInput?.shouldRenderInList === true;
119
-
120
- const hasSearchInputInList =
121
- optionsMode !== 'normal' && shouldRenderSearchInputInList;
122
-
123
- const stringValue = isNotEmpty(value)
124
- ? convertValueToString(value)
125
- : undefined;
126
-
127
- const filteredOptions = useMemo(() => {
128
- if (optionsMode !== 'search') {
129
- return options;
130
- }
131
- if (optionsFilter) {
132
- return optionsFilter(options, searchValue);
133
- }
134
- const lowerCaseValue = searchValue?.toLowerCase();
135
- return options.filter((option) => {
136
- const convertedOption = convertValueToString(option);
137
- return (
138
- convertedOption !== undefined &&
139
- convertedOption.toLowerCase().includes(lowerCaseValue)
140
- );
141
- });
142
- }, [optionsMode, optionsFilter, options, convertValueToString, searchValue]);
143
-
144
- useEffect(() => {
145
- setFocusedListCellIndex(
146
- getActiveValueIndex(filteredOptions, value, convertValueToString),
147
- );
148
- }, [filteredOptions, value, convertValueToString]);
149
-
150
- const handleListClose = (event: Event | SyntheticEvent) => {
151
- setIsListOpen(false);
152
- setSearchValue('');
153
- setShouldShowDefaultOption(true);
154
- onBlur?.(event);
155
- };
156
-
157
- const handleListOpen = () => {
158
- if (!isListOpen) {
159
- setIsListOpen(true);
160
- }
161
- };
162
-
163
- const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
164
- onFocus?.(event);
165
- handleListOpen();
166
- };
167
-
168
- const handleOnClick = () => {
169
- handleListOpen();
170
- };
171
-
172
- const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
173
- if (!isNotEmpty(event.relatedTarget) || !isNotEmpty(list.current)) {
174
- return;
175
- }
176
-
177
- const isActionInsideList = hasExactParent(
178
- event.relatedTarget,
179
- list.current,
180
- );
181
-
182
- // Ниче не делаем если клик был внутри селекта
183
- if (!isActionInsideList) {
184
- handleListClose(event);
185
- }
186
- };
187
-
188
- const handleOnChange = useCallback(
189
- (newValue: Value | undefined) => {
190
- const areValuesEqual = compareValuesOnChange(value, newValue);
191
- if (areValuesEqual) {
192
- return;
193
- }
194
- onChange(newValue);
195
- },
196
- [value, onChange],
197
- );
198
-
199
- const handleOptionSelect = useCallback(
200
- (index: number, event: MouseEvent<HTMLElement> | KeyboardEvent) => {
201
- handleOnChange(index === -1 ? undefined : filteredOptions[index]);
202
- handleListClose(event);
203
- input.current?.blur();
204
- },
205
- [handleOnChange, filteredOptions],
206
- );
207
-
208
- const handleOnType = useCallback(
209
- async (v: string) => {
210
- if (onType === undefined) {
211
- return;
212
- }
213
- if (isMounted()) {
214
- setAreOptionsLoading(true);
215
- }
216
- await onType(v);
217
- if (isMounted()) {
218
- setAreOptionsLoading(false);
219
- }
220
- if (optionsMode === 'dynamic') {
221
- setShouldShowDefaultOption(v === '');
222
- }
223
- },
224
- [onType, optionsMode],
225
- );
226
-
227
- const debounceHandleOnType = useCallback(
228
- debounce(handleOnType, debounceTime),
229
- [handleOnType, debounceTime],
230
- );
231
-
232
- const handleInputChange = (v: string) => {
233
- if (onType !== undefined) {
234
- debounceHandleOnType(v);
235
- }
236
-
237
- if (optionsMode !== 'dynamic') {
238
- setShouldShowDefaultOption(v === '');
239
- }
240
-
241
- if (v === '' && !hasSearchInputInList) {
242
- handleOnChange(undefined);
243
- }
244
-
245
- setSearchValue(v);
246
- };
247
-
248
- const handleKeyDown = (event: KeyboardEvent) => {
249
- if (!isListOpen) {
250
- return;
251
- }
252
-
253
- event.stopPropagation();
254
-
255
- switch (event.code) {
256
- case 'Enter':
257
- case 'NumpadEnter': {
258
- let indexToClick = focusedListCellIndex;
259
-
260
- // если осталось одна опция в списке,
261
- // то выбираем ее нажатием на enter
262
- if (indexToClick === -1 && filteredOptions.length === 1) {
263
- indexToClick = 0;
264
- }
265
-
266
- handleOptionSelect(indexToClick, event);
267
- break;
268
- }
269
-
270
- case 'ArrowDown': {
271
- // чтобы убрать перемещение курсора в инпуте
272
- event.preventDefault();
273
- let newIndex: number = focusedListCellIndex ?? -1;
274
- // ищем первый незадизейбленный вариант, либо дефолтную опцию
275
- for (let i = newIndex; i < newIndex + filteredOptions.length; i++) {
276
- const targetIndex = (i + 1) % filteredOptions.length;
277
- if (
278
- shouldShowDefaultOption &&
279
- hasDefaultOption &&
280
- newIndex > -1 &&
281
- targetIndex === 0
282
- ) {
283
- newIndex = -1;
284
- break;
285
- }
286
- if (!isOptionDisabled(filteredOptions[targetIndex])) {
287
- newIndex = targetIndex;
288
- break;
289
- }
290
- }
291
- setFocusedListCellIndex(newIndex);
292
- break;
293
- }
294
-
295
- case 'ArrowUp': {
296
- // чтобы убрать перемещение курсора в инпуте
297
- event.preventDefault();
298
- const newIndex: number =
299
- (focusedListCellIndex ?? -1) === -1 ? 0 : focusedListCellIndex;
300
- // ищем первый незадизейбленный вариант, либо дефолтную опцию
301
- for (let i = newIndex; i > newIndex - filteredOptions.length; i--) {
302
- const targetIndex = (i > 0 ? i : filteredOptions.length + i) - 1;
303
- if (
304
- shouldShowDefaultOption &&
305
- hasDefaultOption &&
306
- focusedListCellIndex !== -1 &&
307
- targetIndex === filteredOptions.length - 1
308
- ) {
309
- // не выносить сет наружу (приведет к багу)
310
- setFocusedListCellIndex(-1);
311
- break;
312
- }
313
- if (!isOptionDisabled(filteredOptions[targetIndex])) {
314
- // не выносить сет наружу (приведет к багу)
315
- setFocusedListCellIndex(targetIndex);
316
- break;
317
- }
318
- }
319
- break;
320
- }
321
- }
322
- };
323
-
324
- const onArrowClick = () => {
325
- if (isListOpen) {
326
- input.current?.blur();
327
- } else {
328
- input.current?.focus();
329
- }
330
- };
331
-
332
- useOnClickOutsideWithRef(list, handleListClose, inputWrapper);
333
-
334
- const hasEnoughSymbolsToSearch =
335
- searchValue.trim().length >= minSymbolsCountToOpenList;
336
-
337
- const isOpen =
338
- // Пользователь пытается открыть лист
339
- isListOpen &&
340
- // Нам есть что показать:
341
- // Есть опции
342
- (filteredOptions.length > 0 ||
343
- // Дефолтная опция
344
- (defaultOptionLabel !== undefined && !hasEnoughSymbolsToSearch) ||
345
- // Текст "Загрузка..."
346
- inputProps.isLoading ||
347
- // Текст "Совпадений не найдено"
348
- noMatchesLabel !== undefined ||
349
- // У нас есть инпут с поиском внутри листа
350
- hasSearchInputInList) &&
351
- // Последняя проверка на случай, если мы че то ищем в опциях
352
- (optionsMode === 'normal' || hasEnoughSymbolsToSearch);
353
-
354
- const { isReadonly = true } = inputProps;
355
- const shouldUsePointerCursor =
356
- (optionsMode === 'normal' || shouldRenderSearchInputInList) && isReadonly;
357
-
358
- const tweakInputStyles = useMemo(
359
- () =>
360
- merge(
361
- {},
362
- componentStyles.tweakInput,
363
- {
364
- ...(shouldUsePointerCursor
365
- ? { input: { cursor: 'pointer' } }
366
- : undefined),
367
- },
368
- tweakStyles?.tweakInput,
369
- ) as Styles,
370
- [tweakStyles?.tweakInput, shouldUsePointerCursor],
371
- );
372
-
373
- const tweakSearchInputStyles = useTweakStyles(
374
- componentStyles,
375
- tweakStyles,
376
- 'tweakSearchInput',
377
- );
378
-
379
- // Эти значения ставятся в false по дефолту также в useDropdown
380
- const {
381
- shouldUsePopper = false,
382
- shouldRenderInBody = false,
383
- shouldHideOnScroll = false,
384
- } = dropdownOptions ?? {};
385
-
386
- const popperData = useDropdown({
387
- isOpen,
388
- onDropdownClose: handleListClose,
389
- referenceElement: inputWrapper.current,
390
- dropdownElement: list.current,
391
- options: dropdownOptions,
392
- dependenciesForPositionUpdating: [
393
- inputProps.isLoading,
394
- filteredOptions.length,
395
- ],
396
- });
397
-
398
- useEffect(() => {
399
- if (isOpen && onOpen !== undefined) {
400
- onOpen();
401
- }
402
- }, [isOpen, onOpen]);
403
-
404
- const listEl = (
405
- <div
406
- className={clsx(classes.listWrapper, {
407
- [classes.withoutPopper]: !shouldUsePopper,
408
- [classes.listWrapperInBody]: shouldRenderInBody,
409
- })}
410
- ref={list}
411
- style={popperData?.styles.popper as Styles}
412
- onBlur={handleBlur} // обработка для Tab из списка
413
- {...popperData?.attributes.popper}
414
- >
415
- {isOpen && (
416
- <SelectList
417
- options={filteredOptions}
418
- defaultOptionLabel={
419
- hasDefaultOption && shouldShowDefaultOption
420
- ? defaultOptionLabel
421
- : undefined
422
- }
423
- customListHeader={
424
- hasSearchInputInList ? (
425
- <SearchInput
426
- value={searchValue}
427
- onChange={handleInputChange}
428
- tweakStyles={tweakSearchInputStyles}
429
- placeholder="Поиск"
430
- {...searchInput}
431
- />
432
- ) : undefined
433
- }
434
- noMatchesLabel={noMatchesLabel}
435
- focusedIndex={focusedListCellIndex}
436
- activeValue={value}
437
- isLoading={inputProps.isLoading}
438
- loadingLabel={loadingLabel}
439
- tweakStyles={tweakStyles?.tweakSelectList as Styles}
440
- testId={getTestId(testId, 'list')}
441
- // скролл не работает с включеным поппером
442
- shouldScrollToList={
443
- shouldScrollToList && !shouldUsePopper && !shouldHideOnScroll
444
- }
445
- isOptionDisabled={isOptionDisabled}
446
- convertValueToString={convertValueToString}
447
- convertValueToReactNode={convertValueToReactNode}
448
- convertValueToId={convertValueToId}
449
- onOptionClick={handleOptionSelect}
450
- />
451
- )}
452
- </div>
453
- );
454
-
455
- return (
456
- <div className={classes.root} onKeyDown={handleKeyDown}>
457
- <div
458
- className={clsx(classes.inputWrapper, isDisabled && classes.disabled)}
459
- onClick={isDisabled ? undefined : handleOnClick}
460
- ref={inputWrapper}
461
- >
462
- <Input
463
- value={
464
- searchValue !== '' && !shouldRenderSearchInputInList
465
- ? searchValue
466
- : stringValue
467
- }
468
- onChange={handleInputChange}
469
- isActive={isListOpen}
470
- isReadonly={optionsMode === 'normal' || shouldRenderSearchInputInList}
471
- onFocus={handleFocus}
472
- onBlur={handleBlur}
473
- isDisabled={isDisabled}
474
- ref={input}
475
- isLoading={areOptionsLoading}
476
- tweakStyles={tweakInputStyles}
477
- testId={testId}
478
- {...inputProps}
479
- />
480
- <div
481
- onMouseDown={(event: MouseEvent) => {
482
- event.preventDefault();
483
- }}
484
- onClick={onArrowClick}
485
- className={clsx(classes.arrow, isListOpen && classes.activeArrow)}
486
- >
487
- <Icon type={dropdownIcon} />
488
- </div>
489
- </div>
490
- {shouldUsePopper ? (
491
- <Portal
492
- container={shouldRenderInBody ? document.body : inputWrapper.current}
493
- >
494
- <>{listEl}</>
495
- </Portal>
496
- ) : (
497
- <>{isOpen && listEl}</>
498
- )}
499
- </div>
500
- );
501
- }
1
+ import {
2
+ ReactNode,
3
+ FocusEvent,
4
+ KeyboardEvent,
5
+ MouseEvent,
6
+ useCallback,
7
+ useEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ SyntheticEvent,
12
+ } from 'react';
13
+ import { Styles } from 'jss';
14
+ import clsx from 'clsx';
15
+ import { merge } from 'lodash';
16
+ import { debounce } from 'ts-debounce';
17
+ import { Portal } from 'react-overlays';
18
+ import { SelectList } from './SelectList';
19
+ import { IInputProps, Input } from '../Input';
20
+ import { IIconType, Icon } from '../Icon';
21
+ import {
22
+ useIsMounted,
23
+ useTheme,
24
+ useOnClickOutsideWithRef,
25
+ useDropdown,
26
+ useTweakStyles,
27
+ } from '../../hooks';
28
+ import { IDropdownWithPopperOptions } from '../../types';
29
+ import { getTestId, hasExactParent, isNotEmpty } from '../../helpers';
30
+ import {
31
+ defaultConvertFunction,
32
+ defaultCompareFunction,
33
+ getActiveValueIndex,
34
+ defaultIsOptionDisabled,
35
+ } from './helpers';
36
+ import { SelectStyles, styles } from './Select.styles';
37
+ import { ISearchInputProps, SearchInput } from '../SearchInput';
38
+
39
+ export interface ISelectProps<Value>
40
+ extends Omit<IInputProps, 'value' | 'onChange' | 'onBlur' | 'type'> {
41
+ tweakStyles?: SelectStyles;
42
+ defaultOptionLabel?: string;
43
+ noMatchesLabel?: string;
44
+ loadingLabel?: ReactNode;
45
+ optionsMode?: 'search' | 'dynamic' | 'normal';
46
+ debounceTime?: number;
47
+ minSymbolsCountToOpenList?: number;
48
+ dropdownOptions?: IDropdownWithPopperOptions;
49
+ dropdownIcon?: IIconType;
50
+ options: Value[];
51
+ value: Value | undefined;
52
+ shouldScrollToList?: boolean;
53
+ searchInput?: { shouldRenderInList: true } & Pick<
54
+ ISearchInputProps,
55
+ 'placeholder'
56
+ >;
57
+ isOptionDisabled?(option: Value): boolean;
58
+ onChange(value: Value | undefined): void; // подумать как возвращать индекс
59
+ onBlur?(event: Event | SyntheticEvent): void;
60
+ onType?(value: string): Promise<void>;
61
+ optionsFilter?(options: Value[], query: string): Value[];
62
+ onOpen?(): void;
63
+ compareValuesOnChange?(v1: Value | undefined, v2: Value | undefined): boolean;
64
+ // Для избежания проблем юзайте useCallback на эти функции
65
+ // или выносите их из компонента (чтобы не было сайдэфектов от перерендеринга их)
66
+ convertValueToString?(value: Value): string | undefined;
67
+ convertValueToReactNode?(value: Value, isDisabled: boolean): ReactNode;
68
+ convertValueToId?(value: Value): string | undefined;
69
+ }
70
+
71
+ export function Select<Value>({
72
+ options,
73
+ value,
74
+ defaultOptionLabel,
75
+ debounceTime = 400,
76
+ optionsMode = 'normal',
77
+ noMatchesLabel,
78
+ loadingLabel,
79
+ tweakStyles,
80
+ testId,
81
+ isDisabled,
82
+ dropdownOptions,
83
+ minSymbolsCountToOpenList = 0,
84
+ dropdownIcon = 'chevron-down',
85
+ shouldScrollToList = true,
86
+ searchInput,
87
+ onChange,
88
+ onFocus,
89
+ onBlur,
90
+ onType,
91
+ onOpen,
92
+ isOptionDisabled = defaultIsOptionDisabled,
93
+ compareValuesOnChange = defaultCompareFunction,
94
+ convertValueToString = defaultConvertFunction,
95
+ convertValueToId,
96
+ convertValueToReactNode,
97
+ optionsFilter,
98
+ ...inputProps
99
+ }: ISelectProps<Value>): JSX.Element {
100
+ const { classes, componentStyles } = useTheme('Select', styles, tweakStyles);
101
+ const isMounted = useIsMounted();
102
+ const [isListOpen, setIsListOpen] = useState(false);
103
+ const [areOptionsLoading, setAreOptionsLoading] = useState(false);
104
+ const hasDefaultOption = defaultOptionLabel !== undefined;
105
+
106
+ const [focusedListCellIndex, setFocusedListCellIndex] = useState(-1);
107
+ const [searchValue, setSearchValue] = useState('');
108
+
109
+ // если мы ввели что то в строку поиска - то этот булеан будет отключаться
110
+ // вынесен отдельно, из-за проблем с дебаунсом при динамич. опциях
111
+ const [shouldShowDefaultOption, setShouldShowDefaultOption] = useState(true);
112
+
113
+ const inputWrapper = useRef<HTMLDivElement>(null);
114
+ const list = useRef<HTMLDivElement>(null);
115
+ const input = useRef<HTMLInputElement>(null); // TODO ref снаружи?
116
+
117
+ const shouldRenderSearchInputInList =
118
+ searchInput?.shouldRenderInList === true;
119
+
120
+ const hasSearchInputInList =
121
+ optionsMode !== 'normal' && shouldRenderSearchInputInList;
122
+
123
+ const stringValue = isNotEmpty(value)
124
+ ? convertValueToString(value)
125
+ : undefined;
126
+
127
+ const filteredOptions = useMemo(() => {
128
+ if (optionsMode !== 'search') {
129
+ return options;
130
+ }
131
+ if (optionsFilter) {
132
+ return optionsFilter(options, searchValue);
133
+ }
134
+ const lowerCaseValue = searchValue?.toLowerCase();
135
+ return options.filter((option) => {
136
+ const convertedOption = convertValueToString(option);
137
+ return (
138
+ convertedOption !== undefined &&
139
+ convertedOption.toLowerCase().includes(lowerCaseValue)
140
+ );
141
+ });
142
+ }, [optionsMode, optionsFilter, options, convertValueToString, searchValue]);
143
+
144
+ useEffect(() => {
145
+ setFocusedListCellIndex(
146
+ getActiveValueIndex(filteredOptions, value, convertValueToString),
147
+ );
148
+ }, [filteredOptions, value, convertValueToString]);
149
+
150
+ const handleListClose = (event: Event | SyntheticEvent) => {
151
+ setIsListOpen(false);
152
+ setSearchValue('');
153
+ setShouldShowDefaultOption(true);
154
+ onBlur?.(event);
155
+ };
156
+
157
+ const handleListOpen = () => {
158
+ if (!isListOpen) {
159
+ setIsListOpen(true);
160
+ }
161
+ };
162
+
163
+ const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
164
+ onFocus?.(event);
165
+ handleListOpen();
166
+ };
167
+
168
+ const handleOnClick = () => {
169
+ handleListOpen();
170
+ };
171
+
172
+ const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
173
+ // Когда что-то блокирует открытие листа, но блур все равно должен сработать
174
+ // например minSymbolsCount
175
+ if (isListOpen && !isOpen) {
176
+ handleListClose(event);
177
+ return;
178
+ }
179
+
180
+ if (!isNotEmpty(event.relatedTarget) || !isNotEmpty(list.current)) {
181
+ return;
182
+ }
183
+
184
+ const isActionInsideList = hasExactParent(
185
+ event.relatedTarget,
186
+ list.current,
187
+ );
188
+
189
+ // Ниче не делаем если клик был внутри селекта
190
+ if (!isActionInsideList) {
191
+ handleListClose(event);
192
+ }
193
+ };
194
+
195
+ const handleOnChange = useCallback(
196
+ (newValue: Value | undefined) => {
197
+ const areValuesEqual = compareValuesOnChange(value, newValue);
198
+ if (areValuesEqual) {
199
+ return;
200
+ }
201
+ onChange(newValue);
202
+ },
203
+ [value, onChange],
204
+ );
205
+
206
+ const handleOptionSelect = useCallback(
207
+ (index: number, event: MouseEvent<HTMLElement> | KeyboardEvent) => {
208
+ handleOnChange(index === -1 ? undefined : filteredOptions[index]);
209
+ handleListClose(event);
210
+ input.current?.blur();
211
+ },
212
+ [handleOnChange, filteredOptions],
213
+ );
214
+
215
+ const handleOnType = useCallback(
216
+ async (v: string) => {
217
+ if (onType === undefined) {
218
+ return;
219
+ }
220
+ if (isMounted()) {
221
+ setAreOptionsLoading(true);
222
+ }
223
+ await onType(v);
224
+ if (isMounted()) {
225
+ setAreOptionsLoading(false);
226
+ }
227
+ if (optionsMode === 'dynamic') {
228
+ setShouldShowDefaultOption(v === '');
229
+ }
230
+ },
231
+ [onType, optionsMode],
232
+ );
233
+
234
+ const debounceHandleOnType = useCallback(
235
+ debounce(handleOnType, debounceTime),
236
+ [handleOnType, debounceTime],
237
+ );
238
+
239
+ const handleInputChange = (v: string) => {
240
+ if (onType !== undefined) {
241
+ debounceHandleOnType(v);
242
+ }
243
+
244
+ if (optionsMode !== 'dynamic') {
245
+ setShouldShowDefaultOption(v === '');
246
+ }
247
+
248
+ if (v === '' && !hasSearchInputInList) {
249
+ handleOnChange(undefined);
250
+ }
251
+
252
+ setSearchValue(v);
253
+ };
254
+
255
+ const handleKeyDown = (event: KeyboardEvent) => {
256
+ if (!isListOpen) {
257
+ return;
258
+ }
259
+
260
+ event.stopPropagation();
261
+
262
+ switch (event.code) {
263
+ case 'Enter':
264
+ case 'NumpadEnter': {
265
+ let indexToClick = focusedListCellIndex;
266
+
267
+ // если осталось одна опция в списке,
268
+ // то выбираем ее нажатием на enter
269
+ if (indexToClick === -1 && filteredOptions.length === 1) {
270
+ indexToClick = 0;
271
+ }
272
+
273
+ handleOptionSelect(indexToClick, event);
274
+ break;
275
+ }
276
+
277
+ case 'ArrowDown': {
278
+ // чтобы убрать перемещение курсора в инпуте
279
+ event.preventDefault();
280
+ let newIndex: number = focusedListCellIndex ?? -1;
281
+ // ищем первый незадизейбленный вариант, либо дефолтную опцию
282
+ for (let i = newIndex; i < newIndex + filteredOptions.length; i++) {
283
+ const targetIndex = (i + 1) % filteredOptions.length;
284
+ if (
285
+ shouldShowDefaultOption &&
286
+ hasDefaultOption &&
287
+ newIndex > -1 &&
288
+ targetIndex === 0
289
+ ) {
290
+ newIndex = -1;
291
+ break;
292
+ }
293
+ if (!isOptionDisabled(filteredOptions[targetIndex])) {
294
+ newIndex = targetIndex;
295
+ break;
296
+ }
297
+ }
298
+ setFocusedListCellIndex(newIndex);
299
+ break;
300
+ }
301
+
302
+ case 'ArrowUp': {
303
+ // чтобы убрать перемещение курсора в инпуте
304
+ event.preventDefault();
305
+ const newIndex: number =
306
+ (focusedListCellIndex ?? -1) === -1 ? 0 : focusedListCellIndex;
307
+ // ищем первый незадизейбленный вариант, либо дефолтную опцию
308
+ for (let i = newIndex; i > newIndex - filteredOptions.length; i--) {
309
+ const targetIndex = (i > 0 ? i : filteredOptions.length + i) - 1;
310
+ if (
311
+ shouldShowDefaultOption &&
312
+ hasDefaultOption &&
313
+ focusedListCellIndex !== -1 &&
314
+ targetIndex === filteredOptions.length - 1
315
+ ) {
316
+ // не выносить сет наружу (приведет к багу)
317
+ setFocusedListCellIndex(-1);
318
+ break;
319
+ }
320
+ if (!isOptionDisabled(filteredOptions[targetIndex])) {
321
+ // не выносить сет наружу (приведет к багу)
322
+ setFocusedListCellIndex(targetIndex);
323
+ break;
324
+ }
325
+ }
326
+ break;
327
+ }
328
+ }
329
+ };
330
+
331
+ const onArrowClick = () => {
332
+ if (isListOpen) {
333
+ input.current?.blur();
334
+ } else {
335
+ input.current?.focus();
336
+ }
337
+ };
338
+
339
+ useOnClickOutsideWithRef(list, handleListClose, inputWrapper);
340
+
341
+ const hasEnoughSymbolsToSearch =
342
+ searchValue.trim().length >= minSymbolsCountToOpenList;
343
+
344
+ const isOpen =
345
+ // Пользователь пытается открыть лист
346
+ isListOpen &&
347
+ // Нам есть что показать:
348
+ // Есть опции
349
+ (filteredOptions.length > 0 ||
350
+ // Дефолтная опция
351
+ (defaultOptionLabel !== undefined && !hasEnoughSymbolsToSearch) ||
352
+ // Текст "Загрузка..."
353
+ inputProps.isLoading ||
354
+ // Текст "Совпадений не найдено"
355
+ noMatchesLabel !== undefined ||
356
+ // У нас есть инпут с поиском внутри листа
357
+ hasSearchInputInList) &&
358
+ // Последняя проверка на случай, если мы че то ищем в опциях
359
+ (optionsMode === 'normal' || hasEnoughSymbolsToSearch);
360
+
361
+ const { isReadonly = true } = inputProps;
362
+ const shouldUsePointerCursor =
363
+ (optionsMode === 'normal' || shouldRenderSearchInputInList) && isReadonly;
364
+
365
+ const tweakInputStyles = useMemo(
366
+ () =>
367
+ merge(
368
+ {},
369
+ componentStyles.tweakInput,
370
+ {
371
+ ...(shouldUsePointerCursor
372
+ ? { input: { cursor: 'pointer' } }
373
+ : undefined),
374
+ },
375
+ tweakStyles?.tweakInput,
376
+ ) as Styles,
377
+ [tweakStyles?.tweakInput, shouldUsePointerCursor],
378
+ );
379
+
380
+ const tweakSearchInputStyles = useTweakStyles(
381
+ componentStyles,
382
+ tweakStyles,
383
+ 'tweakSearchInput',
384
+ );
385
+
386
+ // Эти значения ставятся в false по дефолту также в useDropdown
387
+ const {
388
+ shouldUsePopper = false,
389
+ shouldRenderInBody = false,
390
+ shouldHideOnScroll = false,
391
+ } = dropdownOptions ?? {};
392
+
393
+ const popperData = useDropdown({
394
+ isOpen,
395
+ onDropdownClose: handleListClose,
396
+ referenceElement: inputWrapper.current,
397
+ dropdownElement: list.current,
398
+ options: dropdownOptions,
399
+ dependenciesForPositionUpdating: [
400
+ inputProps.isLoading,
401
+ filteredOptions.length,
402
+ ],
403
+ });
404
+
405
+ useEffect(() => {
406
+ if (isOpen && onOpen !== undefined) {
407
+ onOpen();
408
+ }
409
+ }, [isOpen, onOpen]);
410
+
411
+ const listEl = (
412
+ <div
413
+ className={clsx(classes.listWrapper, {
414
+ [classes.withoutPopper]: !shouldUsePopper,
415
+ [classes.listWrapperInBody]: shouldRenderInBody,
416
+ })}
417
+ ref={list}
418
+ style={popperData?.styles.popper as Styles}
419
+ onBlur={handleBlur} // обработка для Tab из списка
420
+ {...popperData?.attributes.popper}
421
+ >
422
+ {isOpen && (
423
+ <SelectList
424
+ options={filteredOptions}
425
+ defaultOptionLabel={
426
+ hasDefaultOption && shouldShowDefaultOption
427
+ ? defaultOptionLabel
428
+ : undefined
429
+ }
430
+ customListHeader={
431
+ hasSearchInputInList ? (
432
+ <SearchInput
433
+ value={searchValue}
434
+ onChange={handleInputChange}
435
+ tweakStyles={tweakSearchInputStyles}
436
+ placeholder="Поиск"
437
+ {...searchInput}
438
+ />
439
+ ) : undefined
440
+ }
441
+ noMatchesLabel={noMatchesLabel}
442
+ focusedIndex={focusedListCellIndex}
443
+ activeValue={value}
444
+ isLoading={inputProps.isLoading}
445
+ loadingLabel={loadingLabel}
446
+ tweakStyles={tweakStyles?.tweakSelectList as Styles}
447
+ testId={getTestId(testId, 'list')}
448
+ // скролл не работает с включеным поппером
449
+ shouldScrollToList={
450
+ shouldScrollToList && !shouldUsePopper && !shouldHideOnScroll
451
+ }
452
+ isOptionDisabled={isOptionDisabled}
453
+ convertValueToString={convertValueToString}
454
+ convertValueToReactNode={convertValueToReactNode}
455
+ convertValueToId={convertValueToId}
456
+ onOptionClick={handleOptionSelect}
457
+ />
458
+ )}
459
+ </div>
460
+ );
461
+
462
+ return (
463
+ <div className={classes.root} onKeyDown={handleKeyDown}>
464
+ <div
465
+ className={clsx(classes.inputWrapper, isDisabled && classes.disabled)}
466
+ onClick={isDisabled ? undefined : handleOnClick}
467
+ ref={inputWrapper}
468
+ >
469
+ <Input
470
+ value={
471
+ searchValue !== '' && !shouldRenderSearchInputInList
472
+ ? searchValue
473
+ : stringValue
474
+ }
475
+ onChange={handleInputChange}
476
+ isActive={isListOpen}
477
+ isReadonly={optionsMode === 'normal' || shouldRenderSearchInputInList}
478
+ onFocus={handleFocus}
479
+ onBlur={handleBlur}
480
+ isDisabled={isDisabled}
481
+ ref={input}
482
+ isLoading={areOptionsLoading}
483
+ tweakStyles={tweakInputStyles}
484
+ testId={testId}
485
+ {...inputProps}
486
+ />
487
+ <div
488
+ onMouseDown={(event: MouseEvent) => {
489
+ event.preventDefault();
490
+ }}
491
+ onClick={onArrowClick}
492
+ className={clsx(classes.arrow, isOpen && classes.activeArrow)}
493
+ >
494
+ <Icon type={dropdownIcon} />
495
+ </div>
496
+ </div>
497
+ {shouldUsePopper ? (
498
+ <Portal
499
+ container={shouldRenderInBody ? document.body : inputWrapper.current}
500
+ >
501
+ <>{listEl}</>
502
+ </Portal>
503
+ ) : (
504
+ <>{isOpen && listEl}</>
505
+ )}
506
+ </div>
507
+ );
508
+ }