@transferwise/components 46.52.3 → 46.53.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 (121) hide show
  1. package/build/dateLookup/dateTrigger/DateTrigger.js +8 -4
  2. package/build/dateLookup/dateTrigger/DateTrigger.js.map +1 -1
  3. package/build/dateLookup/dateTrigger/DateTrigger.mjs +8 -4
  4. package/build/dateLookup/dateTrigger/DateTrigger.mjs.map +1 -1
  5. package/build/field/Field.js +36 -8
  6. package/build/field/Field.js.map +1 -1
  7. package/build/field/Field.mjs +37 -9
  8. package/build/field/Field.mjs.map +1 -1
  9. package/build/i18n/en.json +1 -0
  10. package/build/i18n/en.json.js +1 -0
  11. package/build/i18n/en.json.js.map +1 -1
  12. package/build/i18n/en.json.mjs +1 -0
  13. package/build/i18n/en.json.mjs.map +1 -1
  14. package/build/index.js +2 -2
  15. package/build/index.mjs +1 -1
  16. package/build/inlineAlert/InlineAlert.js +13 -6
  17. package/build/inlineAlert/InlineAlert.js.map +1 -1
  18. package/build/inlineAlert/InlineAlert.mjs +13 -6
  19. package/build/inlineAlert/InlineAlert.mjs.map +1 -1
  20. package/build/label/Label.js +35 -4
  21. package/build/label/Label.js.map +1 -1
  22. package/build/label/Label.messages.js +12 -0
  23. package/build/label/Label.messages.js.map +1 -0
  24. package/build/label/Label.messages.mjs +10 -0
  25. package/build/label/Label.messages.mjs.map +1 -0
  26. package/build/label/Label.mjs +36 -5
  27. package/build/label/Label.mjs.map +1 -1
  28. package/build/main.css +4 -8
  29. package/build/styles/dateLookup/dateTrigger/DateTrigger.css +0 -8
  30. package/build/styles/field/Field.css +4 -0
  31. package/build/styles/main.css +4 -8
  32. package/build/tabs/Tab.js +13 -38
  33. package/build/tabs/Tab.js.map +1 -1
  34. package/build/tabs/Tab.mjs +13 -34
  35. package/build/tabs/Tab.mjs.map +1 -1
  36. package/build/tabs/TabList.js +3 -11
  37. package/build/tabs/TabList.js.map +1 -1
  38. package/build/tabs/TabList.mjs +3 -7
  39. package/build/tabs/TabList.mjs.map +1 -1
  40. package/build/tabs/TabPanel.js +3 -16
  41. package/build/tabs/TabPanel.js.map +1 -1
  42. package/build/tabs/TabPanel.mjs +3 -12
  43. package/build/tabs/TabPanel.mjs.map +1 -1
  44. package/build/tabs/Tabs.js +24 -48
  45. package/build/tabs/Tabs.js.map +1 -1
  46. package/build/tabs/Tabs.mjs +24 -47
  47. package/build/tabs/Tabs.mjs.map +1 -1
  48. package/build/tabs/utils.js +0 -1
  49. package/build/tabs/utils.js.map +1 -1
  50. package/build/tabs/utils.mjs +0 -1
  51. package/build/tabs/utils.mjs.map +1 -1
  52. package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
  53. package/build/types/field/Field.d.ts +4 -2
  54. package/build/types/field/Field.d.ts.map +1 -1
  55. package/build/types/index.d.ts +2 -1
  56. package/build/types/index.d.ts.map +1 -1
  57. package/build/types/inlineAlert/InlineAlert.d.ts +9 -0
  58. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  59. package/build/types/label/Label.d.ts +21 -1
  60. package/build/types/label/Label.d.ts.map +1 -1
  61. package/build/types/label/Label.messages.d.ts +8 -0
  62. package/build/types/label/Label.messages.d.ts.map +1 -0
  63. package/build/types/label/index.d.ts +3 -0
  64. package/build/types/label/index.d.ts.map +1 -0
  65. package/build/types/tabs/Tab.d.ts +12 -1
  66. package/build/types/tabs/Tab.d.ts.map +1 -1
  67. package/build/types/tabs/TabList.d.ts +3 -8
  68. package/build/types/tabs/TabList.d.ts.map +1 -1
  69. package/build/types/tabs/TabPanel.d.ts +6 -14
  70. package/build/types/tabs/TabPanel.d.ts.map +1 -1
  71. package/build/types/tabs/Tabs.d.ts +83 -30
  72. package/build/types/tabs/Tabs.d.ts.map +1 -1
  73. package/build/types/tabs/index.d.ts +2 -1
  74. package/build/types/tabs/index.d.ts.map +1 -1
  75. package/build/types/tabs/utils.d.ts +12 -7
  76. package/build/types/tabs/utils.d.ts.map +1 -1
  77. package/package.json +2 -2
  78. package/src/dateInput/DateInput.tests.story.tsx +6 -42
  79. package/src/dateLookup/DateLookup.rtl.spec.tsx +1 -1
  80. package/src/dateLookup/dateTrigger/DateTrigger.css +0 -8
  81. package/src/dateLookup/dateTrigger/DateTrigger.less +0 -8
  82. package/src/dateLookup/dateTrigger/DateTrigger.spec.js +1 -1
  83. package/src/dateLookup/dateTrigger/DateTrigger.tsx +9 -4
  84. package/src/field/Field.css +4 -0
  85. package/src/field/Field.less +5 -0
  86. package/src/field/Field.spec.tsx +41 -5
  87. package/src/field/Field.story.tsx +105 -7
  88. package/src/field/Field.tsx +34 -10
  89. package/src/i18n/en.json +1 -0
  90. package/src/index.ts +2 -1
  91. package/src/inlineAlert/InlineAlert.story.tsx +7 -72
  92. package/src/inlineAlert/InlineAlert.tsx +14 -3
  93. package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.js +5 -10
  94. package/src/inputs/InputGroup.spec.tsx +1 -1
  95. package/src/inputs/SearchInput.spec.tsx +1 -1
  96. package/src/inputs/SelectInput.spec.tsx +1 -1
  97. package/src/label/Label.messages.tsx +8 -0
  98. package/src/label/Label.spec.tsx +53 -4
  99. package/src/label/Label.story.tsx +32 -26
  100. package/src/label/Label.tsx +47 -2
  101. package/src/label/index.ts +2 -0
  102. package/src/main.css +4 -8
  103. package/src/main.less +1 -0
  104. package/src/moneyInput/MoneyInput.story.tsx +11 -11
  105. package/src/radioGroup/RadioGroup.rtl.spec.tsx +1 -1
  106. package/src/select/Select.rtl.spec.tsx +1 -1
  107. package/src/switch/Switch.spec.tsx +1 -1
  108. package/src/switch/Switch.story.tsx +19 -21
  109. package/src/tabs/Tab.tsx +72 -0
  110. package/src/tabs/TabList.tsx +11 -0
  111. package/src/tabs/TabPanel.tsx +14 -0
  112. package/src/tabs/{Tabs.story.js → Tabs.story.tsx} +1 -1
  113. package/src/tabs/{Tabs.js → Tabs.tsx} +111 -74
  114. package/src/tabs/index.ts +2 -0
  115. package/src/tabs/{utils.spec.js → utils.spec.ts} +24 -21
  116. package/src/tabs/{utils.js → utils.ts} +15 -9
  117. package/src/field/Field.tests.story.tsx +0 -33
  118. package/src/tabs/Tab.js +0 -71
  119. package/src/tabs/TabList.js +0 -15
  120. package/src/tabs/TabPanel.js +0 -20
  121. package/src/tabs/index.js +0 -1
@@ -1,36 +1,42 @@
1
1
  const MIN_SWIPE_DISTANCE = 50;
2
2
  const MIN_SWIPE_VELOCITY = 0.1;
3
3
 
4
- const swipedSignificantDistance = (difference) => Math.abs(difference) > MIN_SWIPE_DISTANCE;
4
+ const swipedSignificantDistance = (difference: number) => Math.abs(difference) > MIN_SWIPE_DISTANCE;
5
5
 
6
- const swipedWithSignificantVelocity = (velocity) => velocity > MIN_SWIPE_VELOCITY;
6
+ const swipedWithSignificantVelocity = (velocity: number) => velocity > MIN_SWIPE_VELOCITY;
7
7
 
8
- export const getSwipeVelocity = (start, end) => {
8
+ export interface Swipe {
9
+ x: number;
10
+ y: number;
11
+ time: number;
12
+ }
13
+
14
+ export const getSwipeVelocity = (start: Swipe, end: Swipe) => {
9
15
  const timePassed = end.time - start.time;
10
16
 
11
17
  return getSwipeDifference(start, end) / timePassed;
12
18
  };
13
19
 
14
- export const getSwipeDifference = (start, end, axis = 'x') => {
20
+ export const getSwipeDifference = (start: Swipe, end: Swipe, axis: 'x' | 'y' = 'x') => {
15
21
  return Math.abs(start[axis] - end[axis]);
16
22
  };
17
23
 
18
- export const swipedLeftToRight = (start, end) => {
24
+ export const swipedLeftToRight = (start: Swipe, end: Swipe) => {
19
25
  return end.x > start.x;
20
26
  };
21
27
 
22
- export const swipedRightToLeft = (start, end) => {
28
+ export const swipedRightToLeft = (start: Swipe, end: Swipe) => {
23
29
  return start.x > end.x;
24
30
  };
25
31
 
26
- export const swipeShouldChangeTab = (start, end) => {
32
+ export const swipeShouldChangeTab = (start: Swipe, end: Swipe) => {
27
33
  const difference = getSwipeDifference(start, end);
28
34
  const velocity = getSwipeVelocity(start, end);
29
35
 
30
36
  return swipedSignificantDistance(difference) && swipedWithSignificantVelocity(velocity);
31
37
  };
32
38
 
33
- export function getVelocity(coords) {
39
+ export function getVelocity(coords: Swipe[]) {
34
40
  try {
35
41
  const relevant = coords.slice(Math.max(coords.length - 5, 1));
36
42
  const first = relevant[0];
@@ -47,5 +53,5 @@ export function getVelocity(coords) {
47
53
  `1 - Math.E ** (-0.005 * difference)` provides a % value of how far we want to translate (0.005 being the rate)
48
54
  `Math.min(150, window.innerWidth / 3)` provides the maximum translate value
49
55
  */
50
- export const getElasticDragDifference = (difference) =>
56
+ export const getElasticDragDifference = (difference: number) =>
51
57
  Math.min(150, window.innerWidth / 3) * (1 - Math.E ** (-0.005 * difference));
@@ -1,33 +0,0 @@
1
- import { useState } from 'react';
2
-
3
- import { Input } from '../inputs/Input';
4
- import { Field } from './Field';
5
- import { Sentiment } from '../common';
6
-
7
- export default {
8
- component: Field,
9
- title: 'Field/Tests',
10
- };
11
-
12
- export const WithHelpAndErrorOnBlur = () => {
13
- const [value, setValue] = useState('This is some text');
14
- const [error, setError] = useState<string | undefined>(undefined);
15
- return (
16
- <Field
17
- label="Phone number"
18
- sentiment={error ? Sentiment.NEGATIVE : Sentiment.NEUTRAL}
19
- message={error || 'Please include country code'}
20
- >
21
- <Input
22
- value={value}
23
- onChange={({ target }) => {
24
- setValue(target.value);
25
- setError(undefined);
26
- }}
27
- onBlur={() => {
28
- setError('Something went wrong');
29
- }}
30
- />
31
- </Field>
32
- );
33
- };
package/src/tabs/Tab.js DELETED
@@ -1,71 +0,0 @@
1
- import { clsx } from 'clsx';
2
- import PropTypes from 'prop-types';
3
- import { forwardRef, useEffect, useRef } from 'react';
4
-
5
- const Tab = forwardRef(
6
- (
7
- { children, id, disabled, panelId, selected, onKeyDown, onClick, style, focusTab },
8
- reference,
9
- ) => {
10
- const firstUpdate = useRef(true);
11
-
12
- const checkFocus = () => {
13
- if (firstUpdate.current) {
14
- firstUpdate.current = false;
15
- return;
16
- }
17
-
18
- if (selected && focusTab) {
19
- focusTab();
20
- }
21
- };
22
-
23
- useEffect(() => {
24
- checkFocus();
25
- }, [selected]);
26
-
27
- return (
28
- <li
29
- ref={reference}
30
- className={clsx('tabs__tab', selected ? 'np-text-body-large-bold' : 'np-text-body-large', {
31
- 'tabs__tab--selected': selected,
32
- clickable: !disabled,
33
- disabled,
34
- })}
35
- role="tab"
36
- id={id}
37
- aria-selected={selected ? 'true' : 'false'}
38
- aria-disabled={disabled ? 'true' : 'false'}
39
- aria-controls={disabled ? null : panelId}
40
- tabIndex="0"
41
- style={style}
42
- onKeyDown={disabled ? null : onKeyDown}
43
- onClick={onClick}
44
- >
45
- <span className="tabs__tab__content">{children}</span>
46
- </li>
47
- );
48
- },
49
- );
50
-
51
- Tab.defaultProps = {
52
- disabled: false,
53
- selected: false,
54
- onClick: null,
55
- style: null,
56
- focusTab: null,
57
- };
58
-
59
- Tab.propTypes = {
60
- children: PropTypes.node.isRequired,
61
- disabled: PropTypes.bool,
62
- selected: PropTypes.bool,
63
- id: PropTypes.string.isRequired,
64
- panelId: PropTypes.string.isRequired,
65
- style: PropTypes.shape({ width: PropTypes.string }),
66
- focusTab: PropTypes.func,
67
- onKeyDown: PropTypes.func.isRequired,
68
- onClick: PropTypes.func,
69
- };
70
-
71
- export default Tab;
@@ -1,15 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- const TabList = ({ children }) => {
4
- return (
5
- <ul className="tabs__tab-list" role="tablist">
6
- {children}
7
- </ul>
8
- );
9
- };
10
-
11
- TabList.propTypes = {
12
- children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
13
- };
14
-
15
- export default TabList;
@@ -1,20 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- const TabPanel = ({ children, id, tabId, style }) => {
4
- return (
5
- <div className="tabs__panel" role="tabpanel" id={id} aria-labelledby={tabId} style={style}>
6
- {children}
7
- </div>
8
- );
9
- };
10
-
11
- TabPanel.propTypes = {
12
- children: PropTypes.node.isRequired,
13
- id: PropTypes.string.isRequired,
14
- tabId: PropTypes.string.isRequired,
15
- style: PropTypes.shape({
16
- width: PropTypes.string.isRequired,
17
- }).isRequired,
18
- };
19
-
20
- export default TabPanel;
package/src/tabs/index.js DELETED
@@ -1 +0,0 @@
1
- export { default } from './Tabs';