@transferwise/components 46.0.0 → 46.0.2
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 +15 -9
- package/build/index.esm.js.map +1 -1
- package/build/index.js +15 -9
- package/build/index.js.map +1 -1
- package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/moneyInput/MoneyInput.js +19 -9
- package/src/moneyInput/MoneyInput.story.tsx +25 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyInput.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/MoneyInput.js"],"names":[],"mappings":";;;;AA+DA;IACE,wBAeC;IAZC,mBAAkD;IAClD;;;;;MAUC;IAGH,uDAaC;IAED,+CAWE;IAEF,oCAIE;IAEF,kCAyBE;IAEF,qCAgBE;IAEF,yBAGE;IAFA,mCAA0B;IAI5B,0BAEE;IAEF;;;;MAME;IAEF,0BAuBC;IAED,kBAsBC;IAED,yCAIE;IAEF,+BAKE;IAEF,+CAQE;IAEF,+BAAqE;IAErE,
|
|
1
|
+
{"version":3,"file":"MoneyInput.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/MoneyInput.js"],"names":[],"mappings":";;;;AA+DA;IACE,wBAeC;IAZC,mBAAkD;IAClD;;;;;MAUC;IAGH,uDAaC;IAED,+CAWE;IAEF,oCAIE;IAEF,kCAyBE;IAEF,qCAgBE;IAEF,yBAGE;IAFA,mCAA0B;IAI5B,0BAEE;IAEF;;;;MAME;IAEF,0BAuBC;IAED,kBAsBC;IAED,yCAIE;IAEF,+BAKE;IAEF,+CAQE;IAEF,+BAAqE;IAErE,sCA6IC;CACF"}
|
package/package.json
CHANGED
|
@@ -254,24 +254,34 @@ class MoneyInput extends Component {
|
|
|
254
254
|
this.props;
|
|
255
255
|
const selectOptions = this.getSelectOptions();
|
|
256
256
|
|
|
257
|
-
const
|
|
257
|
+
const getFirstSelectItem = () => {
|
|
258
258
|
if (selectOptions.length !== 0) {
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
const firstItem = selectOptions[0];
|
|
260
|
+
|
|
261
|
+
if (firstItem.type === 'option') {
|
|
262
|
+
return {
|
|
263
|
+
hasOneCurrency: selectOptions.length === 1,
|
|
264
|
+
currency: firstItem.value.currency,
|
|
265
|
+
};
|
|
262
266
|
}
|
|
263
|
-
|
|
264
|
-
|
|
267
|
+
|
|
268
|
+
if (firstItem.type === 'group') {
|
|
269
|
+
return {
|
|
270
|
+
hasOneCurrency: firstItem.options.length === 1,
|
|
271
|
+
currency: firstItem.options[0].value.currency,
|
|
272
|
+
};
|
|
265
273
|
}
|
|
266
274
|
}
|
|
275
|
+
|
|
267
276
|
return null;
|
|
268
277
|
};
|
|
269
278
|
|
|
270
|
-
const
|
|
279
|
+
const firstSelectItem = getFirstSelectItem();
|
|
271
280
|
|
|
272
281
|
const isFixedCurrency =
|
|
273
282
|
!this.state.searchQuery &&
|
|
274
|
-
((
|
|
283
|
+
((firstSelectItem?.hasOneCurrency &&
|
|
284
|
+
firstSelectItem?.currency === selectedCurrency.currency) ||
|
|
275
285
|
!onCurrencyChange);
|
|
276
286
|
|
|
277
287
|
const disabled = !this.props.onAmountChange;
|
|
@@ -351,7 +361,7 @@ class MoneyInput extends Component {
|
|
|
351
361
|
renderValue={(currency, withinTrigger) => {
|
|
352
362
|
return (
|
|
353
363
|
<SelectInputOptionContent
|
|
354
|
-
title={currency.label}
|
|
364
|
+
title={withinTrigger ? currency.currency.toUpperCase() : currency.label}
|
|
355
365
|
note={withinTrigger ? undefined : currency.note}
|
|
356
366
|
icon={<Flag code={currency.currency} intrinsicSize={24} />}
|
|
357
367
|
/>
|
|
@@ -3,8 +3,6 @@ import { within, userEvent } from '@storybook/testing-library';
|
|
|
3
3
|
import { Lock } from '@transferwise/icons';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
|
-
import Drawer from '../drawer';
|
|
7
|
-
|
|
8
6
|
import MoneyInput from '.';
|
|
9
7
|
|
|
10
8
|
export default {
|
|
@@ -82,6 +80,17 @@ const exampleCurrency = {
|
|
|
82
80
|
},
|
|
83
81
|
} as const;
|
|
84
82
|
|
|
83
|
+
const exampleBalanceCurrency = {
|
|
84
|
+
eur: {
|
|
85
|
+
...exampleCurrency.eur,
|
|
86
|
+
label: '123.45 EUR',
|
|
87
|
+
},
|
|
88
|
+
gbp: {
|
|
89
|
+
...exampleCurrency.gbp,
|
|
90
|
+
label: '12.34 GBP',
|
|
91
|
+
},
|
|
92
|
+
} as const;
|
|
93
|
+
|
|
85
94
|
export const SingleCurrency: Story = {
|
|
86
95
|
args: {
|
|
87
96
|
currencies: [],
|
|
@@ -117,6 +126,20 @@ export const MultipleCurrencies: Story = {
|
|
|
117
126
|
},
|
|
118
127
|
};
|
|
119
128
|
|
|
129
|
+
export const BalanceCurrencies: Story = {
|
|
130
|
+
args: {
|
|
131
|
+
currencies: [
|
|
132
|
+
{
|
|
133
|
+
header: 'Balance currencies',
|
|
134
|
+
},
|
|
135
|
+
exampleBalanceCurrency.eur,
|
|
136
|
+
exampleBalanceCurrency.gbp,
|
|
137
|
+
],
|
|
138
|
+
selectedCurrency: exampleBalanceCurrency.eur,
|
|
139
|
+
searchPlaceholder: 'Type a currency / country',
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
120
143
|
export const OpenedInput: Story = {
|
|
121
144
|
...MultipleCurrencies,
|
|
122
145
|
play: ({ canvasElement }) => {
|