@transferwise/components 46.79.1 → 46.81.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 (123) hide show
  1. package/build/avatar/Avatar.js +3 -0
  2. package/build/avatar/Avatar.js.map +1 -1
  3. package/build/avatar/Avatar.mjs +3 -0
  4. package/build/avatar/Avatar.mjs.map +1 -1
  5. package/build/avatarView/AvatarView.js +175 -0
  6. package/build/avatarView/AvatarView.js.map +1 -0
  7. package/build/avatarView/AvatarView.mjs +173 -0
  8. package/build/avatarView/AvatarView.mjs.map +1 -0
  9. package/build/avatarView/NotificationDot.js +59 -0
  10. package/build/avatarView/NotificationDot.js.map +1 -0
  11. package/build/avatarView/NotificationDot.mjs +57 -0
  12. package/build/avatarView/NotificationDot.mjs.map +1 -0
  13. package/build/avatarWrapper/AvatarWrapper.js +10 -4
  14. package/build/avatarWrapper/AvatarWrapper.js.map +1 -1
  15. package/build/avatarWrapper/AvatarWrapper.mjs +10 -4
  16. package/build/avatarWrapper/AvatarWrapper.mjs.map +1 -1
  17. package/build/badge/Badge.js +16 -4
  18. package/build/badge/Badge.js.map +1 -1
  19. package/build/badge/Badge.mjs +15 -3
  20. package/build/badge/Badge.mjs.map +1 -1
  21. package/build/badge/BadgeAssets.js +60 -0
  22. package/build/badge/BadgeAssets.js.map +1 -0
  23. package/build/badge/BadgeAssets.mjs +58 -0
  24. package/build/badge/BadgeAssets.mjs.map +1 -0
  25. package/build/button/Button.js.map +1 -1
  26. package/build/button/Button.mjs.map +1 -1
  27. package/build/button/legacyUtils/legacyUtils.js.map +1 -1
  28. package/build/button/legacyUtils/legacyUtils.mjs.map +1 -1
  29. package/build/common/circle/Circle.js +19 -1
  30. package/build/common/circle/Circle.js.map +1 -1
  31. package/build/common/circle/Circle.mjs +19 -1
  32. package/build/common/circle/Circle.mjs.map +1 -1
  33. package/build/i18n/th.json +5 -0
  34. package/build/i18n/th.json.js +5 -0
  35. package/build/i18n/th.json.js.map +1 -1
  36. package/build/i18n/th.json.mjs +5 -0
  37. package/build/i18n/th.json.mjs.map +1 -1
  38. package/build/i18n/zh-HK.json +5 -0
  39. package/build/i18n/zh-HK.json.js +5 -0
  40. package/build/i18n/zh-HK.json.js.map +1 -1
  41. package/build/i18n/zh-HK.json.mjs +5 -0
  42. package/build/i18n/zh-HK.json.mjs.map +1 -1
  43. package/build/index.js +18 -13
  44. package/build/index.js.map +1 -1
  45. package/build/index.mjs +10 -7
  46. package/build/index.mjs.map +1 -1
  47. package/build/main.css +74 -5
  48. package/build/styles/avatarView/AvatarView.css +36 -0
  49. package/build/styles/avatarView/NotificationDot.css +20 -0
  50. package/build/styles/badge/Badge.css +6 -5
  51. package/build/styles/common/circle/Circle.css +32 -0
  52. package/build/styles/main.css +74 -5
  53. package/build/types/avatar/Avatar.d.ts +3 -0
  54. package/build/types/avatar/Avatar.d.ts.map +1 -1
  55. package/build/types/avatarView/AvatarView.d.ts +26 -0
  56. package/build/types/avatarView/AvatarView.d.ts.map +1 -0
  57. package/build/types/avatarView/NotificationDot.d.ts +8 -0
  58. package/build/types/avatarView/NotificationDot.d.ts.map +1 -0
  59. package/build/types/avatarView/index.d.ts +3 -0
  60. package/build/types/avatarView/index.d.ts.map +1 -0
  61. package/build/types/avatarWrapper/AvatarWrapper.d.ts +3 -0
  62. package/build/types/avatarWrapper/AvatarWrapper.d.ts.map +1 -1
  63. package/build/types/badge/Badge.d.ts +9 -4
  64. package/build/types/badge/Badge.d.ts.map +1 -1
  65. package/build/types/badge/BadgeAssets.d.ts +14 -0
  66. package/build/types/badge/BadgeAssets.d.ts.map +1 -0
  67. package/build/types/badge/index.d.ts +2 -0
  68. package/build/types/badge/index.d.ts.map +1 -1
  69. package/build/types/button/Button.d.ts +1 -1
  70. package/build/types/button/Button.d.ts.map +1 -1
  71. package/build/types/button/legacyUtils/legacyUtils.d.ts +2 -2
  72. package/build/types/button/legacyUtils/legacyUtils.d.ts.map +1 -1
  73. package/build/types/common/circle/Circle.d.ts +2 -0
  74. package/build/types/common/circle/Circle.d.ts.map +1 -1
  75. package/build/types/index.d.ts +3 -1
  76. package/build/types/index.d.ts.map +1 -1
  77. package/build/types/test-utils/index.d.ts +158 -0
  78. package/build/types/test-utils/index.d.ts.map +1 -0
  79. package/build/types/test-utils/jest.setup.d.ts +2 -0
  80. package/build/types/test-utils/jest.setup.d.ts.map +1 -0
  81. package/package.json +2 -1
  82. package/src/avatar/Avatar.tsx +3 -0
  83. package/src/avatarView/AvatarView.css +36 -0
  84. package/src/avatarView/AvatarView.less +27 -0
  85. package/src/avatarView/AvatarView.story.tsx +467 -0
  86. package/src/avatarView/AvatarView.tsx +171 -0
  87. package/src/avatarView/NotificationDot.css +20 -0
  88. package/src/avatarView/NotificationDot.less +24 -0
  89. package/src/avatarView/NotificationDot.tsx +35 -0
  90. package/src/avatarView/index.ts +2 -0
  91. package/src/avatarWrapper/AvatarWrapper.story.tsx +19 -0
  92. package/src/avatarWrapper/AvatarWrapper.tsx +3 -0
  93. package/src/badge/Badge.css +6 -5
  94. package/src/badge/Badge.less +4 -3
  95. package/src/badge/Badge.tsx +20 -6
  96. package/src/badge/BadgeAssets.tsx +61 -0
  97. package/src/badge/index.ts +3 -0
  98. package/src/button/{Button.spec.js → Button.spec.tsx} +3 -2
  99. package/src/button/Button.tsx +1 -1
  100. package/src/button/legacyUtils/{legacyUtils.spec.js → legacyUtils.spec.tsx} +1 -1
  101. package/src/button/legacyUtils/legacyUtils.ts +2 -2
  102. package/src/circularButton/CircularButton.spec.tsx +0 -36
  103. package/src/common/circle/Circle.css +32 -0
  104. package/src/common/circle/Circle.less +35 -0
  105. package/src/common/circle/Circle.tsx +24 -1
  106. package/src/flowNavigation/FlowNavigation.story.tsx +19 -52
  107. package/src/i18n/th.json +5 -0
  108. package/src/i18n/zh-HK.json +5 -0
  109. package/src/index.ts +3 -0
  110. package/src/listItem/ListItem.story.tsx +5 -47
  111. package/src/main.css +74 -5
  112. package/src/main.less +1 -0
  113. package/src/modal/{Modal.rtl.spec.js → Modal.rtl.spec.tsx} +8 -7
  114. package/src/overlayHeader/OverlayHeader.story.tsx +6 -14
  115. package/src/slidingPanel/SlidingPanel.spec.js +1 -1
  116. package/src/ssr.spec.tsx +264 -0
  117. package/src/test-utils/{index.js → index.tsx} +11 -6
  118. package/src/test-utils/{jest.setup.js → jest.setup.ts} +13 -8
  119. package/src/circularButton/__snapshots__/CircularButton.spec.tsx.snap +0 -381
  120. package/src/ssr.spec.js +0 -256
  121. /package/src/button/__snapshots__/{Button.spec.js.snap → Button.spec.tsx.snap} +0 -0
  122. /package/src/dimmer/{Dimmer.rtl.spec.js → Dimmer.rtl.spec.tsx} +0 -0
  123. /package/src/info/{Info.spec.js → Info.spec.jsx} +0 -0
@@ -0,0 +1,264 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { renderToString } from 'react-dom/server';
5
+
6
+ import en from './i18n/en.json';
7
+
8
+ import * as exposedLibraryItems from '.';
9
+
10
+ type ExposedLibraryItemsType = typeof exposedLibraryItems;
11
+ type ExposedLibraryKeysType = keyof ExposedLibraryItemsType;
12
+
13
+ const excluded = new Set<ExposedLibraryKeysType | string>([
14
+ // hooks
15
+ 'useSnackbar',
16
+ 'useDirection',
17
+ 'useLayout',
18
+ 'useScreenSize',
19
+
20
+ // specific components
21
+ 'Provider',
22
+ 'BottomSheet',
23
+ 'DropFade',
24
+ 'SelectInputTriggerButton',
25
+ 'Panel',
26
+ 'ResponsivePanel',
27
+
28
+ // enums
29
+ 'Size',
30
+ 'Width',
31
+ 'Sentiment',
32
+ 'Variant',
33
+ 'Priority',
34
+ 'ControlType',
35
+ 'Type',
36
+ 'Theme',
37
+ 'DateMode',
38
+ 'MonthFormat',
39
+ 'Position',
40
+ 'Scroll',
41
+ 'ProfileType',
42
+ 'Breakpoint',
43
+ 'Layout',
44
+ 'Status',
45
+ 'MarkdownNodeType',
46
+ 'AvatarType',
47
+ 'InfoPresentation',
48
+ 'UploadStep',
49
+ 'DecisionPresentation',
50
+ 'DecisionType',
51
+ 'AlertArrowPosition',
52
+ 'LogoType',
53
+ 'FileType',
54
+ 'Direction',
55
+ 'Typography',
56
+
57
+ // types
58
+ 'SearchInputProps',
59
+ 'SelectInputItem',
60
+ 'SelectInputOptionContentProps',
61
+ 'SelectInputProps',
62
+ 'UploadedFile',
63
+ 'UploadError',
64
+ 'UploadResponse',
65
+ 'LayoutDirection',
66
+
67
+ // utils
68
+ 'SUPPORTED_LANGUAGES',
69
+ 'RTL_LANGUAGES',
70
+ 'DEFAULT_LANG',
71
+ 'DEFAULT_LOCALE',
72
+ 'adjustLocale',
73
+ 'getLangFromLocale',
74
+ 'getCountryFromLocale',
75
+ 'getDirectionFromLocale',
76
+ 'isServerSide',
77
+ 'isBrowser',
78
+
79
+ // other
80
+ 'translations',
81
+ ]);
82
+
83
+ function isNotExcluded(item: ExposedLibraryKeysType) {
84
+ return !excluded.has(item);
85
+ }
86
+
87
+ describe('Server side rendering', () => {
88
+ const componentNames = (
89
+ Object.keys(exposedLibraryItems) as (keyof ExposedLibraryItemsType)[]
90
+ ).filter((moduleName) => isNotExcluded(moduleName));
91
+
92
+ // stick all possible properties we might need to render all components in here
93
+ const allProps: Record<string, unknown> = {
94
+ currencies: [],
95
+ steps: [],
96
+ stepper: {
97
+ steps: [],
98
+ },
99
+ items: [],
100
+ children: 'yo',
101
+ id: '1',
102
+ text: 'test',
103
+ timeout: 0,
104
+ timestamp: 1,
105
+ title: 'trolo',
106
+ name: 'lolo',
107
+ label: 'hello',
108
+ content: 'world',
109
+ currency: 'XYZ',
110
+ amount: 0,
111
+ options: [],
112
+ model: {},
113
+ fields: {},
114
+ media: <h1>Hello</h1>,
115
+ onClick: jest.fn(),
116
+ onChange: jest.fn(),
117
+ status: 'processing',
118
+ size: 'sm',
119
+ body: 'body',
120
+ onClose: jest.fn(),
121
+ onDismiss: jest.fn(),
122
+ onRemove: jest.fn(),
123
+ radios: [
124
+ {
125
+ id: 'id-test-0',
126
+ label: 'Radio1',
127
+ },
128
+ {
129
+ id: 'id-test-0',
130
+ label: 'Radio1',
131
+ },
132
+ ],
133
+ position: 'left',
134
+ open: true,
135
+ tabs: [],
136
+ direction: {
137
+ xs: 'column',
138
+ sm: 'row',
139
+ md: 'column',
140
+ lg: 'row',
141
+ },
142
+ alt: '',
143
+ src: '',
144
+ details: 'yo',
145
+ icon: <svg />,
146
+ badge: <svg />,
147
+ link: 'link',
148
+ href: '#',
149
+ description: 'description',
150
+ 'aria-label': 'a label',
151
+ logo: <svg />,
152
+ chips: [
153
+ {
154
+ value: 1,
155
+ label: 'One',
156
+ },
157
+ {
158
+ value: 2,
159
+ label: 'Two',
160
+ },
161
+ ],
162
+ segments: [
163
+ {
164
+ id: '1',
165
+ value: 'accounting',
166
+ label: 'Accounting',
167
+ },
168
+ {
169
+ id: '2',
170
+ value: 'payroll',
171
+ label: 'Payroll',
172
+ },
173
+ {
174
+ id: '3',
175
+ value: 'reporting',
176
+ label: 'Reporting',
177
+ },
178
+ ],
179
+ };
180
+
181
+ // Override props in case of name collision.
182
+ const overrideProps: Partial<Record<keyof ExposedLibraryItemsType, Record<string, unknown>>> = {
183
+ Alert: { children: undefined, message: 'Fluffy kittens', size: undefined },
184
+ Card: { isExpanded: true },
185
+ CheckboxButton: { children: undefined, onChange: jest.fn() },
186
+ Typeahead: { size: 'md' },
187
+ InputWithDisplayFormat: { displayPattern: '**-**' },
188
+ TextareaWithDisplayFormat: { displayPattern: '**-**' },
189
+ Sticky: { position: 'top' },
190
+ MoneyInput: { selectedCurrency: { currency: 'EUR' } },
191
+ Tabs: { selected: 1, onTabSelect: jest.fn() },
192
+ Markdown: { children: '# Markdown string' },
193
+ SnackbarConsumer: {
194
+ children: jest.fn(),
195
+ },
196
+ SnackbarContext: {
197
+ children: jest.fn(),
198
+ },
199
+ Popover: {
200
+ children: <div />,
201
+ },
202
+ Progress: {
203
+ progress: { value: 50, max: 100 },
204
+ },
205
+ ProgressBar: {
206
+ progress: { value: 50, max: 100 },
207
+ },
208
+ Field: {
209
+ model: 'a model',
210
+ type: 'text',
211
+ children: <input />,
212
+ },
213
+ Input: {
214
+ children: undefined,
215
+ },
216
+ SearchInput: {
217
+ children: undefined,
218
+ },
219
+ TextArea: {
220
+ children: undefined,
221
+ },
222
+ Summary: {
223
+ status: 'done',
224
+ content: undefined,
225
+ },
226
+ Modal: { position: 'top' },
227
+ ActionOption: { action: 'hello' },
228
+ DateLookup: { value: new Date() },
229
+ Link: { size: 16 },
230
+ Tooltip: { children: <>yo</> },
231
+ SelectOption: { placeholder: { media: <img alt="img" /> } },
232
+ };
233
+
234
+ const { Provider } = exposedLibraryItems;
235
+ type ComponentWithProvider = React.ComponentType<unknown> & {
236
+ Provider?: React.ComponentType<unknown>;
237
+ };
238
+
239
+ componentNames.forEach((componentName: ExposedLibraryKeysType) => {
240
+ it(`can render component: ${componentName}`, () => {
241
+ const Component = exposedLibraryItems[componentName] as ComponentWithProvider;
242
+ const newProps = { ...allProps };
243
+
244
+ Object.keys(overrideProps[componentName] ?? {}).forEach((propertyToOverrideKey) => {
245
+ const key = propertyToOverrideKey as keyof (typeof overrideProps)[typeof componentName];
246
+ newProps[key] = overrideProps?.[componentName]?.[key];
247
+ });
248
+
249
+ const view = renderToString(
250
+ <Provider i18n={{ locale: 'en-GB', messages: en }}>
251
+ {componentName.endsWith('Context') && Component.Provider ? (
252
+ <Component.Provider {...newProps} />
253
+ ) : (
254
+ <div>
255
+ <Component {...newProps} />
256
+ </div>
257
+ )}
258
+ </Provider>,
259
+ );
260
+
261
+ expect(view).toStrictEqual(expect.any(String));
262
+ });
263
+ });
264
+ });
@@ -1,8 +1,9 @@
1
+ import { ReactElement, FC } from 'react';
1
2
  import { render, renderHook } from '@testing-library/react';
2
3
  import { userEvent } from '@testing-library/user-event';
3
4
 
4
5
  import { Provider } from '..';
5
- import { DEFAULT_LOCALE } from '../common/locale';
6
+ import { DEFAULT_LOCALE } from '../common';
6
7
  import en from '../i18n/en.json';
7
8
 
8
9
  /**
@@ -10,9 +11,11 @@ import en from '../i18n/en.json';
10
11
  * Source: https://testing-library.com/docs/example-react-intl/#creating-a-custom-render-function
11
12
  *
12
13
  */
13
- function customRender(ui, { locale = DEFAULT_LOCALE, messages = en, ...renderOptions } = {}) {
14
- // eslint-disable-next-line react/prop-types
15
- const Wrapper = ({ children }) => {
14
+ function customRender(
15
+ ui: ReactElement,
16
+ { locale = DEFAULT_LOCALE, messages = en, ...renderOptions } = {},
17
+ ): ReturnType<typeof render> {
18
+ const Wrapper: FC<{ children: React.ReactNode }> = ({ children }) => {
16
19
  return <Provider i18n={{ locale, messages }}>{children}</Provider>;
17
20
  };
18
21
  return render(ui, { wrapper: Wrapper, ...renderOptions });
@@ -21,9 +24,11 @@ function customRender(ui, { locale = DEFAULT_LOCALE, messages = en, ...renderOpt
21
24
  /**
22
25
  * Custom `renderHook` function which wraps passed elements in Provider component
23
26
  * For more info: https://react-hooks-testing-library.com/usage/advanced-hooks#context
24
- *
25
27
  */
26
- function customRenderHook(callback, { locale = DEFAULT_LOCALE, messages = en } = {}) {
28
+ function customRenderHook(
29
+ callback: () => unknown,
30
+ { locale = DEFAULT_LOCALE, messages = en } = {},
31
+ ) {
27
32
  return renderHook(callback, {
28
33
  wrapper: ({ children }) => <Provider i18n={{ locale, messages }}>{children}</Provider>,
29
34
  });
@@ -1,14 +1,19 @@
1
- require('@testing-library/jest-dom');
1
+ import util from 'node:util';
2
+ import '@testing-library/jest-dom';
2
3
 
3
- const { default: Adapter } = require('@cfaester/enzyme-adapter-react-18');
4
- const Enzyme = require('enzyme');
5
- const util = require('node:util');
4
+ import Adapter from '@cfaester/enzyme-adapter-react-18';
5
+ import Enzyme from 'enzyme';
6
+ import fetchMock from 'jest-fetch-mock';
6
7
 
7
- global.fetch = require('jest-fetch-mock');
8
+ global.fetch = fetchMock as unknown as typeof global.fetch;
8
9
 
10
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
9
11
  Enzyme.configure({ adapter: new Adapter() });
10
12
 
11
- global.requestAnimationFrame = (callback) => callback();
13
+ global.requestAnimationFrame = (callback: (time: number) => void): number => {
14
+ callback(performance.now());
15
+ return 0;
16
+ };
12
17
 
13
18
  Object.defineProperty(global, 'TextEncoder', {
14
19
  value: util.TextEncoder,
@@ -18,7 +23,7 @@ Object.defineProperty(global, 'TextEncoder', {
18
23
  // This mock will make tests fail when props error occurs.
19
24
  const { error, warn } = console;
20
25
  // eslint-disable-next-line no-console
21
- console.error = (message, ...args) => {
26
+ console.error = (message: string, ...args: unknown[]): void => {
22
27
  if (/(Invalid prop|Failed prop type)/i.test(message)) {
23
28
  throw new Error(message);
24
29
  }
@@ -27,7 +32,7 @@ console.error = (message, ...args) => {
27
32
  };
28
33
 
29
34
  // eslint-disable-next-line no-console
30
- console.warn = (message, ...args) => {
35
+ console.warn = (message: string, ...args: unknown[]): void => {
31
36
  if (/(Call to useTheme outside a ThemeProvider)/i.test(message)) {
32
37
  return;
33
38
  }