@transferwise/components 0.0.0-experimental-ec79c77 → 0.0.0-experimental-26e5ea6
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.map +1 -1
- package/build/index.js.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/moneyInput/MoneyInput.d.ts +11 -11
- package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
- package/build/types/moneyInput/index.d.ts +1 -1
- package/build/types/moneyInput/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -1
- package/src/moneyInput/MoneyInput.rtl.spec.tsx +1 -1
- package/src/moneyInput/MoneyInput.story.tsx +2 -2
- package/src/moneyInput/MoneyInput.tsx +26 -16
- package/src/moneyInput/index.ts +6 -1
package/build/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { SelectInputGroupItem, SelectInputItem, SelectInputOptionContentPro
|
|
|
8
8
|
export type { TextAreaProps } from './inputs/TextArea';
|
|
9
9
|
export type { UploadedFile, UploadError, UploadResponse } from './uploadInput/types';
|
|
10
10
|
export type { ModalProps } from './modal';
|
|
11
|
-
export type {
|
|
11
|
+
export type { CurrencyHeaderItem, CurrencyItem, CurrencyOptionItem, MoneyInputProps, } from './moneyInput';
|
|
12
12
|
export type { LayoutDirection, TypographyTypes, TitleTypes, BodyTypes, LinkTypes, DisplayTypes, } from './common';
|
|
13
13
|
/**
|
|
14
14
|
* Components
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EACV,oBAAoB,EAC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appedComponentProps } from 'react-intl';
|
|
3
3
|
import { SizeLarge, SizeMedium, SizeSmall } from '../common/propsValues/size';
|
|
4
4
|
import { SelectInputProps } from '../inputs/SelectInput';
|
|
5
|
-
export interface
|
|
5
|
+
export interface CurrencyOptionItem {
|
|
6
|
+
header?: never;
|
|
6
7
|
value: string;
|
|
7
8
|
label: string;
|
|
8
9
|
currency: string;
|
|
9
10
|
note?: string;
|
|
10
11
|
searchable?: string;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
export interface CurrencyHeaderItem {
|
|
13
14
|
header: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
} & CurrencyOption);
|
|
15
|
+
}
|
|
16
|
+
export type CurrencyItem = CurrencyOptionItem | CurrencyHeaderItem;
|
|
17
17
|
export interface MoneyInputProps extends WrappedComponentProps {
|
|
18
18
|
id?: string;
|
|
19
|
-
currencies: readonly
|
|
20
|
-
selectedCurrency:
|
|
21
|
-
onCurrencyChange?: (value:
|
|
19
|
+
currencies: readonly CurrencyItem[];
|
|
20
|
+
selectedCurrency: CurrencyOptionItem;
|
|
21
|
+
onCurrencyChange?: (value: CurrencyOptionItem) => void;
|
|
22
22
|
placeholder?: number;
|
|
23
|
-
amount
|
|
23
|
+
amount: number | null;
|
|
24
24
|
size?: SizeSmall | SizeMedium | SizeLarge;
|
|
25
25
|
onAmountChange?: (value: number | null) => void;
|
|
26
26
|
addon?: React.ReactNode;
|
|
@@ -30,12 +30,12 @@ export interface MoneyInputProps extends WrappedComponentProps {
|
|
|
30
30
|
*/
|
|
31
31
|
onSearchChange?: (value: {
|
|
32
32
|
searchQuery: string;
|
|
33
|
-
filteredOptions:
|
|
33
|
+
filteredOptions: CurrencyItem[];
|
|
34
34
|
}) => void;
|
|
35
35
|
customActionLabel?: React.ReactNode;
|
|
36
36
|
onCustomAction?: () => void;
|
|
37
37
|
classNames?: Record<string, string>;
|
|
38
|
-
selectProps?: Partial<SelectInputProps<
|
|
38
|
+
selectProps?: Partial<SelectInputProps<CurrencyOptionItem>>;
|
|
39
39
|
maxLengthOverride?: number;
|
|
40
40
|
}
|
|
41
41
|
declare const _default: import("react").FC<import("react-intl").WithIntlProps<MoneyInputProps>> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyInput.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/MoneyInput.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAc,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAK/D,OAAO,EAAQ,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEpF,OAAO,EAKL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAM/B,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"MoneyInput.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/MoneyInput.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAc,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAK/D,OAAO,EAAQ,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEpF,OAAO,EAKL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAM/B,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAgDnE,MAAM,WAAW,eAAgB,SAAQ,qBAAqB;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,SAAS,YAAY,EAAE,CAAC;IACpC,gBAAgB,EAAE,kBAAkB,CAAC;IACrC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IAC1C,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,YAAY,EAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3F,iBAAiB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC5D,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;;;;AA2YD,wBAAsC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,7 +16,12 @@ export type {
|
|
|
16
16
|
export type { TextAreaProps } from './inputs/TextArea';
|
|
17
17
|
export type { UploadedFile, UploadError, UploadResponse } from './uploadInput/types';
|
|
18
18
|
export type { ModalProps } from './modal';
|
|
19
|
-
export type {
|
|
19
|
+
export type {
|
|
20
|
+
CurrencyHeaderItem,
|
|
21
|
+
CurrencyItem,
|
|
22
|
+
CurrencyOptionItem,
|
|
23
|
+
MoneyInputProps,
|
|
24
|
+
} from './moneyInput';
|
|
20
25
|
export type {
|
|
21
26
|
LayoutDirection,
|
|
22
27
|
TypographyTypes,
|
|
@@ -62,7 +62,7 @@ describe('MoneyInput', () => {
|
|
|
62
62
|
['12,3', '12,3'],
|
|
63
63
|
['12.3', '12.3'],
|
|
64
64
|
])("ignores the letters when typed '%s' and shows '%s'", (testValue, expectedValue) => {
|
|
65
|
-
render(<MoneyInput {...props} amount={
|
|
65
|
+
render(<MoneyInput {...props} amount={null} />);
|
|
66
66
|
|
|
67
67
|
const input = screen.getByRole('textbox');
|
|
68
68
|
userEvent.type(input, testValue);
|
|
@@ -3,7 +3,7 @@ import { within, userEvent } from '@storybook/testing-library';
|
|
|
3
3
|
import { Lock } from '@transferwise/icons';
|
|
4
4
|
import React, { useState } from 'react';
|
|
5
5
|
|
|
6
|
-
import MoneyInput, {
|
|
6
|
+
import MoneyInput, { CurrencyOptionItem } from '.';
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
component: MoneyInput,
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
13
13
|
const [selectedCurrency, setSelectedCurrency] = useState(args.selectedCurrency);
|
|
14
14
|
|
|
15
|
-
const handleOnCurrencyChange = (value:
|
|
15
|
+
const handleOnCurrencyChange = (value: CurrencyOptionItem) => setSelectedCurrency(value);
|
|
16
16
|
|
|
17
17
|
return (
|
|
18
18
|
<>
|
|
@@ -21,7 +21,8 @@ import Title from '../title';
|
|
|
21
21
|
import messages from './MoneyInput.messages';
|
|
22
22
|
import { formatAmount, parseAmount } from './currencyFormatting';
|
|
23
23
|
|
|
24
|
-
export interface
|
|
24
|
+
export interface CurrencyOptionItem {
|
|
25
|
+
header?: never;
|
|
25
26
|
value: string;
|
|
26
27
|
label: string;
|
|
27
28
|
currency: string;
|
|
@@ -29,7 +30,11 @@ export interface CurrencyOption {
|
|
|
29
30
|
searchable?: string;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
export interface CurrencyHeaderItem {
|
|
34
|
+
header: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type CurrencyItem = CurrencyOptionItem | CurrencyHeaderItem;
|
|
33
38
|
|
|
34
39
|
const isNumberOrNull = (v: unknown): v is number | null => isNumber(v) || isNull(v);
|
|
35
40
|
|
|
@@ -79,11 +84,11 @@ const inputKeyAllowlist = new Set([keyValues.PERIOD, keyValues.COMMA]);
|
|
|
79
84
|
|
|
80
85
|
export interface MoneyInputProps extends WrappedComponentProps {
|
|
81
86
|
id?: string;
|
|
82
|
-
currencies: readonly
|
|
83
|
-
selectedCurrency:
|
|
84
|
-
onCurrencyChange?: (value:
|
|
87
|
+
currencies: readonly CurrencyItem[];
|
|
88
|
+
selectedCurrency: CurrencyOptionItem;
|
|
89
|
+
onCurrencyChange?: (value: CurrencyOptionItem) => void;
|
|
85
90
|
placeholder?: number;
|
|
86
|
-
amount
|
|
91
|
+
amount: number | null;
|
|
87
92
|
size?: SizeSmall | SizeMedium | SizeLarge;
|
|
88
93
|
onAmountChange?: (value: number | null) => void;
|
|
89
94
|
addon?: React.ReactNode;
|
|
@@ -91,11 +96,11 @@ export interface MoneyInputProps extends WrappedComponentProps {
|
|
|
91
96
|
/**
|
|
92
97
|
* Allows the consumer to react to searching, while the search itself is handled internally.
|
|
93
98
|
*/
|
|
94
|
-
onSearchChange?: (value: { searchQuery: string; filteredOptions:
|
|
99
|
+
onSearchChange?: (value: { searchQuery: string; filteredOptions: CurrencyItem[] }) => void;
|
|
95
100
|
customActionLabel?: React.ReactNode;
|
|
96
101
|
onCustomAction?: () => void;
|
|
97
102
|
classNames?: Record<string, string>;
|
|
98
|
-
selectProps?: Partial<SelectInputProps<
|
|
103
|
+
selectProps?: Partial<SelectInputProps<CurrencyOptionItem>>;
|
|
99
104
|
maxLengthOverride?: number;
|
|
100
105
|
}
|
|
101
106
|
|
|
@@ -222,8 +227,8 @@ class MoneyInput extends Component<MoneyInputProps, MoneyInputState> {
|
|
|
222
227
|
getSelectOptions() {
|
|
223
228
|
const selectOptions = filterCurrenciesForQuery(this.props.currencies, this.state.searchQuery);
|
|
224
229
|
|
|
225
|
-
const formattedOptions: SelectInputItem<
|
|
226
|
-
let currentGroupOptions: SelectInputOptionItem<
|
|
230
|
+
const formattedOptions: SelectInputItem<CurrencyOptionItem>[] = [];
|
|
231
|
+
let currentGroupOptions: SelectInputOptionItem<CurrencyOptionItem>[] | undefined;
|
|
227
232
|
|
|
228
233
|
selectOptions.forEach((item) => {
|
|
229
234
|
if (item.header != null) {
|
|
@@ -269,7 +274,7 @@ class MoneyInput extends Component<MoneyInputProps, MoneyInputState> {
|
|
|
269
274
|
});
|
|
270
275
|
}
|
|
271
276
|
|
|
272
|
-
handleSelectChange = (value:
|
|
277
|
+
handleSelectChange = (value: CurrencyOptionItem) => {
|
|
273
278
|
this.handleSearchChange('');
|
|
274
279
|
this.props.onCurrencyChange?.(value);
|
|
275
280
|
};
|
|
@@ -429,12 +434,17 @@ class MoneyInput extends Component<MoneyInputProps, MoneyInputState> {
|
|
|
429
434
|
}
|
|
430
435
|
}
|
|
431
436
|
|
|
432
|
-
function filterCurrenciesForQuery(
|
|
437
|
+
function filterCurrenciesForQuery(
|
|
438
|
+
currencies: readonly CurrencyItem[],
|
|
439
|
+
query: string,
|
|
440
|
+
): CurrencyItem[] {
|
|
433
441
|
if (!query) {
|
|
434
442
|
return [...currencies];
|
|
435
443
|
}
|
|
436
444
|
|
|
437
|
-
const options = currencies.filter(
|
|
445
|
+
const options = currencies.filter(
|
|
446
|
+
(option): option is CurrencyOptionItem => option.header == null,
|
|
447
|
+
);
|
|
438
448
|
const filteredOptions = removeDuplicateValueOptions(options).filter((option) =>
|
|
439
449
|
currencyOptionFitsQuery(option, query),
|
|
440
450
|
);
|
|
@@ -442,7 +452,7 @@ function filterCurrenciesForQuery(currencies: readonly Currency[], query: string
|
|
|
442
452
|
return sortOptionsLabelsToFirst(filteredOptions, query);
|
|
443
453
|
}
|
|
444
454
|
|
|
445
|
-
function removeDuplicateValueOptions(options:
|
|
455
|
+
function removeDuplicateValueOptions(options: CurrencyOptionItem[]) {
|
|
446
456
|
const uniqueValues = new Set<string>();
|
|
447
457
|
return options.filter((option) => {
|
|
448
458
|
if (!uniqueValues.has(option.value)) {
|
|
@@ -453,7 +463,7 @@ function removeDuplicateValueOptions(options: CurrencyOption[]) {
|
|
|
453
463
|
});
|
|
454
464
|
}
|
|
455
465
|
|
|
456
|
-
function currencyOptionFitsQuery(option:
|
|
466
|
+
function currencyOptionFitsQuery(option: CurrencyOptionItem, query: string) {
|
|
457
467
|
if (!option.value) {
|
|
458
468
|
return false;
|
|
459
469
|
}
|
|
@@ -469,7 +479,7 @@ function contains(property: string | undefined, query: string) {
|
|
|
469
479
|
return property && property.toLowerCase().includes(query.toLowerCase());
|
|
470
480
|
}
|
|
471
481
|
|
|
472
|
-
function sortOptionsLabelsToFirst(options:
|
|
482
|
+
function sortOptionsLabelsToFirst(options: CurrencyOptionItem[], query: string) {
|
|
473
483
|
return options.sort((first, second) => {
|
|
474
484
|
const firstContains = contains(first.label, query);
|
|
475
485
|
const secondContains = contains(second.label, query);
|
package/src/moneyInput/index.ts
CHANGED