@transferwise/components 46.85.0 → 46.86.0

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.
Files changed (113) hide show
  1. package/build/avatarLayout/AvatarLayout.js +1 -0
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +1 -0
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/circularButton/CircularButton.js +18 -21
  6. package/build/circularButton/CircularButton.js.map +1 -1
  7. package/build/circularButton/CircularButton.mjs +19 -22
  8. package/build/circularButton/CircularButton.mjs.map +1 -1
  9. package/build/definitionList/DefinitionList.js.map +1 -1
  10. package/build/definitionList/DefinitionList.mjs.map +1 -1
  11. package/build/i18n/de.json +1 -0
  12. package/build/i18n/de.json.js +1 -0
  13. package/build/i18n/de.json.js.map +1 -1
  14. package/build/i18n/de.json.mjs +1 -0
  15. package/build/i18n/de.json.mjs.map +1 -1
  16. package/build/i18n/es.json +1 -0
  17. package/build/i18n/es.json.js +1 -0
  18. package/build/i18n/es.json.js.map +1 -1
  19. package/build/i18n/es.json.mjs +1 -0
  20. package/build/i18n/es.json.mjs.map +1 -1
  21. package/build/i18n/fr.json +6 -5
  22. package/build/i18n/fr.json.js +6 -5
  23. package/build/i18n/fr.json.js.map +1 -1
  24. package/build/i18n/fr.json.mjs +6 -5
  25. package/build/i18n/fr.json.mjs.map +1 -1
  26. package/build/i18n/hu.json +1 -0
  27. package/build/i18n/hu.json.js +1 -0
  28. package/build/i18n/hu.json.js.map +1 -1
  29. package/build/i18n/hu.json.mjs +1 -0
  30. package/build/i18n/hu.json.mjs.map +1 -1
  31. package/build/i18n/id.json +1 -0
  32. package/build/i18n/id.json.js +1 -0
  33. package/build/i18n/id.json.js.map +1 -1
  34. package/build/i18n/id.json.mjs +1 -0
  35. package/build/i18n/id.json.mjs.map +1 -1
  36. package/build/i18n/it.json +1 -0
  37. package/build/i18n/it.json.js +1 -0
  38. package/build/i18n/it.json.js.map +1 -1
  39. package/build/i18n/it.json.mjs +1 -0
  40. package/build/i18n/it.json.mjs.map +1 -1
  41. package/build/i18n/pl.json +1 -0
  42. package/build/i18n/pl.json.js +1 -0
  43. package/build/i18n/pl.json.js.map +1 -1
  44. package/build/i18n/pl.json.mjs +1 -0
  45. package/build/i18n/pl.json.mjs.map +1 -1
  46. package/build/i18n/ro.json +1 -0
  47. package/build/i18n/ro.json.js +1 -0
  48. package/build/i18n/ro.json.js.map +1 -1
  49. package/build/i18n/ro.json.mjs +1 -0
  50. package/build/i18n/ro.json.mjs.map +1 -1
  51. package/build/i18n/th.json +1 -0
  52. package/build/i18n/th.json.js +1 -0
  53. package/build/i18n/th.json.js.map +1 -1
  54. package/build/i18n/th.json.mjs +1 -0
  55. package/build/i18n/th.json.mjs.map +1 -1
  56. package/build/i18n/tr.json +1 -0
  57. package/build/i18n/tr.json.js +1 -0
  58. package/build/i18n/tr.json.js.map +1 -1
  59. package/build/i18n/tr.json.mjs +1 -0
  60. package/build/i18n/tr.json.mjs.map +1 -1
  61. package/build/i18n/zh-CN.json +1 -0
  62. package/build/i18n/zh-CN.json.js +1 -0
  63. package/build/i18n/zh-CN.json.js.map +1 -1
  64. package/build/i18n/zh-CN.json.mjs +1 -0
  65. package/build/i18n/zh-CN.json.mjs.map +1 -1
  66. package/build/main.css +17 -158
  67. package/build/moneyInput/MoneyInput.js.map +1 -1
  68. package/build/moneyInput/MoneyInput.mjs.map +1 -1
  69. package/build/styles/circularButton/CircularButton.css +17 -158
  70. package/build/styles/main.css +17 -158
  71. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  72. package/build/types/circularButton/CircularButton.d.ts +11 -4
  73. package/build/types/circularButton/CircularButton.d.ts.map +1 -1
  74. package/build/types/definitionList/DefinitionList.d.ts +1 -2
  75. package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
  76. package/build/types/moneyInput/MoneyInput.d.ts +1 -1
  77. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  78. package/package.json +3 -3
  79. package/src/avatar/Avatar.story.tsx +4 -1
  80. package/src/avatarLayout/AvatarLayout.story.tsx +2 -0
  81. package/src/avatarLayout/AvatarLayout.tsx +3 -1
  82. package/src/avatarWrapper/AvatarWrapper.story.tsx +4 -0
  83. package/src/badge/Badge.story.tsx +4 -0
  84. package/src/circularButton/CircularButton.css +17 -158
  85. package/src/circularButton/CircularButton.less +22 -91
  86. package/src/circularButton/CircularButton.story.tsx +45 -24
  87. package/src/circularButton/CircularButton.tsx +38 -25
  88. package/src/definitionList/DefinitionList.story.tsx +57 -57
  89. package/src/definitionList/DefinitionList.tsx +1 -1
  90. package/src/i18n/de.json +1 -0
  91. package/src/i18n/es.json +1 -0
  92. package/src/i18n/fr.json +6 -5
  93. package/src/i18n/hu.json +1 -0
  94. package/src/i18n/id.json +1 -0
  95. package/src/i18n/it.json +1 -0
  96. package/src/i18n/pl.json +1 -0
  97. package/src/i18n/ro.json +1 -0
  98. package/src/i18n/th.json +1 -0
  99. package/src/i18n/tr.json +1 -0
  100. package/src/i18n/zh-CN.json +1 -0
  101. package/src/iconButton/IconButton.story.tsx +6 -6
  102. package/src/main.css +17 -158
  103. package/src/moneyInput/MoneyInput.spec.tsx +468 -0
  104. package/src/moneyInput/MoneyInput.tsx +2 -1
  105. package/src/phoneNumberInput/PhoneNumberInput.spec.tsx +283 -0
  106. package/src/slidingPanel/SlidingPanel.spec.tsx +69 -0
  107. package/src/circularButton/_button-label-states.less +0 -34
  108. package/src/definitionList/DefinitionList.spec.js +0 -91
  109. package/src/moneyInput/MoneyInput.rtl.spec.tsx +0 -149
  110. package/src/moneyInput/MoneyInput.spec.js +0 -820
  111. package/src/phoneNumberInput/PhoneNumberInput.rtl.spec.tsx +0 -32
  112. package/src/phoneNumberInput/PhoneNumberInput.spec.js +0 -356
  113. package/src/slidingPanel/SlidingPanel.spec.js +0 -56
@@ -1,32 +0,0 @@
1
- import { Field } from '../field/Field';
2
- import { mockMatchMedia, mockResizeObserver, render, screen, within } from '../test-utils';
3
-
4
- import PhoneNumberInput from './PhoneNumberInput';
5
-
6
- mockMatchMedia();
7
- mockResizeObserver();
8
-
9
- describe('PhoneNumberInput', () => {
10
- it('supports custom `aria-labelledby` attribute', () => {
11
- render(
12
- <>
13
- {/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
14
- <label id="prioritized-label">Prioritized label</label>
15
- <PhoneNumberInput aria-labelledby="prioritized-label" onChange={() => {}} />
16
- </>,
17
- );
18
-
19
- expect(
20
- within(screen.getByLabelText('Prioritized label')).getByRole('textbox'),
21
- ).toBeInTheDocument();
22
- });
23
-
24
- it('supports `Field` for labeling', () => {
25
- render(
26
- <Field label="Phone number">
27
- <PhoneNumberInput initialValue="+12345678" onChange={() => {}} />
28
- </Field>,
29
- );
30
- expect(screen.getAllByRole('group')[0]).toHaveAccessibleName(/^Phone number/);
31
- });
32
- });
@@ -1,356 +0,0 @@
1
- import { shallow, mount } from 'enzyme';
2
- import { useIntl } from 'react-intl';
3
-
4
- import { mockMatchMedia, mockResizeObserver } from '../test-utils';
5
-
6
- import PhoneNumberInput from '.';
7
-
8
- const locale = 'en-GB';
9
- const formatMessage = (message) => message.defaultMessage;
10
- jest.mock('react-intl', () => ({
11
- ...jest.requireActual('react-intl'),
12
- useIntl: jest.fn(() => ({ locale, formatMessage })),
13
- }));
14
-
15
- mockMatchMedia();
16
- mockResizeObserver();
17
-
18
- const simulatePaste = (element, value) =>
19
- element.simulate('paste', { nativeEvent: { clipboardData: { getData: () => value } } });
20
-
21
- describe('Given a telephone number component', () => {
22
- let select;
23
- let input;
24
- let component;
25
- const props = { onChange: jest.fn() };
26
- const PREFIX_SELECT_SELECTOR = 'SelectInput';
27
- const NUMBER_SELECTOR = 'input[name="phoneNumber"]';
28
-
29
- beforeEach(() => {
30
- useIntl.mockReturnValue({ locale, formatMessage });
31
- });
32
-
33
- afterEach(() => {
34
- jest.clearAllMocks();
35
- });
36
-
37
- describe('when initialised without a model', () => {
38
- beforeEach(() => {
39
- component = shallow(<PhoneNumberInput {...props} />);
40
- select = component.find(PREFIX_SELECT_SELECTOR);
41
- input = component.find(NUMBER_SELECTOR);
42
- });
43
-
44
- it('should set prefix control to default UK value', () => {
45
- expect(select.props().value).toBe('+44');
46
- });
47
-
48
- it('should set number control to empty', () => {
49
- expect(input.prop('value')).toBe('');
50
- });
51
-
52
- it('should not disable the select', () => {
53
- expect(select.prop('disabled')).toBeFalsy();
54
- });
55
-
56
- it('should not disable the input', () => {
57
- expect(input.prop('disabled')).toBeFalsy();
58
- });
59
- });
60
-
61
- describe('when a valid model is supplied', () => {
62
- beforeEach(() => {
63
- component = shallow(<PhoneNumberInput {...props} initialValue="+39123456789" />);
64
- select = component.find(PREFIX_SELECT_SELECTOR);
65
- input = component.find(NUMBER_SELECTOR);
66
- });
67
-
68
- it('should set control values correctly', () => {
69
- expect(select.props().value).toBe('+39');
70
- expect(input.prop('value')).toBe('123456789');
71
- });
72
- });
73
-
74
- describe('when an id is supplied', () => {
75
- beforeEach(() => {
76
- component = shallow(<PhoneNumberInput id="mock-id" {...props} />);
77
- select = component.find(PREFIX_SELECT_SELECTOR);
78
- input = component.find(NUMBER_SELECTOR);
79
- });
80
-
81
- it('should render select with undefined id', () => {
82
- expect(select.prop('id')).toBeUndefined();
83
- });
84
-
85
- it('should render input with expected id', () => {
86
- expect(input.prop('id')).toBe('mock-id');
87
- });
88
- });
89
-
90
- describe('when an id is not supplied', () => {
91
- beforeEach(() => {
92
- component = shallow(<PhoneNumberInput {...props} />);
93
- input = component.find(NUMBER_SELECTOR);
94
- });
95
-
96
- it('should render input with unspecified id', () => {
97
- expect(input.prop('id')).toBeUndefined();
98
- });
99
- });
100
-
101
- describe('when pasting', () => {
102
- beforeEach(() => {
103
- component = mount(<PhoneNumberInput {...props} initialValue="+39123456789" />);
104
- select = () => component.find(PREFIX_SELECT_SELECTOR);
105
- input = () => component.find(NUMBER_SELECTOR);
106
- });
107
-
108
- [
109
- { number: '+36303932551', countryCode: '+36', localNumber: '303932551' },
110
- { number: '+39123456781', countryCode: '+39', localNumber: '123456781' },
111
- { number: '+44 7700 900415', countryCode: '+44', localNumber: '7700900415' },
112
- { number: '+2975557308515', countryCode: '+297', localNumber: '5557308515' },
113
- { number: '+297-555-7217-360', countryCode: '+297', localNumber: '5557217360' },
114
- { number: '+213-555-5160-67', countryCode: '+213', localNumber: '555516067' },
115
- { number: '+246-387-5553', countryCode: '+246', localNumber: '3875553' },
116
- { number: '+852-940-5558--6', countryCode: '+852', localNumber: '94055586' },
117
- { number: '+228 253 5558 4', countryCode: '+228', localNumber: '25355584' },
118
- ].forEach(({ number, countryCode, localNumber }) => {
119
- it(`${number} code should update the value properly`, () => {
120
- simulatePaste(component.find('input'), number);
121
-
122
- expect(select().props().value).toBe(countryCode);
123
- expect(input().prop('value')).toBe(localNumber);
124
- expect(props.onChange).toHaveBeenCalledWith(number.replace(/(\s|-)+/g, ''), countryCode);
125
- });
126
- });
127
-
128
- it('should not paste invalid characters', () => {
129
- simulatePaste(component.find('input'), '+36asdasdasd');
130
- expect(select().props().value).toBe('+39');
131
- expect(input().prop('value')).toBe('123456789');
132
- expect(props.onChange).not.toHaveBeenCalled();
133
- });
134
-
135
- it('should not paste countries which are not in the select', () => {
136
- simulatePaste(component.find('input'), '+9992342343423');
137
- expect(select().props().value).toBe('+39');
138
- expect(input().prop('value')).toBe('123456789');
139
- expect(props.onChange).not.toHaveBeenCalled();
140
- });
141
-
142
- it("should not paste numbers which doesn't start with the country code", () => {
143
- simulatePaste(component.find('input'), '0+36303932551');
144
- expect(select().props().value).toBe('+39');
145
- expect(input().prop('value')).toBe('123456789');
146
- expect(props.onChange).not.toHaveBeenCalled();
147
- });
148
-
149
- it("should not paste numbers which doesn't contain a country code", () => {
150
- simulatePaste(component.find('input'), '06303932551');
151
- expect(select().props().value).toBe('+39');
152
- expect(input().prop('value')).toBe('123456789');
153
- expect(props.onChange).not.toHaveBeenCalled();
154
- });
155
- });
156
-
157
- describe('when a model is supplied that could match more than one prefix', () => {
158
- beforeEach(() => {
159
- component = shallow(<PhoneNumberInput {...props} initialValue="+1868123456789" />);
160
- select = component.find(PREFIX_SELECT_SELECTOR);
161
- input = component.find(NUMBER_SELECTOR);
162
- });
163
-
164
- it('should set the select to the longest matching prefix', () => {
165
- expect(select.props().value).toBe('+1868');
166
- });
167
-
168
- it('should set the number input to the rest of the number', () => {
169
- expect(input.prop('value')).toBe('123456789');
170
- });
171
- });
172
-
173
- describe('when a model is supplied with no matching prefix', () => {
174
- beforeEach(() => {
175
- component = shallow(<PhoneNumberInput {...props} initialValue="+999123456789" />);
176
- select = component.find(PREFIX_SELECT_SELECTOR);
177
- input = component.find(NUMBER_SELECTOR);
178
- });
179
-
180
- it('should empty the select', () => {
181
- expect(select.props().value).toBeNull();
182
- });
183
-
184
- it('should put the whole value in the input without the plus', () => {
185
- expect(input.prop('value')).toBe('999123456789');
186
- });
187
- });
188
-
189
- describe('when an invalid model is supplied', () => {
190
- it('should not re-explode model', () => {
191
- component = shallow(<PhoneNumberInput {...props} initialValue="+123" />);
192
- select = component.find(PREFIX_SELECT_SELECTOR);
193
- input = component.find(NUMBER_SELECTOR);
194
-
195
- expect(select.props().value).toBe('+44');
196
- expect(input.prop('value')).toBe('');
197
- });
198
- });
199
-
200
- describe('when disabled is true', () => {
201
- beforeEach(() => {
202
- component = shallow(<PhoneNumberInput {...props} disabled />);
203
- select = component.find(PREFIX_SELECT_SELECTOR);
204
- input = component.find(NUMBER_SELECTOR);
205
- });
206
-
207
- it('should disable the select', () => {
208
- expect(select.prop('disabled')).toBe(true);
209
- });
210
-
211
- it('should disable the input', () => {
212
- expect(input.prop('disabled')).toBe(true);
213
- });
214
- });
215
-
216
- describe('when supplied with a placeholder', () => {
217
- beforeEach(() => {
218
- useIntl.mockReturnValue({ locale: 'es-ES', formatMessage });
219
- component = shallow(
220
- <PhoneNumberInput {...props} initialValue="+12345678" placeholder="placeholder" />,
221
- );
222
- input = component.find(NUMBER_SELECTOR);
223
- });
224
-
225
- it('should use the provided placeholder', () => {
226
- expect(input.prop('placeholder')).toBe('placeholder');
227
- });
228
- });
229
-
230
- describe('when supplied with a search placeholder', () => {
231
- beforeEach(() => {
232
- useIntl.mockReturnValue({ locale: 'es-ES', formatMessage });
233
- component = shallow(
234
- <PhoneNumberInput
235
- {...props}
236
- initialValue="+12345678"
237
- searchPlaceholder="searchPlaceholder"
238
- />,
239
- );
240
- select = component.find(PREFIX_SELECT_SELECTOR);
241
- });
242
-
243
- it('should use the provided searchPlaceholder', () => {
244
- expect(select.prop('filterPlaceholder')).toBe('searchPlaceholder');
245
- });
246
- });
247
-
248
- describe('when supplied with a locale', () => {
249
- describe('and a value', () => {
250
- beforeEach(() => {
251
- useIntl.mockReturnValue({ locale: 'es-ES', formatMessage });
252
- component = shallow(<PhoneNumberInput {...props} initialValue="+12345678" />);
253
- select = component.find(PREFIX_SELECT_SELECTOR);
254
- input = component.find(NUMBER_SELECTOR);
255
- });
256
-
257
- it('should use the prefix of the supplied value', () => {
258
- expect(select.props().value).toBe('+1');
259
- });
260
- });
261
-
262
- describe('and no value', () => {
263
- describe('and no country code', () => {
264
- beforeEach(() => {
265
- useIntl.mockReturnValue({ locale: 'es', formatMessage });
266
- component = shallow(<PhoneNumberInput {...props} />);
267
- select = component.find(PREFIX_SELECT_SELECTOR);
268
- input = component.find(NUMBER_SELECTOR);
269
- });
270
-
271
- it('should default the prefix to the local country', () => {
272
- expect(select.props().value).toBe('+34');
273
- });
274
- });
275
-
276
- describe('and country code', () => {
277
- beforeEach(() => {
278
- useIntl.mockReturnValue({ locale: 'es-ES', formatMessage });
279
- component = shallow(<PhoneNumberInput {...props} countryCode="US" />);
280
- select = component.find(PREFIX_SELECT_SELECTOR);
281
- input = component.find(NUMBER_SELECTOR);
282
- });
283
-
284
- it('should override locale prefix with country specific prefix', () => {
285
- expect(select.props().value).toBe('+1');
286
- });
287
- });
288
- });
289
- });
290
-
291
- describe('when user insert valid value', () => {
292
- beforeEach(() => {
293
- component = mount(<PhoneNumberInput {...props} />);
294
- select = component.find(PREFIX_SELECT_SELECTOR);
295
- input = component.find(NUMBER_SELECTOR);
296
- });
297
-
298
- it('should trigger onChange handler', () => {
299
- input.simulate('change', { target: { value: '123' } });
300
- expect(props.onChange).toHaveBeenCalledWith('+44123', '+44');
301
- });
302
- });
303
-
304
- describe('when user insert an invalid number', () => {
305
- it('should trigger onChange with null value', () => {
306
- component = mount(<PhoneNumberInput {...props} initialValue="+12345678" />);
307
- input = component.find(NUMBER_SELECTOR);
308
-
309
- input.simulate('change', { target: { value: '1' } });
310
- expect(props.onChange).toHaveBeenCalledWith(null, '+1');
311
- });
312
-
313
- it("shouldn't re-trigger onChange and set previousReturned state", () => {
314
- component = shallow(<PhoneNumberInput {...props} />);
315
- select = component.find(PREFIX_SELECT_SELECTOR);
316
- input = component.find(NUMBER_SELECTOR);
317
-
318
- select.simulate('change', { value: { value: '+1', label: '+1' } });
319
- input.simulate('change', { target: { value: '12' } });
320
- expect(props.onChange).not.toHaveBeenCalled();
321
- });
322
- });
323
-
324
- describe('when user insert invalid character', () => {
325
- it('should strip them', () => {
326
- component = mount(<PhoneNumberInput {...props} value="+12345678" />);
327
- input = component.find(NUMBER_SELECTOR);
328
-
329
- input.simulate('change', { target: { value: '123--' } });
330
- expect(props.onChange).toHaveBeenCalledWith('+44123', '+44');
331
- });
332
- });
333
-
334
- describe('overlapping prefix and suffix numbers', () => {
335
- it("shouldn't change the prefix number on matching suffix input", () => {
336
- component = mount(<PhoneNumberInput {...props} countryCode="eg" />);
337
- component.find(NUMBER_SELECTOR).simulate('change', { target: { value: '1111111' } });
338
-
339
- expect(component.find(NUMBER_SELECTOR).props().value).toBe('1111111');
340
- expect(props.onChange).toHaveBeenCalledWith('+201111111', '+20');
341
- });
342
- });
343
-
344
- describe('when selectProps is supplied', () => {
345
- beforeEach(() => {
346
- component = shallow(
347
- <PhoneNumberInput selectProps={{ className: 'custom-class' }} {...props} />,
348
- );
349
- });
350
-
351
- it('renders Select component with expected props', () => {
352
- const select = component.find(PREFIX_SELECT_SELECTOR);
353
- expect(select.prop('className')).toBe('custom-class');
354
- });
355
- });
356
- });
@@ -1,56 +0,0 @@
1
- import { shallow, mount } from 'enzyme';
2
-
3
- import SlidingPanel from './SlidingPanel';
4
-
5
- describe('SlidingPanel', () => {
6
- let component;
7
- const props = {
8
- open: true,
9
- position: 'left',
10
- children: null,
11
- className: undefined,
12
- slidingPanelPositionFixed: false,
13
- showSlidingPanelBorder: false,
14
- testId: undefined,
15
- };
16
-
17
- it('renders with right props', () => {
18
- component = mount(<SlidingPanel {...props} />);
19
- expect(component.find(SlidingPanel)).toHaveLength(1);
20
- expect(component.find(SlidingPanel).props()).toStrictEqual({ ...props });
21
- });
22
-
23
- it('renders CSSTransition with right props', () => {
24
- component = shallow(<SlidingPanel {...props} />);
25
-
26
- expect(cssTransition()).toHaveLength(1);
27
-
28
- expect(cssTransition().props()).toEqual({
29
- className: 'sliding-panel sliding-panel--open-left',
30
- children: null,
31
- });
32
- });
33
-
34
- it('adds fixed class', () => {
35
- component = shallow(<SlidingPanel {...props} slidingPanelPositionFixed />);
36
- expect(cssTransition().prop('className')).toBe(
37
- 'sliding-panel sliding-panel--open-left sliding-panel--fixed',
38
- );
39
- });
40
-
41
- it('adds border classes if showSlidingPanelBorder is set to true', () => {
42
- component = shallow(<SlidingPanel {...props} showSlidingPanelBorder />);
43
- expect(cssTransition().prop('className')).toBe(
44
- 'sliding-panel sliding-panel--open-left sliding-panel--border-left',
45
- );
46
- component = shallow(<SlidingPanel {...props} showSlidingPanelBorder={false} position="left" />);
47
- expect(cssTransition().prop('className')).toBe('sliding-panel sliding-panel--open-left');
48
-
49
- component = shallow(<SlidingPanel {...props} showSlidingPanelBorder position="top" />);
50
- expect(cssTransition().prop('className')).toBe(
51
- 'sliding-panel sliding-panel--open-top sliding-panel--border-top',
52
- );
53
- });
54
-
55
- const cssTransition = () => component.find('div');
56
- });