@true-engineering/true-react-common-ui-kit 1.0.2 → 1.1.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/dist/components/AccountInfo/AccountInfo.d.ts +4 -4
- package/dist/components/AccountInfo/AccountInfo.styles.d.ts +60 -56
- package/dist/components/AddButton/AddButton.d.ts +6 -6
- package/dist/components/AddButton/AddButton.styles.d.ts +23 -23
- package/dist/components/Button/Button.d.ts +19 -33
- package/dist/components/Button/Button.styles.d.ts +144 -144
- package/dist/components/Checkbox/Checkbox.d.ts +16 -27
- package/dist/components/Checkbox/Checkbox.styles.d.ts +39 -42
- package/dist/components/CloseButton/CloseButton.d.ts +4 -4
- package/dist/components/CloseButton/CloseButton.styles.d.ts +22 -22
- package/dist/components/Colors/Colors.styles.d.ts +28 -28
- package/dist/components/CssBaseline/CssBaseline.d.ts +1 -1
- package/dist/components/CssBaseline/CssBaseline.styles.d.ts +7 -7
- package/dist/components/DateInput/DateInput.d.ts +8 -9
- package/dist/components/DateInput/DateInput.styles.d.ts +7 -7
- package/dist/components/DatePicker/DatePicker.d.ts +29 -36
- package/dist/components/DatePicker/DatePicker.styles.d.ts +38 -34
- package/dist/components/DatePicker/DatePickerHeader/DatePickerHeader.d.ts +9 -9
- package/dist/components/DatePicker/DatePickerHeader/DatePickerHeader.styles.d.ts +59 -59
- package/dist/components/DatePicker/DatePickerInput/DatePickerInput.d.ts +7 -9
- package/dist/components/DatePicker/DatePickerInput/DatePickerInput.styles.d.ts +16 -16
- package/dist/components/Description/Description.d.ts +6 -6
- package/dist/components/Description/Description.styles.d.ts +18 -18
- package/dist/components/FiltersPane/FilterInterval/FilterInterval.d.ts +19 -19
- package/dist/components/FiltersPane/FilterInterval/FilterInterval.styles.d.ts +44 -44
- package/dist/components/FiltersPane/FilterMultiSelect/FilterMultiSelect.d.ts +2 -8
- package/dist/components/FiltersPane/FilterSelect/FilterSelect.d.ts +17 -35
- package/dist/components/FiltersPane/FilterSelect/FilterSelect.styles.d.ts +111 -111
- package/dist/components/FiltersPane/FilterSelect/locales.d.ts +6 -10
- package/dist/components/FiltersPane/FilterValueView/FilterValueView.d.ts +1 -9
- package/dist/components/FiltersPane/FilterValueView/FilterValueView.styles.d.ts +8 -8
- package/dist/components/FiltersPane/FilterWithDates/FilterWithDates.d.ts +13 -21
- package/dist/components/FiltersPane/FilterWithDates/FilterWithDates.styles.d.ts +41 -41
- package/dist/components/FiltersPane/FilterWithPeriod/FilterWithPeriod.d.ts +8 -8
- package/dist/components/FiltersPane/FilterWithPeriod/FilterWithPeriod.styles.d.ts +7 -7
- package/dist/components/FiltersPane/FilterWrapper/FilterWrapper.d.ts +18 -41
- package/dist/components/FiltersPane/FilterWrapper/FilterWrapper.styles.d.ts +92 -92
- package/dist/components/FiltersPane/FiltersPane.d.ts +15 -34
- package/dist/components/FiltersPane/FiltersPane.styles.d.ts +50 -50
- package/dist/components/FiltersPane/FiltersPaneSearch/FiltersPaneSearch.d.ts +18 -37
- package/dist/components/FiltersPane/FiltersPaneSearch/FiltersPaneSearch.styles.d.ts +82 -82
- package/dist/components/FiltersPane/locales.d.ts +22 -28
- package/dist/components/FiltersPane/types.d.ts +38 -65
- package/dist/components/Flag/Flag.d.ts +2 -2
- package/dist/components/Flag/Flag.styles.d.ts +8 -8
- package/dist/components/FlexibleTable/FlexibleTable.d.ts +20 -45
- package/dist/components/FlexibleTable/FlexibleTable.styles.d.ts +93 -93
- package/dist/components/FlexibleTable/TableRow.d.ts +21 -38
- package/dist/components/FlexibleTable/TableValue.d.ts +16 -28
- package/dist/components/FlexibleTable/types.d.ts +31 -37
- package/dist/components/Icon/ComplexIconBoilerplate.d.ts +1 -1
- package/dist/components/Icon/Icon.d.ts +2 -2
- package/dist/components/Icon/Icon.styles.d.ts +4 -4
- package/dist/components/Icon/IconBoilerplate.d.ts +1 -1
- package/dist/components/Icon/complexIcons/icons.d.ts +1 -1
- package/dist/components/Icon/icons/icons.d.ts +5 -97
- package/dist/components/IncrementInput/ChangeButton.d.ts +5 -5
- package/dist/components/IncrementInput/IncrementInput.d.ts +3 -4
- package/dist/components/IncrementInput/IncrementInput.styles.d.ts +52 -52
- package/dist/components/Input/Input.d.ts +37 -48
- package/dist/components/Input/Input.styles.d.ts +242 -242
- package/dist/components/List/List.d.ts +12 -12
- package/dist/components/List/List.styles.d.ts +35 -35
- package/dist/components/Modal/Modal.d.ts +19 -19
- package/dist/components/Modal/Modal.styles.d.ts +235 -235
- package/dist/components/MoreMenu/MoreMenu.d.ts +7 -7
- package/dist/components/MoreMenu/MoreMenu.styles.d.ts +45 -45
- package/dist/components/MultiSelect/MultiSelect.d.ts +13 -28
- package/dist/components/MultiSelect/MultiSelect.styles.d.ts +38 -38
- package/dist/components/MultiSelect/MultiSelectInput/MultiSelectInput.d.ts +6 -12
- package/dist/components/MultiSelect/MultiSelectInput/MultiSelectInput.styles.d.ts +58 -58
- package/dist/components/MultiSelectList/MultiSelectList.d.ts +20 -43
- package/dist/components/MultiSelectList/MultiSelectList.styles.d.ts +90 -90
- package/dist/components/MultiSelectList/locales.d.ts +6 -10
- package/dist/components/Notification/Notification.d.ts +9 -14
- package/dist/components/Notification/Notification.styles.d.ts +30 -33
- package/dist/components/NumberInput/NumberInput.d.ts +10 -16
- package/dist/components/NumberInput/helpers.d.ts +2 -10
- package/dist/components/PhoneInput/PhoneInput.d.ts +7 -14
- package/dist/components/PhoneInput/PhoneInput.styles.d.ts +60 -60
- package/dist/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.d.ts +7 -7
- package/dist/components/PhoneInput/PhoneInputCountryList/PhoneInputCountryList.styles.d.ts +74 -78
- package/dist/components/PhoneInput/types.d.ts +11 -11
- package/dist/components/RadioButton/RadioButton.d.ts +8 -18
- package/dist/components/RadioButton/RadioButton.styles.d.ts +25 -25
- package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +374 -634
- package/dist/components/SearchInput/SearchInput.d.ts +2 -12
- package/dist/components/SearchInput/SearchInput.styles.d.ts +32 -32
- package/dist/components/Select/Select.d.ts +22 -50
- package/dist/components/Select/Select.styles.d.ts +53 -53
- package/dist/components/Select/SelectList/SelectList.d.ts +15 -30
- package/dist/components/Select/SelectList/SelectList.styles.d.ts +35 -37
- package/dist/components/Select/helpers.d.ts +2 -9
- package/dist/components/SmartInput/SmartInput.d.ts +16 -28
- package/dist/components/SmartInput/helpers.d.ts +4 -8
- package/dist/components/Switch/Switch.d.ts +13 -26
- package/dist/components/Switch/Switch.styles.d.ts +58 -58
- package/dist/components/TextArea/TextArea.d.ts +23 -26
- package/dist/components/TextArea/TextArea.styles.d.ts +124 -124
- package/dist/components/TextWithInfo/TextWithInfo.d.ts +9 -9
- package/dist/components/TextWithInfo/TextWithInfo.styles.d.ts +40 -40
- package/dist/components/TextWithTooltip/TextWithTooltip.d.ts +12 -12
- package/dist/components/TextWithTooltip/TextWithTooltip.styles.d.ts +10 -10
- package/dist/components/ThemedPreloader/ThemedPreloader.d.ts +4 -4
- package/dist/components/ThemedPreloader/ThemedPreloader.styles.d.ts +10 -10
- package/dist/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.d.ts +1 -1
- package/dist/components/ThemedPreloader/components/DotsPreloader/DotsPreloader.styles.d.ts +35 -35
- package/dist/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.d.ts +2 -2
- package/dist/components/ThemedPreloader/components/SvgPreloader/SvgPreloader.styles.d.ts +5 -5
- package/dist/components/Toaster/Toaster.d.ts +11 -16
- package/dist/components/Toaster/Toaster.styles.d.ts +41 -41
- package/dist/components/Tooltip/Tooltip.d.ts +4 -4
- package/dist/components/Tooltip/Tooltip.styles.d.ts +27 -25
- package/dist/helpers/data-attributes.d.ts +4 -11
- package/dist/helpers/phone.d.ts +8 -28
- package/dist/helpers/utils.d.ts +7 -28
- package/dist/hooks/use-did-mount-effect.d.ts +1 -4
- package/dist/hooks/use-dropdown.d.ts +7 -14
- package/dist/hooks/use-is-mounted.d.ts +1 -1
- package/dist/hooks/use-on-click-outside.d.ts +4 -25
- package/dist/hooks/use-theme.d.ts +5 -10
- package/dist/hooks/use-tweak-styles.d.ts +1 -5
- package/dist/style.css +90 -205
- package/dist/theme.d.ts +55 -51
- package/dist/true-react-common-ui-kit.js +16713 -24318
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +18 -16
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/dist/types.d.ts +23 -77
- package/package.json +1 -1
- package/src/components/Select/Select.tsx +21 -13
- package/src/components/Select/SelectList/SelectList.tsx +8 -6
- package/src/components/Select/helpers.ts +9 -6
- package/src/components/SmartInput/SmartInput.tsx +130 -127
package/dist/types.d.ts
CHANGED
|
@@ -1,89 +1,35 @@
|
|
|
1
1
|
import { Styles } from 'react-jss';
|
|
2
2
|
import { Modifier, Placement } from 'react-overlays/usePopper';
|
|
3
|
-
import {
|
|
4
|
-
ICommonIcon,
|
|
5
|
-
IComplexIcon,
|
|
6
|
-
IPreloaderSvgType,
|
|
7
|
-
ISvgIcon,
|
|
8
|
-
} from './components';
|
|
3
|
+
import { ICommonIcon, IComplexIcon, IPreloaderSvgType, ISvgIcon } from './components';
|
|
9
4
|
export interface IDataAttributes {
|
|
10
|
-
|
|
5
|
+
[key: string]: unknown;
|
|
11
6
|
}
|
|
12
7
|
export interface ICommonProps {
|
|
13
|
-
|
|
8
|
+
data?: IDataAttributes;
|
|
14
9
|
}
|
|
15
10
|
export interface IDropdownWithPopperOptions {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
shouldUsePopper?: boolean;
|
|
12
|
+
shouldRenderInBody?: boolean;
|
|
13
|
+
scrollParent?: 'auto' | 'document' | Element;
|
|
14
|
+
shouldHideOnScroll?: boolean;
|
|
15
|
+
canBeFlipped?: boolean;
|
|
16
|
+
modifiers?: Array<Partial<Modifier<any, any>>>;
|
|
17
|
+
placement?: Placement;
|
|
18
|
+
flipOptions?: Record<string, any>;
|
|
24
19
|
}
|
|
25
|
-
export declare type ComponentStyles<StyleSheet, Props = unknown> = Partial<
|
|
26
|
-
|
|
27
|
-
>;
|
|
28
|
-
export declare type ComponentName =
|
|
29
|
-
| 'AccountInfo'
|
|
30
|
-
| 'AddButton'
|
|
31
|
-
| 'Button'
|
|
32
|
-
| 'CloseButton'
|
|
33
|
-
| 'Checkbox'
|
|
34
|
-
| 'CssBaseline'
|
|
35
|
-
| 'Colors'
|
|
36
|
-
| 'DateInput'
|
|
37
|
-
| 'DatePicker'
|
|
38
|
-
| 'DatePickerInput'
|
|
39
|
-
| 'DatePickerHeader'
|
|
40
|
-
| 'Description'
|
|
41
|
-
| 'DotsPreloader'
|
|
42
|
-
| 'SvgPreloader'
|
|
43
|
-
| 'FiltersPane'
|
|
44
|
-
| 'FilterInterval'
|
|
45
|
-
| 'FilterSelect'
|
|
46
|
-
| 'FilterWithDates'
|
|
47
|
-
| 'FilterWithPeriod'
|
|
48
|
-
| 'FilterWrapper'
|
|
49
|
-
| 'FiltersPaneSearch'
|
|
50
|
-
| 'Flag'
|
|
51
|
-
| 'FlexibleTable'
|
|
52
|
-
| 'Icon'
|
|
53
|
-
| 'IncrementInput'
|
|
54
|
-
| 'Input'
|
|
55
|
-
| 'List'
|
|
56
|
-
| 'Modal'
|
|
57
|
-
| 'MoreMenu'
|
|
58
|
-
| 'MultiSelect'
|
|
59
|
-
| 'MultiSelectInput'
|
|
60
|
-
| 'MultiSelectList'
|
|
61
|
-
| 'Notification'
|
|
62
|
-
| 'PhoneInput'
|
|
63
|
-
| 'PhoneInputCountryList'
|
|
64
|
-
| 'RadioButton'
|
|
65
|
-
| 'SearchInput'
|
|
66
|
-
| 'Select'
|
|
67
|
-
| 'SelectList'
|
|
68
|
-
| 'ScrollIntoViewIfNeeded'
|
|
69
|
-
| 'Switch'
|
|
70
|
-
| 'TextArea'
|
|
71
|
-
| 'TextWithInfo'
|
|
72
|
-
| 'TextWithTooltip'
|
|
73
|
-
| 'ThemedPreloader'
|
|
74
|
-
| 'Tooltip'
|
|
75
|
-
| 'Toaster';
|
|
20
|
+
export declare type ComponentStyles<StyleSheet, Props = unknown> = Partial<Styles<keyof StyleSheet, Props>>;
|
|
21
|
+
export declare type ComponentName = 'AccountInfo' | 'AddButton' | 'Button' | 'CloseButton' | 'Checkbox' | 'CssBaseline' | 'Colors' | 'DateInput' | 'DatePicker' | 'DatePickerInput' | 'DatePickerHeader' | 'Description' | 'DotsPreloader' | 'SvgPreloader' | 'FiltersPane' | 'FilterInterval' | 'FilterSelect' | 'FilterWithDates' | 'FilterWithPeriod' | 'FilterWrapper' | 'FiltersPaneSearch' | 'Flag' | 'FlexibleTable' | 'Icon' | 'IncrementInput' | 'Input' | 'List' | 'Modal' | 'MoreMenu' | 'MultiSelect' | 'MultiSelectInput' | 'MultiSelectList' | 'Notification' | 'PhoneInput' | 'PhoneInputCountryList' | 'RadioButton' | 'SearchInput' | 'Select' | 'SelectList' | 'ScrollIntoViewIfNeeded' | 'Switch' | 'TextArea' | 'TextWithInfo' | 'TextWithTooltip' | 'ThemedPreloader' | 'Tooltip' | 'Toaster';
|
|
76
22
|
export declare type UiKitAnimations = Record<string, any>;
|
|
77
23
|
export declare type UiKitHelpers = Record<string, Styles | (() => Styles)>;
|
|
78
24
|
export interface UiKitTheme {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
25
|
+
name: string;
|
|
26
|
+
components?: Partial<Record<ComponentName, ComponentStyles<any, any>>>;
|
|
27
|
+
icons?: Partial<Record<ICommonIcon, ISvgIcon>>;
|
|
28
|
+
complexIcons?: Partial<Record<IComplexIcon, string>>;
|
|
29
|
+
preloaders?: Partial<Record<IPreloaderSvgType, string>>;
|
|
30
|
+
animations?: UiKitAnimations;
|
|
31
|
+
colors?: Record<string, string>;
|
|
32
|
+
dimensions?: Record<string, number>;
|
|
33
|
+
boxShadows?: Record<string, string>;
|
|
34
|
+
helpers?: UiKitHelpers;
|
|
89
35
|
}
|
package/package.json
CHANGED
|
@@ -22,14 +22,15 @@ import {
|
|
|
22
22
|
useDropdown,
|
|
23
23
|
} from '../../hooks';
|
|
24
24
|
import { IDropdownWithPopperOptions } from '../../types';
|
|
25
|
-
|
|
26
|
-
import { SelectStyles, styles } from './Select.styles';
|
|
25
|
+
import { isNotEmpty } from '../../helpers';
|
|
27
26
|
import {
|
|
28
27
|
defaultConvertFunction,
|
|
29
28
|
defaultCompareFunction,
|
|
30
29
|
getActiveValueIndex,
|
|
31
30
|
} from './helpers';
|
|
32
31
|
|
|
32
|
+
import { SelectStyles, styles } from './Select.styles';
|
|
33
|
+
|
|
33
34
|
export interface ISelectProps<Value>
|
|
34
35
|
extends Omit<IInputProps, 'value' | 'onChange' | 'type'> {
|
|
35
36
|
tweakStyles?: SelectStyles;
|
|
@@ -46,19 +47,17 @@ export interface ISelectProps<Value>
|
|
|
46
47
|
|
|
47
48
|
optionsFilter?: (options: Value[], query: string) => Value[];
|
|
48
49
|
options: Value[];
|
|
49
|
-
value
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
v2: Value | undefined,
|
|
54
|
-
) => boolean;
|
|
50
|
+
value: Value | undefined;
|
|
51
|
+
shouldScrollToList?: boolean;
|
|
52
|
+
onChange(value: Value | undefined): void; // подумать как возвращать индекс
|
|
53
|
+
compareValuesOnChange?(v1: Value | undefined, v2: Value | undefined): boolean;
|
|
55
54
|
// возможно делать какую-то индексацию опций
|
|
56
55
|
|
|
57
56
|
// Для избежания проблем юзайте useCallback на эти функции
|
|
58
57
|
// или выносите их из компонента (чтобы не было сайдэфектов от перерендеринга их)
|
|
59
|
-
convertValueToString
|
|
60
|
-
convertValueToReactNode
|
|
61
|
-
convertValueToId
|
|
58
|
+
convertValueToString?(value: Value): string | undefined;
|
|
59
|
+
convertValueToReactNode?(value: Value): ReactNode;
|
|
60
|
+
convertValueToId?(value: Value): string | undefined;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
export function Select<Value>({
|
|
@@ -85,6 +84,7 @@ export function Select<Value>({
|
|
|
85
84
|
dropdownOptions,
|
|
86
85
|
minSymbolsCountToOpenList = 0,
|
|
87
86
|
dropdownIcon = 'chevron-down',
|
|
87
|
+
shouldScrollToList = true,
|
|
88
88
|
...inputProps
|
|
89
89
|
}: ISelectProps<Value>): JSX.Element {
|
|
90
90
|
const { classes, componentStyles } = useTheme('Select', styles, tweakStyles);
|
|
@@ -104,6 +104,10 @@ export function Select<Value>({
|
|
|
104
104
|
const list = useRef<HTMLDivElement>(null);
|
|
105
105
|
const input = useRef<HTMLInputElement>(null); // TODO ref снаружи?
|
|
106
106
|
|
|
107
|
+
const stringValue = isNotEmpty(value)
|
|
108
|
+
? convertValueToString(value)
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
107
111
|
const filteredOptions = useMemo(() => {
|
|
108
112
|
if (optionsMode !== 'search') {
|
|
109
113
|
return options;
|
|
@@ -369,7 +373,7 @@ export function Select<Value>({
|
|
|
369
373
|
ref={inputWrapper}
|
|
370
374
|
>
|
|
371
375
|
<Input
|
|
372
|
-
value={searchValue !== '' ? searchValue :
|
|
376
|
+
value={searchValue !== '' ? searchValue : stringValue}
|
|
373
377
|
onChange={handleInputChange}
|
|
374
378
|
isActive={isListOpen}
|
|
375
379
|
isReadonly={optionsMode === 'normal'}
|
|
@@ -428,7 +432,11 @@ export function Select<Value>({
|
|
|
428
432
|
tweakStyles={tweakStyles?.tweakSelectList as Styles}
|
|
429
433
|
testId={testId !== undefined ? `${testId}-list` : undefined}
|
|
430
434
|
// скролл не работает с включеным поппером
|
|
431
|
-
shouldScrollToList={
|
|
435
|
+
shouldScrollToList={
|
|
436
|
+
shouldScrollToList &&
|
|
437
|
+
!shouldUsePopper &&
|
|
438
|
+
!shouldHideOnScroll
|
|
439
|
+
}
|
|
432
440
|
/>
|
|
433
441
|
)}
|
|
434
442
|
</div>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { ReactNode, useMemo } from 'react';
|
|
2
|
-
import { ScrollIntoViewIfNeeded } from '../../ScrollIntoViewIfNeeded';
|
|
3
2
|
import clsx from 'clsx';
|
|
4
|
-
|
|
3
|
+
import { ScrollIntoViewIfNeeded } from '../../ScrollIntoViewIfNeeded';
|
|
5
4
|
import { useTheme } from '../../../hooks';
|
|
6
5
|
import { ICommonProps } from '../../../types';
|
|
6
|
+
import { isNotEmpty } from '../../../helpers';
|
|
7
7
|
|
|
8
8
|
import { SelectListStyles, styles } from './SelectList.styles';
|
|
9
9
|
|
|
@@ -19,9 +19,9 @@ export interface ISelectListProps<Value> extends ICommonProps {
|
|
|
19
19
|
onOptionClick: (index: number) => void;
|
|
20
20
|
testId?: string;
|
|
21
21
|
shouldScrollToList?: boolean;
|
|
22
|
-
convertValueToString: (value
|
|
23
|
-
convertValueToReactNode?: (value
|
|
24
|
-
convertValueToId?: (value
|
|
22
|
+
convertValueToString: (value: Value) => string | undefined;
|
|
23
|
+
convertValueToReactNode?: (value: Value) => ReactNode;
|
|
24
|
+
convertValueToId?: (value: Value) => string | undefined;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function isOptionDisabled<Value>(option: Value): boolean {
|
|
@@ -51,7 +51,9 @@ export function SelectList<Value>({
|
|
|
51
51
|
shouldScrollToList = true,
|
|
52
52
|
}: ISelectListProps<Value>): JSX.Element {
|
|
53
53
|
const { classes } = useTheme('SelectList', styles, tweakStyles);
|
|
54
|
-
const activeValueId =
|
|
54
|
+
const activeValueId = isNotEmpty(activeValue)
|
|
55
|
+
? convertValueToId(activeValue)
|
|
56
|
+
: undefined;
|
|
55
57
|
|
|
56
58
|
const convertedToStringOptions = useMemo(
|
|
57
59
|
() => options.map(convertValueToString),
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { isNotEmpty } from '../../helpers';
|
|
2
|
+
|
|
1
3
|
export const defaultConvertFunction = (v: unknown) =>
|
|
2
4
|
v === undefined ? undefined : String(v);
|
|
3
5
|
|
|
4
|
-
export const defaultCompareFunction = <Value>(
|
|
5
|
-
v1
|
|
6
|
-
v2: Value | undefined,
|
|
7
|
-
) => v1 === v2;
|
|
6
|
+
export const defaultCompareFunction = <Value>(v1: Value, v2: Value) =>
|
|
7
|
+
v1 === v2;
|
|
8
8
|
|
|
9
9
|
export const getActiveValueIndex = <Value>(
|
|
10
10
|
options: Value[],
|
|
11
11
|
value: Value | undefined,
|
|
12
|
-
convertFunc: (v
|
|
13
|
-
): number =>
|
|
12
|
+
convertFunc: (v: Value) => string | undefined,
|
|
13
|
+
): number =>
|
|
14
|
+
isNotEmpty(value)
|
|
15
|
+
? options.findIndex((o) => convertFunc(o) === convertFunc(value))
|
|
16
|
+
: -1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useState, useEffect, forwardRef} from 'react';
|
|
1
|
+
import React, { useState, useEffect, forwardRef } from 'react';
|
|
2
2
|
import { Input, IInputProps } from '../Input';
|
|
3
3
|
import {
|
|
4
4
|
CharactersMap,
|
|
@@ -38,140 +38,143 @@ export const SMART_INPUT_REGEX_MAP = {
|
|
|
38
38
|
benefitCert: /^[a-zA-Z0-9/]*$/i,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export const SmartInput = forwardRef<HTMLInputElement, ISmartInputProps>(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
41
|
+
export const SmartInput = forwardRef<HTMLInputElement, ISmartInputProps>(
|
|
42
|
+
(
|
|
43
|
+
{
|
|
44
|
+
onChange,
|
|
45
|
+
isUpperCase,
|
|
46
|
+
smartType = 'default',
|
|
47
|
+
regExp,
|
|
48
|
+
value = '',
|
|
49
|
+
maxLength,
|
|
50
|
+
...rest
|
|
51
|
+
},
|
|
52
|
+
ref,
|
|
53
|
+
) => {
|
|
54
|
+
const [currentValue, setCurrentValue] = useState<string>(
|
|
55
|
+
getUpperCaseIfNeeded(value),
|
|
56
|
+
);
|
|
57
|
+
const [caretPosition, setCaretPosition] = useState<number | null>(null);
|
|
58
|
+
const [input, setInput] = useState<HTMLInputElement | null>(null);
|
|
59
|
+
const regex = regExp || SMART_INPUT_REGEX_MAP[smartType];
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (
|
|
63
|
+
input &&
|
|
64
|
+
input.type !== 'email' &&
|
|
65
|
+
input.selectionStart !== caretPosition
|
|
66
|
+
) {
|
|
67
|
+
input.selectionStart = caretPosition;
|
|
68
|
+
input.selectionEnd = caretPosition;
|
|
69
|
+
}
|
|
70
|
+
}, [caretPosition]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
setCurrentValue(getUpperCaseIfNeeded(value));
|
|
74
|
+
}, [value]);
|
|
75
|
+
|
|
76
|
+
function getUpperCaseIfNeeded(str: string) {
|
|
77
|
+
return isUpperCase ? str.toUpperCase() : str;
|
|
65
78
|
}
|
|
66
|
-
}, [caretPosition]);
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
const handleChange = (
|
|
81
|
+
str: string,
|
|
82
|
+
event?: React.FormEvent<HTMLInputElement>,
|
|
83
|
+
) => {
|
|
84
|
+
const mappedValue = str
|
|
85
|
+
.split('')
|
|
86
|
+
.map((symbol) =>
|
|
87
|
+
regex.test(symbol)
|
|
88
|
+
? symbol
|
|
89
|
+
: transformCaseSensitive(
|
|
90
|
+
smartType,
|
|
91
|
+
smartType !== 'email'
|
|
92
|
+
? CharactersMap
|
|
93
|
+
: { ...CharactersMap, '"': '@' },
|
|
94
|
+
symbol,
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
.filter((symbol) => regex.test(symbol))
|
|
98
|
+
.join('');
|
|
99
|
+
const domElement = event?.currentTarget;
|
|
100
|
+
|
|
101
|
+
if (domElement) {
|
|
102
|
+
if (!input) {
|
|
103
|
+
setInput(domElement);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setCurrentValue(getUpperCaseIfNeeded(mappedValue));
|
|
107
|
+
onChange(getUpperCaseIfNeeded(mappedValue));
|
|
108
|
+
|
|
109
|
+
if (mappedValue !== currentValue) {
|
|
110
|
+
setCaretPosition(domElement.selectionStart);
|
|
111
|
+
} else {
|
|
112
|
+
setCaretPosition(
|
|
113
|
+
domElement.selectionStart ? domElement.selectionStart - 1 : null,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
71
118
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
119
|
+
const handlePaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
|
|
120
|
+
const str = event.clipboardData.getData('text/plain').split('').join('');
|
|
121
|
+
const domElement = event.currentTarget;
|
|
75
122
|
|
|
76
|
-
const handleChange = (
|
|
77
|
-
str: string,
|
|
78
|
-
event?: React.FormEvent<HTMLInputElement>,
|
|
79
|
-
) => {
|
|
80
|
-
const mappedValue = str
|
|
81
|
-
.split('')
|
|
82
|
-
.map((symbol) =>
|
|
83
|
-
regex.test(symbol)
|
|
84
|
-
? symbol
|
|
85
|
-
: transformCaseSensitive(
|
|
86
|
-
smartType,
|
|
87
|
-
smartType !== 'email'
|
|
88
|
-
? CharactersMap
|
|
89
|
-
: { ...CharactersMap, '"': '@' },
|
|
90
|
-
symbol,
|
|
91
|
-
),
|
|
92
|
-
)
|
|
93
|
-
.filter((symbol) => regex.test(symbol))
|
|
94
|
-
.join('');
|
|
95
|
-
const domElement = event?.currentTarget;
|
|
96
|
-
|
|
97
|
-
if (domElement) {
|
|
98
123
|
if (!input) {
|
|
99
124
|
setInput(domElement);
|
|
100
125
|
}
|
|
101
126
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const selectionStart = domElement.selectionStart ?? 0;
|
|
129
|
+
const selectionEnd = domElement.selectionEnd ?? 0;
|
|
130
|
+
|
|
131
|
+
let mappedValue = str
|
|
132
|
+
.split('')
|
|
133
|
+
.map((symbol) =>
|
|
134
|
+
regex.test(symbol)
|
|
135
|
+
? symbol
|
|
136
|
+
: transformCaseSensitive(smartType, TransliterationMap, symbol),
|
|
137
|
+
)
|
|
138
|
+
.filter((letter) => regex.test(letter))
|
|
139
|
+
.join('');
|
|
140
|
+
|
|
141
|
+
const newValueLength =
|
|
142
|
+
mappedValue.length +
|
|
143
|
+
currentValue.length -
|
|
144
|
+
(selectionEnd - selectionStart);
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
maxLength !== undefined &&
|
|
148
|
+
maxLength >= 0 &&
|
|
149
|
+
newValueLength > maxLength
|
|
150
|
+
) {
|
|
151
|
+
const validMappedValueLength =
|
|
152
|
+
mappedValue.length - (newValueLength - maxLength);
|
|
153
|
+
|
|
154
|
+
mappedValue = mappedValue.substring(0, validMappedValueLength);
|
|
111
155
|
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const handlePaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
|
|
116
|
-
const str = event.clipboardData.getData('text/plain').split('').join('');
|
|
117
|
-
const domElement = event.currentTarget;
|
|
118
|
-
|
|
119
|
-
if (!input) {
|
|
120
|
-
setInput(domElement);
|
|
121
|
-
}
|
|
122
156
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
maxLength >= 0 &&
|
|
145
|
-
newValueLength > maxLength
|
|
146
|
-
) {
|
|
147
|
-
const validMappedValueLength =
|
|
148
|
-
mappedValue.length - (newValueLength - maxLength);
|
|
149
|
-
|
|
150
|
-
mappedValue = mappedValue.substring(0, validMappedValueLength);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const newValue = getUpperCaseIfNeeded(
|
|
154
|
-
`${currentValue?.substring(
|
|
155
|
-
0,
|
|
156
|
-
selectionStart,
|
|
157
|
-
)}${mappedValue}${currentValue?.substring(
|
|
158
|
-
selectionEnd,
|
|
159
|
-
)}`,
|
|
157
|
+
const newValue = getUpperCaseIfNeeded(
|
|
158
|
+
`${currentValue?.substring(
|
|
159
|
+
0,
|
|
160
|
+
selectionStart,
|
|
161
|
+
)}${mappedValue}${currentValue?.substring(selectionEnd)}`,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
setCaretPosition(selectionStart + mappedValue.length);
|
|
165
|
+
setCurrentValue(newValue);
|
|
166
|
+
onChange(newValue);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Input
|
|
171
|
+
{...rest}
|
|
172
|
+
ref={ref}
|
|
173
|
+
maxLength={maxLength}
|
|
174
|
+
onChange={handleChange}
|
|
175
|
+
onPaste={handlePaste}
|
|
176
|
+
value={currentValue}
|
|
177
|
+
/>
|
|
160
178
|
);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
setCurrentValue(newValue);
|
|
164
|
-
onChange(newValue);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<Input
|
|
169
|
-
{...rest}
|
|
170
|
-
ref={ref}
|
|
171
|
-
maxLength={maxLength}
|
|
172
|
-
onChange={handleChange}
|
|
173
|
-
onPaste={handlePaste}
|
|
174
|
-
value={currentValue}
|
|
175
|
-
/>
|
|
176
|
-
);
|
|
177
|
-
});
|
|
179
|
+
},
|
|
180
|
+
);
|