@true-engineering/true-react-common-ui-kit 3.40.0 → 3.41.0
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.
- package/README.md +9 -1
- package/dist/components/SmartInput/SmartInput.d.ts +8 -6
- package/dist/components/SmartInput/constants.d.ts +4 -6
- package/dist/components/SmartInput/helpers.d.ts +2 -4
- package/dist/components/SmartInput/types.d.ts +5 -0
- package/dist/true-react-common-ui-kit.js +1081 -940
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +1081 -940
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +98 -98
- package/src/components/MoreMenu/MoreMenu.tsx +93 -93
- package/src/components/SmartInput/SmartInput.stories.tsx +52 -51
- package/src/components/SmartInput/SmartInput.tsx +116 -134
- package/src/components/SmartInput/constants.ts +91 -84
- package/src/components/SmartInput/helpers.ts +26 -13
- package/src/components/SmartInput/types.ts +18 -11
- package/src/components/TextWithTooltip/TextWithTooltip.tsx +156 -156
- package/src/components/WithPopup/WithPopup.styles.ts +45 -45
- package/src/components/WithPopup/WithPopup.tsx +184 -184
- package/src/components/WithTooltip/WithTooltip.stories.tsx +56 -56
- package/src/components/WithTooltip/WithTooltip.styles.ts +7 -7
- package/src/components/WithTooltip/WithTooltip.tsx +67 -67
- package/src/components/WithTooltip/index.ts +2 -2
- package/src/components/index.ts +46 -46
- package/src/theme/types.ts +158 -158
|
@@ -1,134 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
setCaretPosition(selectionStart + mappedValue.length);
|
|
119
|
-
setCurrentValue(newValue);
|
|
120
|
-
onChange(newValue);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<Input
|
|
125
|
-
{...rest}
|
|
126
|
-
ref={ref}
|
|
127
|
-
maxLength={maxLength}
|
|
128
|
-
onChange={handleChange}
|
|
129
|
-
onPaste={handlePaste}
|
|
130
|
-
value={currentValue}
|
|
131
|
-
/>
|
|
132
|
-
);
|
|
133
|
-
},
|
|
134
|
-
);
|
|
1
|
+
import { ClipboardEvent, FormEvent, forwardRef, useRef } from 'react';
|
|
2
|
+
import { isEmpty, isNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
3
|
+
import { useMergedRefs } from '../../hooks';
|
|
4
|
+
import { IInputProps, Input } from '../Input';
|
|
5
|
+
import {
|
|
6
|
+
CharactersMap,
|
|
7
|
+
EmailCharactersMap,
|
|
8
|
+
SMART_INPUT_REGEX_MAP,
|
|
9
|
+
TransliterationMap,
|
|
10
|
+
} from './constants';
|
|
11
|
+
import { mapSymbols } from './helpers';
|
|
12
|
+
import { IInputRawValue, ISmartType } from './types';
|
|
13
|
+
|
|
14
|
+
export interface ISmartInputProps extends Omit<IInputProps, 'onChange'> {
|
|
15
|
+
/** @default 'default' */
|
|
16
|
+
smartType?: ISmartType;
|
|
17
|
+
regExp?: RegExp;
|
|
18
|
+
/** @default false */
|
|
19
|
+
isUpperCase?: boolean;
|
|
20
|
+
/** @default true */
|
|
21
|
+
isTransliterationEnabled?: boolean;
|
|
22
|
+
onChange: (
|
|
23
|
+
value: string,
|
|
24
|
+
rawValue: IInputRawValue,
|
|
25
|
+
event?: FormEvent<HTMLInputElement> | ClipboardEvent<HTMLInputElement>,
|
|
26
|
+
) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const SmartInput = forwardRef<HTMLInputElement, ISmartInputProps>(
|
|
30
|
+
(
|
|
31
|
+
{
|
|
32
|
+
value = '',
|
|
33
|
+
smartType = 'default',
|
|
34
|
+
regExp,
|
|
35
|
+
maxLength,
|
|
36
|
+
isUpperCase = false,
|
|
37
|
+
isTransliterationEnabled = true,
|
|
38
|
+
onChange,
|
|
39
|
+
...rest
|
|
40
|
+
},
|
|
41
|
+
ref,
|
|
42
|
+
) => {
|
|
43
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
44
|
+
const mergedRef = useMergedRefs([ref, inputRef]);
|
|
45
|
+
|
|
46
|
+
const regex = regExp || SMART_INPUT_REGEX_MAP[smartType];
|
|
47
|
+
|
|
48
|
+
const getUpperCaseIfNeeded = (str: string) => (isUpperCase ? str.toUpperCase() : str);
|
|
49
|
+
|
|
50
|
+
const updateCaretPosition = (position: number | null, newValue: string) => {
|
|
51
|
+
const input = inputRef.current;
|
|
52
|
+
if (isNotEmpty(input) && input.type !== 'email') {
|
|
53
|
+
// Нужно для того, чтобы после ререндера позиция каретки не сбросилась
|
|
54
|
+
input.value = newValue;
|
|
55
|
+
input.setSelectionRange(position, position);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleChange = async (str: string, event: FormEvent<HTMLInputElement>) => {
|
|
60
|
+
const isValid = regex.test(str);
|
|
61
|
+
|
|
62
|
+
const charactersMap = smartType === 'email' ? EmailCharactersMap : CharactersMap;
|
|
63
|
+
const newValue = getUpperCaseIfNeeded(
|
|
64
|
+
isValid ? str : mapSymbols(str, regex, charactersMap, isTransliterationEnabled),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
onChange(newValue, { rawValue: str, isValid }, event);
|
|
68
|
+
|
|
69
|
+
const input = inputRef.current;
|
|
70
|
+
if (isNotEmpty(input)) {
|
|
71
|
+
const start = input.selectionStart;
|
|
72
|
+
updateCaretPosition(isEmpty(start) || newValue !== value ? start : start - 1, newValue);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handlePaste = async (event: ClipboardEvent<HTMLInputElement>) => {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
|
|
79
|
+
const str = event.clipboardData.getData('text/plain').split('').join('');
|
|
80
|
+
|
|
81
|
+
const input = event.currentTarget;
|
|
82
|
+
const selectionStart = input.selectionStart ?? 0;
|
|
83
|
+
const selectionEnd = input.selectionEnd ?? 0;
|
|
84
|
+
|
|
85
|
+
const isValid = regex.test(str);
|
|
86
|
+
|
|
87
|
+
let mappedValue = isValid
|
|
88
|
+
? str
|
|
89
|
+
: mapSymbols(str, regex, TransliterationMap, isTransliterationEnabled);
|
|
90
|
+
|
|
91
|
+
const newValueLength = mappedValue.length + value.length - (selectionEnd - selectionStart);
|
|
92
|
+
|
|
93
|
+
if (isNotEmpty(maxLength) && maxLength >= 0 && newValueLength > maxLength) {
|
|
94
|
+
mappedValue = mappedValue.substring(0, mappedValue.length - (newValueLength - maxLength));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const newValue = getUpperCaseIfNeeded(
|
|
98
|
+
`${value.substring(0, selectionStart)}${mappedValue}${value.substring(selectionEnd)}`,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
onChange(newValue, { rawValue: str, isValid }, event);
|
|
102
|
+
updateCaretPosition(selectionStart + mappedValue.length, newValue);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Input
|
|
107
|
+
{...rest}
|
|
108
|
+
ref={mergedRef}
|
|
109
|
+
value={value}
|
|
110
|
+
maxLength={maxLength}
|
|
111
|
+
onPaste={handlePaste}
|
|
112
|
+
onChange={handleChange}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
);
|
|
@@ -1,84 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
import { ICharactersMap } from './types';
|
|
2
|
+
|
|
3
|
+
export const SMART_INPUT_REGEX_MAP = {
|
|
4
|
+
default: /./i,
|
|
5
|
+
agencyName: /^[a-zA-Z\s0-9-]*$/i,
|
|
6
|
+
surname: /^[a-zA-Z\s-]*$/i,
|
|
7
|
+
name: /^[a-zA-Z\s-.`']*$/i,
|
|
8
|
+
surnameRuEn: /^[a-zA-Zа-яА-Я\s-]*$/i,
|
|
9
|
+
nameRuEn: /^[a-zA-Zа-яА-Я\s-.`']*$/i,
|
|
10
|
+
email: /^[a-zA-Z0-9@_\-.+']*$/i,
|
|
11
|
+
digits: /^[0-9]*$/i,
|
|
12
|
+
docNumber: /^[a-zA-Z0-9]*$/i,
|
|
13
|
+
benefitCert: /^[a-zA-Z0-9/]*$/i,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const CharactersMap: ICharactersMap = {
|
|
17
|
+
й: 'q',
|
|
18
|
+
ц: 'w',
|
|
19
|
+
у: 'e',
|
|
20
|
+
к: 'r',
|
|
21
|
+
е: 't',
|
|
22
|
+
н: 'y',
|
|
23
|
+
г: 'u',
|
|
24
|
+
ш: 'i',
|
|
25
|
+
щ: 'o',
|
|
26
|
+
з: 'p',
|
|
27
|
+
х: '[',
|
|
28
|
+
ъ: ']',
|
|
29
|
+
ф: 'a',
|
|
30
|
+
ы: 's',
|
|
31
|
+
в: 'd',
|
|
32
|
+
а: 'f',
|
|
33
|
+
п: 'g',
|
|
34
|
+
р: 'h',
|
|
35
|
+
о: 'j',
|
|
36
|
+
л: 'k',
|
|
37
|
+
д: 'l',
|
|
38
|
+
ж: ';',
|
|
39
|
+
э: "'",
|
|
40
|
+
я: 'z',
|
|
41
|
+
ч: 'x',
|
|
42
|
+
с: 'c',
|
|
43
|
+
м: 'v',
|
|
44
|
+
и: 'b',
|
|
45
|
+
т: 'n',
|
|
46
|
+
ь: 'm',
|
|
47
|
+
б: ',',
|
|
48
|
+
ю: '.',
|
|
49
|
+
ё: '`',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const EmailCharactersMap: ICharactersMap = {
|
|
53
|
+
...CharactersMap,
|
|
54
|
+
'"': '@',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const TransliterationMap: ICharactersMap = {
|
|
58
|
+
й: 'i',
|
|
59
|
+
ц: 'ts',
|
|
60
|
+
у: 'u',
|
|
61
|
+
к: 'k',
|
|
62
|
+
е: 'e',
|
|
63
|
+
н: 'n',
|
|
64
|
+
г: 'g',
|
|
65
|
+
ш: 'sh',
|
|
66
|
+
щ: 'shch',
|
|
67
|
+
з: 'z',
|
|
68
|
+
х: 'h',
|
|
69
|
+
ъ: 'ie',
|
|
70
|
+
ф: 'f',
|
|
71
|
+
ы: 'y',
|
|
72
|
+
в: 'v',
|
|
73
|
+
а: 'a',
|
|
74
|
+
п: 'p',
|
|
75
|
+
р: 'r',
|
|
76
|
+
о: 'o',
|
|
77
|
+
л: 'l',
|
|
78
|
+
д: 'd',
|
|
79
|
+
ж: 'zh',
|
|
80
|
+
э: 'e',
|
|
81
|
+
я: 'ia',
|
|
82
|
+
ч: 'ch',
|
|
83
|
+
с: 's',
|
|
84
|
+
м: 'm',
|
|
85
|
+
и: 'i',
|
|
86
|
+
т: 't',
|
|
87
|
+
ь: '',
|
|
88
|
+
б: 'b',
|
|
89
|
+
ю: 'iu',
|
|
90
|
+
ё: 'e',
|
|
91
|
+
};
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ICharactersMap } from './types';
|
|
2
|
+
|
|
3
|
+
export const mapSymbols = (
|
|
4
|
+
str: string,
|
|
5
|
+
regex: RegExp,
|
|
6
|
+
charactersMap: ICharactersMap,
|
|
7
|
+
isTransliterationEnabled: boolean,
|
|
8
|
+
): string =>
|
|
9
|
+
str
|
|
10
|
+
.split('')
|
|
11
|
+
.map((symbol) => {
|
|
12
|
+
if (regex.test(symbol)) {
|
|
13
|
+
return symbol;
|
|
14
|
+
}
|
|
15
|
+
if (!isTransliterationEnabled) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const mappedSymbol = charactersMap[symbol.toLowerCase()] ?? symbol;
|
|
20
|
+
|
|
21
|
+
const isUpperCase = symbol.toUpperCase() === symbol;
|
|
22
|
+
const result = isUpperCase ? mappedSymbol.toUpperCase() : mappedSymbol;
|
|
23
|
+
|
|
24
|
+
return regex.test(result) ? result : '';
|
|
25
|
+
})
|
|
26
|
+
.join('');
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
| '
|
|
10
|
-
| '
|
|
11
|
-
| '
|
|
1
|
+
export type ICharactersMap = Record<string, string>;
|
|
2
|
+
|
|
3
|
+
export interface IInputRawValue {
|
|
4
|
+
rawValue: string;
|
|
5
|
+
isValid: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ISmartType =
|
|
9
|
+
| 'name'
|
|
10
|
+
| 'nameRuEn'
|
|
11
|
+
| 'surname'
|
|
12
|
+
| 'surnameRuEn'
|
|
13
|
+
| 'email'
|
|
14
|
+
| 'agencyName'
|
|
15
|
+
| 'default'
|
|
16
|
+
| 'digits'
|
|
17
|
+
| 'docNumber'
|
|
18
|
+
| 'benefitCert';
|