@true-engineering/true-react-common-ui-kit 1.5.1 → 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 (239) hide show
  1. package/LICENSE +201 -201
  2. package/dist/components/Flag/augment.d.ts +1 -1
  3. package/dist/components/Icon/complexIcons/augment.d.ts +1 -1
  4. package/dist/components/Input/Input.d.ts +4 -4
  5. package/dist/true-react-common-ui-kit.js +62 -59
  6. package/dist/true-react-common-ui-kit.js.map +1 -1
  7. package/dist/true-react-common-ui-kit.umd.cjs +62 -59
  8. package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
  9. package/dist/vite-env.d.ts +1 -1
  10. package/package.json +91 -91
  11. package/src/components/AccountInfo/AccountInfo.stories.tsx +35 -35
  12. package/src/components/AccountInfo/AccountInfo.styles.ts +55 -55
  13. package/src/components/AccountInfo/AccountInfo.tsx +106 -106
  14. package/src/components/AccountInfo/index.ts +2 -2
  15. package/src/components/AddButton/AddButton.stories.tsx +21 -21
  16. package/src/components/AddButton/AddButton.styles.ts +34 -34
  17. package/src/components/AddButton/AddButton.tsx +49 -49
  18. package/src/components/AddButton/index.ts +2 -2
  19. package/src/components/Button/Button.stories.tsx +61 -61
  20. package/src/components/Button/Button.styles.ts +196 -196
  21. package/src/components/Button/Button.tsx +195 -195
  22. package/src/components/Button/index.ts +2 -2
  23. package/src/components/Checkbox/Checkbox.stories.tsx +35 -35
  24. package/src/components/Checkbox/Checkbox.styles.ts +59 -59
  25. package/src/components/Checkbox/Checkbox.tsx +93 -93
  26. package/src/components/Checkbox/index.ts +2 -2
  27. package/src/components/CloseButton/CloseButton.styles.ts +34 -34
  28. package/src/components/CloseButton/CloseButton.tsx +37 -37
  29. package/src/components/CloseButton/index.ts +2 -2
  30. package/src/components/Colors/Colors.stories.tsx +7 -7
  31. package/src/components/Colors/Colors.styles.ts +38 -38
  32. package/src/components/Colors/Colors.tsx +34 -34
  33. package/src/components/Colors/index.ts +2 -2
  34. package/src/components/CssBaseline/CssBaseline.styles.ts +15 -15
  35. package/src/components/CssBaseline/CssBaseline.tsx +17 -17
  36. package/src/components/CssBaseline/index.ts +2 -2
  37. package/src/components/DateInput/DateInput.stories.tsx +63 -63
  38. package/src/components/DateInput/DateInput.styles.ts +14 -14
  39. package/src/components/DateInput/DateInput.tsx +60 -60
  40. package/src/components/DateInput/index.ts +2 -2
  41. package/src/components/DatePicker/DatePicker.stories.tsx +96 -96
  42. package/src/components/DatePicker/DatePicker.styles.ts +54 -54
  43. package/src/components/DatePicker/DatePicker.tsx +358 -358
  44. package/src/components/DatePicker/DatePickerHeader/DatePickerHeader.styles.ts +84 -84
  45. package/src/components/DatePicker/DatePickerHeader/DatePickerHeader.tsx +94 -94
  46. package/src/components/DatePicker/DatePickerHeader/index.ts +1 -1
  47. package/src/components/DatePicker/DatePickerInput/DatePickerInput.styles.ts +25 -25
  48. package/src/components/DatePicker/DatePickerInput/DatePickerInput.tsx +31 -31
  49. package/src/components/DatePicker/DatePickerInput/index.ts +1 -1
  50. package/src/components/DatePicker/index.ts +4 -4
  51. package/src/components/Description/Description.stories.tsx +29 -29
  52. package/src/components/Description/Description.styles.ts +31 -31
  53. package/src/components/Description/Description.tsx +69 -69
  54. package/src/components/Description/index.ts +2 -2
  55. package/src/components/FiltersPane/FilterInterval/FilterInterval.styles.ts +64 -64
  56. package/src/components/FiltersPane/FilterInterval/FilterInterval.tsx +162 -162
  57. package/src/components/FiltersPane/FilterInterval/index.ts +1 -1
  58. package/src/components/FiltersPane/FilterMultiSelect/FilterMultiSelect.tsx +14 -14
  59. package/src/components/FiltersPane/FilterMultiSelect/index.ts +1 -1
  60. package/src/components/FiltersPane/FilterSelect/FilterSelect.styles.ts +144 -144
  61. package/src/components/FiltersPane/FilterSelect/FilterSelect.tsx +397 -397
  62. package/src/components/FiltersPane/FilterSelect/index.ts +1 -1
  63. package/src/components/FiltersPane/FilterSelect/locales.ts +37 -37
  64. package/src/components/FiltersPane/FilterValueView/FilterValueView.styles.tsx +15 -15
  65. package/src/components/FiltersPane/FilterValueView/FilterValueView.tsx +186 -186
  66. package/src/components/FiltersPane/FilterValueView/index.tsx +1 -1
  67. package/src/components/FiltersPane/FilterWithDates/FilterWithDates.styles.ts +60 -60
  68. package/src/components/FiltersPane/FilterWithDates/FilterWithDates.tsx +222 -222
  69. package/src/components/FiltersPane/FilterWithDates/index.ts +1 -1
  70. package/src/components/FiltersPane/FilterWithPeriod/FilterWithPeriod.styles.ts +17 -17
  71. package/src/components/FiltersPane/FilterWithPeriod/FilterWithPeriod.tsx +231 -231
  72. package/src/components/FiltersPane/FilterWithPeriod/index.ts +1 -1
  73. package/src/components/FiltersPane/FilterWrapper/FilterWrapper.styles.ts +110 -110
  74. package/src/components/FiltersPane/FilterWrapper/FilterWrapper.tsx +360 -360
  75. package/src/components/FiltersPane/FilterWrapper/index.ts +1 -1
  76. package/src/components/FiltersPane/FiltersPane.stories.tsx +308 -308
  77. package/src/components/FiltersPane/FiltersPane.styles.ts +71 -71
  78. package/src/components/FiltersPane/FiltersPane.tsx +193 -193
  79. package/src/components/FiltersPane/FiltersPaneSearch/FiltersPaneSearch.styles.ts +109 -109
  80. package/src/components/FiltersPane/FiltersPaneSearch/FiltersPaneSearch.tsx +175 -175
  81. package/src/components/FiltersPane/FiltersPaneSearch/index.ts +1 -1
  82. package/src/components/FiltersPane/index.ts +20 -20
  83. package/src/components/FiltersPane/locales.ts +107 -107
  84. package/src/components/FiltersPane/types.ts +126 -126
  85. package/src/components/Flag/Flag.stories.tsx +29 -29
  86. package/src/components/Flag/Flag.styles.ts +18 -18
  87. package/src/components/Flag/Flag.tsx +28 -28
  88. package/src/components/Flag/augment.d.ts +1 -1
  89. package/src/components/Flag/index.ts +2 -2
  90. package/src/components/FlexibleTable/FlexibleTable.stories.tsx +80 -80
  91. package/src/components/FlexibleTable/FlexibleTable.styles.ts +131 -131
  92. package/src/components/FlexibleTable/FlexibleTable.tsx +243 -243
  93. package/src/components/FlexibleTable/TableRow.tsx +171 -171
  94. package/src/components/FlexibleTable/TableValue.tsx +83 -83
  95. package/src/components/FlexibleTable/fixture-test.ts +254 -254
  96. package/src/components/FlexibleTable/index.ts +3 -3
  97. package/src/components/FlexibleTable/types.ts +58 -58
  98. package/src/components/Icon/ComplexIconBoilerplate.tsx +17 -17
  99. package/src/components/Icon/Icon.stories.tsx +88 -88
  100. package/src/components/Icon/Icon.styles.ts +10 -10
  101. package/src/components/Icon/Icon.tsx +34 -34
  102. package/src/components/Icon/IconBoilerplate.tsx +42 -42
  103. package/src/components/Icon/complexIcons/augment.d.ts +1 -1
  104. package/src/components/Icon/complexIcons/avatarGreen.svg +57 -57
  105. package/src/components/Icon/complexIcons/icons.ts +7 -7
  106. package/src/components/Icon/complexIcons/index.ts +1 -1
  107. package/src/components/Icon/icons/icons.ts +838 -838
  108. package/src/components/Icon/icons/index.ts +1 -1
  109. package/src/components/Icon/index.ts +4 -4
  110. package/src/components/IncrementInput/ChangeButton.tsx +34 -34
  111. package/src/components/IncrementInput/IncrementInput.stories.tsx +34 -34
  112. package/src/components/IncrementInput/IncrementInput.styles.ts +77 -77
  113. package/src/components/IncrementInput/IncrementInput.tsx +95 -95
  114. package/src/components/IncrementInput/index.ts +2 -2
  115. package/src/components/Input/Input.stories.tsx +92 -92
  116. package/src/components/Input/Input.styles.ts +305 -305
  117. package/src/components/Input/Input.tsx +324 -310
  118. package/src/components/Input/index.ts +2 -2
  119. package/src/components/List/List.stories.tsx +62 -62
  120. package/src/components/List/List.styles.ts +52 -52
  121. package/src/components/List/List.tsx +82 -82
  122. package/src/components/List/index.ts +2 -2
  123. package/src/components/Modal/Modal.stories.tsx +113 -113
  124. package/src/components/Modal/Modal.styles.ts +308 -308
  125. package/src/components/Modal/Modal.tsx +210 -210
  126. package/src/components/Modal/index.ts +2 -2
  127. package/src/components/MoreMenu/MoreMenu.stories.tsx +46 -46
  128. package/src/components/MoreMenu/MoreMenu.styles.ts +70 -70
  129. package/src/components/MoreMenu/MoreMenu.tsx +102 -102
  130. package/src/components/MoreMenu/index.ts +2 -2
  131. package/src/components/MultiSelect/MultiSelect.stories.tsx +46 -46
  132. package/src/components/MultiSelect/MultiSelect.styles.ts +55 -55
  133. package/src/components/MultiSelect/MultiSelect.tsx +98 -98
  134. package/src/components/MultiSelect/MultiSelectInput/MultiSelectInput.styles.ts +73 -73
  135. package/src/components/MultiSelect/MultiSelectInput/MultiSelectInput.tsx +62 -62
  136. package/src/components/MultiSelect/MultiSelectInput/index.ts +1 -1
  137. package/src/components/MultiSelect/index.ts +3 -3
  138. package/src/components/MultiSelectList/MultiSelectList.styles.ts +125 -125
  139. package/src/components/MultiSelectList/MultiSelectList.tsx +519 -519
  140. package/src/components/MultiSelectList/index.ts +2 -2
  141. package/src/components/MultiSelectList/locales.ts +37 -37
  142. package/src/components/Notification/Notification.stories.tsx +51 -51
  143. package/src/components/Notification/Notification.styles.ts +50 -50
  144. package/src/components/Notification/Notification.tsx +84 -84
  145. package/src/components/Notification/index.ts +2 -2
  146. package/src/components/NumberInput/NumberInput.stories.tsx +36 -36
  147. package/src/components/NumberInput/NumberInput.tsx +154 -154
  148. package/src/components/NumberInput/helpers.ts +87 -87
  149. package/src/components/NumberInput/index.ts +1 -1
  150. package/src/components/PhoneInput/PhoneInput.stories.tsx +71 -71
  151. package/src/components/PhoneInput/PhoneInput.styles.ts +84 -84
  152. package/src/components/PhoneInput/PhoneInput.tsx +223 -223
  153. package/src/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.stories.tsx +21 -21
  154. package/src/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.styles.ts +100 -100
  155. package/src/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.tsx +171 -171
  156. package/src/components/PhoneInput/PhoneInputCountryList/index.ts +2 -2
  157. package/src/components/PhoneInput/index.ts +6 -6
  158. package/src/components/PhoneInput/phone-info.ts +2167 -2167
  159. package/src/components/PhoneInput/types.ts +16 -16
  160. package/src/components/RadioButton/RadioButton.stories.tsx +46 -46
  161. package/src/components/RadioButton/RadioButton.styles.ts +37 -37
  162. package/src/components/RadioButton/RadioButton.tsx +56 -56
  163. package/src/components/RadioButton/index.ts +2 -2
  164. package/src/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.ts +66 -66
  165. package/src/components/ScrollIntoViewIfNeeded/index.ts +1 -1
  166. package/src/components/SearchInput/SearchInput.stories.tsx +24 -24
  167. package/src/components/SearchInput/SearchInput.styles.ts +50 -50
  168. package/src/components/SearchInput/SearchInput.tsx +63 -63
  169. package/src/components/SearchInput/index.ts +2 -2
  170. package/src/components/Select/Select.stories.tsx +258 -258
  171. package/src/components/Select/Select.styles.ts +85 -85
  172. package/src/components/Select/Select.tsx +508 -508
  173. package/src/components/Select/SelectList/SelectList.styles.ts +68 -68
  174. package/src/components/Select/SelectList/SelectList.tsx +139 -139
  175. package/src/components/Select/SelectList/index.ts +1 -1
  176. package/src/components/Select/helpers.ts +21 -21
  177. package/src/components/Select/index.ts +3 -3
  178. package/src/components/SmartInput/SmartInput.stories.tsx +63 -63
  179. package/src/components/SmartInput/SmartInput.tsx +180 -180
  180. package/src/components/SmartInput/helpers.ts +85 -85
  181. package/src/components/SmartInput/index.ts +1 -1
  182. package/src/components/Switch/Switch.stories.tsx +40 -40
  183. package/src/components/Switch/Switch.styles.ts +75 -75
  184. package/src/components/Switch/Switch.tsx +89 -89
  185. package/src/components/Switch/index.ts +2 -2
  186. package/src/components/TextArea/TextArea.stories.tsx +35 -35
  187. package/src/components/TextArea/TextArea.styles.ts +153 -153
  188. package/src/components/TextArea/TextArea.tsx +178 -178
  189. package/src/components/TextArea/index.ts +2 -2
  190. package/src/components/TextWithInfo/TextWithInfo.stories.tsx +53 -53
  191. package/src/components/TextWithInfo/TextWithInfo.styles.ts +60 -60
  192. package/src/components/TextWithInfo/TextWithInfo.tsx +67 -67
  193. package/src/components/TextWithInfo/index.ts +2 -2
  194. package/src/components/TextWithTooltip/TextWithTooltip.stories.tsx +58 -58
  195. package/src/components/TextWithTooltip/TextWithTooltip.styles.ts +19 -19
  196. package/src/components/TextWithTooltip/TextWithTooltip.tsx +163 -163
  197. package/src/components/TextWithTooltip/index.ts +2 -2
  198. package/src/components/ThemedPreloader/ThemedPreloader.stories.tsx +41 -41
  199. package/src/components/ThemedPreloader/ThemedPreloader.styles.ts +21 -21
  200. package/src/components/ThemedPreloader/ThemedPreloader.tsx +56 -56
  201. package/src/components/ThemedPreloader/components/DefaultPreloader/DefaultPreloader.tsx +34 -34
  202. package/src/components/ThemedPreloader/components/DefaultPreloader/index.ts +1 -1
  203. package/src/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.styles.ts +54 -54
  204. package/src/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.tsx +18 -18
  205. package/src/components/ThemedPreloader/components/DotsPreloader/index.ts +2 -2
  206. package/src/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.styles.ts +11 -11
  207. package/src/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.tsx +32 -32
  208. package/src/components/ThemedPreloader/components/SvgPreloader/index.ts +2 -2
  209. package/src/components/ThemedPreloader/components/index.ts +2 -2
  210. package/src/components/ThemedPreloader/index.ts +2 -2
  211. package/src/components/Toaster/Toaster.stories.tsx +34 -34
  212. package/src/components/Toaster/Toaster.styles.ts +59 -59
  213. package/src/components/Toaster/Toaster.tsx +113 -113
  214. package/src/components/Toaster/index.ts +2 -2
  215. package/src/components/Tooltip/Tooltip.stories.tsx +21 -21
  216. package/src/components/Tooltip/Tooltip.styles.ts +45 -45
  217. package/src/components/Tooltip/Tooltip.tsx +40 -40
  218. package/src/components/Tooltip/index.ts +3 -3
  219. package/src/components/Tooltip/types.ts +1 -1
  220. package/src/components/index.ts +36 -36
  221. package/src/helpers/colors.ts +2 -2
  222. package/src/helpers/data-attributes.ts +18 -18
  223. package/src/helpers/dateHelpers/date-helpers.ts +9 -9
  224. package/src/helpers/index.ts +5 -5
  225. package/src/helpers/phone.ts +106 -106
  226. package/src/helpers/popper-helpers.ts +17 -17
  227. package/src/helpers/snippets.tsx +5 -5
  228. package/src/helpers/utils.ts +178 -178
  229. package/src/hooks/index.ts +6 -6
  230. package/src/hooks/use-did-mount-effect.ts +21 -21
  231. package/src/hooks/use-dropdown.ts +85 -85
  232. package/src/hooks/use-is-mounted.ts +15 -15
  233. package/src/hooks/use-on-click-outside.ts +92 -92
  234. package/src/hooks/use-theme.ts +36 -36
  235. package/src/hooks/use-tweak-styles.ts +14 -14
  236. package/src/index.ts +6 -6
  237. package/src/theme.ts +155 -155
  238. package/src/types.ts +106 -106
  239. package/src/vite-env.d.ts +1 -1
@@ -1,310 +1,324 @@
1
- import {
2
- forwardRef,
3
- useRef,
4
- useState,
5
- MutableRefObject,
6
- FormEvent,
7
- FocusEvent,
8
- MouseEvent,
9
- KeyboardEvent,
10
- ClipboardEvent,
11
- InputHTMLAttributes,
12
- ReactElement,
13
- } from 'react';
14
- import clsx from 'clsx';
15
- import InputMask, { Props as ReactInputMaskProps } from 'react-input-mask';
16
-
17
- import { Icon, IIconType } from '../Icon';
18
- import { ThemedPreloader } from '../ThemedPreloader';
19
- import { addDataAttributes, addDataTestId, isNotEmpty } from '../../helpers';
20
- import { ICommonProps } from '../../types';
21
- import { useTheme, useTweakStyles } from '../../hooks';
22
-
23
- import { InputStyles, styles } from './Input.styles';
24
- import { renderIcon } from '../../helpers/snippets';
25
-
26
- export const DEFAULT_SIZE = 6;
27
-
28
- export interface IInputProps extends ICommonProps {
29
- tweakStyles?: InputStyles;
30
- value?: string;
31
- label?: string;
32
- placeholder?: string;
33
- /**
34
- * @default `text`
35
- */
36
- type?: 'text' | 'password' | 'email' | 'number';
37
- isDisabled?: boolean;
38
- /**
39
- * @default true
40
- */
41
- hasFloatingLabel?: boolean;
42
- isReadonly?: boolean;
43
- isInvalid?: boolean;
44
- isActive?: boolean;
45
- isClearable?: boolean;
46
- infoMessage?: string;
47
- errorMessage?: string;
48
- /**
49
- * @default `bottom`
50
- */
51
- errorPosition?: 'top' | 'bottom';
52
- inlineStyle?:
53
- | 'top'
54
- | 'bottom'
55
- | 'top-left'
56
- | 'top-right'
57
- | 'bottom-left'
58
- | 'bottom-right'
59
- | 'left'
60
- | 'right'
61
- | 'middle';
62
- border?: 'top' | 'bottom' | 'left' | 'right';
63
- isRequired?: boolean;
64
- isLoading?: boolean;
65
- /**
66
- * Должна ли ширина input'а подстраиваться под ширину контента
67
- * @default false
68
- */
69
- isAutoSizeable?: boolean;
70
- /**
71
- * Ширина input'а по умолчанию. Используется только вместе с `isAutoSizeable` равному `true`
72
- * @default 6
73
- */
74
- defaultSize?: number;
75
- iconType?: IIconType | ReactElement;
76
- units?: string;
77
- name?: string;
78
- mask?: ReactInputMaskProps['mask'];
79
- maskPlaceholder?: ReactInputMaskProps['maskPlaceholder'];
80
- hasRequiredLabel?: boolean;
81
- shouldFocusOnMount?: boolean;
82
- maxLength?: number;
83
- testId?: string;
84
- tabIndex?: number;
85
-
86
- onChange(value: string, event: FormEvent<HTMLInputElement>): void;
87
- onFocus?(event: FocusEvent<HTMLInputElement>): void;
88
- onBlur?(event: FocusEvent<HTMLInputElement>): void;
89
- onPaste?(event: ClipboardEvent<HTMLInputElement>): void;
90
- onIconClick?(): void;
91
- onKeyDown?(event: KeyboardEvent<HTMLInputElement>): void;
92
- }
93
-
94
- export const Input = forwardRef<HTMLInputElement, IInputProps>(
95
- (
96
- {
97
- value = '',
98
- label,
99
- placeholder,
100
- type = 'text',
101
- isDisabled,
102
- isReadonly,
103
- hasFloatingLabel = true,
104
- isInvalid = false,
105
- isActive = false,
106
- isClearable = false,
107
- infoMessage,
108
- errorMessage,
109
- errorPosition = 'bottom',
110
- inlineStyle,
111
- border,
112
- isRequired,
113
- isLoading,
114
- isAutoSizeable,
115
- defaultSize = DEFAULT_SIZE,
116
- iconType,
117
- name,
118
- mask,
119
- maskPlaceholder,
120
- hasRequiredLabel,
121
- data,
122
- tweakStyles,
123
- maxLength,
124
- shouldFocusOnMount,
125
- units,
126
- testId,
127
- tabIndex,
128
- onChange,
129
- onPaste,
130
- onFocus,
131
- onBlur,
132
- onIconClick,
133
- onKeyDown,
134
- },
135
- ref,
136
- ) => {
137
- const { classes, componentStyles } = useTheme('Input', styles, tweakStyles);
138
-
139
- const [isFocused, setFocused] = useState(false);
140
- const inputRef = useRef<HTMLInputElement>(null);
141
-
142
- const handleChange = (event: FormEvent<HTMLInputElement>) => {
143
- onChange(event.currentTarget.value, event);
144
- };
145
-
146
- const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
147
- setFocused(true);
148
- onFocus?.(event);
149
- };
150
-
151
- const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
152
- setFocused(false);
153
- onBlur?.(event);
154
- };
155
-
156
- // для SmartInput нужен event, иначе onChange не вызовется
157
- const handleOnInputClear = async (event: MouseEvent<HTMLDivElement>) => {
158
- // await не убирать (важно для порядка выполнения (сначала onChange, затем focus)
159
- await onChange('', event as any);
160
- const input = (ref as MutableRefObject<HTMLInputElement>) ?? inputRef;
161
- input.current?.focus();
162
- };
163
-
164
- const hasFocus = isFocused || isActive;
165
- const hasClearIcon = isClearable && value.length > 0;
166
- const hasControls = hasClearIcon || iconType !== undefined || isLoading;
167
- const hasValue = value !== undefined && value !== '';
168
- const hasUnits = units !== undefined && units !== '';
169
- const hasLabel = isNotEmpty(label);
170
- const hasPlaceholder =
171
- (!hasLabel || (hasFocus && !isReadonly)) && isNotEmpty(placeholder);
172
-
173
- const props: InputHTMLAttributes<HTMLInputElement> = {
174
- className: clsx(classes.input, {
175
- [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
176
- [classes.withIcons]: hasControls,
177
- [classes.withControls]: hasControls,
178
- [classes.floatingLabelWithoutPadding]:
179
- hasFloatingLabel && hasLabel && border === 'bottom',
180
- }),
181
- onFocus: handleFocus,
182
- onBlur: handleBlur,
183
- onChange: handleChange,
184
- onKeyDown,
185
- onPaste,
186
- value,
187
- type,
188
- disabled: isDisabled,
189
- placeholder: hasPlaceholder ? placeholder : undefined,
190
- name,
191
- maxLength,
192
- autoFocus: shouldFocusOnMount,
193
- readOnly: isReadonly,
194
- size: isAutoSizeable ? defaultSize : undefined,
195
- tabIndex,
196
- ...addDataTestId(testId),
197
- };
198
-
199
- const tweakPreloaderStyles = useTweakStyles(
200
- componentStyles,
201
- tweakStyles,
202
- 'tweakPreloader',
203
- );
204
-
205
- return (
206
- <div className={classes.root}>
207
- <div
208
- className={clsx(
209
- classes.inputWrapper,
210
- {
211
- [classes.required]: isRequired && !hasRequiredLabel,
212
- [classes.invalid]: isInvalid,
213
- [classes.focused]: hasFocus,
214
- [classes.disabled]: isDisabled,
215
- [classes.autosize]: isAutoSizeable,
216
- },
217
- inlineStyle !== undefined && classes[inlineStyle],
218
- border !== undefined && classes[`border-${border}`],
219
- )}
220
- data-value={isAutoSizeable ? value : undefined}
221
- {...addDataAttributes(data)}
222
- >
223
- {mask === undefined ? (
224
- <input ref={ref ?? inputRef} {...props} />
225
- ) : (
226
- <InputMask
227
- // Баг в типизации react-input-mask
228
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
229
- // @ts-ignore: No overload matches this call
230
- ref={ref ?? inputRef}
231
- mask={mask}
232
- maskPlaceholder={maskPlaceholder}
233
- {...props}
234
- />
235
- )}
236
- {hasLabel && (
237
- <span
238
- className={clsx(classes.label, {
239
- [classes.invalidLabel]: isInvalid,
240
- [classes.requiredLabel]: hasRequiredLabel && !isRequired,
241
- [classes.activeLabel]: (hasFocus && !isReadonly) || hasValue,
242
- [classes.floating]: hasFloatingLabel,
243
- // Обсуждаемо, сделал так, потому что не хочется создавать новую пропсу, на каждый чих в стилях
244
- [classes.floatingWithoutPadding]:
245
- hasFloatingLabel && border === 'bottom',
246
- })}
247
- >
248
- {label}
249
- </span>
250
- )}
251
-
252
- {(hasValue || (isFocused && !hasPlaceholder)) && hasUnits && (
253
- <div
254
- className={clsx(classes.unitsWrapper, {
255
- [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
256
- })}
257
- >
258
- <span className={classes.fakeValue}>{value}</span>
259
- <span className={classes.units}>{units}</span>
260
- </div>
261
- )}
262
-
263
- {hasControls && (
264
- <div className={classes.controls}>
265
- {isLoading && (
266
- <div className={clsx(classes.inputIcon, classes.loading)}>
267
- <ThemedPreloader tweakStyles={tweakPreloaderStyles} />
268
- </div>
269
- )}
270
-
271
- {!isDisabled && hasClearIcon && (
272
- <div
273
- // .clearIcon extend .icon
274
- className={clsx(classes.clearIcon, classes.activeIcon)}
275
- // превентим блур с инпута (важно)
276
- onMouseDown={(event) => event.preventDefault()}
277
- onClick={handleOnInputClear}
278
- >
279
- <Icon type="close" />
280
- </div>
281
- )}
282
- {iconType !== undefined && (
283
- <div
284
- // .inputIcon extend .icon
285
- className={clsx(classes.inputIcon, {
286
- [classes.activeIcon]:
287
- !isDisabled && onIconClick !== undefined,
288
- })}
289
- onClick={!isDisabled ? onIconClick : undefined}
290
- >
291
- {renderIcon(iconType)}
292
- </div>
293
- )}
294
- </div>
295
- )}
296
- </div>
297
- {isNotEmpty(infoMessage) && (
298
- <div className={classes.info}>{infoMessage}</div>
299
- )}
300
- {isNotEmpty(errorMessage) && (
301
- <div
302
- className={clsx(classes.error, classes[`error-${errorPosition}`])}
303
- >
304
- {errorMessage}
305
- </div>
306
- )}
307
- </div>
308
- );
309
- },
310
- );
1
+ import {
2
+ forwardRef,
3
+ useRef,
4
+ useState,
5
+ MutableRefObject,
6
+ FormEvent,
7
+ FocusEvent,
8
+ MouseEvent,
9
+ KeyboardEvent,
10
+ ClipboardEvent,
11
+ InputHTMLAttributes,
12
+ ReactElement,
13
+ } from 'react';
14
+ import clsx from 'clsx';
15
+ import InputMask, { Props as ReactInputMaskBaseProps } from 'react-input-mask';
16
+
17
+ import { Icon, IIconType } from '../Icon';
18
+ import { ThemedPreloader } from '../ThemedPreloader';
19
+ import { addDataAttributes, addDataTestId, isNotEmpty } from '../../helpers';
20
+ import { ICommonProps } from '../../types';
21
+ import { useTheme, useTweakStyles } from '../../hooks';
22
+
23
+ import { InputStyles, styles } from './Input.styles';
24
+ import { renderIcon } from '../../helpers/snippets';
25
+
26
+ export const DEFAULT_SIZE = 6;
27
+
28
+ type IReactInputMaskProps = Pick<
29
+ Partial<ReactInputMaskBaseProps>,
30
+ | 'mask'
31
+ | 'maskChar'
32
+ | 'maskPlaceholder'
33
+ | 'alwaysShowMask'
34
+ | 'beforeMaskedStateChange'
35
+ >;
36
+
37
+ export interface IInputProps extends ICommonProps, IReactInputMaskProps {
38
+ tweakStyles?: InputStyles;
39
+ value?: string;
40
+ label?: string;
41
+ placeholder?: string;
42
+ /**
43
+ * @default `text`
44
+ */
45
+ type?: 'text' | 'password' | 'email' | 'number';
46
+ isDisabled?: boolean;
47
+ /**
48
+ * @default true
49
+ */
50
+ hasFloatingLabel?: boolean;
51
+ isReadonly?: boolean;
52
+ isInvalid?: boolean;
53
+ isActive?: boolean;
54
+ isClearable?: boolean;
55
+ infoMessage?: string;
56
+ errorMessage?: string;
57
+ /**
58
+ * @default `bottom`
59
+ */
60
+ errorPosition?: 'top' | 'bottom';
61
+ inlineStyle?:
62
+ | 'top'
63
+ | 'bottom'
64
+ | 'top-left'
65
+ | 'top-right'
66
+ | 'bottom-left'
67
+ | 'bottom-right'
68
+ | 'left'
69
+ | 'right'
70
+ | 'middle';
71
+ border?: 'top' | 'bottom' | 'left' | 'right';
72
+ isRequired?: boolean;
73
+ isLoading?: boolean;
74
+ /**
75
+ * Должна ли ширина input'а подстраиваться под ширину контента
76
+ * @default false
77
+ */
78
+ isAutoSizeable?: boolean;
79
+ /**
80
+ * Ширина input'а по умолчанию. Используется только вместе с `isAutoSizeable` равному `true`
81
+ * @default 6
82
+ */
83
+ defaultSize?: number;
84
+ iconType?: IIconType | ReactElement;
85
+ units?: string;
86
+ name?: string;
87
+ hasRequiredLabel?: boolean;
88
+ shouldFocusOnMount?: boolean;
89
+ maxLength?: number;
90
+ testId?: string;
91
+ tabIndex?: number;
92
+
93
+ onChange(value: string, event: FormEvent<HTMLInputElement>): void;
94
+ onFocus?(event: FocusEvent<HTMLInputElement>): void;
95
+ onBlur?(event: FocusEvent<HTMLInputElement>): void;
96
+ onPaste?(event: ClipboardEvent<HTMLInputElement>): void;
97
+ onIconClick?(): void;
98
+ onKeyDown?(event: KeyboardEvent<HTMLInputElement>): void;
99
+ }
100
+
101
+ export const Input = forwardRef<HTMLInputElement, IInputProps>(
102
+ (
103
+ {
104
+ value = '',
105
+ label,
106
+ placeholder,
107
+ type = 'text',
108
+ isDisabled,
109
+ isReadonly,
110
+ hasFloatingLabel = true,
111
+ isInvalid = false,
112
+ isActive = false,
113
+ isClearable = false,
114
+ infoMessage,
115
+ errorMessage,
116
+ errorPosition = 'bottom',
117
+ inlineStyle,
118
+ border,
119
+ isRequired,
120
+ isLoading,
121
+ isAutoSizeable,
122
+ defaultSize = DEFAULT_SIZE,
123
+ iconType,
124
+ name,
125
+ hasRequiredLabel,
126
+ data,
127
+ tweakStyles,
128
+ maxLength,
129
+ shouldFocusOnMount,
130
+ units,
131
+ testId,
132
+ tabIndex,
133
+ onChange,
134
+ onPaste,
135
+ onFocus,
136
+ onBlur,
137
+ onIconClick,
138
+ onKeyDown,
139
+ // Пропсы react-input-mask
140
+ mask,
141
+ maskChar,
142
+ maskPlaceholder,
143
+ alwaysShowMask,
144
+ beforeMaskedStateChange,
145
+ },
146
+ ref,
147
+ ) => {
148
+ const { classes, componentStyles } = useTheme('Input', styles, tweakStyles);
149
+
150
+ const [isFocused, setFocused] = useState(false);
151
+ const inputRef = useRef<HTMLInputElement>(null);
152
+
153
+ const handleChange = (event: FormEvent<HTMLInputElement>) => {
154
+ onChange(event.currentTarget.value, event);
155
+ };
156
+
157
+ const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
158
+ setFocused(true);
159
+ onFocus?.(event);
160
+ };
161
+
162
+ const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
163
+ setFocused(false);
164
+ onBlur?.(event);
165
+ };
166
+
167
+ // для SmartInput нужен event, иначе onChange не вызовется
168
+ const handleOnInputClear = async (event: MouseEvent<HTMLDivElement>) => {
169
+ // await не убирать (важно для порядка выполнения (сначала onChange, затем focus)
170
+ await onChange('', event as any);
171
+ const input = (ref as MutableRefObject<HTMLInputElement>) ?? inputRef;
172
+ input.current?.focus();
173
+ };
174
+
175
+ const hasFocus = isFocused || isActive;
176
+ const hasClearIcon = isClearable && value.length > 0;
177
+ const hasControls = hasClearIcon || iconType !== undefined || isLoading;
178
+ const hasValue = value !== undefined && value !== '';
179
+ const hasUnits = units !== undefined && units !== '';
180
+ const hasLabel = isNotEmpty(label);
181
+ const hasPlaceholder =
182
+ (!hasLabel || (hasFocus && !isReadonly)) && isNotEmpty(placeholder);
183
+
184
+ const props: InputHTMLAttributes<HTMLInputElement> = {
185
+ className: clsx(classes.input, {
186
+ [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
187
+ [classes.withIcons]: hasControls,
188
+ [classes.withControls]: hasControls,
189
+ [classes.floatingLabelWithoutPadding]:
190
+ hasFloatingLabel && hasLabel && border === 'bottom',
191
+ }),
192
+ onFocus: handleFocus,
193
+ onBlur: handleBlur,
194
+ onChange: handleChange,
195
+ onKeyDown,
196
+ onPaste,
197
+ value,
198
+ type,
199
+ disabled: isDisabled,
200
+ placeholder: hasPlaceholder ? placeholder : undefined,
201
+ name,
202
+ maxLength,
203
+ autoFocus: shouldFocusOnMount,
204
+ readOnly: isReadonly,
205
+ size: isAutoSizeable ? defaultSize : undefined,
206
+ tabIndex,
207
+ ...addDataTestId(testId),
208
+ };
209
+
210
+ const tweakPreloaderStyles = useTweakStyles(
211
+ componentStyles,
212
+ tweakStyles,
213
+ 'tweakPreloader',
214
+ );
215
+
216
+ return (
217
+ <div className={classes.root}>
218
+ <div
219
+ className={clsx(
220
+ classes.inputWrapper,
221
+ {
222
+ [classes.required]: isRequired && !hasRequiredLabel,
223
+ [classes.invalid]: isInvalid,
224
+ [classes.focused]: hasFocus,
225
+ [classes.disabled]: isDisabled,
226
+ [classes.autosize]: isAutoSizeable,
227
+ },
228
+ inlineStyle !== undefined && classes[inlineStyle],
229
+ border !== undefined && classes[`border-${border}`],
230
+ )}
231
+ data-value={isAutoSizeable ? value : undefined}
232
+ {...addDataAttributes(data)}
233
+ >
234
+ {mask === undefined ? (
235
+ <input ref={ref ?? inputRef} {...props} />
236
+ ) : (
237
+ <InputMask
238
+ // Баг в типизации react-input-mask
239
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
240
+ // @ts-ignore: No overload matches this call
241
+ ref={ref ?? inputRef}
242
+ mask={mask}
243
+ maskChar={maskChar}
244
+ maskPlaceholder={maskPlaceholder}
245
+ alwaysShowMask={alwaysShowMask}
246
+ beforeMaskedStateChange={beforeMaskedStateChange}
247
+ {...props}
248
+ />
249
+ )}
250
+ {hasLabel && (
251
+ <span
252
+ className={clsx(classes.label, {
253
+ [classes.invalidLabel]: isInvalid,
254
+ [classes.requiredLabel]: hasRequiredLabel && !isRequired,
255
+ [classes.activeLabel]: (hasFocus && !isReadonly) || hasValue,
256
+ [classes.floating]: hasFloatingLabel,
257
+ // Обсуждаемо, сделал так, потому что не хочется создавать новую пропсу, на каждый чих в стилях
258
+ [classes.floatingWithoutPadding]:
259
+ hasFloatingLabel && border === 'bottom',
260
+ })}
261
+ >
262
+ {label}
263
+ </span>
264
+ )}
265
+
266
+ {(hasValue || (isFocused && !hasPlaceholder)) && hasUnits && (
267
+ <div
268
+ className={clsx(classes.unitsWrapper, {
269
+ [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
270
+ })}
271
+ >
272
+ <span className={classes.fakeValue}>{value}</span>
273
+ <span className={classes.units}>{units}</span>
274
+ </div>
275
+ )}
276
+
277
+ {hasControls && (
278
+ <div className={classes.controls}>
279
+ {isLoading && (
280
+ <div className={clsx(classes.inputIcon, classes.loading)}>
281
+ <ThemedPreloader tweakStyles={tweakPreloaderStyles} />
282
+ </div>
283
+ )}
284
+
285
+ {!isDisabled && hasClearIcon && (
286
+ <div
287
+ // .clearIcon extend .icon
288
+ className={clsx(classes.clearIcon, classes.activeIcon)}
289
+ // превентим блур с инпута (важно)
290
+ onMouseDown={(event) => event.preventDefault()}
291
+ onClick={handleOnInputClear}
292
+ >
293
+ <Icon type="close" />
294
+ </div>
295
+ )}
296
+ {iconType !== undefined && (
297
+ <div
298
+ // .inputIcon extend .icon
299
+ className={clsx(classes.inputIcon, {
300
+ [classes.activeIcon]:
301
+ !isDisabled && onIconClick !== undefined,
302
+ })}
303
+ onClick={!isDisabled ? onIconClick : undefined}
304
+ >
305
+ {renderIcon(iconType)}
306
+ </div>
307
+ )}
308
+ </div>
309
+ )}
310
+ </div>
311
+ {isNotEmpty(infoMessage) && (
312
+ <div className={classes.info}>{infoMessage}</div>
313
+ )}
314
+ {isNotEmpty(errorMessage) && (
315
+ <div
316
+ className={clsx(classes.error, classes[`error-${errorPosition}`])}
317
+ >
318
+ {errorMessage}
319
+ </div>
320
+ )}
321
+ </div>
322
+ );
323
+ },
324
+ );
@@ -1,2 +1,2 @@
1
- export * from './Input';
2
- export type { InputStyles } from './Input.styles';
1
+ export * from './Input';
2
+ export type { InputStyles } from './Input.styles';