@true-engineering/true-react-common-ui-kit 3.45.1 → 4.0.0-alpha0

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 (122) hide show
  1. package/README.md +0 -40
  2. package/dist/components/CloseButton/CloseButton.d.ts +1 -1
  3. package/dist/components/ControlGroup/ControlGroup.d.ts +10 -0
  4. package/dist/components/ControlGroup/ControlGroup.stories.d.ts +7 -0
  5. package/dist/components/ControlGroup/ControlGroup.styles.d.ts +3 -0
  6. package/dist/components/ControlGroup/index.d.ts +2 -0
  7. package/dist/components/ControlWrapper/ControlWrapper.d.ts +27 -0
  8. package/dist/components/ControlWrapper/ControlWrapper.stories.d.ts +6 -0
  9. package/dist/components/ControlWrapper/ControlWrapper.styles.d.ts +6 -0
  10. package/dist/components/ControlWrapper/index.d.ts +2 -0
  11. package/dist/components/DateInput/DateInput.d.ts +3 -3
  12. package/dist/components/DatePicker/components/DatePickerHeader/DatePickerHeader.styles.d.ts +1 -1
  13. package/dist/components/DatePicker/types.d.ts +1 -1
  14. package/dist/components/FiltersPane/FiltersPane.stories.d.ts +1 -2
  15. package/dist/components/FiltersPane/components/FilterWithDates/FilterWithDates.d.ts +1 -1
  16. package/dist/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.d.ts +1 -2
  17. package/dist/components/Input/Input.d.ts +5 -52
  18. package/dist/components/Input/Input.stories.d.ts +4 -13
  19. package/dist/components/Input/Input.styles.d.ts +5 -4
  20. package/dist/components/Input/InputBase.d.ts +24 -0
  21. package/dist/components/Input/index.d.ts +1 -0
  22. package/dist/components/Input/types.d.ts +3 -4
  23. package/dist/components/NumberInput/NumberInput.d.ts +3 -3
  24. package/dist/components/PhoneInput/PhoneInput.d.ts +3 -3
  25. package/dist/components/PhoneInput/PhoneInput.stories.d.ts +2 -2
  26. package/dist/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.d.ts +3 -2
  27. package/dist/components/PhoneInput/types.d.ts +2 -0
  28. package/dist/components/SearchInput/SearchInput.d.ts +1 -3
  29. package/dist/components/SearchInput/SearchInput.stories.d.ts +11 -1
  30. package/dist/components/SearchInput/SearchInput.styles.d.ts +1 -1
  31. package/dist/components/Select/Select.d.ts +5 -5
  32. package/dist/components/Select/Select.styles.d.ts +17 -16
  33. package/dist/components/Select/types.d.ts +3 -0
  34. package/dist/components/SmartInput/SmartInput.d.ts +3 -3
  35. package/dist/components/TextArea/TextArea.d.ts +5 -14
  36. package/dist/components/TextArea/TextArea.styles.d.ts +8 -2
  37. package/dist/components/WithPopup/WithPopup.d.ts +3 -10
  38. package/dist/components/WithPopup/WithPopup.styles.d.ts +1 -1
  39. package/dist/components/WithPopup/types.d.ts +0 -3
  40. package/dist/components/WithTooltip/WithTooltip.styles.d.ts +0 -1
  41. package/dist/components/index.d.ts +2 -0
  42. package/dist/theme/common.d.ts +13 -5
  43. package/dist/theme/types.d.ts +4 -2
  44. package/dist/true-react-common-ui-kit.js +1184 -1029
  45. package/dist/true-react-common-ui-kit.js.map +1 -1
  46. package/dist/true-react-common-ui-kit.umd.cjs +1164 -1009
  47. package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
  48. package/dist/types.d.ts +2 -1
  49. package/package.json +1 -1
  50. package/src/components/Button/Button.stories.tsx +4 -8
  51. package/src/components/CloseButton/CloseButton.tsx +4 -4
  52. package/src/components/ControlGroup/ControlGroup.stories.tsx +40 -0
  53. package/src/components/ControlGroup/ControlGroup.styles.ts +46 -0
  54. package/src/components/ControlGroup/ControlGroup.tsx +55 -0
  55. package/src/components/ControlGroup/index.ts +2 -0
  56. package/src/components/ControlWrapper/ControlWrapper.stories.tsx +45 -0
  57. package/src/components/ControlWrapper/ControlWrapper.styles.ts +185 -0
  58. package/src/components/ControlWrapper/ControlWrapper.tsx +151 -0
  59. package/src/components/ControlWrapper/index.ts +2 -0
  60. package/src/components/DateInput/DateInput.styles.ts +2 -7
  61. package/src/components/DateInput/DateInput.tsx +4 -4
  62. package/src/components/DatePicker/DatePicker.tsx +3 -3
  63. package/src/components/DatePicker/components/DatePickerHeader/DatePickerHeader.styles.ts +7 -41
  64. package/src/components/DatePicker/components/DatePickerHeader/DatePickerHeader.tsx +18 -26
  65. package/src/components/DatePicker/types.ts +1 -1
  66. package/src/components/FileItem/FileItem.stories.tsx +4 -8
  67. package/src/components/FiltersPane/FiltersPane.stories.tsx +0 -4
  68. package/src/components/FiltersPane/components/FilterInterval/FilterInterval.styles.ts +9 -7
  69. package/src/components/FiltersPane/components/FilterInterval/FilterInterval.tsx +1 -8
  70. package/src/components/FiltersPane/components/FilterSelect/FilterSelect.styles.ts +7 -5
  71. package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.tsx +7 -9
  72. package/src/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.styles.ts +12 -17
  73. package/src/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.tsx +2 -5
  74. package/src/components/IconButton/IconButton.stories.tsx +5 -5
  75. package/src/components/IncrementInput/IncrementInput.stories.tsx +0 -2
  76. package/src/components/IncrementInput/IncrementInput.styles.ts +9 -9
  77. package/src/components/Input/Input.stories.tsx +17 -25
  78. package/src/components/Input/Input.styles.ts +50 -260
  79. package/src/components/Input/Input.tsx +22 -285
  80. package/src/components/Input/InputBase.tsx +250 -0
  81. package/src/components/Input/index.ts +1 -0
  82. package/src/components/Input/types.ts +3 -32
  83. package/src/components/MultiSelectList/MultiSelectList.styles.ts +7 -5
  84. package/src/components/Notification/Notification.stories.tsx +2 -6
  85. package/src/components/NumberInput/NumberInput.stories.tsx +0 -2
  86. package/src/components/NumberInput/NumberInput.tsx +4 -7
  87. package/src/components/PhoneInput/PhoneInput.stories.tsx +6 -10
  88. package/src/components/PhoneInput/PhoneInput.styles.ts +13 -10
  89. package/src/components/PhoneInput/PhoneInput.tsx +9 -12
  90. package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.styles.ts +6 -4
  91. package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.tsx +6 -6
  92. package/src/components/PhoneInput/types.ts +4 -0
  93. package/src/components/SearchInput/SearchInput.stories.tsx +1 -0
  94. package/src/components/SearchInput/SearchInput.styles.ts +17 -27
  95. package/src/components/SearchInput/SearchInput.tsx +13 -34
  96. package/src/components/Select/CustomSelect.stories.tsx +6 -9
  97. package/src/components/Select/MultiSelect.stories.tsx +4 -12
  98. package/src/components/Select/Select.stories.tsx +3 -11
  99. package/src/components/Select/Select.styles.ts +28 -42
  100. package/src/components/Select/Select.tsx +73 -81
  101. package/src/components/Select/types.ts +5 -0
  102. package/src/components/SmartInput/SmartInput.stories.tsx +0 -1
  103. package/src/components/SmartInput/SmartInput.tsx +4 -4
  104. package/src/components/Status/Status.stories.tsx +3 -7
  105. package/src/components/TextArea/TextArea.stories.tsx +1 -3
  106. package/src/components/TextArea/TextArea.styles.ts +27 -126
  107. package/src/components/TextArea/TextArea.tsx +86 -112
  108. package/src/components/TextButton/TextButton.stories.tsx +4 -8
  109. package/src/components/WithPopup/WithPopup.stories.tsx +0 -1
  110. package/src/components/WithPopup/WithPopup.styles.ts +0 -2
  111. package/src/components/WithPopup/WithPopup.tsx +10 -36
  112. package/src/components/WithPopup/types.ts +0 -7
  113. package/src/components/WithTooltip/WithTooltip.styles.ts +0 -6
  114. package/src/components/WithTooltip/WithTooltip.tsx +2 -7
  115. package/src/components/index.ts +2 -0
  116. package/src/theme/common.ts +15 -6
  117. package/src/theme/types.ts +8 -4
  118. package/src/types.ts +3 -0
  119. package/dist/components/Input/constants.d.ts +0 -1
  120. package/dist/components/WithPopup/helpers.d.ts +0 -2
  121. package/src/components/Input/constants.ts +0 -1
  122. package/src/components/WithPopup/helpers.ts +0 -9
@@ -0,0 +1,250 @@
1
+ import {
2
+ ChangeEvent,
3
+ CSSProperties,
4
+ FocusEvent,
5
+ forwardRef,
6
+ InputHTMLAttributes,
7
+ MutableRefObject,
8
+ ReactNode,
9
+ useCallback,
10
+ useEffect,
11
+ useRef,
12
+ useState,
13
+ } from 'react';
14
+ import InputMask, { Props as ReactInputMaskBaseProps } from 'react-input-mask';
15
+ import clsx from 'clsx';
16
+ import {
17
+ addDataTestId,
18
+ isNotEmpty,
19
+ isReactNodeNotEmpty,
20
+ isStringNotEmpty,
21
+ mergeRefs,
22
+ } from '@true-engineering/true-react-platform-helpers';
23
+ import { useTweakStyles } from '../../hooks';
24
+ import { IClickHandlerEvent, ICommonProps } from '../../types';
25
+ import { ControlWrapper, IControlWrapperProps } from '../ControlWrapper';
26
+ import { IChangeInputEvent } from './types';
27
+ import { IInputStyles, useStyles } from './Input.styles';
28
+
29
+ export interface IInputBaseProps
30
+ extends ICommonProps<IInputStyles>,
31
+ Pick<
32
+ IControlWrapperProps,
33
+ | 'label'
34
+ | 'icon'
35
+ | 'groupPlacement'
36
+ | 'isInvalid'
37
+ | 'isRequired'
38
+ | 'isLoading'
39
+ | 'isDisabled'
40
+ | 'onIconClick'
41
+ >,
42
+ Pick<
43
+ InputHTMLAttributes<HTMLInputElement>,
44
+ | 'type'
45
+ | 'inputMode'
46
+ | 'autoComplete'
47
+ | 'name'
48
+ | 'maxLength'
49
+ | 'tabIndex'
50
+ | 'placeholder'
51
+ | 'onFocus'
52
+ | 'onBlur'
53
+ | 'onPaste'
54
+ | 'onKeyDown'
55
+ >,
56
+ Pick<
57
+ Partial<ReactInputMaskBaseProps>,
58
+ 'mask' | 'maskPlaceholder' | 'alwaysShowMask' | 'beforeMaskedStateChange'
59
+ > {
60
+ value?: string;
61
+ units?: ReactNode;
62
+ /** @default false */
63
+ isReadonly?: boolean;
64
+ /** @default false */
65
+ isActive?: boolean;
66
+ /** @default false */
67
+ isClearable?: boolean;
68
+ /** @default false */
69
+ shouldFocusOnMount?: boolean;
70
+ /** @default false */
71
+ isAutoSized?: boolean;
72
+ /** @default false */
73
+ shouldAlwaysShowPlaceholder?: boolean;
74
+ onChange(value: string, event: IChangeInputEvent): void;
75
+ }
76
+
77
+ export const InputBase = forwardRef<HTMLInputElement, IInputBaseProps>(
78
+ (
79
+ {
80
+ value = '',
81
+ placeholder,
82
+ label,
83
+ type = 'text',
84
+ isDisabled,
85
+ autoComplete,
86
+ inputMode: initialInputMode,
87
+ isReadonly,
88
+ isInvalid,
89
+ isActive,
90
+ isClearable,
91
+ isAutoSized,
92
+ name,
93
+ tweakStyles,
94
+ maxLength,
95
+ shouldFocusOnMount,
96
+ units,
97
+ testId,
98
+ tabIndex,
99
+ onChange,
100
+ onPaste,
101
+ onFocus,
102
+ onBlur,
103
+ onKeyDown,
104
+ // Пропсы react-input-mask
105
+ mask,
106
+ maskPlaceholder,
107
+ alwaysShowMask,
108
+ shouldAlwaysShowPlaceholder,
109
+ beforeMaskedStateChange,
110
+ ...controlProps
111
+ },
112
+ ref,
113
+ ) => {
114
+ const classes = useStyles({ theme: tweakStyles });
115
+
116
+ const tweakControlWrapperStyles = useTweakStyles({
117
+ tweakStyles,
118
+ className: 'tweakControlWrapper',
119
+ currentComponentName: 'Input',
120
+ });
121
+
122
+ const [isFocused, setFocused] = useState(false);
123
+ const [unitsWidth, setUnitsWidth] = useState<number>();
124
+
125
+ const inputRef = useRef<HTMLInputElement>(null);
126
+ const mergedRef = mergeRefs([ref, inputRef]);
127
+
128
+ // Try to guess input-mode if possible
129
+ const inputMode: IInputBaseProps['inputMode'] =
130
+ initialInputMode ??
131
+ (['email', 'tel', 'url'].includes(type) ? (type as 'email' | 'tel' | 'url') : undefined);
132
+
133
+ const hasFocus = isFocused || isActive;
134
+ const hasValue = isNotEmpty(value) && value !== '';
135
+ const hasUnits = isReactNodeNotEmpty(units);
136
+ const hasPlaceholder =
137
+ (!isReactNodeNotEmpty(label) || hasFocus || shouldAlwaysShowPlaceholder) &&
138
+ isStringNotEmpty(placeholder);
139
+
140
+ const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
141
+ onChange(event.currentTarget.value, event);
142
+ };
143
+
144
+ const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
145
+ setFocused(true);
146
+ onFocus?.(event);
147
+ };
148
+
149
+ const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
150
+ setFocused(false);
151
+ onBlur?.(event);
152
+ };
153
+
154
+ // для SmartInput нужен event, иначе onChange не вызовется
155
+ const handleInputClear = async (event: IClickHandlerEvent) => {
156
+ // await не убирать (важно для порядка выполнения (сначала onChange, затем focus)
157
+ await onChange('', event);
158
+ inputRef.current?.focus();
159
+ };
160
+
161
+ const unitsRef = useCallback(
162
+ (node: HTMLDivElement | null) => {
163
+ setUnitsWidth(node?.clientWidth);
164
+ },
165
+ [units],
166
+ );
167
+
168
+ const props: InputHTMLAttributes<HTMLInputElement> = {
169
+ className: clsx(classes.input, {
170
+ [classes.withUnits]: hasUnits,
171
+ [classes.withLabel]: isReactNodeNotEmpty(label),
172
+ [classes.autoSized]: isAutoSized,
173
+ [classes.focusedInput]: isFocused,
174
+ [classes.disabledInput]: isDisabled,
175
+ [classes.invalidInput]: isInvalid,
176
+ }),
177
+ style:
178
+ hasUnits && hasValue
179
+ ? ({ '--units-width': `${unitsWidth}px` } as CSSProperties)
180
+ : undefined,
181
+ value,
182
+ type,
183
+ autoComplete,
184
+ inputMode,
185
+ disabled: isDisabled,
186
+ placeholder: hasPlaceholder ? placeholder : undefined,
187
+ name,
188
+ maxLength,
189
+ readOnly: isReadonly,
190
+ tabIndex,
191
+ onKeyDown,
192
+ onPaste,
193
+ onFocus: handleFocus,
194
+ onBlur: handleBlur,
195
+ onChange: handleChange,
196
+ ...addDataTestId(testId, 'input'),
197
+ };
198
+
199
+ useEffect(() => {
200
+ // It works much better than autoFocus for mobile devices
201
+ if (shouldFocusOnMount) {
202
+ inputRef.current?.focus();
203
+ }
204
+ }, []);
205
+
206
+ const inputContent = (
207
+ <>
208
+ {isNotEmpty(mask) ? (
209
+ <InputMask
210
+ ref={mergedRef as unknown as MutableRefObject<InputMask>}
211
+ mask={mask}
212
+ maskPlaceholder={maskPlaceholder}
213
+ alwaysShowMask={alwaysShowMask}
214
+ beforeMaskedStateChange={beforeMaskedStateChange}
215
+ {...props}
216
+ />
217
+ ) : (
218
+ <input ref={mergedRef} {...props} />
219
+ )}
220
+
221
+ {(hasUnits || isAutoSized) && <div className={classes.fakeValue}>{value}</div>}
222
+ {hasUnits && hasValue && (
223
+ <div className={classes.units} ref={unitsRef}>
224
+ {units}
225
+ </div>
226
+ )}
227
+ </>
228
+ );
229
+
230
+ return (
231
+ <ControlWrapper
232
+ label={label}
233
+ isDisabled={isDisabled}
234
+ isFocused={hasFocus}
235
+ isInvalid={isInvalid}
236
+ hasValue={hasValue || hasPlaceholder}
237
+ isFullWidth={!isAutoSized}
238
+ tweakStyles={tweakControlWrapperStyles}
239
+ onClear={isClearable && hasValue ? handleInputClear : undefined}
240
+ {...controlProps}
241
+ >
242
+ {hasUnits || isAutoSized ? (
243
+ <div className={classes.autoSizeWrapper}>{inputContent}</div>
244
+ ) : (
245
+ inputContent
246
+ )}
247
+ </ControlWrapper>
248
+ );
249
+ },
250
+ );
@@ -1,3 +1,4 @@
1
1
  export * from './Input';
2
+ export * from './InputBase';
2
3
  export * from './types';
3
4
  export type { IInputStyles } from './Input.styles';
@@ -1,33 +1,4 @@
1
- import { InputHTMLAttributes } from 'react';
2
- import { Props as ReactInputMaskBaseProps } from 'react-input-mask';
1
+ import { ChangeEvent } from 'react';
2
+ import { IClickHandlerEvent } from '../../types';
3
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
- | 'inputMode'
17
- | 'onBlur'
18
- | 'onFocus'
19
- | 'onInput'
20
- | 'onKeyDown'
21
- | 'onPaste'
22
- >;
23
- // Возможно это лучше заменить на
24
- // Omit< InputHTMLAttributes<HTMLInputElement>,
25
- // | 'className'
26
- // | 'value'
27
- // | 'onChange'
28
- // | 'disabled'
29
- // | 'required'
30
- // | 'autoFocus'
31
- // | 'readOnly'
32
- // | 'size'
33
- // >
4
+ export type IChangeInputEvent = ChangeEvent<HTMLInputElement> | IClickHandlerEvent;
@@ -1,4 +1,4 @@
1
- import { colors, helpers, ITweakStyles, createThemedStyles } from '../../theme';
1
+ import { colors, createThemedStyles, helpers, ITweakStyles } from '../../theme';
2
2
  import { IButtonStyles } from '../Button';
3
3
  import { ICheckboxStyles } from '../Checkbox';
4
4
  import { ISearchInputStyles } from '../SearchInput';
@@ -91,10 +91,12 @@ export const useStyles = createThemedStyles('MultiSelectList', {
91
91
 
92
92
  export const searchInputStyles: ISearchInputStyles = {
93
93
  tweakInput: {
94
- inputWrapper: {
95
- backgroundColor: 'transparent',
96
- border: 'none',
97
- height: 40,
94
+ tweakControlWrapper: {
95
+ root: {
96
+ '--control-height': '40px',
97
+ backgroundColor: 'transparent',
98
+ border: 'none',
99
+ },
98
100
  },
99
101
  },
100
102
  };
@@ -3,11 +3,7 @@ import { iconsList, IIconType } from '../Icon';
3
3
  import { complexIcons } from '../Icon/complexIcons';
4
4
  import { INotificationProps, Notification } from './Notification';
5
5
 
6
- const iconTypes = [
7
- undefined,
8
- ...Object.keys(iconsList),
9
- ...Object.keys(complexIcons),
10
- ] as IIconType[];
6
+ const icons = [undefined, ...Object.keys(iconsList), ...Object.keys(complexIcons)] as IIconType[];
11
7
 
12
8
  const lorem = 'Lorem ipsum dolor, sit amet consectetur adipisicing';
13
9
 
@@ -28,7 +24,7 @@ export default {
28
24
  },
29
25
  argTypes: {
30
26
  size: { control: 'inline-radio', options: ['s', 'm', 'l'] },
31
- icon: { options: iconTypes, control: 'select' },
27
+ icon: { options: icons, control: 'select' },
32
28
  type: {
33
29
  control: 'inline-radio',
34
30
  options: ['error', 'info', 'warning', 'ok', 'not-ok', 'custom'],
@@ -25,8 +25,6 @@ Default.args = {
25
25
  placeholder: 'Placeholder',
26
26
  infoMessage: 'Message Info',
27
27
  units: 'RUB',
28
- hasFloatingLabel: true,
29
- hasRequiredLabel: true,
30
28
  isInvalid: false,
31
29
  errorMessage: 'Error Text',
32
30
  isDisabled: false,
@@ -1,4 +1,4 @@
1
- import { FormEvent, KeyboardEvent, FocusEvent, forwardRef, useState } from 'react';
1
+ import { FocusEvent, forwardRef, KeyboardEvent, useState } from 'react';
2
2
  import { isStringNotEmpty } from '@true-engineering/true-react-platform-helpers';
3
3
  import {
4
4
  formatNumber,
@@ -9,7 +9,7 @@ import {
9
9
  stringToNumber,
10
10
  } from '../../helpers';
11
11
  import { useDidMountEffect } from '../../hooks';
12
- import { Input, IInputProps } from '../Input';
12
+ import { IChangeInputEvent, IInputProps, Input } from '../Input';
13
13
  import { constructRegExp, formatNumberWithDefault, getNewCaretPosition } from './helpers';
14
14
 
15
15
  export interface INumberInputProps extends Omit<IInputProps, 'value' | 'onChange' | 'type'> {
@@ -25,7 +25,7 @@ export interface INumberInputProps extends Omit<IInputProps, 'value' | 'onChange
25
25
  canBeNegative?: boolean;
26
26
  min?: number;
27
27
  max?: number;
28
- onChange: (value: number | undefined, event?: FormEvent<HTMLInputElement>) => void;
28
+ onChange: (value: number | undefined, event?: IChangeInputEvent) => void;
29
29
  }
30
30
 
31
31
  export const NumberInput = forwardRef<HTMLInputElement, INumberInputProps>(
@@ -60,10 +60,7 @@ export const NumberInput = forwardRef<HTMLInputElement, INumberInputProps>(
60
60
  setShowedValue(isStringNotEmpty(v) ? v : formatNumber(defaultValue));
61
61
  };
62
62
 
63
- const handleChange = async (
64
- inputValue: string,
65
- event: FormEvent<HTMLInputElement>,
66
- ): Promise<void> => {
63
+ const handleChange = async (inputValue: string, event: IChangeInputEvent): Promise<void> => {
67
64
  const oldValue = showedValue;
68
65
  const target = event.target as HTMLInputElement;
69
66
  const defaultCaretPos = target.selectionStart ?? 0;
@@ -5,8 +5,8 @@ import { iconsList } from '../Icon';
5
5
  import { PhoneInput } from './PhoneInput';
6
6
  import { IPhoneValue } from './types';
7
7
 
8
- const iconTypes = [undefined, ...Object.keys(iconsList)];
9
- const inlineStyles = [undefined, 'left', 'right', 'middle'];
8
+ const icons = [undefined, ...Object.keys(iconsList)];
9
+ const groupPlacements = [undefined, 'left', 'right', 'middle'];
10
10
  const borders = [undefined, 'left', 'top', 'right', 'bottom'];
11
11
  const errorPositions = ['bottom', 'top'];
12
12
  const countryCodes = phoneInfo.map((info) => info.countryCode);
@@ -15,10 +15,10 @@ export default {
15
15
  title: 'Inputs/PhoneInput',
16
16
  component: PhoneInput,
17
17
  argTypes: {
18
- iconType: { control: 'select', options: iconTypes },
18
+ icon: { control: 'select', options: icons },
19
19
  errorPosition: { control: 'inline-radio', options: errorPositions },
20
20
  border: { control: 'inline-radio', options: borders },
21
- inlineStyle: { control: 'select', options: inlineStyles },
21
+ groupPlacement: { control: 'select', options: groupPlacements },
22
22
  defaultCountryCode: { control: 'select', options: countryCodes },
23
23
  },
24
24
  };
@@ -37,20 +37,16 @@ export const Default = Template.bind({});
37
37
  Default.args = {
38
38
  label: 'Label',
39
39
  infoMessage: 'Message Info',
40
- border: undefined,
41
- iconType: undefined,
40
+ icon: undefined,
42
41
  isInvalid: false,
43
42
  errorMessage: 'Error Text',
44
- errorPosition: 'bottom',
45
- hasFloatingLabel: true,
46
- hasRequiredLabel: true,
47
43
  isActive: false,
48
44
  isDisabled: false,
49
45
  isRequired: false,
50
46
  isReadonly: false,
51
47
  isClearable: false,
52
48
  isLoading: false,
53
- inlineStyle: undefined,
49
+ groupPlacement: undefined,
54
50
  };
55
51
 
56
52
  Default.parameters = {
@@ -1,4 +1,4 @@
1
- import { colors, dimensions, ITweakStyles, createThemedStyles } from '../../theme';
1
+ import { colors, createThemedStyles, dimensions, ITweakStyles } from '../../theme';
2
2
  import { IInputStyles } from '../Input';
3
3
  import { IPhoneInputCountryListStyles } from './components';
4
4
 
@@ -9,6 +9,7 @@ export const useStyles = createThemedStyles('PhoneInput', {
9
9
  width: '100%',
10
10
  position: 'relative',
11
11
  boxSizing: 'border-box',
12
+ zIndex: 0,
12
13
  },
13
14
 
14
15
  countrySelectContainer: {
@@ -16,14 +17,14 @@ export const useStyles = createThemedStyles('PhoneInput', {
16
17
  left: 1,
17
18
  top: 1,
18
19
  width: COUNTRY_SELECT_WIDTH,
19
- height: dimensions.CONTROL_HEIGHT - 2,
20
+ height: dimensions.CONTROL.HEIGHT - 2,
20
21
  display: 'flex',
21
22
  alignItems: 'center',
22
23
  justifyContent: 'center',
23
24
  borderRight: ['solid', 1, colors.BORDER_MAIN],
24
25
  transition: 'border-color 0.2s ease-in',
25
26
  cursor: 'pointer',
26
- zIndex: 2,
27
+ zIndex: dimensions.Z_INDEX.CONTROL_FOCUS + 1,
27
28
  },
28
29
 
29
30
  disabledCountrySelect: {
@@ -64,20 +65,22 @@ export const useStyles = createThemedStyles('PhoneInput', {
64
65
  flagListContainer: {
65
66
  position: 'absolute',
66
67
  width: '100%',
67
- top: dimensions.CONTROL_HEIGHT + 6,
68
+ top: dimensions.CONTROL.HEIGHT + 6,
68
69
  left: -1,
69
70
  zIndex: 3,
70
71
  },
71
72
  });
72
73
 
73
74
  export const inputStyles: IInputStyles = {
74
- inputWrapper: {
75
- paddingLeft: COUNTRY_SELECT_WIDTH,
76
- },
75
+ tweakControlWrapper: {
76
+ root: {
77
+ paddingLeft: COUNTRY_SELECT_WIDTH,
78
+ },
77
79
 
78
- label: {
79
- marginLeft: COUNTRY_SELECT_WIDTH,
80
- },
80
+ label: {
81
+ marginLeft: COUNTRY_SELECT_WIDTH,
82
+ },
83
+ }
81
84
  };
82
85
 
83
86
  export type IPhoneInputStyles = ITweakStyles<
@@ -1,23 +1,23 @@
1
- import { FC, useState, useRef, useMemo, MouseEvent, FocusEvent, FormEvent } from 'react';
1
+ import { FC, FocusEvent, useMemo, useRef, useState } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import { addDataTestId, getTestId } from '@true-engineering/true-react-platform-helpers';
4
4
  import {
5
+ addDataAttributes,
6
+ findCountryByCode,
5
7
  getCountryCodeFromPhone,
6
8
  getFullPhone,
7
9
  getPhoneMask,
8
10
  getPhoneObjFromString,
9
- findCountryByCode,
10
- addDataAttributes,
11
11
  } from '../../helpers';
12
12
  import { useOnClickOutsideWithRef, useTweakStyles } from '../../hooks';
13
13
  import { ICommonProps } from '../../types';
14
14
  import { Flag } from '../Flag';
15
15
  import { Icon } from '../Icon';
16
- import { IInputProps, Input } from '../Input';
16
+ import { IChangeInputEvent, IInputProps, Input } from '../Input';
17
17
  import { PhoneInputCountryList } from './components';
18
18
  import { DEFAULT_VALUE } from './constants';
19
- import { IPhoneInfo, IPhoneValue } from './types';
20
- import { useStyles, IPhoneInputStyles, inputStyles } from './PhoneInput.styles';
19
+ import { IChangePhoneInputEvent, IPhoneInfo, IPhoneValue } from './types';
20
+ import { inputStyles, IPhoneInputStyles, useStyles } from './PhoneInput.styles';
21
21
 
22
22
  export interface IPhoneInputProps
23
23
  extends Omit<
@@ -33,10 +33,7 @@ export interface IPhoneInputProps
33
33
  noMatchesLabel?: string;
34
34
  /** @default { phoneNumber: '', dialCode: '' } */
35
35
  value?: IPhoneValue;
36
- onChange: (
37
- phone: IPhoneValue,
38
- event: MouseEvent | KeyboardEvent | FormEvent<HTMLInputElement>,
39
- ) => void;
36
+ onChange: (phone: IPhoneValue, event: IChangePhoneInputEvent) => void;
40
37
  }
41
38
 
42
39
  export const PhoneInput: FC<IPhoneInputProps> = ({
@@ -86,7 +83,7 @@ export const PhoneInput: FC<IPhoneInputProps> = ({
86
83
  setIsListOpen(false);
87
84
  };
88
85
 
89
- const handleChange = (inputValue: string, event: FormEvent<HTMLInputElement>) => {
86
+ const handleChange = (inputValue: string, event: IChangeInputEvent) => {
90
87
  // if (event.type === 'change') - нужно из-за InputMask
91
88
  // Помимо change, еще могут приходить focus и blur, когда input пустой и тогда происходят неприятные сайд-эффекты
92
89
  if (event.type === 'change') {
@@ -121,7 +118,7 @@ export const PhoneInput: FC<IPhoneInputProps> = ({
121
118
  }
122
119
  };
123
120
 
124
- const handleSelect = (newPhoneInfo: IPhoneInfo, event: MouseEvent | KeyboardEvent) => {
121
+ const handleSelect = (newPhoneInfo: IPhoneInfo, event: IChangePhoneInputEvent) => {
125
122
  if (newPhoneInfo.countryCode !== countryCode) {
126
123
  onChange(
127
124
  {
@@ -15,7 +15,7 @@ export const useStyles = createThemedStyles('PhoneInputCountryList', {
15
15
 
16
16
  searchContainer: {
17
17
  width: '100%',
18
- height: dimensions.CONTROL_HEIGHT,
18
+ height: dimensions.CONTROL.HEIGHT,
19
19
  display: 'flex',
20
20
  alignItems: 'center',
21
21
  boxSizing: 'border-box',
@@ -85,9 +85,11 @@ export const useStyles = createThemedStyles('PhoneInputCountryList', {
85
85
  });
86
86
 
87
87
  export const inputStyles: IInputStyles = {
88
- inputWrapper: {
89
- border: 'none',
90
- height: 'calc(var(--control-height) - 2px)',
88
+ tweakControlWrapper: {
89
+ root: {
90
+ border: 'none',
91
+ height: 'calc(var(--control-height) - 2px)',
92
+ },
91
93
  },
92
94
 
93
95
  input: {
@@ -1,23 +1,23 @@
1
- import { FC, MouseEvent, useState, useEffect, useMemo } from 'react';
1
+ import { FC, useEffect, useMemo, useState } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import { phoneInfo } from '../../../../constants';
4
4
  import {
5
5
  checkSearchStringInCountry,
6
- getCountryTextByLocale,
7
6
  findCountryIndexByCode,
7
+ getCountryTextByLocale,
8
8
  sortCountriesByLocale,
9
9
  } from '../../../../helpers';
10
10
  import { useTweakStyles } from '../../../../hooks';
11
11
  import { ICommonProps } from '../../../../types';
12
12
  import { Flag } from '../../../Flag';
13
13
  import { Icon } from '../../../Icon';
14
- import { Input } from '../../../Input';
14
+ import { IChangeInputEvent, Input } from '../../../Input';
15
15
  import { ScrollIntoViewIfNeeded } from '../../../ScrollIntoViewIfNeeded';
16
16
  import { IPhoneInfo } from '../../types';
17
17
  import {
18
- useStyles,
19
- IPhoneInputCountryListStyles,
20
18
  inputStyles,
19
+ IPhoneInputCountryListStyles,
20
+ useStyles,
21
21
  } from './PhoneInputCountryList.styles';
22
22
 
23
23
  export interface IPhoneInputCountryListProps
@@ -27,7 +27,7 @@ export interface IPhoneInputCountryListProps
27
27
  placeholder: string;
28
28
  noMatchesLabel: string;
29
29
  closeList: () => void;
30
- onChange: (country: IPhoneInfo, event: MouseEvent | KeyboardEvent) => void;
30
+ onChange: (country: IPhoneInfo, event: IChangeInputEvent | KeyboardEvent) => void;
31
31
  }
32
32
 
33
33
  export const PhoneInputCountryList: FC<IPhoneInputCountryListProps> = ({
@@ -1,3 +1,5 @@
1
+ import { IChangeInputEvent } from '../Input';
2
+
1
3
  export interface IPhoneInfo {
2
4
  countryEn: string;
3
5
  countryRu: string;
@@ -14,3 +16,5 @@ export interface IPhoneValue {
14
16
  dialCode?: string;
15
17
  countryCode?: string;
16
18
  }
19
+
20
+ export type IChangePhoneInputEvent = IChangeInputEvent | KeyboardEvent;
@@ -20,4 +20,5 @@ export const Default = Template.bind({});
20
20
 
21
21
  Default.args = {
22
22
  placeholder: 'Поиск',
23
+ isAutoSized: false,
23
24
  };