@transferwise/components 0.0.0-experimental-85b9dd1 → 0.0.0-experimental-0db2ae7
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 +335 -234
- package/build/index.esm.js.map +1 -1
- package/build/index.js +336 -235
- package/build/index.js.map +1 -1
- package/build/types/common/locale/index.d.ts +43 -26
- 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 -2
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
- 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 +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +7 -11
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
- package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +27 -22
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/data/countries.d.ts +10 -5
- 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 +1 -8
- 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 +4 -8
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +2 -0
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +1 -0
- 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 +1 -2
- 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 +13 -11
- package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +2 -0
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +1 -0
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +3 -0
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +1 -0
- 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 +1 -6
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +1 -2
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +1 -7
- 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 +7 -11
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +54 -82
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/build/types/withDisplayFormat/index.d.ts +2 -1
- package/build/types/withDisplayFormat/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/locale/index.js +139 -0
- package/src/common/locale/{index.spec.ts → index.spec.js} +4 -4
- package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
- package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
- package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
- package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
- package/src/index.ts +2 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
- package/src/inputWithDisplayFormat/index.ts +2 -0
- package/src/phoneNumberInput/PhoneNumberInput.js +210 -0
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +22 -18
- package/src/phoneNumberInput/data/{countries.ts → countries.js} +1 -9
- package/src/phoneNumberInput/data/countries.spec.js +12 -0
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +4 -0
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.ts → excludeCountries.js} +5 -6
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.ts → excludeCountries.spec.js} +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.ts → explodeNumberModel.spec.js} +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/index.js +27 -0
- package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +36 -0
- package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +11 -0
- package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.ts → findCountryByCode.spec.js} +1 -0
- package/src/phoneNumberInput/utils/findCountryByCode/index.js +10 -0
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +11 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +26 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +67 -0
- package/src/phoneNumberInput/utils/{index.ts → index.js} +2 -0
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +1 -0
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +25 -0
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +66 -0
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +1 -0
- package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.ts → isStringNumeric.spec.js} +1 -0
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +10 -0
- package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.ts → isValidPhoneNumber.spec.js} +1 -1
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +2 -0
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +25 -0
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +3 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
- package/src/textareaWithDisplayFormat/index.ts +2 -0
- package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
- package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
- package/src/withDisplayFormat/index.ts +2 -0
- package/src/common/locale/index.ts +0 -96
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
- package/src/inputWithDisplayFormat/index.js +0 -1
- package/src/phoneNumberInput/PhoneNumberInput.tsx +0 -193
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +0 -3
- package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +0 -24
- package/src/phoneNumberInput/utils/findCountryByCode/index.ts +0 -12
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +0 -12
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +0 -102
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +0 -12
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +0 -1
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +0 -7
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +0 -4
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +0 -20
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +0 -6
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
- package/src/textareaWithDisplayFormat/index.js +0 -1
- package/src/withDisplayFormat/index.js +0 -1
- /package/src/phoneNumberInput/{PhoneNumberInput.story.tsx → PhoneNumberInput.story.js} +0 -0
- /package/src/phoneNumberInput/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.ts → cleanNumber.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/excludeCountries/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.ts → findCountryByPrefix.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/isStringNumeric/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.ts → longestMatchingPrefix.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.ts → setDefaultPrefix.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{sortArrayByProperty.spec.ts → sortArrayByProperty.spec.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function sortArrayByProperty(arrayToSort: any, property: any): any[];
|
|
2
2
|
//# sourceMappingURL=sortArrayByProperty.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortArrayByProperty.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.
|
|
1
|
+
{"version":3,"file":"sortArrayByProperty.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js"],"names":[],"mappings":"AACO,4EACkE"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface TextareaWithDisplayFormatProps {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare const TextareaWithDisplayFormat: React.FC<TextareaWithDisplayFormatProps>;
|
|
9
|
-
|
|
10
|
-
export default TextareaWithDisplayFormat;
|
|
11
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type WithDisplayFormatProps } from '../withDisplayFormat';
|
|
3
|
+
export interface TextareaWithDisplayFormatProps extends Omit<WithDisplayFormatProps, 'render'> {
|
|
4
|
+
}
|
|
5
|
+
declare const TextareaWithDisplayFormat: (props: TextareaWithDisplayFormatProps) => import("react").JSX.Element;
|
|
6
|
+
export default TextareaWithDisplayFormat;
|
|
7
|
+
//# sourceMappingURL=TextareaWithDisplayFormat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextareaWithDisplayFormat.d.ts","sourceRoot":"","sources":["../../../src/textareaWithDisplayFormat/TextareaWithDisplayFormat.
|
|
1
|
+
{"version":3,"file":"TextareaWithDisplayFormat.d.ts","sourceRoot":"","sources":["../../../src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx"],"names":[],"mappings":";AACA,OAA0B,EAAE,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,MAAM,WAAW,8BAA+B,SAAQ,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC;CAAG;AAEjG,QAAA,MAAM,yBAAyB,UAAW,8BAA8B,gCAKvE,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/textareaWithDisplayFormat/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/textareaWithDisplayFormat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,YAAY,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -1,90 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Component, KeyboardEvent, ClipboardEvent, ChangeEvent, FocusEvent } from 'react';
|
|
2
|
+
import { HistoryNavigator } from '../common';
|
|
3
|
+
import { InputProps } from '../inputs/Input';
|
|
4
|
+
import { TextAreaProps } from '../inputs/TextArea';
|
|
5
|
+
type HTMLTextElement = HTMLInputElement | HTMLTextAreaElement;
|
|
6
|
+
type TypeElementAttrs = InputProps | TextAreaProps;
|
|
7
|
+
export type EventType = 'KeyDown' | 'Paste' | 'Cut' | 'Undo' | 'Redo' | 'Backspace' | 'Delete' | 'Initial';
|
|
8
|
+
interface WithDisplayFormatState {
|
|
9
|
+
value: string;
|
|
10
|
+
historyNavigator: HistoryNavigator;
|
|
11
|
+
prevDisplayPattern: string;
|
|
12
|
+
triggerType: EventType;
|
|
13
|
+
triggerEvent: KeyboardEvent<HTMLTextElement> | null;
|
|
14
|
+
pastedLength: number;
|
|
15
|
+
selectionStart: number;
|
|
16
|
+
selectionEnd: number;
|
|
17
|
+
}
|
|
18
|
+
export interface WithDisplayFormatProps<T extends TypeElementAttrs = TypeElementAttrs> extends Pick<TypeElementAttrs, 'className' | 'disabled' | 'id' | 'maxLength' | 'minLength' | 'name' | 'placeholder' | 'readOnly' | 'required' | 'inputMode'> {
|
|
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?: TypeElementAttrs['autoComplete'] | 'disabled';
|
|
27
|
+
onChange?: (value: string) => void;
|
|
28
|
+
onBlur?: (value: string) => void;
|
|
29
|
+
onFocus?: (value: string) => void;
|
|
30
|
+
render: (renderProps: T) => JSX.Element;
|
|
31
|
+
}
|
|
32
|
+
declare class WithDisplayFormat<T extends TypeElementAttrs> extends Component<WithDisplayFormatProps<T>, WithDisplayFormatState> {
|
|
33
|
+
props: WithDisplayFormatProps<T> & Required<Pick<WithDisplayFormatProps<T>, keyof typeof WithDisplayFormat.defaultProps>>;
|
|
34
|
+
static defaultProps: {
|
|
35
|
+
autoComplete: string;
|
|
36
|
+
displayPattern: string;
|
|
37
|
+
value: string;
|
|
38
|
+
};
|
|
39
|
+
constructor(props: WithDisplayFormatProps);
|
|
40
|
+
static getDerivedStateFromProps({ displayPattern }: WithDisplayFormatProps, { prevDisplayPattern, value, historyNavigator }: WithDisplayFormatState): {
|
|
41
|
+
prevDisplayPattern: string;
|
|
42
|
+
value: string;
|
|
6
43
|
triggerType: null;
|
|
7
44
|
triggerEvent: null;
|
|
8
45
|
pastedLength: number;
|
|
9
46
|
} | null;
|
|
10
|
-
|
|
11
|
-
state: {
|
|
12
|
-
value: any;
|
|
13
|
-
historyNavigator: HistoryNavigator;
|
|
14
|
-
prevDisplayPattern: any;
|
|
15
|
-
triggerType: null;
|
|
16
|
-
triggerEvent: null;
|
|
17
|
-
};
|
|
18
|
-
getUserAction: (unformattedValue: any) => any;
|
|
47
|
+
getUserAction: (unformattedValue: string) => EventType | string;
|
|
19
48
|
resetEvent: () => void;
|
|
20
|
-
detectUndoRedo: (event:
|
|
21
|
-
handleOnKeyDown: (event:
|
|
22
|
-
handleOnPaste: (event:
|
|
49
|
+
detectUndoRedo: (event: KeyboardEvent<HTMLTextElement>) => "Undo" | "Redo" | null;
|
|
50
|
+
handleOnKeyDown: (event: KeyboardEvent<HTMLTextElement>) => void;
|
|
51
|
+
handleOnPaste: (event: ClipboardEvent<HTMLTextElement>) => void;
|
|
23
52
|
handleOnCut: () => void;
|
|
24
|
-
isKeyAllowed: (action:
|
|
25
|
-
handleOnChange: (event:
|
|
26
|
-
handleOnBlur: (event:
|
|
27
|
-
handleOnFocus: (event:
|
|
28
|
-
handleDelete: (unformattedValue:
|
|
29
|
-
handleCursorPositioning: (action:
|
|
30
|
-
render():
|
|
53
|
+
isKeyAllowed: (action: EventType | string) => boolean;
|
|
54
|
+
handleOnChange: (event: ChangeEvent<HTMLTextElement>) => void;
|
|
55
|
+
handleOnBlur: (event: FocusEvent<HTMLTextElement>) => void;
|
|
56
|
+
handleOnFocus: (event: FocusEvent<HTMLTextElement>) => void;
|
|
57
|
+
handleDelete: (unformattedValue: string, action: EventType) => string;
|
|
58
|
+
handleCursorPositioning: (action: string) => void;
|
|
59
|
+
render(): JSX.Element;
|
|
31
60
|
}
|
|
32
|
-
|
|
33
|
-
namespace propTypes {
|
|
34
|
-
const autoComplete: any;
|
|
35
|
-
const className: any;
|
|
36
|
-
const disabled: any;
|
|
37
|
-
const id: any;
|
|
38
|
-
const maxLength: any;
|
|
39
|
-
const minLength: any;
|
|
40
|
-
const name: any;
|
|
41
|
-
const onFocus: any;
|
|
42
|
-
const onBlur: any;
|
|
43
|
-
const onChange: any;
|
|
44
|
-
const placeholder: any;
|
|
45
|
-
const readOnly: any;
|
|
46
|
-
const render: any;
|
|
47
|
-
const required: any;
|
|
48
|
-
const displayPattern: any;
|
|
49
|
-
const type: any;
|
|
50
|
-
const inputMode: any;
|
|
51
|
-
const value: any;
|
|
52
|
-
}
|
|
53
|
-
namespace defaultProps {
|
|
54
|
-
const autoComplete_1: string;
|
|
55
|
-
export { autoComplete_1 as autoComplete };
|
|
56
|
-
const className_1: null;
|
|
57
|
-
export { className_1 as className };
|
|
58
|
-
const disabled_1: boolean;
|
|
59
|
-
export { disabled_1 as disabled };
|
|
60
|
-
const id_1: null;
|
|
61
|
-
export { id_1 as id };
|
|
62
|
-
const maxLength_1: null;
|
|
63
|
-
export { maxLength_1 as maxLength };
|
|
64
|
-
const minLength_1: null;
|
|
65
|
-
export { minLength_1 as minLength };
|
|
66
|
-
const name_1: null;
|
|
67
|
-
export { name_1 as name };
|
|
68
|
-
const placeholder_1: null;
|
|
69
|
-
export { placeholder_1 as placeholder };
|
|
70
|
-
const readOnly_1: boolean;
|
|
71
|
-
export { readOnly_1 as readOnly };
|
|
72
|
-
const required_1: boolean;
|
|
73
|
-
export { required_1 as required };
|
|
74
|
-
const displayPattern_1: string;
|
|
75
|
-
export { displayPattern_1 as displayPattern };
|
|
76
|
-
const type_1: string;
|
|
77
|
-
export { type_1 as type };
|
|
78
|
-
const inputMode_1: null;
|
|
79
|
-
export { inputMode_1 as inputMode };
|
|
80
|
-
const value_1: string;
|
|
81
|
-
export { value_1 as value };
|
|
82
|
-
const onFocus_1: null;
|
|
83
|
-
export { onFocus_1 as onFocus };
|
|
84
|
-
const onBlur_1: null;
|
|
85
|
-
export { onBlur_1 as onBlur };
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
import { Component } from "react";
|
|
89
|
-
import { HistoryNavigator } from "../common";
|
|
61
|
+
export default WithDisplayFormat;
|
|
90
62
|
//# sourceMappingURL=WithDisplayFormat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithDisplayFormat.d.ts","sourceRoot":"","sources":["../../../src/withDisplayFormat/WithDisplayFormat.
|
|
1
|
+
{"version":3,"file":"WithDisplayFormat.d.ts","sourceRoot":"","sources":["../../../src/withDisplayFormat/WithDisplayFormat.tsx"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/withDisplayFormat/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/withDisplayFormat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
}
|
|
@@ -24,8 +24,8 @@ describe('locale utils', () => {
|
|
|
24
24
|
['zh_HK', 'zh'],
|
|
25
25
|
['ja-JP', 'ja'],
|
|
26
26
|
['zhHK', null],
|
|
27
|
-
[null
|
|
28
|
-
[undefined
|
|
27
|
+
[null, null],
|
|
28
|
+
[undefined, null],
|
|
29
29
|
['', null],
|
|
30
30
|
[' ', null],
|
|
31
31
|
['ar-dz', null],
|
|
@@ -51,8 +51,8 @@ describe('locale utils', () => {
|
|
|
51
51
|
['zh_HK', 'zh-HK'],
|
|
52
52
|
['ja-JP', 'ja-JP'],
|
|
53
53
|
['zhHK', null],
|
|
54
|
-
[null
|
|
55
|
-
[undefined
|
|
54
|
+
[null, null],
|
|
55
|
+
[undefined, null],
|
|
56
56
|
['', null],
|
|
57
57
|
[' ', null],
|
|
58
58
|
['ar-dz', 'ar-DZ'],
|
package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts}
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import getSymbolsInPatternWithPosition from '../getSymbolsInPatternWithPosition';
|
|
2
|
+
import type { SymbolWithPosition } from '../getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition';
|
|
2
3
|
|
|
3
|
-
const formatWithPattern = (value, pattern) => {
|
|
4
|
+
const formatWithPattern = (value: string, pattern: string): string => {
|
|
4
5
|
if (!value || value === '') {
|
|
5
6
|
return '';
|
|
6
7
|
}
|
|
@@ -9,13 +10,16 @@ const formatWithPattern = (value, pattern) => {
|
|
|
9
10
|
|
|
10
11
|
const patternWithSymbolsPosition = getSymbolsInPatternWithPosition(pattern);
|
|
11
12
|
|
|
12
|
-
let patternSymbol = [];
|
|
13
|
+
let patternSymbol: SymbolWithPosition[] = [];
|
|
13
14
|
// valueArray.length increments during the cycle cause we are adding new elements.
|
|
14
15
|
for (let index = 0; index < valueArray.length; index += 1) {
|
|
15
|
-
patternSymbol = patternWithSymbolsPosition.filter((
|
|
16
|
+
patternSymbol = patternWithSymbolsPosition.filter((pattern) => pattern.index === index);
|
|
16
17
|
// Add pattern's symbol at n position
|
|
17
18
|
if (patternSymbol.length === 1) {
|
|
18
|
-
|
|
19
|
+
const last = patternSymbol.pop();
|
|
20
|
+
if (last) {
|
|
21
|
+
valueArray.splice(index, 0, last.symbol);
|
|
22
|
+
}
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import getCountOfSymbolsInSelection from '../getCountOfSymbolsInSelection';
|
|
2
2
|
import { getDistanceToNextSymbol, getDistanceToPreviousSymbol } from '../getDistanceToSymbol';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
action,
|
|
6
|
-
selectionStart,
|
|
7
|
-
selectionEnd,
|
|
8
|
-
pattern,
|
|
9
|
-
pastedLength,
|
|
10
|
-
) => {
|
|
4
|
+
const getCursorPositionAfterActionStroke = (
|
|
5
|
+
action: string,
|
|
6
|
+
selectionStart: number,
|
|
7
|
+
selectionEnd: number,
|
|
8
|
+
pattern: string,
|
|
9
|
+
pastedLength: number,
|
|
10
|
+
): number => {
|
|
11
11
|
let cursorPosition = selectionStart;
|
|
12
12
|
|
|
13
13
|
switch (action) {
|
|
@@ -38,4 +38,4 @@ const getCursorPositionAfteractionstroke = (
|
|
|
38
38
|
return cursorPosition;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export default
|
|
41
|
+
export default getCursorPositionAfterActionStroke;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export type SymbolWithPosition = {
|
|
2
|
+
index: number;
|
|
3
|
+
symbol: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const getSymbolsInPatternWithPosition = (pattern: string): SymbolWithPosition[] => {
|
|
7
|
+
const patternWithSymbolsPosition: SymbolWithPosition[] = [];
|
|
3
8
|
const patternArray = pattern.split('');
|
|
4
9
|
patternArray.forEach((symbol, index) => {
|
|
5
10
|
if (symbol !== '*') {
|
package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const unformatWithPattern = (value, pattern) => {
|
|
1
|
+
const unformatWithPattern = (value: string, pattern: string): string => {
|
|
2
2
|
let valueArray = [''];
|
|
3
3
|
if (value && value.length > 0) {
|
|
4
4
|
valueArray = value.toString().split('');
|
|
@@ -8,6 +8,7 @@ const unformatWithPattern = (value, pattern) => {
|
|
|
8
8
|
return valueArray.join('');
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const getSymbolsInPattern = (pattern)
|
|
11
|
+
const getSymbolsInPattern = (pattern: string): string[] =>
|
|
12
|
+
pattern.split('').filter((symbol) => symbol !== '*');
|
|
12
13
|
|
|
13
14
|
export default unformatWithPattern;
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Types
|
|
3
3
|
*/
|
|
4
4
|
export type { InputProps } from './inputs/Input';
|
|
5
|
+
export type { InputWithDisplayFormatProps } from './inputWithDisplayFormat';
|
|
5
6
|
export type { InputGroupProps } from './inputs/InputGroup';
|
|
6
7
|
export type { SearchInputProps } from './inputs/SearchInput';
|
|
7
8
|
export type {
|
|
@@ -14,6 +15,7 @@ export type {
|
|
|
14
15
|
SelectInputTriggerButtonProps,
|
|
15
16
|
} from './inputs/SelectInput';
|
|
16
17
|
export type { TextAreaProps } from './inputs/TextArea';
|
|
18
|
+
export type { TextareaWithDisplayFormatProps } from './textareaWithDisplayFormat';
|
|
17
19
|
export type { UploadedFile, UploadError, UploadResponse } from './uploadInput/types';
|
|
18
20
|
export type { ModalProps } from './modal';
|
|
19
21
|
export type {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Input, type InputProps } from '../inputs/Input';
|
|
2
|
+
import WithDisplayFormat, { type WithDisplayFormatProps } from '../withDisplayFormat';
|
|
3
|
+
|
|
4
|
+
export interface InputWithDisplayFormatProps extends Omit<WithDisplayFormatProps, 'render'> {}
|
|
5
|
+
|
|
6
|
+
const InputWithDisplayFormat = (props: InputWithDisplayFormatProps) => (
|
|
7
|
+
<WithDisplayFormat<InputProps> {...props} render={(renderProps) => <Input {...renderProps} />} />
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export default InputWithDisplayFormat;
|