@transferwise/components 0.0.0-experimental-50e1f17 → 0.0.0-experimental-08d336e

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 (42) hide show
  1. package/build/index.esm.js +3327 -3404
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +3326 -3402
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/logo/Logo.css +1 -1
  7. package/build/styles/main.css +1 -1
  8. package/build/styles/moneyInput/MoneyInput.css +1 -1
  9. package/build/types/common/hooks/useLayout/useLayout.d.ts +9 -6
  10. package/build/types/common/hooks/useLayout/useLayout.d.ts.map +1 -1
  11. package/build/types/index.d.ts +1 -0
  12. package/build/types/index.d.ts.map +1 -1
  13. package/build/types/inputs/SelectInput.d.ts +1 -2
  14. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  15. package/build/types/logo/Logo.d.ts.map +1 -1
  16. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  17. package/package.json +1 -1
  18. package/src/common/hooks/useLayout/useLayout.ts +21 -49
  19. package/src/common/responsivePanel/ResponsivePanel.spec.js +3 -1
  20. package/src/dateLookup/DateLookup.testingLibrary.spec.js +1 -19
  21. package/src/dateLookup/dateHeader/DateHeader.spec.js +2 -0
  22. package/src/drawer/Drawer.rtl.spec.js +3 -1
  23. package/src/drawer/Drawer.spec.js +2 -0
  24. package/src/index.ts +1 -0
  25. package/src/info/Info.spec.js +7 -11
  26. package/src/inputs/SelectInput.tsx +0 -8
  27. package/src/logo/Logo.css +1 -1
  28. package/src/logo/Logo.js +9 -18
  29. package/src/logo/Logo.less +21 -2
  30. package/src/logo/__snapshots__/Logo.spec.js.snap +168 -72
  31. package/src/main.css +1 -1
  32. package/src/modal/Modal.rtl.spec.js +3 -1
  33. package/src/modal/Modal.spec.js +2 -0
  34. package/src/modal/Modal.tsx +2 -2
  35. package/src/moneyInput/MoneyInput.css +1 -1
  36. package/src/moneyInput/MoneyInput.js +34 -82
  37. package/src/moneyInput/MoneyInput.less +28 -24
  38. package/src/moneyInput/MoneyInput.spec.js +112 -243
  39. package/src/moneyInput/MoneyInput.story.tsx +1 -51
  40. package/src/ssr.spec.js +1 -0
  41. package/src/uploadInput/UploadInput.spec.tsx +3 -1
  42. package/src/moneyInput/MoneyInput.rtl.spec.js +0 -71
@@ -1,8 +1,10 @@
1
1
  import { Position } from '../common';
2
- import { render, fireEvent, screen } from '../test-utils';
2
+ import { render, fireEvent, screen, mockMatchMedia } from '../test-utils';
3
3
 
4
4
  import Modal from './Modal';
5
5
 
6
+ mockMatchMedia();
7
+
6
8
  describe('Modal', () => {
7
9
  const props = {
8
10
  onClose: jest.fn(),
@@ -1,10 +1,12 @@
1
1
  import { mount } from 'enzyme';
2
2
 
3
3
  import { Title } from '..';
4
+ import { mockMatchMedia } from '../test-utils';
4
5
 
5
6
  import Modal from './Modal';
6
7
 
7
8
  jest.useFakeTimers();
9
+ mockMatchMedia();
8
10
  jest.mock('../common');
9
11
 
10
12
  const defaultLocale = 'en-GB';
@@ -52,7 +52,7 @@ const Modal = ({
52
52
  }: ModalProps) => {
53
53
  const checkSpecialClasses = (classToCheck: string) =>
54
54
  className?.split(' ').includes(classToCheck);
55
- const { isMobile, isMedium: isTablet } = useLayout();
55
+ const { isMedium } = useLayout();
56
56
 
57
57
  // These should be replaced with props in breaking change.
58
58
  const isCompact = checkSpecialClasses('compact');
@@ -60,7 +60,7 @@ const Modal = ({
60
60
 
61
61
  const contentReference = useRef<HTMLDivElement>(null);
62
62
 
63
- return isMobile || isTablet ? (
63
+ return !isMedium ? (
64
64
  <Drawer
65
65
  open={open}
66
66
  headerTitle={title}
@@ -1 +1 @@
1
- .tw-money-input .tw-money-input__fixed-currency{padding-left:0!important}[dir=rtl] .tw-money-input .tw-money-input__fixed-currency{padding-left:0!important;padding-right:0!important}.tw-money-input .tw-money-input__fixed-currency.input-md .money-input-currency-flag{margin-bottom:2px}.np-theme-personal .tw-money-input .tw-money-input__fixed-currency.input-md .money-input-currency-flag{margin-bottom:1px}.tw-money-input .tw-money-input__fixed-currency.input-lg .money-input-currency-flag{margin-bottom:4px}.np-theme-personal .tw-money-input .tw-money-input__fixed-currency.input-lg .money-input-currency-flag{margin-bottom:3px}.tw-money-input .tw-money-input__fixed-currency .money-input-currency-flag{vertical-align:middle}.tw-money-input .tw-money-input__fixed-currency .np-text-title-subsection{font-weight:var(--font-weight-normal)}.tw-money-input__keyline{background-color:#86a7bd1a;background-color:var(--color-background-neutral);border:1px solid #0000001a;border:1px solid var(--color-border-neutral);height:24px;height:var(--size-24);margin-right:24px;margin-right:var(--size-24);transform:translateY(4px);width:2px}[dir=rtl] .tw-money-input__keyline{margin-left:24px;margin-left:var(--size-24);margin-right:0}.tw-money-input__fixed-currency{position:relative}.tw-money-input__fixed-currency span{color:#5d7079;color:var(--color-content-secondary)}__text{font-size:1rem;font-size:var(--font-size-16)}.input-group-sm .np-text-title-subsection,.input-group-sm .tw-money-input__text{font-size:.875rem;font-size:var(--font-size-14)}.input-group-md .np-text-title-subsection{font-size:1rem;font-size:var(--font-size-16)}.input-group-lg .tw-money-input__text{font-size:1.375rem;font-size:var(--font-size-22)}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-form-control{lol:"money-input";align-items:center;display:flex;max-height:50px}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-form-control span:not(.tw-icon){font-weight:400;font-weight:var(--font-weight-regular);min-width:2.6em}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-form-control .money-input-currency-flag{display:inline-block!important;margin-left:2px;margin-right:2px}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-button-input{box-shadow:none;padding:0 16px;padding:0 var(--padding-small);text-align:center}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-button-input:active,.tw-money-input .amount-currency-select-btn>.np-input-group>.np-button-input:hover:not(:focus){box-shadow:none}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-button-input .np-text-body-large{overflow:visible;text-overflow:clip}.tw-money-input .amount-currency-select-btn>.np-input-group>.np-form-control>span.tw-icon{position:static}.np-theme-personal .tw-money-input__keyline{display:none}.np-theme-personal .tw-money-input.input-group-sm .form-control{min-height:34px}.np-theme-personal .tw-money-input.input-group-md .amount-currency-select-btn .np-form-control--size-md,.np-theme-personal .tw-money-input.input-group-md .form-control{min-height:53px}.np-theme-personal .tw-money-input .tw-money-input__fixed-currency .np-text-title-subsection{color:#768e9c;color:var(--color-content-tertiary);font-weight:600;font-weight:var(--font-weight-semi-bold)}.np-theme-personal .tw-money-input button{border:none}.np-theme-personal .tw-money-input .np-text-title-subsection{color:var(--color-interactive-primary)}.np-theme-personal .tw-money-input .amount-currency-select-btn .money-input-currency-flag{margin-right:0;margin-top:0}.np-theme-personal .tw-money-input .amount-currency-select-btn .np-form-control--size-md .np-text-body-large{margin-left:4px;margin-right:4px}.np-theme-personal .tw-money-input .amount-currency-select-btn .np-form-control--size-lg .np-text-body-large{margin-left:9px;margin-right:9px}
1
+ .tw-money-input .tw-money-input__fixed-currency{padding-left:0!important}[dir=rtl] .tw-money-input .tw-money-input__fixed-currency{padding-left:0!important;padding-right:0!important}.tw-money-input .tw-money-input__fixed-currency.input-md .currency-flag{margin-bottom:2px}.np-theme-personal .tw-money-input .tw-money-input__fixed-currency.input-md .currency-flag{margin-bottom:1px}.tw-money-input .tw-money-input__fixed-currency.input-lg .currency-flag{margin-bottom:4px}.np-theme-personal .tw-money-input .tw-money-input__fixed-currency.input-lg .currency-flag{margin-bottom:3px}.tw-money-input .tw-money-input__fixed-currency .currency-flag{vertical-align:middle}.tw-money-input .tw-money-input__fixed-currency .np-text-title-subsection{font-weight:var(--font-weight-normal)}.tw-money-input__keyline{background-color:#86a7bd1a;background-color:var(--color-background-neutral);border:1px solid #0000001a;border:1px solid var(--color-border-neutral);height:24px;height:var(--size-24);margin-right:24px;margin-right:var(--size-24);transform:translateY(4px);width:2px}[dir=rtl] .tw-money-input__keyline{margin-left:24px;margin-left:var(--size-24);margin-right:0}.tw-money-input__fixed-currency{position:relative}.tw-money-input__fixed-currency span{color:#5d7079;color:var(--color-content-secondary)}__text{font-size:1rem;font-size:var(--font-size-16)}.input-group-sm .np-text-title-subsection,.input-group-sm .tw-money-input__text{font-size:.875rem;font-size:var(--font-size-14)}.input-group-md .np-text-title-subsection{font-size:1rem;font-size:var(--font-size-16)}.input-group-lg .tw-money-input__text{font-size:1.375rem;font-size:var(--font-size-22)}.tw-money-input .amount-currency-select-btn>.np-select>.btn{align-items:center;display:flex;max-height:50px}.tw-money-input .amount-currency-select-btn>.np-select>.btn span:not(.tw-icon){font-weight:400;font-weight:var(--font-weight-regular);min-width:2.6em}.tw-money-input .amount-currency-select-btn>.np-select>.btn .currency-flag{display:inline-block!important;margin-left:2px;margin-right:2px}.tw-money-input .amount-currency-select-btn>.np-select>.np-dropdown-toggle{padding:0 16px;padding:0 var(--padding-small);text-align:center}.np-theme-personal .tw-money-input .amount-currency-select-btn>.np-select>.np-dropdown-toggle,.np-theme-personal .tw-money-input .amount-currency-select-btn>.np-select>.np-dropdown-toggle:active,.np-theme-personal .tw-money-input .amount-currency-select-btn>.np-select>.np-dropdown-toggle:hover:not(:focus){box-shadow:none}.np-theme-personal .tw-money-input .amount-currency-select-btn>.np-select>.np-dropdown-toggle .np-text-body-large{overflow:visible;text-overflow:clip}.np-theme-personal .tw-money-input .amount-currency-select-btn>.np-select>.np-dropdown-toggle .np-text-body-large .tw-money-input__text.np-text-title-subsection{font-weight:600;font-weight:var(--font-weight-semi-bold)}.tw-money-input .amount-currency-select-btn>.np-select>.np-btn>span.tw-icon{position:static}.np-theme-personal .tw-money-input__keyline{display:none}.np-theme-personal .tw-money-input.input-group-sm .form-control{min-height:34px}.np-theme-personal .tw-money-input.input-group-md .amount-currency-select-btn .btn-md,.np-theme-personal .tw-money-input.input-group-md .form-control{min-height:53px}.np-theme-personal .tw-money-input .tw-money-input__fixed-currency .np-text-title-subsection{color:#768e9c;color:var(--color-content-tertiary);font-weight:600;font-weight:var(--font-weight-semi-bold)}.np-theme-personal .tw-money-input button{border:none}.np-theme-personal .tw-money-input .np-text-title-subsection{color:var(--color-interactive-primary)}.np-theme-personal .tw-money-input .np-select-filter:focus{outline:none}.np-theme-personal .tw-money-input .amount-currency-select-btn .currency-flag{margin-right:0;margin-top:0}.np-theme-personal .tw-money-input .amount-currency-select-btn .np-btn-md .np-text-body-large{margin-left:4px;margin-right:4px}.np-theme-personal .tw-money-input .amount-currency-select-btn .np-btn-lg .np-text-body-large{margin-left:9px;margin-right:9px}
@@ -1,5 +1,4 @@
1
1
  import { isEmpty, isNumber, isNull } from '@transferwise/neptune-validation';
2
- import { Flag } from '@wise/art';
3
2
  import classNames from 'classnames';
4
3
  import PropTypes from 'prop-types';
5
4
  import { Component } from 'react';
@@ -10,7 +9,7 @@ import { Key as keyValues } from '../common/key';
10
9
  import keyCodes from '../common/keyCodes';
11
10
  import { Size } from '../common/propsValues/size';
12
11
  import { Input } from '../inputs/Input';
13
- import { SelectInput, SelectInputOptionContent } from '../inputs/SelectInput';
12
+ import Select from '../select';
14
13
  import Title from '../title';
15
14
 
16
15
  import messages from './MoneyInput.messages';
@@ -24,7 +23,7 @@ const Currency = PropTypes.shape({
24
23
  note: PropTypes.string,
25
24
  searchable: PropTypes.string,
26
25
  });
27
-
26
+ const CUSTOM_ACTION = 'CUSTOM_ACTION';
28
27
  const isNumberOrNull = (v) => isNumber(v) || isNull(v);
29
28
 
30
29
  const formatAmountIfSet = (amount, currency, locale, maxLengthOverride) => {
@@ -68,7 +67,6 @@ class MoneyInput extends Component {
68
67
  this.formatMessage = this.props.intl.formatMessage;
69
68
  this.state = {
70
69
  searchQuery: '',
71
- selectedOption: this.props.selectedCurrency,
72
70
  formattedAmount: formatAmountIfSet(
73
71
  props.amount,
74
72
  props.selectedCurrency.currency,
@@ -167,37 +165,14 @@ class MoneyInput extends Component {
167
165
  this.amountFocused = true;
168
166
  };
169
167
 
170
- mapOption = (item) => {
171
- return {
172
- type: 'option',
173
- value: item,
174
- filterMatchers: [item.value, item.label, item.note, item.searchable],
175
- };
176
- };
177
-
178
168
  getSelectOptions() {
179
169
  const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
180
170
 
181
- let formattedOptions = [];
182
- let groupIndex = null;
183
-
184
- selectOptions.forEach((item) => {
185
- if (item.header) {
186
- formattedOptions.push({
187
- type: 'group',
188
- label: item.header,
189
- options: [],
190
- });
191
- groupIndex = formattedOptions.length - 1;
192
- } else {
193
- if (groupIndex === null) {
194
- formattedOptions.push(this.mapOption(item));
195
- } else {
196
- formattedOptions[groupIndex]?.options.push(this.mapOption(item));
197
- }
198
- }
199
- });
200
- return formattedOptions;
171
+ if (this.props.onCustomAction) {
172
+ selectOptions.push({ value: CUSTOM_ACTION, label: this.props.customActionLabel });
173
+ }
174
+
175
+ return selectOptions;
201
176
  }
202
177
 
203
178
  setAmount() {
@@ -226,14 +201,11 @@ class MoneyInput extends Component {
226
201
 
227
202
  handleSelectChange = (value) => {
228
203
  this.handleSearchChange('');
229
- this.setState({ selectedOption: value });
230
- this.props.onCurrencyChange(value);
231
- };
232
204
 
233
- handleCustomAction = () => {
234
- this.handleSearchChange('');
235
- if (this.props.onCustomAction) {
205
+ if (this.props.onCustomAction && value.value === CUSTOM_ACTION) {
236
206
  this.props.onCustomAction();
207
+ } else {
208
+ this.props.onCurrencyChange(value);
237
209
  }
238
210
  };
239
211
 
@@ -253,25 +225,10 @@ class MoneyInput extends Component {
253
225
  const { selectedCurrency, onCurrencyChange, size, addon, id, selectProps, maxLengthOverride } =
254
226
  this.props;
255
227
  const selectOptions = this.getSelectOptions();
256
-
257
- const firstOptionValue = () => {
258
- if (selectOptions.length !== 0) {
259
- const firstOption = selectOptions[0];
260
- if (firstOption.type === 'option') {
261
- return firstOption.value.value;
262
- }
263
- if (firstOption.type === 'group' && firstOption.options.length !== 0) {
264
- return firstOption.options[0].value.value;
265
- }
266
- }
267
- return null;
268
- };
269
-
270
- const firstOption = firstOptionValue();
271
-
272
228
  const isFixedCurrency =
273
- (selectOptions.length === 1 && firstOption === selectedCurrency.currency) ||
274
- !onCurrencyChange;
229
+ !this.state.searchQuery &&
230
+ ((selectOptions.length === 1 && selectOptions[0].currency === selectedCurrency.currency) ||
231
+ !onCurrencyChange);
275
232
 
276
233
  const disabled = !this.props.onAmountChange;
277
234
  return (
@@ -348,35 +305,30 @@ class MoneyInput extends Component {
348
305
  this.style('amount-currency-select-btn'),
349
306
  )}
350
307
  >
351
- <SelectInput
352
- items={selectOptions}
353
- value={this.state.selectedOption}
354
- renderValue={(currency, withinTrigger) => {
355
- return (
356
- <SelectInputOptionContent
357
- title={currency.label}
358
- note={withinTrigger ? undefined : currency.note}
359
- icon={
360
- <span className={classNames('money-input-currency-flag')}>
361
- <Flag code={currency.value} intrinsicSize={24} />
362
- </span>
363
- }
364
- />
365
- );
308
+ <Select
309
+ id={id ? `${id}-select` : undefined}
310
+ classNames={this.props.classNames}
311
+ options={selectOptions}
312
+ selected={{
313
+ ...selectedCurrency,
314
+ label: (
315
+ <Title
316
+ as="span"
317
+ type={Typography.TITLE_SUBSECTION}
318
+ className="tw-money-input__text"
319
+ >
320
+ {selectedCurrency.label}
321
+ </Title>
322
+ ),
323
+ note: null,
366
324
  }}
367
- renderFooter={() =>
368
- this.props.onCustomAction ? (
369
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events
370
- <div role="button" tabIndex="0" onClick={this.handleCustomAction}>
371
- {this.props.customActionLabel}
372
- </div>
373
- ) : null
374
- }
375
325
  placeholder={this.formatMessage(messages.selectPlaceholder)}
376
- filterable
377
- filterPlaceholder={this.props.searchPlaceholder}
378
- disabled={disabled}
326
+ searchPlaceholder={this.props.searchPlaceholder}
327
+ searchValue={this.state.searchQuery}
379
328
  size={size}
329
+ required
330
+ dropdownWidth={Size.LARGE}
331
+ inverse
380
332
  onChange={this.handleSelectChange}
381
333
  onSearchChange={this.handleSearchChange}
382
334
  {...selectProps}
@@ -10,7 +10,7 @@
10
10
  // there's got to be a better way to do it
11
11
 
12
12
  &.input-md {
13
- .money-input-currency-flag {
13
+ .currency-flag {
14
14
  margin-bottom: 2px;
15
15
 
16
16
  .np-theme-personal & {
@@ -20,7 +20,7 @@
20
20
  }
21
21
 
22
22
  &.input-lg {
23
- .money-input-currency-flag {
23
+ .currency-flag {
24
24
  margin-bottom: 4px;
25
25
 
26
26
  .np-theme-personal & {
@@ -29,7 +29,7 @@
29
29
  }
30
30
  }
31
31
 
32
- .money-input-currency-flag {
32
+ .currency-flag {
33
33
  vertical-align: middle;
34
34
  }
35
35
 
@@ -83,8 +83,7 @@
83
83
  }
84
84
  }
85
85
 
86
- .tw-money-input .amount-currency-select-btn > .np-input-group > .np-form-control {
87
- lol: 'money-input';
86
+ .tw-money-input .amount-currency-select-btn > .np-select > .btn {
88
87
  display: flex;
89
88
  align-items: center;
90
89
  max-height: 50px;
@@ -94,35 +93,36 @@
94
93
  font-weight: var(--font-weight-regular);
95
94
  }
96
95
 
97
- .money-input-currency-flag {
96
+ .currency-flag {
98
97
  margin-right: 2px;
99
98
  margin-left: 2px;
100
99
  display: inline-block !important; // override a hidden-xs in select option which has too much logic around it
101
100
  }
102
101
  }
103
102
 
104
- // .np-select -> .np-input-group
105
- // .np-dropdown-toggle -> .np-button-input
106
- // .btn -> .np-form-control
107
- // .currency-flag -> .money-input-currency-flag
108
-
109
- .tw-money-input .amount-currency-select-btn > .np-input-group > .np-button-input {
103
+ .tw-money-input .amount-currency-select-btn > .np-select > .np-dropdown-toggle {
110
104
  padding: 0 var(--padding-small);
111
105
  text-align: center;
112
- box-shadow: none;
113
106
 
114
- &:hover:not(:focus),
115
- &:active {
107
+ .np-theme-personal & {
116
108
  box-shadow: none;
117
- }
118
109
 
119
- .np-text-body-large {
120
- overflow: visible;
121
- text-overflow: clip;
110
+ &:hover:not(:focus),
111
+ &:active {
112
+ box-shadow: none;
113
+ }
114
+
115
+ .np-text-body-large {
116
+ .tw-money-input__text.np-text-title-subsection {
117
+ font-weight: var(--font-weight-semi-bold);
118
+ }
119
+ overflow: visible;
120
+ text-overflow: clip;
121
+ }
122
122
  }
123
123
  }
124
124
 
125
- .tw-money-input .amount-currency-select-btn > .np-input-group > .np-form-control > span.tw-icon {
125
+ .tw-money-input .amount-currency-select-btn > .np-select > .np-btn > span.tw-icon {
126
126
  position: static;
127
127
  }
128
128
 
@@ -139,7 +139,7 @@
139
139
 
140
140
  .tw-money-input.input-group-md {
141
141
  .form-control,
142
- .amount-currency-select-btn .np-form-control--size-md {
142
+ .amount-currency-select-btn .btn-md {
143
143
  min-height: 53px;
144
144
  }
145
145
  }
@@ -160,20 +160,24 @@
160
160
  color: var(--color-interactive-primary);
161
161
  }
162
162
 
163
+ .np-select-filter:focus {
164
+ outline: none;
165
+ }
166
+
163
167
  .amount-currency-select-btn {
164
- .money-input-currency-flag {
168
+ .currency-flag {
165
169
  margin-right: 0;
166
170
  margin-top: 0;
167
171
  }
168
172
 
169
- .np-form-control--size-md {
173
+ .np-btn-md {
170
174
  .np-text-body-large {
171
175
  margin-left: 4px;
172
176
  margin-right: 4px;
173
177
  }
174
178
  }
175
179
 
176
- .np-form-control--size-lg {
180
+ .np-btn-lg {
177
181
  .np-text-body-large {
178
182
  margin-left: 9px;
179
183
  margin-right: 9px;