@true-engineering/true-react-common-ui-kit 2.7.0 → 3.0.0-alpha.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.
Files changed (478) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +0 -26
  3. package/dist/components/AccountInfo/AccountInfo.d.ts +2 -3
  4. package/dist/components/AccountInfo/AccountInfo.styles.d.ts +6 -64
  5. package/dist/components/AccountInfo/index.d.ts +1 -1
  6. package/dist/components/AddButton/AddButton.d.ts +2 -3
  7. package/dist/components/AddButton/AddButton.styles.d.ts +3 -28
  8. package/dist/components/AddButton/index.d.ts +1 -1
  9. package/dist/components/Button/Button.d.ts +2 -4
  10. package/dist/components/Button/Button.styles.d.ts +8 -150
  11. package/dist/components/Button/index.d.ts +1 -1
  12. package/dist/components/Checkbox/Checkbox.d.ts +3 -17
  13. package/dist/components/Checkbox/Checkbox.styles.d.ts +3 -50
  14. package/dist/components/Checkbox/index.d.ts +1 -1
  15. package/dist/components/CloseButton/CloseButton.d.ts +3 -5
  16. package/dist/components/CloseButton/CloseButton.styles.d.ts +3 -27
  17. package/dist/components/CloseButton/index.d.ts +1 -1
  18. package/dist/components/Colors/Colors.styles.d.ts +1 -32
  19. package/dist/components/Colors/index.d.ts +0 -1
  20. package/dist/components/CssBaseline/CssBaseline.d.ts +2 -4
  21. package/dist/components/CssBaseline/CssBaseline.styles.d.ts +3 -11
  22. package/dist/components/CssBaseline/index.d.ts +1 -1
  23. package/dist/components/DateInput/DateInput.d.ts +3 -3
  24. package/dist/components/DateInput/DateInput.styles.d.ts +6 -11
  25. package/dist/components/DateInput/index.d.ts +1 -1
  26. package/dist/components/DatePicker/DatePicker.d.ts +5 -7
  27. package/dist/components/DatePicker/DatePicker.styles.d.ts +6 -33
  28. package/dist/components/DatePicker/components/DatePickerHeader/DatePickerHeader.d.ts +3 -3
  29. package/dist/components/DatePicker/components/DatePickerHeader/DatePickerHeader.styles.d.ts +7 -69
  30. package/dist/components/DatePicker/components/DatePickerHeader/index.d.ts +1 -1
  31. package/dist/components/DatePicker/index.d.ts +2 -2
  32. package/dist/components/Description/Description.d.ts +2 -3
  33. package/dist/components/Description/Description.styles.d.ts +3 -24
  34. package/dist/components/Description/index.d.ts +1 -1
  35. package/dist/components/FiltersPane/FiltersPane.d.ts +6 -8
  36. package/dist/components/FiltersPane/FiltersPane.styles.d.ts +8 -56
  37. package/dist/components/FiltersPane/components/FilterInterval/FilterInterval.d.ts +2 -4
  38. package/dist/components/FiltersPane/components/FilterInterval/FilterInterval.styles.d.ts +15 -52
  39. package/dist/components/FiltersPane/components/FilterInterval/index.d.ts +1 -1
  40. package/dist/components/FiltersPane/components/FilterSelect/FilterSelect.d.ts +2 -4
  41. package/dist/components/FiltersPane/components/FilterSelect/FilterSelect.styles.d.ts +15 -124
  42. package/dist/components/FiltersPane/components/FilterSelect/index.d.ts +1 -1
  43. package/dist/components/FiltersPane/components/FilterValueView/FilterValueView.d.ts +3 -1
  44. package/dist/components/FiltersPane/components/FilterValueView/FilterValueView.styles.d.ts +3 -12
  45. package/dist/components/FiltersPane/components/FilterValueView/index.d.ts +1 -1
  46. package/dist/components/FiltersPane/components/FilterWithDates/FilterWithDates.d.ts +5 -7
  47. package/dist/components/FiltersPane/components/FilterWithDates/FilterWithDates.styles.d.ts +26 -47
  48. package/dist/components/FiltersPane/components/FilterWithDates/index.d.ts +1 -1
  49. package/dist/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.d.ts +4 -6
  50. package/dist/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.styles.d.ts +7 -12
  51. package/dist/components/FiltersPane/components/FilterWithPeriod/index.d.ts +1 -1
  52. package/dist/components/FiltersPane/components/FilterWrapper/FilterWrapper.d.ts +5 -6
  53. package/dist/components/FiltersPane/components/FilterWrapper/FilterWrapper.styles.d.ts +6 -96
  54. package/dist/components/FiltersPane/components/FilterWrapper/index.d.ts +1 -1
  55. package/dist/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.d.ts +2 -4
  56. package/dist/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.styles.d.ts +10 -91
  57. package/dist/components/FiltersPane/components/FiltersPaneSearch/index.d.ts +1 -1
  58. package/dist/components/FiltersPane/helpers.d.ts +1 -1
  59. package/dist/components/FiltersPane/index.d.ts +1 -1
  60. package/dist/components/FiltersPane/types.d.ts +1 -1
  61. package/dist/components/Flag/Flag.d.ts +2 -3
  62. package/dist/components/Flag/Flag.styles.d.ts +3 -12
  63. package/dist/components/Flag/augment.d.ts +1 -1
  64. package/dist/components/Flag/index.d.ts +1 -1
  65. package/dist/components/FlexibleTable/FlexibleTable.d.ts +4 -6
  66. package/dist/components/FlexibleTable/FlexibleTable.styles.d.ts +7 -101
  67. package/dist/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.d.ts +17 -0
  68. package/dist/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.d.ts +3 -0
  69. package/dist/components/FlexibleTable/components/FlexibleTableCell/index.d.ts +2 -0
  70. package/dist/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.d.ts +19 -0
  71. package/dist/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.d.ts +6 -0
  72. package/dist/components/FlexibleTable/components/FlexibleTableRow/index.d.ts +2 -0
  73. package/dist/components/FlexibleTable/components/index.d.ts +2 -2
  74. package/dist/components/FlexibleTable/index.d.ts +2 -1
  75. package/dist/components/FlexibleTable/types.d.ts +1 -1
  76. package/dist/components/Icon/Icon.d.ts +2 -3
  77. package/dist/components/Icon/Icon.styles.d.ts +3 -8
  78. package/dist/components/Icon/complexIcons/augment.d.ts +1 -1
  79. package/dist/components/Icon/icons-list.d.ts +1 -1
  80. package/dist/components/Icon/index.d.ts +1 -1
  81. package/dist/components/IncrementInput/IncrementInput.d.ts +3 -3
  82. package/dist/components/IncrementInput/IncrementInput.styles.d.ts +7 -61
  83. package/dist/components/IncrementInput/index.d.ts +1 -1
  84. package/dist/components/Input/Input.d.ts +2 -4
  85. package/dist/components/Input/Input.styles.d.ts +6 -247
  86. package/dist/components/Input/index.d.ts +1 -1
  87. package/dist/components/List/List.d.ts +3 -5
  88. package/dist/components/List/List.styles.d.ts +3 -11
  89. package/dist/components/List/index.d.ts +2 -1
  90. package/dist/components/{ListItem → List}/types.d.ts +0 -5
  91. package/dist/components/Modal/Modal.d.ts +2 -4
  92. package/dist/components/Modal/Modal.styles.d.ts +6 -239
  93. package/dist/components/Modal/index.d.ts +1 -1
  94. package/dist/components/MoreMenu/MoreMenu.d.ts +4 -6
  95. package/dist/components/MoreMenu/MoreMenu.styles.d.ts +6 -54
  96. package/dist/components/MoreMenu/index.d.ts +1 -1
  97. package/dist/components/MultiSelect/MultiSelect.d.ts +8 -8
  98. package/dist/components/MultiSelect/MultiSelect.styles.d.ts +7 -44
  99. package/dist/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.d.ts +4 -4
  100. package/dist/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.styles.d.ts +3 -62
  101. package/dist/components/MultiSelect/components/MultiSelectInput/index.d.ts +1 -1
  102. package/dist/components/MultiSelect/index.d.ts +2 -2
  103. package/dist/components/MultiSelect/types.d.ts +1 -1
  104. package/dist/components/MultiSelectList/MultiSelectList.d.ts +2 -4
  105. package/dist/components/MultiSelectList/MultiSelectList.styles.d.ts +13 -105
  106. package/dist/components/MultiSelectList/index.d.ts +1 -1
  107. package/dist/components/Notification/Notification.d.ts +4 -6
  108. package/dist/components/Notification/Notification.styles.d.ts +3 -37
  109. package/dist/components/Notification/index.d.ts +1 -1
  110. package/dist/components/Notification/types.d.ts +1 -1
  111. package/dist/components/PhoneInput/PhoneInput.d.ts +3 -3
  112. package/dist/components/PhoneInput/PhoneInput.styles.d.ts +9 -66
  113. package/dist/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.d.ts +2 -3
  114. package/dist/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.styles.d.ts +7 -83
  115. package/dist/components/PhoneInput/components/PhoneInputCountryList/index.d.ts +1 -1
  116. package/dist/components/PhoneInput/index.d.ts +2 -2
  117. package/dist/components/RadioButton/RadioButton.d.ts +3 -4
  118. package/dist/components/RadioButton/RadioButton.styles.d.ts +3 -30
  119. package/dist/components/RadioButton/index.d.ts +1 -1
  120. package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +4 -4
  121. package/dist/components/SearchInput/SearchInput.d.ts +3 -4
  122. package/dist/components/SearchInput/SearchInput.styles.d.ts +7 -39
  123. package/dist/components/SearchInput/index.d.ts +1 -1
  124. package/dist/components/Select/Select.d.ts +3 -4
  125. package/dist/components/Select/Select.styles.d.ts +33 -80
  126. package/dist/components/Select/components/SelectList/SelectList.d.ts +2 -4
  127. package/dist/components/Select/components/SelectList/SelectList.styles.d.ts +3 -57
  128. package/dist/components/Select/components/SelectList/index.d.ts +1 -1
  129. package/dist/components/Select/components/SelectListItem/SelectListItem.styles.d.ts +2 -2
  130. package/dist/components/Select/index.d.ts +2 -2
  131. package/dist/components/SmartInput/SmartInput.d.ts +2 -2
  132. package/dist/components/SmartInput/helpers.d.ts +2 -2
  133. package/dist/components/SmartInput/types.d.ts +1 -1
  134. package/dist/components/Switch/Switch.d.ts +2 -4
  135. package/dist/components/Switch/Switch.styles.d.ts +3 -62
  136. package/dist/components/Switch/index.d.ts +1 -1
  137. package/dist/components/TextArea/TextArea.d.ts +2 -4
  138. package/dist/components/TextArea/TextArea.styles.d.ts +3 -128
  139. package/dist/components/TextArea/index.d.ts +1 -1
  140. package/dist/components/TextWithInfo/TextWithInfo.d.ts +2 -3
  141. package/dist/components/TextWithInfo/TextWithInfo.styles.d.ts +3 -48
  142. package/dist/components/TextWithInfo/index.d.ts +1 -1
  143. package/dist/components/TextWithTooltip/TextWithTooltip.d.ts +2 -3
  144. package/dist/components/TextWithTooltip/TextWithTooltip.styles.d.ts +6 -14
  145. package/dist/components/TextWithTooltip/index.d.ts +1 -1
  146. package/dist/components/ThemedPreloader/ThemedPreloader.d.ts +2 -3
  147. package/dist/components/ThemedPreloader/ThemedPreloader.styles.d.ts +7 -14
  148. package/dist/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.d.ts +2 -4
  149. package/dist/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.styles.d.ts +3 -43
  150. package/dist/components/ThemedPreloader/components/DotsPreloader/index.d.ts +1 -1
  151. package/dist/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.d.ts +2 -3
  152. package/dist/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.styles.d.ts +3 -9
  153. package/dist/components/ThemedPreloader/components/SvgPreloader/index.d.ts +1 -1
  154. package/dist/components/ThemedPreloader/index.d.ts +2 -2
  155. package/dist/components/Toaster/Toaster.d.ts +4 -5
  156. package/dist/components/Toaster/Toaster.styles.d.ts +6 -45
  157. package/dist/components/Toaster/index.d.ts +1 -1
  158. package/dist/components/Toaster/types.d.ts +1 -1
  159. package/dist/components/Tooltip/Tooltip.d.ts +2 -3
  160. package/dist/components/Tooltip/Tooltip.styles.d.ts +3 -35
  161. package/dist/components/Tooltip/index.d.ts +1 -1
  162. package/dist/components/index.d.ts +0 -1
  163. package/dist/helpers/index.d.ts +0 -2
  164. package/dist/helpers/phone.d.ts +3 -0
  165. package/dist/hooks/index.d.ts +0 -1
  166. package/dist/hooks/use-tweak-styles.d.ts +21 -2
  167. package/dist/index.d.ts +1 -1
  168. package/dist/theme/Provider.d.ts +11 -0
  169. package/dist/{theme.d.ts → theme/common.d.ts} +6 -10
  170. package/dist/theme/helpers.d.ts +10 -0
  171. package/dist/theme/index.d.ts +4 -0
  172. package/dist/theme/types.d.ts +72 -0
  173. package/dist/true-react-common-ui-kit.js +3074 -2663
  174. package/dist/true-react-common-ui-kit.js.map +1 -1
  175. package/dist/true-react-common-ui-kit.umd.cjs +3020 -2609
  176. package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
  177. package/dist/types.d.ts +4 -22
  178. package/dist/vite-env.d.ts +1 -1
  179. package/package.json +93 -93
  180. package/src/components/AccountInfo/AccountInfo.stories.tsx +32 -32
  181. package/src/components/AccountInfo/AccountInfo.styles.ts +51 -55
  182. package/src/components/AccountInfo/AccountInfo.tsx +79 -76
  183. package/src/components/AccountInfo/constants.ts +1 -1
  184. package/src/components/AccountInfo/index.ts +2 -2
  185. package/src/components/AddButton/AddButton.stories.tsx +21 -21
  186. package/src/components/AddButton/AddButton.styles.ts +34 -34
  187. package/src/components/AddButton/AddButton.tsx +49 -48
  188. package/src/components/AddButton/index.ts +2 -2
  189. package/src/components/Button/Button.stories.tsx +56 -56
  190. package/src/components/Button/Button.styles.ts +201 -196
  191. package/src/components/Button/Button.tsx +147 -153
  192. package/src/components/Button/constants.ts +9 -9
  193. package/src/components/Button/index.ts +3 -3
  194. package/src/components/Button/types.ts +5 -5
  195. package/src/components/Checkbox/Checkbox.stories.tsx +28 -32
  196. package/src/components/Checkbox/Checkbox.styles.ts +46 -62
  197. package/src/components/Checkbox/Checkbox.tsx +83 -105
  198. package/src/components/Checkbox/index.ts +2 -2
  199. package/src/components/CloseButton/CloseButton.styles.ts +33 -34
  200. package/src/components/CloseButton/CloseButton.tsx +33 -35
  201. package/src/components/CloseButton/index.ts +2 -2
  202. package/src/components/Colors/Colors.stories.tsx +7 -7
  203. package/src/components/Colors/Colors.styles.ts +36 -38
  204. package/src/components/Colors/Colors.tsx +26 -26
  205. package/src/components/Colors/index.ts +1 -2
  206. package/src/components/CssBaseline/CssBaseline.styles.ts +14 -15
  207. package/src/components/CssBaseline/CssBaseline.tsx +13 -15
  208. package/src/components/CssBaseline/index.ts +2 -2
  209. package/src/components/DateInput/DateInput.stories.tsx +61 -61
  210. package/src/components/DateInput/DateInput.styles.ts +18 -14
  211. package/src/components/DateInput/DateInput.tsx +95 -82
  212. package/src/components/DateInput/constants.ts +2 -2
  213. package/src/components/DateInput/index.ts +3 -3
  214. package/src/components/DatePicker/DatePicker.stories.tsx +87 -87
  215. package/src/components/DatePicker/DatePicker.styles.ts +38 -44
  216. package/src/components/DatePicker/DatePicker.tsx +308 -309
  217. package/src/components/DatePicker/components/DatePickerHeader/DatePickerHeader.styles.ts +88 -84
  218. package/src/components/DatePicker/components/DatePickerHeader/DatePickerHeader.tsx +89 -79
  219. package/src/components/DatePicker/components/DatePickerHeader/index.ts +2 -2
  220. package/src/components/DatePicker/components/PopperContainer/PopperContainer.tsx +6 -6
  221. package/src/components/DatePicker/components/PopperContainer/index.ts +1 -1
  222. package/src/components/DatePicker/components/index.ts +2 -2
  223. package/src/components/DatePicker/constants.ts +6 -6
  224. package/src/components/DatePicker/helpers.ts +23 -23
  225. package/src/components/DatePicker/index.ts +4 -4
  226. package/src/components/DatePicker/types.ts +45 -45
  227. package/src/components/Description/Description.stories.tsx +27 -27
  228. package/src/components/Description/Description.styles.ts +30 -31
  229. package/src/components/Description/Description.tsx +59 -59
  230. package/src/components/Description/constants.ts +1 -1
  231. package/src/components/Description/index.ts +2 -2
  232. package/src/components/FiltersPane/FiltersPane.stories.tsx +295 -295
  233. package/src/components/FiltersPane/FiltersPane.styles.ts +87 -71
  234. package/src/components/FiltersPane/FiltersPane.tsx +155 -150
  235. package/src/components/FiltersPane/components/Filter/Filter.tsx +203 -203
  236. package/src/components/FiltersPane/components/Filter/index.ts +1 -1
  237. package/src/components/FiltersPane/components/FilterInterval/FilterInterval.styles.ts +60 -64
  238. package/src/components/FiltersPane/components/FilterInterval/FilterInterval.tsx +154 -141
  239. package/src/components/FiltersPane/components/FilterInterval/index.ts +2 -2
  240. package/src/components/FiltersPane/components/FilterMultiSelect/FilterMultiSelect.tsx +10 -10
  241. package/src/components/FiltersPane/components/FilterMultiSelect/index.ts +1 -1
  242. package/src/components/FiltersPane/components/FilterSelect/FilterSelect.styles.ts +138 -143
  243. package/src/components/FiltersPane/components/FilterSelect/FilterSelect.tsx +359 -346
  244. package/src/components/FiltersPane/components/FilterSelect/index.ts +2 -2
  245. package/src/components/FiltersPane/components/FilterValueView/FilterValueView.styles.tsx +15 -15
  246. package/src/components/FiltersPane/components/FilterValueView/FilterValueView.tsx +165 -163
  247. package/src/components/FiltersPane/components/FilterValueView/index.tsx +2 -2
  248. package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.styles.ts +67 -60
  249. package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.tsx +210 -181
  250. package/src/components/FiltersPane/components/FilterWithDates/index.ts +2 -2
  251. package/src/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.styles.ts +21 -17
  252. package/src/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.tsx +177 -174
  253. package/src/components/FiltersPane/components/FilterWithPeriod/index.ts +2 -2
  254. package/src/components/FiltersPane/components/FilterWrapper/FilterWrapper.styles.ts +115 -110
  255. package/src/components/FiltersPane/components/FilterWrapper/FilterWrapper.tsx +167 -149
  256. package/src/components/FiltersPane/components/FilterWrapper/index.ts +2 -2
  257. package/src/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.styles.ts +116 -109
  258. package/src/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.tsx +168 -155
  259. package/src/components/FiltersPane/components/FiltersPaneSearch/index.ts +2 -2
  260. package/src/components/FiltersPane/components/index.ts +9 -9
  261. package/src/components/FiltersPane/constants.ts +137 -137
  262. package/src/components/FiltersPane/helpers.ts +26 -26
  263. package/src/components/FiltersPane/index.ts +5 -5
  264. package/src/components/FiltersPane/types.ts +156 -156
  265. package/src/components/Flag/Flag.stories.tsx +29 -29
  266. package/src/components/Flag/Flag.styles.ts +17 -18
  267. package/src/components/Flag/Flag.tsx +25 -27
  268. package/src/components/Flag/augment.d.ts +1 -1
  269. package/src/components/Flag/index.ts +2 -2
  270. package/src/components/FlexibleTable/FlexibleTable.stories.tsx +350 -338
  271. package/src/components/FlexibleTable/FlexibleTable.styles.ts +104 -131
  272. package/src/components/FlexibleTable/FlexibleTable.tsx +196 -205
  273. package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.ts +28 -0
  274. package/src/components/FlexibleTable/components/{TableValue/TableValue.tsx → FlexibleTableCell/FlexibleTableCell.tsx} +73 -74
  275. package/src/components/FlexibleTable/components/FlexibleTableCell/index.ts +2 -0
  276. package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.ts +19 -0
  277. package/src/components/FlexibleTable/components/{TableRow/TableRow.tsx → FlexibleTableRow/FlexibleTableRow.tsx} +151 -152
  278. package/src/components/FlexibleTable/components/FlexibleTableRow/index.ts +2 -0
  279. package/src/components/FlexibleTable/components/index.ts +2 -2
  280. package/src/components/FlexibleTable/constants.ts +1 -1
  281. package/src/components/FlexibleTable/index.ts +4 -3
  282. package/src/components/FlexibleTable/types.ts +52 -52
  283. package/src/components/Icon/Icon.stories.tsx +86 -86
  284. package/src/components/Icon/Icon.styles.ts +10 -10
  285. package/src/components/Icon/Icon.tsx +26 -27
  286. package/src/components/Icon/complexIcons/augment.d.ts +1 -1
  287. package/src/components/Icon/complexIcons/avatarGreen.svg +57 -57
  288. package/src/components/Icon/complexIcons/icons.ts +5 -5
  289. package/src/components/Icon/complexIcons/index.ts +1 -1
  290. package/src/components/Icon/components/ComplexIconBoilerplate/ComplexIconBoilerplate.tsx +16 -16
  291. package/src/components/Icon/components/ComplexIconBoilerplate/index.ts +1 -1
  292. package/src/components/Icon/components/IconBolerplate/IconBoilerplate.tsx +43 -43
  293. package/src/components/Icon/components/IconBolerplate/index.ts +1 -1
  294. package/src/components/Icon/components/index.ts +2 -2
  295. package/src/components/Icon/helpers.ts +9 -9
  296. package/src/components/Icon/icons-list.ts +826 -856
  297. package/src/components/Icon/index.ts +4 -4
  298. package/src/components/Icon/types.ts +16 -16
  299. package/src/components/IncrementInput/IncrementInput.stories.tsx +31 -31
  300. package/src/components/IncrementInput/IncrementInput.styles.ts +77 -77
  301. package/src/components/IncrementInput/IncrementInput.tsx +104 -80
  302. package/src/components/IncrementInput/index.ts +2 -2
  303. package/src/components/Input/Input.stories.tsx +86 -86
  304. package/src/components/Input/Input.styles.ts +307 -307
  305. package/src/components/Input/Input.tsx +311 -308
  306. package/src/components/Input/constants.ts +1 -1
  307. package/src/components/Input/index.ts +3 -3
  308. package/src/components/Input/types.ts +6 -6
  309. package/src/components/List/List.stories.tsx +63 -63
  310. package/src/components/List/List.styles.ts +51 -14
  311. package/src/components/List/List.tsx +51 -36
  312. package/src/components/List/index.ts +3 -2
  313. package/src/components/{ListItem → List}/types.ts +13 -19
  314. package/src/components/Modal/Modal.stories.tsx +105 -105
  315. package/src/components/Modal/Modal.styles.ts +303 -305
  316. package/src/components/Modal/Modal.tsx +186 -184
  317. package/src/components/Modal/index.ts +3 -3
  318. package/src/components/Modal/types.ts +17 -17
  319. package/src/components/MoreMenu/MoreMenu.stories.tsx +46 -46
  320. package/src/components/MoreMenu/MoreMenu.styles.ts +68 -70
  321. package/src/components/MoreMenu/MoreMenu.tsx +93 -90
  322. package/src/components/MoreMenu/index.ts +2 -2
  323. package/src/components/MultiSelect/MultiSelect.stories.tsx +46 -46
  324. package/src/components/MultiSelect/MultiSelect.styles.ts +59 -55
  325. package/src/components/MultiSelect/MultiSelect.tsx +101 -92
  326. package/src/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.styles.ts +73 -73
  327. package/src/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.tsx +52 -51
  328. package/src/components/MultiSelect/components/MultiSelectInput/index.ts +2 -2
  329. package/src/components/MultiSelect/components/index.ts +1 -1
  330. package/src/components/MultiSelect/index.ts +4 -4
  331. package/src/components/MultiSelect/types.ts +1 -1
  332. package/src/components/MultiSelectList/MultiSelectList.styles.ts +132 -124
  333. package/src/components/MultiSelectList/MultiSelectList.tsx +460 -441
  334. package/src/components/MultiSelectList/constants.ts +21 -21
  335. package/src/components/MultiSelectList/helpers.ts +11 -11
  336. package/src/components/MultiSelectList/index.ts +3 -3
  337. package/src/components/MultiSelectList/types.ts +15 -15
  338. package/src/components/Notification/Notification.stories.tsx +46 -46
  339. package/src/components/Notification/Notification.styles.ts +55 -50
  340. package/src/components/Notification/Notification.tsx +75 -78
  341. package/src/components/Notification/index.ts +3 -3
  342. package/src/components/Notification/types.ts +1 -1
  343. package/src/components/NumberInput/NumberInput.stories.tsx +35 -35
  344. package/src/components/NumberInput/NumberInput.tsx +133 -133
  345. package/src/components/NumberInput/helpers.ts +86 -86
  346. package/src/components/NumberInput/index.ts +1 -1
  347. package/src/components/PhoneInput/PhoneInput.stories.tsx +70 -70
  348. package/src/components/PhoneInput/PhoneInput.styles.ts +89 -84
  349. package/src/components/PhoneInput/PhoneInput.tsx +210 -193
  350. package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.stories.tsx +21 -21
  351. package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.styles.ts +103 -100
  352. package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.tsx +155 -145
  353. package/src/components/PhoneInput/components/PhoneInputCountryList/index.ts +2 -2
  354. package/src/components/PhoneInput/components/index.ts +1 -1
  355. package/src/components/PhoneInput/constants.ts +3 -3
  356. package/src/components/PhoneInput/index.ts +5 -5
  357. package/src/components/PhoneInput/phone-info.ts +2147 -2147
  358. package/src/components/PhoneInput/types.ts +16 -16
  359. package/src/components/RadioButton/RadioButton.stories.tsx +46 -46
  360. package/src/components/RadioButton/RadioButton.styles.ts +37 -37
  361. package/src/components/RadioButton/RadioButton.tsx +55 -55
  362. package/src/components/RadioButton/index.ts +2 -2
  363. package/src/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.ts +54 -54
  364. package/src/components/ScrollIntoViewIfNeeded/constants.ts +12 -12
  365. package/src/components/ScrollIntoViewIfNeeded/index.ts +1 -1
  366. package/src/components/SearchInput/SearchInput.stories.tsx +23 -23
  367. package/src/components/SearchInput/SearchInput.styles.ts +50 -50
  368. package/src/components/SearchInput/SearchInput.tsx +56 -51
  369. package/src/components/SearchInput/index.ts +2 -2
  370. package/src/components/Select/MultiSelect.stories.tsx +240 -240
  371. package/src/components/Select/Select.stories.tsx +235 -235
  372. package/src/components/Select/Select.styles.ts +146 -96
  373. package/src/components/Select/Select.tsx +574 -574
  374. package/src/components/Select/components/SelectList/SelectList.styles.ts +71 -72
  375. package/src/components/Select/components/SelectList/SelectList.tsx +157 -158
  376. package/src/components/Select/components/SelectList/index.ts +2 -2
  377. package/src/components/Select/components/SelectListItem/SelectListItem.styles.ts +14 -14
  378. package/src/components/Select/components/SelectListItem/SelectListItem.tsx +68 -68
  379. package/src/components/Select/components/SelectListItem/index.ts +1 -1
  380. package/src/components/Select/components/index.ts +2 -2
  381. package/src/components/Select/constants.ts +2 -2
  382. package/src/components/Select/helpers.ts +27 -26
  383. package/src/components/Select/index.ts +4 -4
  384. package/src/components/Select/types.ts +1 -1
  385. package/src/components/SmartInput/SmartInput.stories.tsx +51 -51
  386. package/src/components/SmartInput/SmartInput.tsx +124 -124
  387. package/src/components/SmartInput/constants.ts +84 -84
  388. package/src/components/SmartInput/helpers.ts +13 -13
  389. package/src/components/SmartInput/index.ts +2 -2
  390. package/src/components/SmartInput/types.ts +11 -11
  391. package/src/components/Switch/Switch.stories.tsx +40 -40
  392. package/src/components/Switch/Switch.styles.ts +75 -75
  393. package/src/components/Switch/Switch.tsx +76 -79
  394. package/src/components/Switch/index.ts +3 -3
  395. package/src/components/Switch/types.ts +4 -4
  396. package/src/components/TextArea/TextArea.stories.tsx +35 -35
  397. package/src/components/TextArea/TextArea.styles.ts +153 -153
  398. package/src/components/TextArea/TextArea.tsx +171 -174
  399. package/src/components/TextArea/index.ts +2 -2
  400. package/src/components/TextWithInfo/TextWithInfo.stories.tsx +53 -53
  401. package/src/components/TextWithInfo/TextWithInfo.styles.ts +59 -60
  402. package/src/components/TextWithInfo/TextWithInfo.tsx +61 -60
  403. package/src/components/TextWithInfo/index.ts +2 -2
  404. package/src/components/TextWithTooltip/TextWithTooltip.stories.tsx +58 -58
  405. package/src/components/TextWithTooltip/TextWithTooltip.styles.ts +21 -19
  406. package/src/components/TextWithTooltip/TextWithTooltip.tsx +149 -143
  407. package/src/components/TextWithTooltip/index.ts +2 -2
  408. package/src/components/ThemedPreloader/ThemedPreloader.stories.tsx +41 -41
  409. package/src/components/ThemedPreloader/ThemedPreloader.styles.ts +26 -21
  410. package/src/components/ThemedPreloader/ThemedPreloader.tsx +55 -47
  411. package/src/components/ThemedPreloader/components/DefaultPreloader/DefaultPreloader.tsx +29 -29
  412. package/src/components/ThemedPreloader/components/DefaultPreloader/index.ts +1 -1
  413. package/src/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.styles.ts +54 -54
  414. package/src/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.tsx +15 -18
  415. package/src/components/ThemedPreloader/components/DotsPreloader/index.ts +2 -2
  416. package/src/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.styles.ts +11 -11
  417. package/src/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.tsx +24 -25
  418. package/src/components/ThemedPreloader/components/SvgPreloader/index.ts +2 -2
  419. package/src/components/ThemedPreloader/components/index.ts +3 -3
  420. package/src/components/ThemedPreloader/constants.ts +1 -1
  421. package/src/components/ThemedPreloader/index.ts +4 -4
  422. package/src/components/ThemedPreloader/types.ts +3 -3
  423. package/src/components/Toaster/Toaster.stories.tsx +30 -30
  424. package/src/components/Toaster/Toaster.styles.ts +60 -59
  425. package/src/components/Toaster/Toaster.tsx +114 -108
  426. package/src/components/Toaster/constants.ts +1 -1
  427. package/src/components/Toaster/index.ts +3 -3
  428. package/src/components/Toaster/types.ts +1 -1
  429. package/src/components/Tooltip/Tooltip.stories.tsx +19 -19
  430. package/src/components/Tooltip/Tooltip.styles.ts +49 -45
  431. package/src/components/Tooltip/Tooltip.tsx +39 -35
  432. package/src/components/Tooltip/index.ts +3 -3
  433. package/src/components/Tooltip/types.ts +1 -1
  434. package/src/components/index.ts +36 -37
  435. package/src/helpers/index.ts +3 -5
  436. package/src/helpers/misc.ts +158 -158
  437. package/src/helpers/phone.ts +90 -87
  438. package/src/helpers/popper-helpers.ts +17 -17
  439. package/src/helpers/snippets.tsx +6 -6
  440. package/src/hooks/index.ts +5 -6
  441. package/src/hooks/use-did-mount-effect.ts +18 -18
  442. package/src/hooks/use-dropdown.ts +82 -82
  443. package/src/hooks/use-is-mounted.ts +15 -15
  444. package/src/hooks/use-on-click-outside.ts +77 -77
  445. package/src/hooks/use-tweak-styles.ts +57 -13
  446. package/src/index.ts +6 -6
  447. package/src/theme/Provider.tsx +21 -0
  448. package/src/{theme.ts → theme/common.ts} +149 -149
  449. package/src/theme/helpers.ts +74 -0
  450. package/src/theme/index.ts +4 -0
  451. package/src/theme/types.ts +137 -0
  452. package/src/types.ts +30 -109
  453. package/src/vite-env.d.ts +1 -1
  454. package/dist/components/FlexibleTable/components/TableRow/TableRow.d.ts +0 -28
  455. package/dist/components/FlexibleTable/components/TableRow/index.d.ts +0 -1
  456. package/dist/components/FlexibleTable/components/TableValue/TableValue.d.ts +0 -21
  457. package/dist/components/FlexibleTable/components/TableValue/index.d.ts +0 -1
  458. package/dist/components/IncrementInput/components/ChangeButton/ChangeButton.d.ts +0 -10
  459. package/dist/components/IncrementInput/components/ChangeButton/index.d.ts +0 -1
  460. package/dist/components/IncrementInput/components/index.d.ts +0 -1
  461. package/dist/components/ListItem/ListItem.d.ts +0 -6
  462. package/dist/components/ListItem/ListItem.styles.d.ts +0 -35
  463. package/dist/components/ListItem/constants.d.ts +0 -1
  464. package/dist/components/ListItem/index.d.ts +0 -3
  465. package/dist/helpers/deprecated.d.ts +0 -12
  466. package/dist/hooks/use-theme.d.ts +0 -9
  467. package/src/components/FlexibleTable/components/TableRow/index.ts +0 -1
  468. package/src/components/FlexibleTable/components/TableValue/index.ts +0 -1
  469. package/src/components/IncrementInput/components/ChangeButton/ChangeButton.tsx +0 -33
  470. package/src/components/IncrementInput/components/ChangeButton/index.ts +0 -1
  471. package/src/components/IncrementInput/components/index.ts +0 -1
  472. package/src/components/ListItem/ListItem.stories.tsx +0 -67
  473. package/src/components/ListItem/ListItem.styles.ts +0 -48
  474. package/src/components/ListItem/ListItem.tsx +0 -44
  475. package/src/components/ListItem/constants.ts +0 -5
  476. package/src/components/ListItem/index.ts +0 -3
  477. package/src/helpers/deprecated.ts +0 -23
  478. package/src/hooks/use-theme.ts +0 -32
@@ -1,441 +1,460 @@
1
- import { useEffect, useState, useMemo, useRef, useCallback, ReactNode } from 'react';
2
- import clsx from 'clsx';
3
- import { debounce } from 'ts-debounce';
4
- import { addDataAttributes } from '../../helpers';
5
- import { useIsMounted, useTheme, useTweakStyles } from '../../hooks';
6
- import { ICommonProps } from '../../types';
7
- import { Button } from '../Button';
8
- import { Checkbox, ICheckboxProps } from '../Checkbox';
9
- import { SearchInput } from '../SearchInput';
10
- import { ThemedPreloader } from '../ThemedPreloader';
11
- import { DEFAULT_LOCALE, MultiSelectLocales } from './constants';
12
- import { defaultConvertFunction, getLocale } from './helpers';
13
- import { IMultiSelectListValues, IMultiSelectLocale, IMultiSelectLocaleKey } from './types';
14
- import { MultiSelectListStyles, styles } from './MultiSelectList.styles';
15
-
16
- export interface IMultiSelectListProps<Value, Option> extends ICommonProps {
17
- tweakStyles?: MultiSelectListStyles;
18
- value?: Value;
19
- isSearchEnabled?: boolean;
20
- width?: number | string;
21
- localeKey?: IMultiSelectLocaleKey;
22
- locale?: Partial<IMultiSelectLocale>;
23
- onClose?: () => void;
24
- onChange: (val?: Value) => void;
25
- options?: Option[];
26
- fetchOptions?: (val?: string, page?: number) => Promise<Option[]>;
27
- getValueView?: (val: Option) => ReactNode;
28
- getValueId?: (val: Option) => string;
29
- getValueString?: (val: Option) => string;
30
- isGroupingEnabled?: boolean;
31
- checkboxPosition?: 'left' | 'right';
32
- pageSize?: number;
33
- searchMaxLength?: number;
34
- testId?: string;
35
- }
36
-
37
- export function MultiSelectList<Value extends IMultiSelectListValues<Option>, Option = string>({
38
- value,
39
- tweakStyles,
40
- data,
41
- isSearchEnabled = false,
42
- width,
43
- localeKey = DEFAULT_LOCALE,
44
- locale = MultiSelectLocales[localeKey],
45
- onChange,
46
- onClose,
47
- options,
48
- fetchOptions,
49
- isGroupingEnabled = isSearchEnabled,
50
- getValueView = defaultConvertFunction,
51
- getValueId = defaultConvertFunction,
52
- getValueString = defaultConvertFunction,
53
- checkboxPosition = 'left',
54
- pageSize,
55
- searchMaxLength,
56
- testId,
57
- }: IMultiSelectListProps<Value, Option>): JSX.Element {
58
- const isMounted = useIsMounted();
59
- const { classes, componentStyles } = useTheme('MultiSelectList', styles, tweakStyles, { width });
60
-
61
- const tweakCheckboxStyles = useTweakStyles(componentStyles, tweakStyles, 'tweakCheckbox');
62
-
63
- const tweakSearchInputStyles = useTweakStyles(componentStyles, tweakStyles, 'tweakSearchInput');
64
-
65
- const tweakClearButtonStyles = useTweakStyles(componentStyles, tweakStyles, 'tweakClearButton');
66
-
67
- const translates = useMemo(() => getLocale(localeKey, locale), [localeKey, locale]);
68
-
69
- const chosenValues = value?.include;
70
- const chosenValuesIds = useMemo(() => chosenValues?.map(getValueId), [getValueId, chosenValues]);
71
-
72
- const [keyCursorOn, setKeyCursorOn] = useState(0);
73
- const [searchValue, setSearchValue] = useState('');
74
- // Опции, которые получаем с бека при изменении строки поиска
75
- const [allOptions, setAllOptions] = useState<Option[]>([]);
76
-
77
- const [isLoading, setIsLoading] = useState(false);
78
- const [isLoadingOptionsOnScroll, setLoadingOptionsOnScroll] = useState(false);
79
-
80
- const [activePage, setActivePage] = useState(0);
81
- const [isMaxPage, setIsMaxPage] = useState(false);
82
-
83
- const observer = useRef<IntersectionObserver>();
84
-
85
- const unchosenOptions = useMemo(
86
- () => allOptions.filter((v) => !chosenValuesIds?.includes(getValueId(v))),
87
- [getValueId, allOptions, chosenValuesIds],
88
- );
89
-
90
- const handleSearchInputChange = useCallback(
91
- async (inputValue?: string) => {
92
- if (fetchOptions === undefined) {
93
- return;
94
- }
95
- setIsLoading(true);
96
-
97
- try {
98
- const response = await fetchOptions(inputValue?.trim() ?? '');
99
- if (isMounted() && response !== undefined) {
100
- setAllOptions(response);
101
- setActivePage(0);
102
- setIsMaxPage(
103
- response.length === 0 || (pageSize !== undefined && response.length < pageSize),
104
- );
105
- }
106
- } finally {
107
- if (isMounted()) {
108
- setIsLoading(false);
109
- }
110
- }
111
- },
112
- [fetchOptions, pageSize],
113
- );
114
-
115
- const changeSearchValue = useCallback(debounce(handleSearchInputChange), [
116
- handleSearchInputChange,
117
- ]);
118
-
119
- function handleOnChange(inputValue: string) {
120
- setSearchValue(inputValue);
121
-
122
- if (fetchOptions === undefined) {
123
- if (options !== undefined) {
124
- const lowerSearchValue = inputValue.toLowerCase();
125
- setAllOptions(
126
- options.filter((o) => getValueString(o).toLowerCase().includes(lowerSearchValue)),
127
- );
128
- }
129
- } else {
130
- setIsLoading(true);
131
- changeSearchValue(inputValue);
132
- }
133
- }
134
-
135
- const handleSelectValue = (val: Option[]) => {
136
- if (val.length === 0) {
137
- onChange(undefined);
138
- return;
139
- }
140
-
141
- onChange({
142
- include: val,
143
- } as Value);
144
- };
145
-
146
- const handleClear = () => {
147
- onChange(undefined);
148
- };
149
-
150
- const onSelect: ICheckboxProps<Option>['onSelect'] = (val) => {
151
- handleSelectValue(
152
- val.isSelected
153
- ? [...(chosenValues ?? []), val.value]
154
- : chosenValues?.filter((v) => getValueId(v) !== getValueId(val.value)) ?? [],
155
- );
156
- };
157
-
158
- const handleKeyDown = (event: KeyboardEvent) => {
159
- // TODO: это все очень плохо работает
160
- if (event.code === 'Escape') {
161
- onChange(value);
162
- if (onClose) {
163
- onClose();
164
- }
165
- }
166
- if (event.code === 'ArrowDown') {
167
- if (keyCursorOn < unchosenOptions.length + (value?.include.length ?? 0) - 1) {
168
- setKeyCursorOn(keyCursorOn + 1);
169
- }
170
- }
171
- if (event.code === 'ArrowUp') {
172
- if (keyCursorOn >= 1) {
173
- setKeyCursorOn(keyCursorOn - 1);
174
- }
175
- }
176
- if (event.code === 'Enter') {
177
- if (
178
- unchosenOptions[keyCursorOn] === undefined &&
179
- (value === undefined || value.include.length === 0)
180
- ) {
181
- return;
182
- }
183
- if (value !== undefined) {
184
- if (keyCursorOn < value.include.length) {
185
- onChange({
186
- ...value,
187
- include:
188
- value.include.filter(
189
- (val) => getValueId(val) !== getValueId(value.include[keyCursorOn]),
190
- ) ?? [],
191
- });
192
- } else {
193
- onChange({
194
- ...value,
195
- include: [...value.include, unchosenOptions[keyCursorOn - value.include.length]],
196
- });
197
- }
198
- } else {
199
- onChange({
200
- include: [unchosenOptions[keyCursorOn]],
201
- } as Value);
202
- }
203
- }
204
- };
205
-
206
- const getIsValueChosen = (id: string) => chosenValues?.some((v) => getValueId(v) === id);
207
-
208
- const handleLoadItemsOnScroll = useCallback(
209
- async (inputValue?: string, page?: number) => {
210
- if (fetchOptions === undefined) {
211
- return;
212
- }
213
-
214
- setLoadingOptionsOnScroll(true);
215
-
216
- try {
217
- const response = await fetchOptions(inputValue ?? '', page ?? 0);
218
- if (isMounted()) {
219
- if (response.length > 0) {
220
- setAllOptions((prevState) => [...prevState, ...response]);
221
- }
222
- if (response.length === 0 || (pageSize !== undefined && response.length < pageSize)) {
223
- setIsMaxPage(true);
224
- }
225
- }
226
- } finally {
227
- if (isMounted()) {
228
- setLoadingOptionsOnScroll(false);
229
- }
230
- }
231
- },
232
- [fetchOptions, getValueId],
233
- );
234
-
235
- const initIntersectionObserver = useCallback(
236
- (node: HTMLDivElement) => {
237
- if (isLoadingOptionsOnScroll || isMaxPage) {
238
- return;
239
- }
240
-
241
- if (observer.current) {
242
- observer.current.disconnect();
243
- }
244
-
245
- observer.current = new IntersectionObserver(async (entries) => {
246
- if (entries[0].isIntersecting) {
247
- await handleLoadItemsOnScroll(searchValue, activePage + 1);
248
- if (isMounted()) {
249
- setActivePage((prevState) => prevState + 1);
250
- }
251
- }
252
- });
253
-
254
- if (node) {
255
- observer.current.observe(node);
256
- }
257
- },
258
- [activePage, handleLoadItemsOnScroll, isLoadingOptionsOnScroll, isMaxPage, searchValue],
259
- );
260
-
261
- useEffect(() => {
262
- if (fetchOptions === undefined) {
263
- setAllOptions(options ?? []);
264
- return;
265
- }
266
-
267
- const doFetchOptions = async () => {
268
- setIsLoading(true);
269
-
270
- try {
271
- const response = await fetchOptions('');
272
- if (response !== undefined && isMounted()) {
273
- if (response.length === 0 || (pageSize !== undefined && response.length < pageSize)) {
274
- setIsMaxPage(true);
275
- }
276
- setAllOptions(response);
277
- }
278
- } finally {
279
- if (isMounted()) {
280
- setIsLoading(false);
281
- }
282
- }
283
- };
284
- doFetchOptions();
285
- }, []);
286
-
287
- useEffect(() => {
288
- document.addEventListener('keydown', handleKeyDown, false);
289
-
290
- return () => {
291
- document.removeEventListener('keydown', handleKeyDown, false);
292
- };
293
- });
294
-
295
- const mainOptionsList = isGroupingEnabled ? unchosenOptions : allOptions;
296
-
297
- const hasSelectedOptionsGroup =
298
- isGroupingEnabled && chosenValues !== undefined && chosenValues.length > 0;
299
-
300
- const shouldShowNothingFoundMessage = !isLoading && allOptions.length === 0;
301
-
302
- const shouldShowAllOptionsLabel =
303
- isGroupingEnabled &&
304
- unchosenOptions.length > 0 &&
305
- chosenValues !== undefined &&
306
- chosenValues.length > 0;
307
-
308
- const shouldShowPreloader = isLoading || isLoadingOptionsOnScroll;
309
-
310
- const shouldShowOptionsList = !isLoading && allOptions.length !== 0;
311
-
312
- return (
313
- <div className={classes.root} {...addDataAttributes(data)}>
314
- {isSearchEnabled && (
315
- <div className={classes.dropdownInput}>
316
- <SearchInput
317
- value={searchValue}
318
- placeholder={translates.searchPlaceholder}
319
- onChange={handleOnChange}
320
- tweakStyles={tweakSearchInputStyles}
321
- maxLength={searchMaxLength}
322
- testId={testId !== undefined ? `${testId}-search` : undefined}
323
- shouldFocusOnMount
324
- />
325
- </div>
326
- )}
327
- {shouldShowOptionsList && (
328
- <div
329
- className={classes.list}
330
- data-testid={testId !== undefined ? `${testId}-list` : undefined}
331
- >
332
- {/* Выбранные */}
333
- {hasSelectedOptionsGroup && (
334
- <>
335
- <div
336
- className={clsx(
337
- classes.label,
338
- classes.labelChosen,
339
- !isSearchEnabled && classes.withoutTopGap,
340
- )}
341
- >
342
- {translates.chosen}
343
- </div>
344
- {chosenValues?.map((val) => {
345
- const id = getValueId(val);
346
- const view = getValueView(val);
347
-
348
- return (
349
- <div
350
- className={clsx(
351
- classes.item,
352
- // keyCursorOn === index && classes.selectedItem,
353
- )}
354
- key={id}
355
- >
356
- <Checkbox
357
- onSelect={onSelect}
358
- isChecked
359
- value={val}
360
- tweakStyles={tweakCheckboxStyles}
361
- labelPosition={checkboxPosition === 'left' ? 'right' : 'left'}
362
- >
363
- <div className={classes.option} data-option={id}>
364
- {view}
365
- </div>
366
- </Checkbox>
367
- </div>
368
- );
369
- })}
370
- </>
371
- )}
372
-
373
- {!isLoading && (
374
- <>
375
- {/* Не выбранные (или все если нет группировки) */}
376
- {shouldShowAllOptionsLabel && <div className={classes.label}>{translates.all}</div>}
377
-
378
- {mainOptionsList.map((val, index) => {
379
- const id = getValueId(val);
380
- const view = getValueView(val);
381
-
382
- return (
383
- <div
384
- className={clsx(
385
- classes.item,
386
- // keyCursorOn === index + (value?.include.length ?? 0) &&
387
- // classes.selectedItem,
388
- )}
389
- ref={
390
- mainOptionsList.length - 1 === index ? initIntersectionObserver : undefined
391
- }
392
- key={id}
393
- >
394
- <Checkbox
395
- onSelect={onSelect}
396
- isChecked={getIsValueChosen(id)}
397
- value={val}
398
- tweakStyles={tweakCheckboxStyles}
399
- labelPosition={checkboxPosition === 'left' ? 'right' : 'left'}
400
- >
401
- <div className={classes.option} data-option={id}>
402
- {view}
403
- </div>
404
- </Checkbox>
405
- </div>
406
- );
407
- })}
408
- </>
409
- )}
410
- </div>
411
- )}
412
-
413
- {/* Preloader */}
414
- {shouldShowPreloader && (
415
- <div className={classes.preloader}>
416
- <ThemedPreloader type="dots" />
417
- </div>
418
- )}
419
-
420
- {/* Nothing found */}
421
- {shouldShowNothingFoundMessage && (
422
- <div className={classes.nothingFound}>{translates.nothingFound}</div>
423
- )}
424
-
425
- {/* Controls */}
426
- <div className={classes.panel}>
427
- <div className={classes.clear}>
428
- <Button
429
- onClick={handleClear}
430
- size="s"
431
- view="text"
432
- testId={testId !== undefined ? `${testId}-clear-button` : undefined}
433
- tweakStyles={tweakClearButtonStyles}
434
- >
435
- {translates.clear}
436
- </Button>
437
- </div>
438
- </div>
439
- </div>
440
- );
441
- }
1
+ import { useEffect, useState, useMemo, useRef, useCallback, ReactNode } from 'react';
2
+ import clsx from 'clsx';
3
+ import { debounce } from 'ts-debounce';
4
+ import { addDataAttributes } from '../../helpers';
5
+ import { useIsMounted, useTweakStyles } from '../../hooks';
6
+ import { ICommonProps } from '../../types';
7
+ import { Button } from '../Button';
8
+ import { Checkbox, ICheckboxProps } from '../Checkbox';
9
+ import { SearchInput } from '../SearchInput';
10
+ import { ThemedPreloader } from '../ThemedPreloader';
11
+ import { DEFAULT_LOCALE, MultiSelectLocales } from './constants';
12
+ import { defaultConvertFunction, getLocale } from './helpers';
13
+ import { IMultiSelectListValues, IMultiSelectLocale, IMultiSelectLocaleKey } from './types';
14
+ import {
15
+ useStyles,
16
+ IMultiSelectListStyles,
17
+ checkboxStyles,
18
+ searchInputStyles,
19
+ clearButtonStyles,
20
+ } from './MultiSelectList.styles';
21
+
22
+ export interface IMultiSelectListProps<Value, Option> extends ICommonProps<IMultiSelectListStyles> {
23
+ value?: Value;
24
+ isSearchEnabled?: boolean;
25
+ width?: number | string;
26
+ localeKey?: IMultiSelectLocaleKey;
27
+ locale?: Partial<IMultiSelectLocale>;
28
+ onClose?: () => void;
29
+ onChange: (val?: Value) => void;
30
+ options?: Option[];
31
+ fetchOptions?: (val?: string, page?: number) => Promise<Option[]>;
32
+ getValueView?: (val: Option) => ReactNode;
33
+ getValueId?: (val: Option) => string;
34
+ getValueString?: (val: Option) => string;
35
+ isGroupingEnabled?: boolean;
36
+ checkboxPosition?: 'left' | 'right';
37
+ pageSize?: number;
38
+ searchMaxLength?: number;
39
+ }
40
+
41
+ export function MultiSelectList<Value extends IMultiSelectListValues<Option>, Option = string>({
42
+ value,
43
+ tweakStyles,
44
+ data,
45
+ isSearchEnabled = false,
46
+ width = 220,
47
+ localeKey = DEFAULT_LOCALE,
48
+ locale = MultiSelectLocales[localeKey],
49
+ onChange,
50
+ onClose,
51
+ options,
52
+ fetchOptions,
53
+ isGroupingEnabled = isSearchEnabled,
54
+ getValueView = defaultConvertFunction,
55
+ getValueId = defaultConvertFunction,
56
+ getValueString = defaultConvertFunction,
57
+ checkboxPosition = 'left',
58
+ pageSize,
59
+ searchMaxLength,
60
+ testId,
61
+ }: IMultiSelectListProps<Value, Option>): JSX.Element {
62
+ const isMounted = useIsMounted();
63
+ const classes = useStyles({ theme: tweakStyles });
64
+
65
+ const tweakCheckboxStyles = useTweakStyles({
66
+ innerStyles: checkboxStyles,
67
+ tweakStyles,
68
+ className: 'tweakCheckbox',
69
+ currentComponentName: 'MultiSelectList',
70
+ });
71
+
72
+ const tweakSearchInputStyles = useTweakStyles({
73
+ innerStyles: searchInputStyles,
74
+ tweakStyles,
75
+ className: 'tweakSearchInput',
76
+ currentComponentName: 'MultiSelectList',
77
+ });
78
+
79
+ const tweakClearButtonStyles = useTweakStyles({
80
+ innerStyles: clearButtonStyles,
81
+ tweakStyles,
82
+ className: 'tweakClearButton',
83
+ currentComponentName: 'MultiSelectList',
84
+ });
85
+
86
+ const [keyCursorOn, setKeyCursorOn] = useState(0);
87
+ const [searchValue, setSearchValue] = useState('');
88
+ // Опции, которые получаем с бека при изменении строки поиска
89
+ const [allOptions, setAllOptions] = useState<Option[]>([]);
90
+
91
+ const [isLoading, setIsLoading] = useState(false);
92
+ const [isLoadingOptionsOnScroll, setLoadingOptionsOnScroll] = useState(false);
93
+
94
+ const [activePage, setActivePage] = useState(0);
95
+ const [isMaxPage, setIsMaxPage] = useState(false);
96
+
97
+ const observer = useRef<IntersectionObserver>();
98
+
99
+ const chosenValues = value?.include;
100
+
101
+ const translates = useMemo(() => getLocale(localeKey, locale), [localeKey, locale]);
102
+ const chosenValuesIds = useMemo(() => chosenValues?.map(getValueId), [getValueId, chosenValues]);
103
+
104
+ const unchosenOptions = useMemo(
105
+ () => allOptions.filter((v) => !chosenValuesIds?.includes(getValueId(v))),
106
+ [getValueId, allOptions, chosenValuesIds],
107
+ );
108
+
109
+ const handleSearchInputChange = useCallback(
110
+ async (inputValue?: string) => {
111
+ if (fetchOptions === undefined) {
112
+ return;
113
+ }
114
+ setIsLoading(true);
115
+
116
+ try {
117
+ const response = await fetchOptions(inputValue?.trim() ?? '');
118
+ if (isMounted() && response !== undefined) {
119
+ setAllOptions(response);
120
+ setActivePage(0);
121
+ setIsMaxPage(
122
+ response.length === 0 || (pageSize !== undefined && response.length < pageSize),
123
+ );
124
+ }
125
+ } finally {
126
+ if (isMounted()) {
127
+ setIsLoading(false);
128
+ }
129
+ }
130
+ },
131
+ [fetchOptions, pageSize],
132
+ );
133
+
134
+ const changeSearchValue = useCallback(debounce(handleSearchInputChange), [
135
+ handleSearchInputChange,
136
+ ]);
137
+
138
+ function handleOnChange(inputValue: string) {
139
+ setSearchValue(inputValue);
140
+
141
+ if (fetchOptions === undefined) {
142
+ if (options !== undefined) {
143
+ const lowerSearchValue = inputValue.toLowerCase();
144
+ setAllOptions(
145
+ options.filter((o) => getValueString(o).toLowerCase().includes(lowerSearchValue)),
146
+ );
147
+ }
148
+ } else {
149
+ setIsLoading(true);
150
+ changeSearchValue(inputValue);
151
+ }
152
+ }
153
+
154
+ const handleSelectValue = (val: Option[]) => {
155
+ if (val.length === 0) {
156
+ onChange(undefined);
157
+ return;
158
+ }
159
+
160
+ onChange({
161
+ include: val,
162
+ } as Value);
163
+ };
164
+
165
+ const handleClear = () => {
166
+ onChange(undefined);
167
+ };
168
+
169
+ const onSelect: ICheckboxProps<Option>['onSelect'] = (val) => {
170
+ handleSelectValue(
171
+ val.isSelected
172
+ ? [...(chosenValues ?? []), val.value]
173
+ : chosenValues?.filter((v) => getValueId(v) !== getValueId(val.value)) ?? [],
174
+ );
175
+ };
176
+
177
+ const handleKeyDown = (event: KeyboardEvent) => {
178
+ // TODO: это все очень плохо работает
179
+ if (event.code === 'Escape') {
180
+ onChange(value);
181
+ if (onClose) {
182
+ onClose();
183
+ }
184
+ }
185
+ if (event.code === 'ArrowDown') {
186
+ if (keyCursorOn < unchosenOptions.length + (value?.include.length ?? 0) - 1) {
187
+ setKeyCursorOn(keyCursorOn + 1);
188
+ }
189
+ }
190
+ if (event.code === 'ArrowUp') {
191
+ if (keyCursorOn >= 1) {
192
+ setKeyCursorOn(keyCursorOn - 1);
193
+ }
194
+ }
195
+ if (event.code === 'Enter') {
196
+ if (
197
+ unchosenOptions[keyCursorOn] === undefined &&
198
+ (value === undefined || value.include.length === 0)
199
+ ) {
200
+ return;
201
+ }
202
+ if (value !== undefined) {
203
+ if (keyCursorOn < value.include.length) {
204
+ onChange({
205
+ ...value,
206
+ include:
207
+ value.include.filter(
208
+ (val) => getValueId(val) !== getValueId(value.include[keyCursorOn]),
209
+ ) ?? [],
210
+ });
211
+ } else {
212
+ onChange({
213
+ ...value,
214
+ include: [...value.include, unchosenOptions[keyCursorOn - value.include.length]],
215
+ });
216
+ }
217
+ } else {
218
+ onChange({
219
+ include: [unchosenOptions[keyCursorOn]],
220
+ } as Value);
221
+ }
222
+ }
223
+ };
224
+
225
+ const getIsValueChosen = (id: string) => chosenValues?.some((v) => getValueId(v) === id);
226
+
227
+ const handleLoadItemsOnScroll = useCallback(
228
+ async (inputValue?: string, page?: number) => {
229
+ if (fetchOptions === undefined) {
230
+ return;
231
+ }
232
+
233
+ setLoadingOptionsOnScroll(true);
234
+
235
+ try {
236
+ const response = await fetchOptions(inputValue ?? '', page ?? 0);
237
+ if (isMounted()) {
238
+ if (response.length > 0) {
239
+ setAllOptions((prevState) => [...prevState, ...response]);
240
+ }
241
+ if (response.length === 0 || (pageSize !== undefined && response.length < pageSize)) {
242
+ setIsMaxPage(true);
243
+ }
244
+ }
245
+ } finally {
246
+ if (isMounted()) {
247
+ setLoadingOptionsOnScroll(false);
248
+ }
249
+ }
250
+ },
251
+ [fetchOptions, getValueId],
252
+ );
253
+
254
+ const initIntersectionObserver = useCallback(
255
+ (node: HTMLDivElement) => {
256
+ if (isLoadingOptionsOnScroll || isMaxPage) {
257
+ return;
258
+ }
259
+
260
+ if (observer.current) {
261
+ observer.current.disconnect();
262
+ }
263
+
264
+ observer.current = new IntersectionObserver(async (entries) => {
265
+ if (entries[0].isIntersecting) {
266
+ await handleLoadItemsOnScroll(searchValue, activePage + 1);
267
+ if (isMounted()) {
268
+ setActivePage((prevState) => prevState + 1);
269
+ }
270
+ }
271
+ });
272
+
273
+ if (node) {
274
+ observer.current.observe(node);
275
+ }
276
+ },
277
+ [activePage, handleLoadItemsOnScroll, isLoadingOptionsOnScroll, isMaxPage, searchValue],
278
+ );
279
+
280
+ useEffect(() => {
281
+ if (fetchOptions === undefined) {
282
+ setAllOptions(options ?? []);
283
+ return;
284
+ }
285
+
286
+ const doFetchOptions = async () => {
287
+ setIsLoading(true);
288
+
289
+ try {
290
+ const response = await fetchOptions('');
291
+ if (response !== undefined && isMounted()) {
292
+ if (response.length === 0 || (pageSize !== undefined && response.length < pageSize)) {
293
+ setIsMaxPage(true);
294
+ }
295
+ setAllOptions(response);
296
+ }
297
+ } finally {
298
+ if (isMounted()) {
299
+ setIsLoading(false);
300
+ }
301
+ }
302
+ };
303
+ doFetchOptions();
304
+ }, []);
305
+
306
+ useEffect(() => {
307
+ document.addEventListener('keydown', handleKeyDown, false);
308
+
309
+ return () => {
310
+ document.removeEventListener('keydown', handleKeyDown, false);
311
+ };
312
+ });
313
+
314
+ const mainOptionsList = isGroupingEnabled ? unchosenOptions : allOptions;
315
+
316
+ const hasSelectedOptionsGroup =
317
+ isGroupingEnabled && chosenValues !== undefined && chosenValues.length > 0;
318
+
319
+ const shouldShowNothingFoundMessage = !isLoading && allOptions.length === 0;
320
+
321
+ const shouldShowAllOptionsLabel =
322
+ isGroupingEnabled &&
323
+ unchosenOptions.length > 0 &&
324
+ chosenValues !== undefined &&
325
+ chosenValues.length > 0;
326
+
327
+ const shouldShowPreloader = isLoading || isLoadingOptionsOnScroll;
328
+
329
+ const shouldShowOptionsList = !isLoading && allOptions.length !== 0;
330
+
331
+ return (
332
+ <div className={classes.root} style={{ width }} {...addDataAttributes(data)}>
333
+ {isSearchEnabled && (
334
+ <div className={classes.dropdownInput}>
335
+ <SearchInput
336
+ value={searchValue}
337
+ placeholder={translates.searchPlaceholder}
338
+ onChange={handleOnChange}
339
+ tweakStyles={tweakSearchInputStyles}
340
+ maxLength={searchMaxLength}
341
+ testId={testId !== undefined ? `${testId}-search` : undefined}
342
+ shouldFocusOnMount
343
+ />
344
+ </div>
345
+ )}
346
+ {shouldShowOptionsList && (
347
+ <div
348
+ className={classes.list}
349
+ data-testid={testId !== undefined ? `${testId}-list` : undefined}
350
+ >
351
+ {/* Выбранные */}
352
+ {hasSelectedOptionsGroup && (
353
+ <>
354
+ <div
355
+ className={clsx(
356
+ classes.label,
357
+ classes.labelChosen,
358
+ !isSearchEnabled && classes.withoutTopGap,
359
+ )}
360
+ >
361
+ {translates.chosen}
362
+ </div>
363
+ {chosenValues?.map((val) => {
364
+ const id = getValueId(val);
365
+ const view = getValueView(val);
366
+
367
+ return (
368
+ <div
369
+ className={clsx(
370
+ classes.item,
371
+ // keyCursorOn === index && classes.selectedItem,
372
+ )}
373
+ key={id}
374
+ >
375
+ <Checkbox
376
+ onSelect={onSelect}
377
+ isChecked
378
+ value={val}
379
+ tweakStyles={tweakCheckboxStyles}
380
+ labelPosition={checkboxPosition === 'left' ? 'right' : 'left'}
381
+ >
382
+ <div className={classes.option} data-option={id}>
383
+ {view}
384
+ </div>
385
+ </Checkbox>
386
+ </div>
387
+ );
388
+ })}
389
+ </>
390
+ )}
391
+
392
+ {!isLoading && (
393
+ <>
394
+ {/* Не выбранные (или все если нет группировки) */}
395
+ {shouldShowAllOptionsLabel && <div className={classes.label}>{translates.all}</div>}
396
+
397
+ {mainOptionsList.map((val, index) => {
398
+ const id = getValueId(val);
399
+ const view = getValueView(val);
400
+
401
+ return (
402
+ <div
403
+ className={clsx(
404
+ classes.item,
405
+ // keyCursorOn === index + (value?.include.length ?? 0) &&
406
+ // classes.selectedItem,
407
+ )}
408
+ ref={
409
+ mainOptionsList.length - 1 === index ? initIntersectionObserver : undefined
410
+ }
411
+ key={id}
412
+ >
413
+ <Checkbox
414
+ onSelect={onSelect}
415
+ isChecked={getIsValueChosen(id)}
416
+ value={val}
417
+ tweakStyles={tweakCheckboxStyles}
418
+ labelPosition={checkboxPosition === 'left' ? 'right' : 'left'}
419
+ >
420
+ <div className={classes.option} data-option={id}>
421
+ {view}
422
+ </div>
423
+ </Checkbox>
424
+ </div>
425
+ );
426
+ })}
427
+ </>
428
+ )}
429
+ </div>
430
+ )}
431
+
432
+ {/* Preloader */}
433
+ {shouldShowPreloader && (
434
+ <div className={classes.preloader}>
435
+ <ThemedPreloader type="dots" />
436
+ </div>
437
+ )}
438
+
439
+ {/* Nothing found */}
440
+ {shouldShowNothingFoundMessage && (
441
+ <div className={classes.nothingFound}>{translates.nothingFound}</div>
442
+ )}
443
+
444
+ {/* Controls */}
445
+ <div className={classes.panel}>
446
+ <div className={classes.clear}>
447
+ <Button
448
+ onClick={handleClear}
449
+ size="s"
450
+ view="text"
451
+ testId={testId !== undefined ? `${testId}-clear-button` : undefined}
452
+ tweakStyles={tweakClearButtonStyles}
453
+ >
454
+ {translates.clear}
455
+ </Button>
456
+ </div>
457
+ </div>
458
+ </div>
459
+ );
460
+ }