@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.
@@ -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,sCAmIC;CACF"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "46.0.0",
3
+ "version": "46.0.2",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -254,24 +254,34 @@ class MoneyInput extends Component {
254
254
  this.props;
255
255
  const selectOptions = this.getSelectOptions();
256
256
 
257
- const getFirstOption = () => {
257
+ const getFirstSelectItem = () => {
258
258
  if (selectOptions.length !== 0) {
259
- const firstOption = selectOptions[0];
260
- if (firstOption.type === 'option') {
261
- return firstOption.value;
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
- if (firstOption.type === 'group' && firstOption.options.length !== 0) {
264
- return firstOption.options[0].value;
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 firstOption = getFirstOption();
279
+ const firstSelectItem = getFirstSelectItem();
271
280
 
272
281
  const isFixedCurrency =
273
282
  !this.state.searchQuery &&
274
- ((selectOptions.length === 1 && firstOption.currency === selectedCurrency.currency) ||
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 }) => {