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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +6 -0
  3. package/dist/true-react-common-ui-kit.js +61 -60
  4. package/dist/true-react-common-ui-kit.js.map +1 -1
  5. package/dist/true-react-common-ui-kit.umd.cjs +61 -60
  6. package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
  7. package/package.json +1 -1
  8. package/src/components/AccountInfo/AccountInfo.stories.tsx +32 -32
  9. package/src/components/AccountInfo/AccountInfo.tsx +80 -80
  10. package/src/components/AddButton/AddButton.stories.tsx +21 -21
  11. package/src/components/AddButton/AddButton.tsx +52 -52
  12. package/src/components/Button/Button.stories.tsx +56 -56
  13. package/src/components/Button/Button.tsx +129 -129
  14. package/src/components/Checkbox/Checkbox.stories.tsx +28 -28
  15. package/src/components/CloseButton/CloseButton.tsx +34 -34
  16. package/src/components/Colors/Colors.stories.tsx +7 -7
  17. package/src/components/DateInput/DateInput.tsx +90 -90
  18. package/src/components/DateInput/constants.ts +2 -2
  19. package/src/components/DatePicker/DatePicker.tsx +308 -308
  20. package/src/components/Description/Description.stories.tsx +27 -27
  21. package/src/components/Description/Description.tsx +61 -61
  22. package/src/components/FiltersPane/FiltersPane.tsx +158 -158
  23. package/src/components/FiltersPane/components/Filter/Filter.tsx +203 -203
  24. package/src/components/FiltersPane/components/FilterValueView/FilterValueView.tsx +166 -166
  25. package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.tsx +210 -210
  26. package/src/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.tsx +177 -177
  27. package/src/components/FiltersPane/components/FilterWrapper/FilterWrapper.tsx +167 -167
  28. package/src/components/Flag/Flag.stories.tsx +29 -29
  29. package/src/components/Flag/Flag.tsx +26 -26
  30. package/src/components/Flag/augment.d.ts +1 -1
  31. package/src/components/FlexibleTable/FlexibleTable.stories.tsx +267 -267
  32. package/src/components/FlexibleTable/FlexibleTable.styles.ts +110 -110
  33. package/src/components/FlexibleTable/FlexibleTable.tsx +271 -271
  34. package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.ts +38 -38
  35. package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.tsx +83 -83
  36. package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.ts +25 -25
  37. package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.tsx +196 -196
  38. package/src/components/FlexibleTable/helpers.ts +13 -13
  39. package/src/components/FlexibleTable/types.ts +52 -52
  40. package/src/components/Icon/Icon.stories.tsx +86 -86
  41. package/src/components/Icon/complexIcons/augment.d.ts +1 -1
  42. package/src/components/Icon/complexIcons/avatarGreen.svg +57 -57
  43. package/src/components/Icon/complexIcons/index.ts +1 -1
  44. package/src/components/IncrementInput/IncrementInput.tsx +105 -105
  45. package/src/components/Input/Input.tsx +297 -297
  46. package/src/components/Input/types.ts +32 -32
  47. package/src/components/List/List.stories.tsx +70 -70
  48. package/src/components/List/List.tsx +33 -33
  49. package/src/components/List/components/ListItem/ListItem.tsx +57 -57
  50. package/src/components/Modal/Modal.stories.tsx +105 -105
  51. package/src/components/Modal/Modal.tsx +196 -196
  52. package/src/components/MoreMenu/MoreMenu.styles.ts +68 -68
  53. package/src/components/MultiSelect/MultiSelect.stories.tsx +46 -46
  54. package/src/components/MultiSelect/MultiSelect.tsx +106 -106
  55. package/src/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.tsx +53 -53
  56. package/src/components/MultiSelectList/MultiSelectList.tsx +461 -461
  57. package/src/components/Notification/Notification.stories.tsx +46 -46
  58. package/src/components/Notification/Notification.tsx +69 -69
  59. package/src/components/NumberInput/NumberInput.tsx +137 -137
  60. package/src/components/NumberInput/index.ts +1 -1
  61. package/src/components/PhoneInput/PhoneInput.tsx +214 -214
  62. package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.tsx +155 -155
  63. package/src/components/PhoneInput/types.ts +16 -16
  64. package/src/components/RadioButton/RadioButton.stories.tsx +46 -46
  65. package/src/components/RadioButton/RadioButton.tsx +57 -57
  66. package/src/components/ScrollIntoViewIfNeeded/index.ts +1 -1
  67. package/src/components/Select/CustomSelect.stories.tsx +217 -217
  68. package/src/components/Select/MultiSelect.stories.tsx +240 -240
  69. package/src/components/Select/Select.stories.tsx +235 -235
  70. package/src/components/Select/constants.ts +2 -2
  71. package/src/components/Select/types.ts +1 -1
  72. package/src/components/Selector/Selector.stories.tsx +62 -62
  73. package/src/components/Selector/Selector.styles.ts +164 -164
  74. package/src/components/Selector/Selector.tsx +115 -115
  75. package/src/components/Selector/index.ts +2 -2
  76. package/src/components/Selector/types.ts +12 -12
  77. package/src/components/Skeleton/Skeleton.stories.tsx +19 -19
  78. package/src/components/SmartInput/SmartInput.tsx +134 -134
  79. package/src/components/Status/Status.stories.tsx +73 -73
  80. package/src/components/Status/Status.styles.ts +143 -143
  81. package/src/components/Status/Status.tsx +49 -49
  82. package/src/components/Status/constants.ts +11 -11
  83. package/src/components/Status/index.ts +3 -3
  84. package/src/components/Status/types.ts +5 -5
  85. package/src/components/Switch/Switch.stories.tsx +40 -40
  86. package/src/components/Switch/Switch.tsx +75 -75
  87. package/src/components/TextArea/TextArea.tsx +180 -180
  88. package/src/components/TextButton/TextButton.stories.tsx +46 -46
  89. package/src/components/TextButton/TextButton.styles.ts +129 -129
  90. package/src/components/TextButton/TextButton.tsx +103 -103
  91. package/src/components/TextButton/index.ts +4 -4
  92. package/src/components/TextWithInfo/TextWithInfo.stories.tsx +53 -53
  93. package/src/components/TextWithInfo/TextWithInfo.tsx +62 -62
  94. package/src/components/TextWithTooltip/TextWithTooltip.stories.tsx +58 -58
  95. package/src/components/ThemedPreloader/ThemedPreloader.stories.tsx +41 -41
  96. package/src/components/ThemedPreloader/ThemedPreloader.tsx +54 -54
  97. package/src/components/ThemedPreloader/components/DefaultPreloader/index.ts +1 -1
  98. package/src/components/Toaster/Toaster.stories.tsx +30 -30
  99. package/src/components/Toaster/Toaster.tsx +108 -108
  100. package/src/components/Tooltip/Tooltip.stories.tsx +19 -19
  101. package/src/components/Tooltip/Tooltip.tsx +35 -35
  102. package/src/components/Tooltip/types.ts +1 -1
  103. package/src/components/WithPopup/WithPopup.tsx +1 -0
  104. package/src/helpers/popper-helpers.ts +17 -17
  105. package/src/hooks/use-dropdown.ts +84 -84
  106. package/src/hooks/use-is-mounted.ts +15 -15
  107. package/src/theme/helpers.ts +76 -76
  108. package/src/vite-env.d.ts +1 -1
@@ -1,297 +1,297 @@
1
- import {
2
- forwardRef,
3
- useRef,
4
- useState,
5
- MutableRefObject,
6
- FormEvent,
7
- FocusEvent,
8
- MouseEvent,
9
- InputHTMLAttributes,
10
- ReactNode,
11
- } from 'react';
12
- import InputMask from 'react-input-mask';
13
- import clsx from 'clsx';
14
- import {
15
- addDataTestId,
16
- isReactNodeNotEmpty,
17
- isStringNotEmpty,
18
- } from '@true-engineering/true-react-platform-helpers';
19
- import { addDataAttributes } from '../../helpers';
20
- import { useTweakStyles } from '../../hooks';
21
- import { ICommonProps } from '../../types';
22
- import { renderIcon, Icon, IIcon } from '../Icon';
23
- import { ThemedPreloader } from '../ThemedPreloader';
24
- import { DEFAULT_SIZE } from './constants';
25
- import { IInputHTMLBaseProps, IReactInputMaskProps } from './types';
26
- import { useStyles, IInputStyles } from './Input.styles';
27
-
28
- export interface IInputProps
29
- extends ICommonProps<IInputStyles>,
30
- IReactInputMaskProps,
31
- IInputHTMLBaseProps {
32
- value?: string;
33
- label?: ReactNode;
34
- /** @default false */
35
- isDisabled?: boolean;
36
- /** @default true */
37
- hasFloatingLabel?: boolean;
38
- /** @default false */
39
- isReadonly?: boolean;
40
- /** @default false */
41
- isInvalid?: boolean;
42
- /** @default false */
43
- isActive?: boolean;
44
- /** @default false */
45
- isClearable?: boolean;
46
- infoMessage?: string;
47
- errorMessage?: string;
48
- /** @default 'bottom' */
49
- errorPosition?: 'top' | 'bottom';
50
- inlineStyle?:
51
- | 'top'
52
- | 'bottom'
53
- | 'top-left'
54
- | 'top-right'
55
- | 'bottom-left'
56
- | 'bottom-right'
57
- | 'left'
58
- | 'right'
59
- | 'middle';
60
- border?: 'top' | 'bottom' | 'left' | 'right';
61
- /** @default false */
62
- isRequired?: boolean;
63
- /** @default false */
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?: IIcon;
76
- units?: string;
77
- /** @default false */
78
- hasRequiredLabel?: boolean;
79
- /** @default false */
80
- shouldFocusOnMount?: boolean;
81
- /** @default false */
82
- shouldAlwaysShowPlaceholder?: boolean;
83
- onChange: (value: string, event: FormEvent<HTMLInputElement>) => void;
84
- onIconClick?: () => void;
85
- }
86
-
87
- export const Input = forwardRef<HTMLInputElement, IInputProps>(
88
- (
89
- {
90
- value = '',
91
- label,
92
- placeholder,
93
- type = 'text',
94
- isDisabled,
95
- isReadonly = false,
96
- hasFloatingLabel = true,
97
- isInvalid = false,
98
- isActive = false,
99
- isClearable = false,
100
- infoMessage,
101
- errorMessage,
102
- errorPosition = 'bottom',
103
- inlineStyle,
104
- border,
105
- isRequired = false,
106
- isLoading = false,
107
- isAutoSizeable = false,
108
- defaultSize = DEFAULT_SIZE,
109
- iconType,
110
- hasRequiredLabel,
111
- data,
112
- tweakStyles,
113
- shouldFocusOnMount = false,
114
- units,
115
- testId,
116
- onChange,
117
- onFocus,
118
- onBlur,
119
- onIconClick,
120
- // Пропсы react-input-mask
121
- mask,
122
- maskPlaceholder,
123
- alwaysShowMask,
124
- shouldAlwaysShowPlaceholder = false,
125
- beforeMaskedStateChange,
126
- ...inputProps
127
- },
128
- ref,
129
- ) => {
130
- const classes = useStyles({ theme: tweakStyles });
131
-
132
- const tweakPreloaderStyles = useTweakStyles({
133
- tweakStyles,
134
- className: 'tweakPreloader',
135
- currentComponentName: 'Input',
136
- });
137
-
138
- const [isFocused, setFocused] = useState(false);
139
- const inputRef = useRef<HTMLInputElement>(null);
140
-
141
- const handleChange = (event: FormEvent<HTMLInputElement>) => {
142
- onChange(event.currentTarget.value, event);
143
- };
144
-
145
- const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
146
- setFocused(true);
147
- onFocus?.(event);
148
- };
149
-
150
- const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
151
- setFocused(false);
152
- onBlur?.(event);
153
- };
154
-
155
- // для SmartInput нужен event, иначе onChange не вызовется
156
- const handleOnInputClear = async (event: MouseEvent<HTMLDivElement>) => {
157
- // await не убирать (важно для порядка выполнения (сначала onChange, затем focus)
158
- await onChange('', event as any);
159
- const input = (ref as MutableRefObject<HTMLInputElement>) ?? inputRef;
160
- input.current?.focus();
161
- };
162
-
163
- const hasFocus = isFocused || isActive;
164
- const hasClearIcon = isClearable && value.length > 0;
165
- const hasControls = hasClearIcon || iconType !== undefined || isLoading;
166
- const hasValue = value !== undefined && value !== '';
167
- const hasUnits = units !== undefined && units !== '';
168
- const hasLabel = isReactNodeNotEmpty(label);
169
- const hasPlaceholder =
170
- (!hasLabel || (hasFocus && !isReadonly) || shouldAlwaysShowPlaceholder) &&
171
- isStringNotEmpty(placeholder);
172
- const shouldShowUnits = (hasValue || (isFocused && !hasPlaceholder)) && hasUnits;
173
-
174
- const props: InputHTMLAttributes<HTMLInputElement> = {
175
- ...inputProps,
176
- ...addDataTestId(testId),
177
- className: clsx(classes.input, {
178
- [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
179
- [classes.withIcons]: hasControls,
180
- [classes.withControls]: hasControls,
181
- [classes.withUnits]: shouldShowUnits,
182
- [classes.floatingLabelWithoutPadding]: hasFloatingLabel && hasLabel && border === 'bottom',
183
- }),
184
- onFocus: handleFocus,
185
- onBlur: handleBlur,
186
- onChange: handleChange,
187
- value,
188
- type,
189
- disabled: isDisabled,
190
- placeholder: hasPlaceholder ? placeholder : undefined,
191
- autoFocus: shouldFocusOnMount,
192
- readOnly: isReadonly,
193
- size: isAutoSizeable ? defaultSize : undefined,
194
- };
195
-
196
- return (
197
- <div className={classes.root}>
198
- <div
199
- className={clsx(
200
- classes.inputWrapper,
201
- {
202
- [classes.required]: isRequired && !hasRequiredLabel,
203
- [classes.invalid]: isInvalid,
204
- [classes.focused]: hasFocus,
205
- [classes.disabled]: isDisabled,
206
- [classes.autosize]: isAutoSizeable,
207
- },
208
- inlineStyle !== undefined && classes[inlineStyle],
209
- border !== undefined && classes[`border-${border}`],
210
- )}
211
- data-value={isAutoSizeable ? value : undefined}
212
- {...addDataAttributes(data)}
213
- >
214
- {mask === undefined ? (
215
- <input ref={ref ?? inputRef} {...props} />
216
- ) : (
217
- <InputMask
218
- // Баг в типизации react-input-mask
219
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
220
- // @ts-ignore: No overload matches this call
221
- ref={ref ?? inputRef}
222
- mask={mask}
223
- maskPlaceholder={maskPlaceholder}
224
- alwaysShowMask={alwaysShowMask}
225
- beforeMaskedStateChange={beforeMaskedStateChange}
226
- {...props}
227
- />
228
- )}
229
- {hasLabel && (
230
- <span
231
- className={clsx(classes.label, {
232
- [classes.invalidLabel]: isInvalid,
233
- [classes.requiredLabel]: hasRequiredLabel && !isRequired,
234
- [classes.activeLabel]: (hasFocus && !isReadonly) || hasValue,
235
- [classes.floating]: hasFloatingLabel,
236
- // Обсуждаемо, сделал так, потому что не хочется создавать новую пропсу, на каждый чих в стилях
237
- [classes.floatingWithoutPadding]: hasFloatingLabel && border === 'bottom',
238
- })}
239
- >
240
- {label}
241
- </span>
242
- )}
243
-
244
- {shouldShowUnits && (
245
- <div
246
- className={clsx(classes.unitsWrapper, {
247
- [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
248
- })}
249
- >
250
- <span className={classes.fakeValue}>{value}</span>
251
- <span className={classes.units}>{units}</span>
252
- </div>
253
- )}
254
-
255
- {hasControls && (
256
- <div className={classes.controls}>
257
- {isLoading && (
258
- <div className={clsx(classes.inputIcon, classes.loading)}>
259
- <ThemedPreloader tweakStyles={tweakPreloaderStyles} />
260
- </div>
261
- )}
262
-
263
- {!isDisabled && hasClearIcon && (
264
- <div
265
- // .clearIcon extend .icon
266
- className={clsx(classes.clearIcon, classes.activeIcon)}
267
- // превентим блур с инпута (важно)
268
- onMouseDown={(event) => event.preventDefault()}
269
- onClick={handleOnInputClear}
270
- >
271
- <Icon type="close" />
272
- </div>
273
- )}
274
- {isReactNodeNotEmpty(iconType) && (
275
- <div
276
- // .inputIcon extend .icon
277
- className={clsx(classes.inputIcon, {
278
- [classes.activeIcon]: !isDisabled && onIconClick !== undefined,
279
- })}
280
- onClick={!isDisabled ? onIconClick : undefined}
281
- >
282
- {renderIcon(iconType)}
283
- </div>
284
- )}
285
- </div>
286
- )}
287
- </div>
288
- {isStringNotEmpty(infoMessage) && <div className={classes.info}>{infoMessage}</div>}
289
- {isStringNotEmpty(errorMessage) && (
290
- <div className={clsx(classes.error, classes[`error-${errorPosition}`])}>
291
- {errorMessage}
292
- </div>
293
- )}
294
- </div>
295
- );
296
- },
297
- );
1
+ import {
2
+ forwardRef,
3
+ useRef,
4
+ useState,
5
+ MutableRefObject,
6
+ FormEvent,
7
+ FocusEvent,
8
+ MouseEvent,
9
+ InputHTMLAttributes,
10
+ ReactNode,
11
+ } from 'react';
12
+ import InputMask from 'react-input-mask';
13
+ import clsx from 'clsx';
14
+ import {
15
+ addDataTestId,
16
+ isReactNodeNotEmpty,
17
+ isStringNotEmpty,
18
+ } from '@true-engineering/true-react-platform-helpers';
19
+ import { addDataAttributes } from '../../helpers';
20
+ import { useTweakStyles } from '../../hooks';
21
+ import { ICommonProps } from '../../types';
22
+ import { renderIcon, Icon, IIcon } from '../Icon';
23
+ import { ThemedPreloader } from '../ThemedPreloader';
24
+ import { DEFAULT_SIZE } from './constants';
25
+ import { IInputHTMLBaseProps, IReactInputMaskProps } from './types';
26
+ import { useStyles, IInputStyles } from './Input.styles';
27
+
28
+ export interface IInputProps
29
+ extends ICommonProps<IInputStyles>,
30
+ IReactInputMaskProps,
31
+ IInputHTMLBaseProps {
32
+ value?: string;
33
+ label?: ReactNode;
34
+ /** @default false */
35
+ isDisabled?: boolean;
36
+ /** @default true */
37
+ hasFloatingLabel?: boolean;
38
+ /** @default false */
39
+ isReadonly?: boolean;
40
+ /** @default false */
41
+ isInvalid?: boolean;
42
+ /** @default false */
43
+ isActive?: boolean;
44
+ /** @default false */
45
+ isClearable?: boolean;
46
+ infoMessage?: string;
47
+ errorMessage?: string;
48
+ /** @default 'bottom' */
49
+ errorPosition?: 'top' | 'bottom';
50
+ inlineStyle?:
51
+ | 'top'
52
+ | 'bottom'
53
+ | 'top-left'
54
+ | 'top-right'
55
+ | 'bottom-left'
56
+ | 'bottom-right'
57
+ | 'left'
58
+ | 'right'
59
+ | 'middle';
60
+ border?: 'top' | 'bottom' | 'left' | 'right';
61
+ /** @default false */
62
+ isRequired?: boolean;
63
+ /** @default false */
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?: IIcon;
76
+ units?: string;
77
+ /** @default false */
78
+ hasRequiredLabel?: boolean;
79
+ /** @default false */
80
+ shouldFocusOnMount?: boolean;
81
+ /** @default false */
82
+ shouldAlwaysShowPlaceholder?: boolean;
83
+ onChange: (value: string, event: FormEvent<HTMLInputElement>) => void;
84
+ onIconClick?: () => void;
85
+ }
86
+
87
+ export const Input = forwardRef<HTMLInputElement, IInputProps>(
88
+ (
89
+ {
90
+ value = '',
91
+ label,
92
+ placeholder,
93
+ type = 'text',
94
+ isDisabled,
95
+ isReadonly = false,
96
+ hasFloatingLabel = true,
97
+ isInvalid = false,
98
+ isActive = false,
99
+ isClearable = false,
100
+ infoMessage,
101
+ errorMessage,
102
+ errorPosition = 'bottom',
103
+ inlineStyle,
104
+ border,
105
+ isRequired = false,
106
+ isLoading = false,
107
+ isAutoSizeable = false,
108
+ defaultSize = DEFAULT_SIZE,
109
+ iconType,
110
+ hasRequiredLabel,
111
+ data,
112
+ tweakStyles,
113
+ shouldFocusOnMount = false,
114
+ units,
115
+ testId,
116
+ onChange,
117
+ onFocus,
118
+ onBlur,
119
+ onIconClick,
120
+ // Пропсы react-input-mask
121
+ mask,
122
+ maskPlaceholder,
123
+ alwaysShowMask,
124
+ shouldAlwaysShowPlaceholder = false,
125
+ beforeMaskedStateChange,
126
+ ...inputProps
127
+ },
128
+ ref,
129
+ ) => {
130
+ const classes = useStyles({ theme: tweakStyles });
131
+
132
+ const tweakPreloaderStyles = useTweakStyles({
133
+ tweakStyles,
134
+ className: 'tweakPreloader',
135
+ currentComponentName: 'Input',
136
+ });
137
+
138
+ const [isFocused, setFocused] = useState(false);
139
+ const inputRef = useRef<HTMLInputElement>(null);
140
+
141
+ const handleChange = (event: FormEvent<HTMLInputElement>) => {
142
+ onChange(event.currentTarget.value, event);
143
+ };
144
+
145
+ const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
146
+ setFocused(true);
147
+ onFocus?.(event);
148
+ };
149
+
150
+ const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
151
+ setFocused(false);
152
+ onBlur?.(event);
153
+ };
154
+
155
+ // для SmartInput нужен event, иначе onChange не вызовется
156
+ const handleOnInputClear = async (event: MouseEvent<HTMLDivElement>) => {
157
+ // await не убирать (важно для порядка выполнения (сначала onChange, затем focus)
158
+ await onChange('', event as any);
159
+ const input = (ref as MutableRefObject<HTMLInputElement>) ?? inputRef;
160
+ input.current?.focus();
161
+ };
162
+
163
+ const hasFocus = isFocused || isActive;
164
+ const hasClearIcon = isClearable && value.length > 0;
165
+ const hasControls = hasClearIcon || iconType !== undefined || isLoading;
166
+ const hasValue = value !== undefined && value !== '';
167
+ const hasUnits = units !== undefined && units !== '';
168
+ const hasLabel = isReactNodeNotEmpty(label);
169
+ const hasPlaceholder =
170
+ (!hasLabel || (hasFocus && !isReadonly) || shouldAlwaysShowPlaceholder) &&
171
+ isStringNotEmpty(placeholder);
172
+ const shouldShowUnits = (hasValue || (isFocused && !hasPlaceholder)) && hasUnits;
173
+
174
+ const props: InputHTMLAttributes<HTMLInputElement> = {
175
+ ...inputProps,
176
+ ...addDataTestId(testId),
177
+ className: clsx(classes.input, {
178
+ [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
179
+ [classes.withIcons]: hasControls,
180
+ [classes.withControls]: hasControls,
181
+ [classes.withUnits]: shouldShowUnits,
182
+ [classes.floatingLabelWithoutPadding]: hasFloatingLabel && hasLabel && border === 'bottom',
183
+ }),
184
+ onFocus: handleFocus,
185
+ onBlur: handleBlur,
186
+ onChange: handleChange,
187
+ value,
188
+ type,
189
+ disabled: isDisabled,
190
+ placeholder: hasPlaceholder ? placeholder : undefined,
191
+ autoFocus: shouldFocusOnMount,
192
+ readOnly: isReadonly,
193
+ size: isAutoSizeable ? defaultSize : undefined,
194
+ };
195
+
196
+ return (
197
+ <div className={classes.root}>
198
+ <div
199
+ className={clsx(
200
+ classes.inputWrapper,
201
+ {
202
+ [classes.required]: isRequired && !hasRequiredLabel,
203
+ [classes.invalid]: isInvalid,
204
+ [classes.focused]: hasFocus,
205
+ [classes.disabled]: isDisabled,
206
+ [classes.autosize]: isAutoSizeable,
207
+ },
208
+ inlineStyle !== undefined && classes[inlineStyle],
209
+ border !== undefined && classes[`border-${border}`],
210
+ )}
211
+ data-value={isAutoSizeable ? value : undefined}
212
+ {...addDataAttributes(data)}
213
+ >
214
+ {mask === undefined ? (
215
+ <input ref={ref ?? inputRef} {...props} />
216
+ ) : (
217
+ <InputMask
218
+ // Баг в типизации react-input-mask
219
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
220
+ // @ts-ignore: No overload matches this call
221
+ ref={ref ?? inputRef}
222
+ mask={mask}
223
+ maskPlaceholder={maskPlaceholder}
224
+ alwaysShowMask={alwaysShowMask}
225
+ beforeMaskedStateChange={beforeMaskedStateChange}
226
+ {...props}
227
+ />
228
+ )}
229
+ {hasLabel && (
230
+ <span
231
+ className={clsx(classes.label, {
232
+ [classes.invalidLabel]: isInvalid,
233
+ [classes.requiredLabel]: hasRequiredLabel && !isRequired,
234
+ [classes.activeLabel]: (hasFocus && !isReadonly) || hasValue,
235
+ [classes.floating]: hasFloatingLabel,
236
+ // Обсуждаемо, сделал так, потому что не хочется создавать новую пропсу, на каждый чих в стилях
237
+ [classes.floatingWithoutPadding]: hasFloatingLabel && border === 'bottom',
238
+ })}
239
+ >
240
+ {label}
241
+ </span>
242
+ )}
243
+
244
+ {shouldShowUnits && (
245
+ <div
246
+ className={clsx(classes.unitsWrapper, {
247
+ [classes.withFloatingLabel]: hasFloatingLabel && hasLabel,
248
+ })}
249
+ >
250
+ <span className={classes.fakeValue}>{value}</span>
251
+ <span className={classes.units}>{units}</span>
252
+ </div>
253
+ )}
254
+
255
+ {hasControls && (
256
+ <div className={classes.controls}>
257
+ {isLoading && (
258
+ <div className={clsx(classes.inputIcon, classes.loading)}>
259
+ <ThemedPreloader tweakStyles={tweakPreloaderStyles} />
260
+ </div>
261
+ )}
262
+
263
+ {!isDisabled && hasClearIcon && (
264
+ <div
265
+ // .clearIcon extend .icon
266
+ className={clsx(classes.clearIcon, classes.activeIcon)}
267
+ // превентим блур с инпута (важно)
268
+ onMouseDown={(event) => event.preventDefault()}
269
+ onClick={handleOnInputClear}
270
+ >
271
+ <Icon type="close" />
272
+ </div>
273
+ )}
274
+ {isReactNodeNotEmpty(iconType) && (
275
+ <div
276
+ // .inputIcon extend .icon
277
+ className={clsx(classes.inputIcon, {
278
+ [classes.activeIcon]: !isDisabled && onIconClick !== undefined,
279
+ })}
280
+ onClick={!isDisabled ? onIconClick : undefined}
281
+ >
282
+ {renderIcon(iconType)}
283
+ </div>
284
+ )}
285
+ </div>
286
+ )}
287
+ </div>
288
+ {isStringNotEmpty(infoMessage) && <div className={classes.info}>{infoMessage}</div>}
289
+ {isStringNotEmpty(errorMessage) && (
290
+ <div className={clsx(classes.error, classes[`error-${errorPosition}`])}>
291
+ {errorMessage}
292
+ </div>
293
+ )}
294
+ </div>
295
+ );
296
+ },
297
+ );
@@ -1,32 +1,32 @@
1
- import { InputHTMLAttributes } from 'react';
2
- import { Props as ReactInputMaskBaseProps } from 'react-input-mask';
3
-
4
- export type IReactInputMaskProps = Pick<
5
- Partial<ReactInputMaskBaseProps>,
6
- 'mask' | 'maskPlaceholder' | 'alwaysShowMask' | 'beforeMaskedStateChange'
7
- >;
8
-
9
- export type IInputHTMLBaseProps = Pick<
10
- InputHTMLAttributes<HTMLInputElement>,
11
- | 'maxLength'
12
- | 'name'
13
- | 'tabIndex'
14
- | 'placeholder'
15
- | 'type'
16
- | 'onBlur'
17
- | 'onFocus'
18
- | 'onInput'
19
- | 'onKeyDown'
20
- | 'onPaste'
21
- >;
22
- // Возможно это лучше заменить на
23
- // Omit< InputHTMLAttributes<HTMLInputElement>,
24
- // | 'className'
25
- // | 'value'
26
- // | 'onChange'
27
- // | 'disabled'
28
- // | 'required'
29
- // | 'autoFocus'
30
- // | 'readOnly'
31
- // | 'size'
32
- // >
1
+ import { InputHTMLAttributes } from 'react';
2
+ import { Props as ReactInputMaskBaseProps } from 'react-input-mask';
3
+
4
+ export type IReactInputMaskProps = Pick<
5
+ Partial<ReactInputMaskBaseProps>,
6
+ 'mask' | 'maskPlaceholder' | 'alwaysShowMask' | 'beforeMaskedStateChange'
7
+ >;
8
+
9
+ export type IInputHTMLBaseProps = Pick<
10
+ InputHTMLAttributes<HTMLInputElement>,
11
+ | 'maxLength'
12
+ | 'name'
13
+ | 'tabIndex'
14
+ | 'placeholder'
15
+ | 'type'
16
+ | 'onBlur'
17
+ | 'onFocus'
18
+ | 'onInput'
19
+ | 'onKeyDown'
20
+ | 'onPaste'
21
+ >;
22
+ // Возможно это лучше заменить на
23
+ // Omit< InputHTMLAttributes<HTMLInputElement>,
24
+ // | 'className'
25
+ // | 'value'
26
+ // | 'onChange'
27
+ // | 'disabled'
28
+ // | 'required'
29
+ // | 'autoFocus'
30
+ // | 'readOnly'
31
+ // | 'size'
32
+ // >