@transferwise/components 0.0.0-experimental-778ee44 → 0.0.0-experimental-ae2a4e7
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/build/index.esm.js +226 -327
- package/build/index.esm.js.map +1 -1
- package/build/index.js +227 -328
- package/build/index.js.map +1 -1
- package/build/types/common/locale/index.d.ts +26 -43
- package/build/types/common/locale/index.d.ts.map +1 -1
- package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
- package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +2 -3
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +1 -5
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
- package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
- package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
- package/build/types/index.d.ts +0 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +11 -5
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/index.d.ts +1 -2
- package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/inputs/Input.d.ts +6 -8
- package/build/types/inputs/Input.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +30 -27
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/data/countries.d.ts +5 -10
- package/build/types/phoneNumberInput/data/countries.d.ts.map +1 -1
- package/build/types/phoneNumberInput/index.d.ts +1 -1
- package/build/types/phoneNumberInput/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts +8 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +8 -4
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts +2 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/index.d.ts +11 -13
- package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts +6 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +2 -1
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +7 -1
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +11 -5
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts +1 -2
- package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +82 -55
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/build/types/withDisplayFormat/index.d.ts +1 -2
- package/build/types/withDisplayFormat/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/locale/{index.spec.js → index.spec.ts} +0 -4
- package/src/common/locale/index.ts +96 -0
- package/src/common/textFormat/formatWithPattern/{formatWithPattern.ts → formatWithPattern.js} +4 -8
- package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.ts → getCursorPositionAfterKeystroke.js} +8 -9
- package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.ts → getSymbolsInPatternWithPosition.js} +2 -7
- package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.ts → unformatWithPattern.js} +2 -3
- package/src/index.ts +0 -2
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +14 -0
- package/src/inputWithDisplayFormat/index.js +1 -0
- package/src/inputs/Input.tsx +11 -6
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +18 -22
- package/src/phoneNumberInput/PhoneNumberInput.tsx +201 -0
- package/src/phoneNumberInput/data/{countries.js → countries.ts} +9 -1
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +3 -0
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.js → excludeCountries.spec.ts} +1 -1
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.js → excludeCountries.ts} +6 -5
- package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.js → explodeNumberModel.spec.ts} +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +25 -0
- package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.js → findCountryByCode.spec.ts} +0 -1
- package/src/phoneNumberInput/utils/findCountryByCode/index.ts +12 -0
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +12 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +102 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +12 -0
- package/src/phoneNumberInput/utils/{index.js → index.ts} +0 -2
- package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.js → isStringNumeric.spec.ts} +0 -1
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +1 -0
- package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.js → isValidPhoneNumber.spec.ts} +1 -1
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +7 -0
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +4 -0
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +20 -0
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +6 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +14 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +1 -3
- package/src/textareaWithDisplayFormat/index.js +1 -0
- package/src/withDisplayFormat/{WithDisplayFormat.tsx → WithDisplayFormat.js} +104 -111
- package/src/withDisplayFormat/index.js +1 -0
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +0 -2
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +0 -1
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +0 -2
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +0 -1
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +0 -3
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +0 -1
- package/src/common/locale/index.js +0 -139
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +0 -11
- package/src/inputWithDisplayFormat/index.ts +0 -2
- package/src/phoneNumberInput/PhoneNumberInput.js +0 -210
- package/src/phoneNumberInput/data/countries.spec.js +0 -12
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +0 -4
- package/src/phoneNumberInput/utils/explodeNumberModel/index.js +0 -27
- package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +0 -36
- package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +0 -11
- package/src/phoneNumberInput/utils/findCountryByCode/index.js +0 -10
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +0 -11
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +0 -26
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +0 -67
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +0 -1
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +0 -25
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +0 -66
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +0 -1
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +0 -10
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +0 -2
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +0 -25
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +0 -3
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +0 -32
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +0 -11
- package/src/textareaWithDisplayFormat/index.ts +0 -2
- package/src/withDisplayFormat/index.ts +0 -2
- /package/src/phoneNumberInput/{PhoneNumberInput.story.js → PhoneNumberInput.story.tsx} +0 -0
- /package/src/phoneNumberInput/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.js → cleanNumber.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/excludeCountries/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.js → findCountryByPrefix.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/isStringNumeric/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.js → longestMatchingPrefix.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.js → setDefaultPrefix.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{sortArrayByProperty.spec.js → sortArrayByProperty.spec.ts} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { Component } from 'react';
|
|
2
3
|
|
|
3
4
|
import { HistoryNavigator } from '../common';
|
|
4
5
|
import {
|
|
@@ -9,65 +10,14 @@ import {
|
|
|
9
10
|
getDistanceToPreviousSymbol,
|
|
10
11
|
getDistanceToNextSymbol,
|
|
11
12
|
} from '../common/textFormat';
|
|
12
|
-
import { InputProps } from '../inputs/Input';
|
|
13
|
-
import { TextAreaProps } from '../inputs/TextArea';
|
|
14
|
-
import { Merge } from '../utils';
|
|
15
|
-
|
|
16
|
-
export type TextInputProps = Merge<
|
|
17
|
-
InputProps,
|
|
18
|
-
{
|
|
19
|
-
value?: string;
|
|
20
|
-
displayPattern: string;
|
|
21
|
-
/**
|
|
22
|
-
* autocomplete hides our form help so we need to disable it when help text
|
|
23
|
-
* is present. Chrome ignores autocomplete=off, the only way to disable it is
|
|
24
|
-
* to provide an 'invalid' value, for which 'disabled' serves.
|
|
25
|
-
*/
|
|
26
|
-
autoComplete?: InputProps['autoComplete'] | 'disabled';
|
|
27
|
-
onChange?: (value: string) => void;
|
|
28
|
-
onBlur?: (value: string) => void;
|
|
29
|
-
onFocus?: (value: string) => void;
|
|
30
|
-
}
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
export type Props = typeof WithDisplayFormat.defaultProps & {
|
|
34
|
-
render: (renderProps: InputProps | TextAreaProps) => JSX.Element;
|
|
35
|
-
} & TextInputProps;
|
|
36
|
-
|
|
37
|
-
export type EventType =
|
|
38
|
-
| 'KeyDown'
|
|
39
|
-
| 'Paste'
|
|
40
|
-
| 'Cut'
|
|
41
|
-
| 'Undo'
|
|
42
|
-
| 'Redo'
|
|
43
|
-
| 'Backspace'
|
|
44
|
-
| 'Delete'
|
|
45
|
-
| null;
|
|
46
|
-
|
|
47
|
-
type State = {
|
|
48
|
-
value: string;
|
|
49
|
-
historyNavigator: HistoryNavigator;
|
|
50
|
-
prevDisplayPattern?: string;
|
|
51
|
-
triggerType?: EventType;
|
|
52
|
-
triggerEvent?: KeyboardEvent<HTMLInputElement> | null;
|
|
53
|
-
pastedLength?: number;
|
|
54
|
-
selectionStart?: HTMLInputElement['selectionStart'];
|
|
55
|
-
selectionEnd?: HTMLInputElement['selectionEnd'];
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
class WithDisplayFormat extends Component<Props, State> {
|
|
59
|
-
static defaultProps = {
|
|
60
|
-
autoComplete: 'off',
|
|
61
|
-
displayPattern: '',
|
|
62
|
-
type: 'text',
|
|
63
|
-
value: '',
|
|
64
|
-
};
|
|
65
13
|
|
|
66
|
-
|
|
14
|
+
class WithDisplayFormat extends Component {
|
|
15
|
+
constructor(props) {
|
|
67
16
|
super(props);
|
|
68
|
-
const
|
|
17
|
+
const { value, displayPattern } = props;
|
|
18
|
+
const unformattedValue = unformatWithPattern(value, displayPattern);
|
|
69
19
|
this.state = {
|
|
70
|
-
value: formatWithPattern(unformattedValue,
|
|
20
|
+
value: formatWithPattern(unformattedValue, displayPattern),
|
|
71
21
|
historyNavigator: new HistoryNavigator(),
|
|
72
22
|
prevDisplayPattern: props.displayPattern,
|
|
73
23
|
triggerType: null,
|
|
@@ -75,11 +25,12 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
75
25
|
};
|
|
76
26
|
}
|
|
77
27
|
|
|
78
|
-
static getDerivedStateFromProps(
|
|
79
|
-
{ displayPattern }
|
|
80
|
-
{ prevDisplayPattern =
|
|
81
|
-
|
|
82
|
-
|
|
28
|
+
static getDerivedStateFromProps(nextProps, previousState) {
|
|
29
|
+
const { displayPattern } = nextProps;
|
|
30
|
+
const { prevDisplayPattern } = previousState;
|
|
31
|
+
if (previousState.prevDisplayPattern !== displayPattern) {
|
|
32
|
+
const { value, historyNavigator } = previousState;
|
|
33
|
+
|
|
83
34
|
const unFormattedValue = unformatWithPattern(value, prevDisplayPattern);
|
|
84
35
|
historyNavigator.reset();
|
|
85
36
|
|
|
@@ -94,37 +45,32 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
94
45
|
return null;
|
|
95
46
|
}
|
|
96
47
|
|
|
97
|
-
getUserAction = (unformattedValue
|
|
48
|
+
getUserAction = (unformattedValue) => {
|
|
98
49
|
const { triggerEvent, triggerType, value } = this.state;
|
|
99
50
|
const { displayPattern } = this.props;
|
|
100
51
|
|
|
101
|
-
|
|
102
|
-
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
52
|
+
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
103
53
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
54
|
+
if (triggerType === 'Paste' || triggerType === 'Cut') {
|
|
55
|
+
return triggerType;
|
|
56
|
+
}
|
|
107
57
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
58
|
+
if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
|
|
59
|
+
return triggerEvent.shiftKey ? 'Redo' : 'Undo';
|
|
60
|
+
}
|
|
61
|
+
// Detect mouse event redo
|
|
62
|
+
if (triggerEvent.ctrlKey && charCode === 'd') {
|
|
63
|
+
return 'Delete';
|
|
64
|
+
}
|
|
115
65
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
unformattedValue.length <= unformatWithPattern(value, displayPattern).length
|
|
120
|
-
) {
|
|
66
|
+
// Android Fix.
|
|
67
|
+
if (typeof triggerEvent.key === 'undefined') {
|
|
68
|
+
if (unformattedValue.length <= unformatWithPattern(value, displayPattern).length) {
|
|
121
69
|
return 'Backspace';
|
|
122
70
|
}
|
|
123
|
-
return triggerEvent.key as EventType;
|
|
124
|
-
} else {
|
|
125
|
-
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
126
|
-
return 'Paste';
|
|
127
71
|
}
|
|
72
|
+
|
|
73
|
+
return triggerEvent.key;
|
|
128
74
|
};
|
|
129
75
|
|
|
130
76
|
resetEvent = () => {
|
|
@@ -135,7 +81,7 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
135
81
|
});
|
|
136
82
|
};
|
|
137
83
|
|
|
138
|
-
detectUndoRedo = (event
|
|
84
|
+
detectUndoRedo = (event) => {
|
|
139
85
|
const charCode = String.fromCharCode(event.which).toLowerCase();
|
|
140
86
|
if ((event.ctrlKey || event.metaKey) && charCode === 'z') {
|
|
141
87
|
return event.shiftKey ? 'Redo' : 'Undo';
|
|
@@ -143,9 +89,9 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
143
89
|
return null;
|
|
144
90
|
};
|
|
145
91
|
|
|
146
|
-
handleOnKeyDown = (event
|
|
92
|
+
handleOnKeyDown = (event) => {
|
|
147
93
|
event.persist();
|
|
148
|
-
const { selectionStart, selectionEnd } = event.target
|
|
94
|
+
const { selectionStart, selectionEnd } = event.target;
|
|
149
95
|
const { historyNavigator } = this.state;
|
|
150
96
|
const { displayPattern } = this.props;
|
|
151
97
|
|
|
@@ -168,7 +114,7 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
168
114
|
}
|
|
169
115
|
};
|
|
170
116
|
|
|
171
|
-
handleOnPaste = (event
|
|
117
|
+
handleOnPaste = (event) => {
|
|
172
118
|
const { displayPattern } = this.props;
|
|
173
119
|
const pastedLength = unformatWithPattern(
|
|
174
120
|
event.clipboardData.getData('Text'),
|
|
@@ -182,19 +128,23 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
182
128
|
this.setState({ triggerType: 'Cut' });
|
|
183
129
|
};
|
|
184
130
|
|
|
185
|
-
isKeyAllowed = (action
|
|
131
|
+
isKeyAllowed = (action) => {
|
|
186
132
|
const { displayPattern } = this.props;
|
|
187
133
|
const symbolsInPattern = displayPattern.split('').filter((character) => character !== '*');
|
|
188
134
|
|
|
189
|
-
return !symbolsInPattern.includes(action
|
|
135
|
+
return !symbolsInPattern.includes(action);
|
|
190
136
|
};
|
|
191
137
|
|
|
192
|
-
handleOnChange = (event
|
|
193
|
-
const { historyNavigator, triggerType } = this.state;
|
|
138
|
+
handleOnChange = (event) => {
|
|
139
|
+
const { historyNavigator, triggerEvent, triggerType } = this.state;
|
|
194
140
|
const { displayPattern, onChange } = this.props;
|
|
195
141
|
const { value } = event.target;
|
|
196
142
|
let unformattedValue = unformatWithPattern(value, displayPattern);
|
|
197
|
-
const action =
|
|
143
|
+
const action =
|
|
144
|
+
triggerEvent === null
|
|
145
|
+
? // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
146
|
+
'Paste'
|
|
147
|
+
: this.getUserAction(unformattedValue);
|
|
198
148
|
if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
|
|
199
149
|
return;
|
|
200
150
|
}
|
|
@@ -208,20 +158,19 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
208
158
|
|
|
209
159
|
this.handleCursorPositioning(action);
|
|
210
160
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const broadcastValue = unformatWithPattern(newFormattedValue, displayPattern);
|
|
215
|
-
onChange(broadcastValue);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
161
|
+
const broadcastValue = unformatWithPattern(newFormattedValue, displayPattern);
|
|
162
|
+
|
|
163
|
+
this.setState({ value: newFormattedValue }, this.resetEvent(), onChange(broadcastValue));
|
|
218
164
|
};
|
|
219
165
|
|
|
220
|
-
handleOnBlur = (event
|
|
221
|
-
|
|
166
|
+
handleOnBlur = (event) => {
|
|
167
|
+
const { displayPattern, onBlur } = this.props;
|
|
168
|
+
if (onBlur) {
|
|
169
|
+
onBlur(unformatWithPattern(event.target.value, displayPattern));
|
|
170
|
+
}
|
|
222
171
|
};
|
|
223
172
|
|
|
224
|
-
handleOnFocus = (event
|
|
173
|
+
handleOnFocus = (event) => {
|
|
225
174
|
const { displayPattern, onFocus } = this.props;
|
|
226
175
|
if (onFocus) {
|
|
227
176
|
this.handleOnChange(event);
|
|
@@ -229,14 +178,13 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
229
178
|
}
|
|
230
179
|
};
|
|
231
180
|
|
|
232
|
-
handleDelete = (unformattedValue
|
|
181
|
+
handleDelete = (unformattedValue, action) => {
|
|
233
182
|
const { displayPattern } = this.props;
|
|
234
183
|
const { selectionStart, selectionEnd } = this.state;
|
|
235
184
|
const newStack = [...unformattedValue];
|
|
236
185
|
if (selectionStart === selectionEnd) {
|
|
237
186
|
let startPosition =
|
|
238
|
-
(selectionStart
|
|
239
|
-
getCountOfSymbolsInSelection(0, selectionStart, displayPattern);
|
|
187
|
+
selectionStart - getCountOfSymbolsInSelection(0, selectionStart, displayPattern);
|
|
240
188
|
let toDelete = 0;
|
|
241
189
|
|
|
242
190
|
let count = getDistanceToNextSymbol(selectionStart, displayPattern);
|
|
@@ -255,21 +203,21 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
255
203
|
return newStack.join('');
|
|
256
204
|
};
|
|
257
205
|
|
|
258
|
-
handleCursorPositioning = (action
|
|
206
|
+
handleCursorPositioning = (action) => {
|
|
259
207
|
const { displayPattern } = this.props;
|
|
260
208
|
const { triggerEvent, selectionStart, selectionEnd, pastedLength } = this.state;
|
|
261
209
|
|
|
262
210
|
const cursorPosition = getCursorPositionAfterKeystroke(
|
|
263
211
|
action,
|
|
264
|
-
selectionStart
|
|
265
|
-
selectionEnd
|
|
212
|
+
selectionStart,
|
|
213
|
+
selectionEnd,
|
|
266
214
|
displayPattern,
|
|
267
|
-
pastedLength
|
|
215
|
+
pastedLength,
|
|
268
216
|
);
|
|
269
217
|
|
|
270
218
|
setTimeout(() => {
|
|
271
219
|
if (triggerEvent) {
|
|
272
|
-
|
|
220
|
+
triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
|
|
273
221
|
}
|
|
274
222
|
this.setState({ selectionStart: cursorPosition, selectionEnd: cursorPosition });
|
|
275
223
|
}, 0);
|
|
@@ -316,4 +264,49 @@ class WithDisplayFormat extends Component<Props, State> {
|
|
|
316
264
|
}
|
|
317
265
|
}
|
|
318
266
|
|
|
267
|
+
WithDisplayFormat.propTypes = {
|
|
268
|
+
/**
|
|
269
|
+
* autocomplete hides our form help so we need to disable it when help text
|
|
270
|
+
* is present. Chrome ignores autocomplete=off, the only way to disable it is
|
|
271
|
+
* to provide an 'invalid' value, for which 'disabled' serves.
|
|
272
|
+
*/
|
|
273
|
+
autoComplete: PropTypes.oneOf(['on', 'off', 'disabled']),
|
|
274
|
+
className: PropTypes.string,
|
|
275
|
+
disabled: PropTypes.bool,
|
|
276
|
+
id: PropTypes.string,
|
|
277
|
+
maxLength: PropTypes.number,
|
|
278
|
+
minLength: PropTypes.number,
|
|
279
|
+
name: PropTypes.string,
|
|
280
|
+
onFocus: PropTypes.func,
|
|
281
|
+
onBlur: PropTypes.func,
|
|
282
|
+
onChange: PropTypes.func.isRequired,
|
|
283
|
+
placeholder: PropTypes.string,
|
|
284
|
+
readOnly: PropTypes.bool,
|
|
285
|
+
render: PropTypes.func.isRequired,
|
|
286
|
+
required: PropTypes.bool,
|
|
287
|
+
displayPattern: PropTypes.string,
|
|
288
|
+
type: PropTypes.string,
|
|
289
|
+
inputMode: PropTypes.string,
|
|
290
|
+
value: PropTypes.string,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
WithDisplayFormat.defaultProps = {
|
|
294
|
+
autoComplete: 'off',
|
|
295
|
+
className: null,
|
|
296
|
+
disabled: false,
|
|
297
|
+
id: null,
|
|
298
|
+
maxLength: null,
|
|
299
|
+
minLength: null,
|
|
300
|
+
name: null,
|
|
301
|
+
placeholder: null,
|
|
302
|
+
readOnly: false,
|
|
303
|
+
required: false,
|
|
304
|
+
displayPattern: '',
|
|
305
|
+
type: 'text',
|
|
306
|
+
inputMode: null,
|
|
307
|
+
value: '',
|
|
308
|
+
onFocus: null,
|
|
309
|
+
onBlur: null,
|
|
310
|
+
};
|
|
311
|
+
|
|
319
312
|
export default WithDisplayFormat;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './WithDisplayFormat';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/filterOptionsForQuery/index.js"],"names":[],"mappings":"AASO,qEAC0D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js"],"names":[],"mappings":""}
|
package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isOptionAndFitsQuery.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js"],"names":[],"mappings":"AAQO,6CAJI,MAAM,SACN,MAAM,GACJ,OAAO,CAMa;AAE1B,+DAQN"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { Direction } from '..';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default language
|
|
5
|
-
*
|
|
6
|
-
* @type {string}
|
|
7
|
-
*/
|
|
8
|
-
export const DEFAULT_LANG = 'en';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Default locale
|
|
12
|
-
*
|
|
13
|
-
* @type {string}
|
|
14
|
-
*/
|
|
15
|
-
export const DEFAULT_LOCALE = 'en-GB';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Array of languages that are written from the right to the left
|
|
19
|
-
*
|
|
20
|
-
* @type {string[]}
|
|
21
|
-
*/
|
|
22
|
-
export const RTL_LANGUAGES = ['ar', 'he'];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated The source of truth for supported languages lives in Crab.
|
|
26
|
-
* @type {string[]}
|
|
27
|
-
*/
|
|
28
|
-
export const SUPPORTED_LANGUAGES = [
|
|
29
|
-
DEFAULT_LANG,
|
|
30
|
-
'de',
|
|
31
|
-
'es',
|
|
32
|
-
'fr',
|
|
33
|
-
'hu',
|
|
34
|
-
'id',
|
|
35
|
-
'it',
|
|
36
|
-
'ja',
|
|
37
|
-
'pl',
|
|
38
|
-
'pt',
|
|
39
|
-
'ro',
|
|
40
|
-
'ru',
|
|
41
|
-
'th',
|
|
42
|
-
'tr',
|
|
43
|
-
'uk',
|
|
44
|
-
'zh',
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Verifies and adjusts locale (replace `_` with `-`)
|
|
49
|
-
* Returns null if locale is unrecognized by {Intl.Locale}
|
|
50
|
-
*
|
|
51
|
-
* @param {string} locale (`es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
52
|
-
* @returns {string|null}
|
|
53
|
-
*/
|
|
54
|
-
export function adjustLocale(locale) {
|
|
55
|
-
if (!locale || locale.trim().length === 0) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const { baseName } = new Intl.Locale(locale.trim().replace('_', '-'));
|
|
60
|
-
return baseName;
|
|
61
|
-
} catch (error) {
|
|
62
|
-
// eslint-disable-next-line no-console
|
|
63
|
-
console.error(error);
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Provides corresponding lang (iso2) for provided locale
|
|
70
|
-
* if locale is invalid or language is unsupported returns null
|
|
71
|
-
*
|
|
72
|
-
* @deprecated The use of this function almost always breaks language variants
|
|
73
|
-
* e.g. Simplified and Traditional Chinese.
|
|
74
|
-
* There should be no use case for this function.
|
|
75
|
-
* To select the correct translations from a translations object, pass the
|
|
76
|
-
* locale directly into Crab's getLocalisedMessages.
|
|
77
|
-
* @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
78
|
-
* @returns {string|null} two-letter ISO639-1 language
|
|
79
|
-
*/
|
|
80
|
-
export function getLangFromLocale(locale) {
|
|
81
|
-
const adjustedLocale = adjustLocale(locale);
|
|
82
|
-
if (adjustedLocale === null) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
const { language } = new Intl.Locale(adjustedLocale);
|
|
87
|
-
|
|
88
|
-
if (SUPPORTED_LANGUAGES.includes(language)) {
|
|
89
|
-
return language;
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
// eslint-disable-next-line no-console
|
|
94
|
-
console.error(error);
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Provides corresponding country code (iso2) for locales code with explicit region value (`es-ES`, `en-GB`, `ja-JP` etc.)
|
|
101
|
-
* if the value is invalid or missing region it returns null
|
|
102
|
-
*
|
|
103
|
-
* @param {string} locale
|
|
104
|
-
* @returns {string|null}
|
|
105
|
-
*/
|
|
106
|
-
export function getCountryFromLocale(locale) {
|
|
107
|
-
const adjustedLocale = adjustLocale(locale);
|
|
108
|
-
if (adjustedLocale === null) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const { region } = new Intl.Locale(adjustedLocale);
|
|
113
|
-
return region ?? null;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
// eslint-disable-next-line no-console
|
|
116
|
-
console.error(error);
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Provides the layout direction for a given locale.
|
|
123
|
-
* If locale is invalid or language is unsupported returns Direction.LTR
|
|
124
|
-
*
|
|
125
|
-
* @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
126
|
-
* @returns {Direction} The layout direction based on the locale
|
|
127
|
-
*/
|
|
128
|
-
export function getDirectionFromLocale(locale) {
|
|
129
|
-
try {
|
|
130
|
-
const adjustedLocale = adjustLocale(locale);
|
|
131
|
-
const { language } = new Intl.Locale(adjustedLocale);
|
|
132
|
-
|
|
133
|
-
return RTL_LANGUAGES.includes(language) ? Direction.RTL : Direction.LTR;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
// eslint-disable-next-line no-console
|
|
136
|
-
console.error(error);
|
|
137
|
-
return Direction.LTR;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Input, type InputProps } from '../inputs/Input';
|
|
2
|
-
import WithDisplayFormat, { type TextInputProps } from '../withDisplayFormat';
|
|
3
|
-
|
|
4
|
-
const InputWithDisplayFormat = (props: TextInputProps) => (
|
|
5
|
-
<WithDisplayFormat
|
|
6
|
-
{...props}
|
|
7
|
-
render={(renderProps) => <Input {...(renderProps as InputProps)} />}
|
|
8
|
-
/>
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
export default InputWithDisplayFormat;
|