@transferwise/components 46.0.4 → 46.0.5

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,sCA6IC;CACF"}
1
+ {"version":3,"file":"MoneyInput.d.ts","sourceRoot":"","sources":["../../../src/moneyInput/MoneyInput.js"],"names":[],"mappings":";;;;AA+DA;IACE,wBAcC;IAXC,mBAAkD;IAClD;;;;MASC;IAGH,uDAaC;IAED,+CAWE;IAEF,oCAIE;IAEF,kCAyBE;IAEF,qCAgBE;IAEF,yBAGE;IAFA,mCAA0B;IAI5B,0BAEE;IAEF;;;;MAME;IAEF,0BAuBC;IAED,kBAsBC;IAED,yCAGE;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.4",
3
+ "version": "46.0.5",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -68,7 +68,6 @@ class MoneyInput extends Component {
68
68
  this.formatMessage = this.props.intl.formatMessage;
69
69
  this.state = {
70
70
  searchQuery: '',
71
- selectedOption: this.props.selectedCurrency,
72
71
  formattedAmount: formatAmountIfSet(
73
72
  props.amount,
74
73
  props.selectedCurrency.currency,
@@ -226,7 +225,6 @@ class MoneyInput extends Component {
226
225
 
227
226
  handleSelectChange = (value) => {
228
227
  this.handleSearchChange('');
229
- this.setState({ selectedOption: value });
230
228
  this.props.onCurrencyChange(value);
231
229
  };
232
230
 
@@ -356,7 +354,7 @@ class MoneyInput extends Component {
356
354
  >
357
355
  <SelectInput
358
356
  items={selectOptions}
359
- value={this.state.selectedOption}
357
+ value={selectedCurrency}
360
358
  compareValues="currency"
361
359
  renderValue={(currency, withinTrigger) => {
362
360
  return (
@@ -1,19 +1,33 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
  import { within, userEvent } from '@storybook/testing-library';
3
3
  import { Lock } from '@transferwise/icons';
4
- import React from 'react';
4
+ import React, { useState } from 'react';
5
5
 
6
6
  import MoneyInput from '.';
7
7
 
8
8
  export default {
9
9
  component: MoneyInput,
10
10
  title: 'Forms/MoneyInput',
11
- render: (args) => (
12
- <>
13
- <label htmlFor={args.id as string}>Editable money input label</label>
14
- <MoneyInput {...args} />
15
- </>
16
- ),
11
+ render: (args) => {
12
+ // eslint-disable-next-line react-hooks/rules-of-hooks
13
+ const [selectedCurrency, setSelectedCurrency] = useState(
14
+ args.selectedCurrency as SelectedOption,
15
+ );
16
+ const currencies = args.currencies as SelectedOption[];
17
+
18
+ const handleOnCurrencyChange = (value: SelectedOption) => setSelectedCurrency(value);
19
+
20
+ return (
21
+ <>
22
+ <label htmlFor={args.id as string}>Editable money input label</label>
23
+ <MoneyInput
24
+ {...args}
25
+ selectedCurrency={selectedCurrency}
26
+ onCurrencyChange={currencies.length > 1 ? handleOnCurrencyChange : undefined}
27
+ />
28
+ </>
29
+ );
30
+ },
17
31
  args: {
18
32
  id: 'money-input',
19
33
  amount: 1000,
@@ -28,6 +42,8 @@ export default {
28
42
 
29
43
  type Story = StoryObj<typeof MoneyInput>;
30
44
 
45
+ type SelectedOption = (typeof exampleCurrency)[keyof typeof exampleCurrency];
46
+
31
47
  const exampleCurrency = {
32
48
  eur: {
33
49
  value: 'EUR',