@transferwise/components 0.0.0-experimental-d11e9c5 → 0.0.0-experimental-76bb7cd

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 (124) hide show
  1. package/build/avatar/Avatar.js +0 -3
  2. package/build/avatar/Avatar.js.map +1 -1
  3. package/build/avatar/Avatar.mjs +0 -3
  4. package/build/avatar/Avatar.mjs.map +1 -1
  5. package/build/avatarWrapper/AvatarWrapper.js +4 -10
  6. package/build/avatarWrapper/AvatarWrapper.js.map +1 -1
  7. package/build/avatarWrapper/AvatarWrapper.mjs +4 -10
  8. package/build/avatarWrapper/AvatarWrapper.mjs.map +1 -1
  9. package/build/badge/Badge.js +1 -3
  10. package/build/badge/Badge.js.map +1 -1
  11. package/build/badge/Badge.mjs +1 -3
  12. package/build/badge/Badge.mjs.map +1 -1
  13. package/build/button/Button.js.map +1 -1
  14. package/build/button/Button.mjs.map +1 -1
  15. package/build/button/legacyUtils/legacyUtils.js.map +1 -1
  16. package/build/button/legacyUtils/legacyUtils.mjs.map +1 -1
  17. package/build/common/circle/Circle.js +1 -17
  18. package/build/common/circle/Circle.js.map +1 -1
  19. package/build/common/circle/Circle.mjs +1 -17
  20. package/build/common/circle/Circle.mjs.map +1 -1
  21. package/build/index.js +121 -128
  22. package/build/index.js.map +1 -1
  23. package/build/index.mjs +29 -33
  24. package/build/index.mjs.map +1 -1
  25. package/build/main.css +5 -109
  26. package/build/styles/badge/Badge.css +5 -6
  27. package/build/styles/common/circle/Circle.css +0 -32
  28. package/build/styles/main.css +5 -109
  29. package/build/types/avatar/Avatar.d.ts +0 -3
  30. package/build/types/avatar/Avatar.d.ts.map +1 -1
  31. package/build/types/avatarWrapper/AvatarWrapper.d.ts +0 -3
  32. package/build/types/avatarWrapper/AvatarWrapper.d.ts.map +1 -1
  33. package/build/types/badge/Badge.d.ts +1 -5
  34. package/build/types/badge/Badge.d.ts.map +1 -1
  35. package/build/types/badge/index.d.ts +0 -2
  36. package/build/types/badge/index.d.ts.map +1 -1
  37. package/build/types/button/Button.d.ts +1 -1
  38. package/build/types/button/Button.d.ts.map +1 -1
  39. package/build/types/button/legacyUtils/legacyUtils.d.ts +2 -2
  40. package/build/types/button/legacyUtils/legacyUtils.d.ts.map +1 -1
  41. package/build/types/common/circle/Circle.d.ts +0 -2
  42. package/build/types/common/circle/Circle.d.ts.map +1 -1
  43. package/build/types/index.d.ts +1 -3
  44. package/build/types/index.d.ts.map +1 -1
  45. package/build/types/test-utils/index.d.ts +158 -0
  46. package/build/types/test-utils/index.d.ts.map +1 -0
  47. package/build/types/test-utils/jest.setup.d.ts +2 -0
  48. package/build/types/test-utils/jest.setup.d.ts.map +1 -0
  49. package/package.json +4 -3
  50. package/src/avatar/Avatar.tsx +0 -3
  51. package/src/avatarWrapper/AvatarWrapper.tsx +0 -3
  52. package/src/badge/Badge.css +5 -6
  53. package/src/badge/Badge.less +3 -4
  54. package/src/badge/Badge.tsx +1 -8
  55. package/src/badge/index.ts +0 -3
  56. package/src/button/{Button.spec.js → Button.spec.tsx} +3 -2
  57. package/src/button/Button.tsx +1 -1
  58. package/src/button/legacyUtils/{legacyUtils.spec.js → legacyUtils.spec.tsx} +1 -1
  59. package/src/button/legacyUtils/legacyUtils.ts +2 -2
  60. package/src/common/circle/Circle.css +0 -32
  61. package/src/common/circle/Circle.less +0 -35
  62. package/src/common/circle/Circle.tsx +1 -22
  63. package/src/decision/Decision.story.tsx +46 -10
  64. package/src/flowNavigation/FlowNavigation.story.tsx +48 -10
  65. package/src/index.ts +0 -4
  66. package/src/listItem/ListItem.story.tsx +43 -5
  67. package/src/main.css +5 -109
  68. package/src/main.less +0 -2
  69. package/src/modal/{Modal.rtl.spec.js → Modal.rtl.spec.tsx} +8 -7
  70. package/src/navigationOption/NavigationOption.story.tsx +65 -14
  71. package/src/overlayHeader/OverlayHeader.story.tsx +10 -5
  72. package/src/radio/Radio.story.tsx +5 -5
  73. package/src/radioGroup/RadioGroup.story.tsx +3 -3
  74. package/src/selectOption/SelectOption.story.tsx +30 -31
  75. package/src/slidingPanel/SlidingPanel.spec.js +1 -1
  76. package/src/ssr.spec.tsx +264 -0
  77. package/src/test-utils/{index.js → index.tsx} +11 -6
  78. package/src/test-utils/{jest.setup.js → jest.setup.ts} +13 -8
  79. package/src/tile/Tile.story.tsx +6 -2
  80. package/build/avatarView/AvatarView.js +0 -163
  81. package/build/avatarView/AvatarView.js.map +0 -1
  82. package/build/avatarView/AvatarView.mjs +0 -161
  83. package/build/avatarView/AvatarView.mjs.map +0 -1
  84. package/build/avatarView/NotificationDot.js +0 -59
  85. package/build/avatarView/NotificationDot.js.map +0 -1
  86. package/build/avatarView/NotificationDot.mjs +0 -57
  87. package/build/avatarView/NotificationDot.mjs.map +0 -1
  88. package/build/badge/BadgeAssets.js +0 -85
  89. package/build/badge/BadgeAssets.js.map +0 -1
  90. package/build/badge/BadgeAssets.mjs +0 -83
  91. package/build/badge/BadgeAssets.mjs.map +0 -1
  92. package/build/styles/avatarGroup/AvatarGroup.css +0 -29
  93. package/build/styles/avatarView/AvatarView.css +0 -42
  94. package/build/styles/avatarView/NotificationDot.css +0 -20
  95. package/build/types/avatarGroup/AvatarGroup.d.ts +0 -18
  96. package/build/types/avatarGroup/AvatarGroup.d.ts.map +0 -1
  97. package/build/types/avatarGroup/index.d.ts +0 -3
  98. package/build/types/avatarGroup/index.d.ts.map +0 -1
  99. package/build/types/avatarView/AvatarView.d.ts +0 -19
  100. package/build/types/avatarView/AvatarView.d.ts.map +0 -1
  101. package/build/types/avatarView/NotificationDot.d.ts +0 -8
  102. package/build/types/avatarView/NotificationDot.d.ts.map +0 -1
  103. package/build/types/avatarView/index.d.ts +0 -3
  104. package/build/types/avatarView/index.d.ts.map +0 -1
  105. package/build/types/badge/BadgeAssets.d.ts +0 -15
  106. package/build/types/badge/BadgeAssets.d.ts.map +0 -1
  107. package/src/avatarGroup/AvatarGroup.css +0 -29
  108. package/src/avatarGroup/AvatarGroup.less +0 -42
  109. package/src/avatarGroup/AvatarGroup.story.tsx +0 -284
  110. package/src/avatarGroup/AvatarGroup.tsx +0 -117
  111. package/src/avatarGroup/index.ts +0 -2
  112. package/src/avatarView/AvatarView.css +0 -42
  113. package/src/avatarView/AvatarView.less +0 -33
  114. package/src/avatarView/AvatarView.story.tsx +0 -425
  115. package/src/avatarView/AvatarView.tsx +0 -141
  116. package/src/avatarView/NotificationDot.css +0 -20
  117. package/src/avatarView/NotificationDot.less +0 -24
  118. package/src/avatarView/NotificationDot.tsx +0 -35
  119. package/src/avatarView/index.ts +0 -2
  120. package/src/badge/BadgeAssets.tsx +0 -65
  121. package/src/ssr.spec.js +0 -256
  122. /package/src/button/__snapshots__/{Button.spec.js.snap → Button.spec.tsx.snap} +0 -0
  123. /package/src/dimmer/{Dimmer.rtl.spec.js → Dimmer.rtl.spec.tsx} +0 -0
  124. /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
  }
@@ -1,7 +1,7 @@
1
1
  import { action } from '@storybook/addon-actions';
2
2
  import { text, boolean } from '@storybook/addon-knobs';
3
3
 
4
- import AvatarView from '../avatarView';
4
+ import Avatar from '../avatar';
5
5
  import { Size } from '../common';
6
6
 
7
7
  import Tile from '.';
@@ -41,7 +41,11 @@ export const Basic = () => {
41
41
  description={description}
42
42
  disabled={disabled}
43
43
  href="#href1"
44
- media={<AvatarView name="Henry Mike" />}
44
+ media={
45
+ <Avatar size="md" type="initials">
46
+ HM
47
+ </Avatar>
48
+ }
45
49
  size={medium ? Size.MEDIUM : Size.SMALL}
46
50
  title={title}
47
51
  onClick={action('onClick')}
@@ -1,163 +0,0 @@
1
- 'use strict';
2
-
3
- var Badge = require('../badge/Badge.js');
4
- var BadgeAssets = require('../badge/BadgeAssets.js');
5
- var NotificationDot = require('./NotificationDot.js');
6
- var Circle = require('../common/circle/Circle.js');
7
- var Image = require('../image/Image.js');
8
- var React = require('react');
9
- var clsx = require('clsx');
10
- require('../common/theme.js');
11
- require('../common/direction.js');
12
- require('../common/propsValues/control.js');
13
- require('../common/propsValues/breakpoint.js');
14
- var size = require('../common/propsValues/size.js');
15
- require('../common/propsValues/typography.js');
16
- require('../common/propsValues/width.js');
17
- require('../common/propsValues/type.js');
18
- require('../common/propsValues/dateMode.js');
19
- require('../common/propsValues/monthFormat.js');
20
- require('../common/propsValues/position.js');
21
- require('../common/propsValues/layouts.js');
22
- require('../common/propsValues/status.js');
23
- require('../common/propsValues/sentiment.js');
24
- require('../common/propsValues/profileType.js');
25
- require('../common/propsValues/variant.js');
26
- require('../common/propsValues/scroll.js');
27
- require('../common/propsValues/markdownNodeType.js');
28
- require('../common/fileType.js');
29
- var initials = require('../common/initials.js');
30
- var icons = require('@transferwise/icons');
31
- require('react-intl');
32
- require('../common/closeButton/CloseButton.messages.js');
33
- var jsxRuntime = require('react/jsx-runtime');
34
-
35
- function AvatarView({
36
- children = undefined,
37
- size = 48,
38
- selected,
39
- notification,
40
- badge,
41
- interactive = false,
42
- className,
43
- style,
44
- imgSrc,
45
- type,
46
- name,
47
- ...restProps
48
- }) {
49
- return /*#__PURE__*/jsxRuntime.jsx(Circle, {
50
- size: size,
51
- fixedSize: true,
52
- className: clsx.clsx('np-avatar-view', interactive ? 'np-avatar-view-interactive' : 'np-avatar-view-non-interactive', {
53
- 'np-avatar-view-selected': selected
54
- }, className),
55
- ...restProps,
56
- children: /*#__PURE__*/jsxRuntime.jsx(Badges, {
57
- avatar: {
58
- size,
59
- notification,
60
- selected
61
- },
62
- ...badge,
63
- children: /*#__PURE__*/jsxRuntime.jsx(Circle, {
64
- size: size,
65
- fixedSize: true,
66
- className: clsx.clsx('np-avatar-view-content'),
67
- enableBorder: !interactive || selected,
68
- style: {
69
- ...(selected && {
70
- '--circle-border-color': 'var(--color-interactive-primary)'
71
- }),
72
- ...style
73
- },
74
- children: children === undefined ? /*#__PURE__*/jsxRuntime.jsx(Profile, {
75
- imgSrc,
76
- type,
77
- name
78
- }) : children
79
- })
80
- })
81
- });
82
- }
83
- /** Size of badge depends on size of avatar */
84
- const MAP_BADGE_ASSET_SIZE = {
85
- 16: 'sm',
86
- 24: 'sm',
87
- 32: 'sm',
88
- 40: 'sm',
89
- 48: 'sm',
90
- 56: 'lg',
91
- 72: 'lg'
92
- };
93
- /** Certain sizes of AvatarView has a custom offset of Badge */
94
- const MAP_BADGE_POSITION = {
95
- 24: -6,
96
- 32: -4
97
- };
98
- /**
99
- * Adds build-in badges to AvatarView
100
- */
101
- function Badges({
102
- children,
103
- avatar,
104
- ...badge
105
- }) {
106
- const {
107
- size: size$1 = 48,
108
- selected,
109
- notification
110
- } = avatar;
111
- const anyCustomBadge = Object.keys(badge).length > 0;
112
- if ((anyCustomBadge || selected) && size$1 > 16) {
113
- const badgeSize = MAP_BADGE_ASSET_SIZE[size$1] ?? size.Size.SMALL;
114
- return /*#__PURE__*/jsxRuntime.jsx(Badge, {
115
- size: badgeSize,
116
- badge: /*#__PURE__*/jsxRuntime.jsx(BadgeAssets, {
117
- ...(selected ? {
118
- status: 'positive'
119
- } : badge),
120
- size: badgeSize
121
- }),
122
- style: {
123
- // @ts-expect-error CSS custom props allowed
124
- '--badge-content-position': `${MAP_BADGE_POSITION[size$1] ?? 0}px`
125
- },
126
- children: children
127
- });
128
- }
129
- if (notification) {
130
- return /*#__PURE__*/jsxRuntime.jsx(NotificationDot, {
131
- avatarSize: size$1,
132
- children: children
133
- });
134
- }
135
- return children;
136
- }
137
- /**
138
- * Common logic for entities (personal & business profiles or recipients)
139
- */
140
- function Profile({
141
- imgSrc,
142
- name,
143
- type
144
- }) {
145
- const [tryLoadImage, setTryLoadImage] = React.useState(true);
146
- if (imgSrc && tryLoadImage) {
147
- return /*#__PURE__*/jsxRuntime.jsx(Image.default, {
148
- src: imgSrc,
149
- alt: "",
150
- onError: () => setTryLoadImage(false)
151
- });
152
- }
153
- if (type) {
154
- return type.toLowerCase() === 'business' ? /*#__PURE__*/jsxRuntime.jsx(icons.Briefcase, {}) : /*#__PURE__*/jsxRuntime.jsx(icons.Profile, {});
155
- }
156
- if (name) {
157
- return initials.getInitials(name);
158
- }
159
- return /*#__PURE__*/jsxRuntime.jsx(icons.Profile, {});
160
- }
161
-
162
- module.exports = AvatarView;
163
- //# sourceMappingURL=AvatarView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AvatarView.js","sources":["../../src/avatarView/AvatarView.tsx"],"sourcesContent":["import Badge, { BadgeAssets, BadgeProps, BadgeAssetsProps } from '../badge';\nimport NotificationDot from './NotificationDot';\nimport Circle from '../common/circle';\nimport Image from '../image';\nimport { HTMLAttributes, PropsWithChildren, useState } from 'react';\nimport { clsx } from 'clsx';\nimport { getInitials, Size } from '../common';\nimport {\n Briefcase as BusinessProfileIcon,\n Profile as PersonalProfileIcon,\n} from '@transferwise/icons';\n\nexport type Props = {\n imgSrc?: string | null;\n /**\n * Entity name (person (profile or recipient) or business name), it will be boilded down to 1 or 2 chars (initials)\n */\n name?: string | null;\n type?: 'personal' | 'business';\n size?: 16 | 24 | 32 | 40 | 48 | 56 | 72;\n notification?: boolean;\n badge?: BadgeAssetsProps;\n interactive?: boolean;\n selected?: boolean;\n style?: Pick<React.CSSProperties, 'border' | 'backgroundColor' | 'color'>;\n} & Pick<\n HTMLAttributes<HTMLDivElement>,\n 'className' | 'children' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-describedby'\n>;\n\nfunction AvatarView({\n children = undefined,\n size = 48,\n selected,\n notification,\n badge,\n interactive = false,\n className,\n style,\n imgSrc,\n type,\n name,\n ...restProps\n}: Props) {\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx(\n 'np-avatar-view',\n interactive ? 'np-avatar-view-interactive' : 'np-avatar-view-non-interactive',\n { 'np-avatar-view-selected': selected },\n className,\n )}\n {...restProps}\n >\n <Badges avatar={{ size, notification, selected }} {...badge}>\n <Circle\n size={size}\n fixedSize\n className={clsx('np-avatar-view-content')}\n enableBorder={!interactive || selected}\n style={{\n ...(selected && { '--circle-border-color': 'var(--color-interactive-primary)' }),\n ...style,\n }}\n >\n {children === undefined ? <Profile {...{ imgSrc, type, name }} /> : children}\n </Circle>\n </Badges>\n </Circle>\n );\n}\n\n/** Size of badge depends on size of avatar */\nconst MAP_BADGE_ASSET_SIZE = {\n 16: 'sm',\n 24: 'sm',\n 32: 'sm',\n 40: 'sm',\n 48: 'sm',\n 56: 'lg',\n 72: 'lg',\n};\n\n/** Certain sizes of AvatarView has a custom offset of Badge */\nconst MAP_BADGE_POSITION = {\n 24: -6,\n 32: -4,\n};\n\ntype BadgesProps = BadgeAssetsProps &\n PropsWithChildren<{\n avatar: Pick<Props, 'selected' | 'size' | 'notification'>;\n }>;\n\n/**\n * Adds build-in badges to AvatarView\n */\nfunction Badges({ children, avatar, ...badge }: BadgesProps) {\n const { size = 48, selected, notification } = avatar;\n const anyCustomBadge = Object.keys(badge).length > 0;\n if ((anyCustomBadge || selected) && size > 16) {\n const badgeSize: BadgeProps['size'] = MAP_BADGE_ASSET_SIZE[size] ?? Size.SMALL;\n return (\n <Badge\n size={badgeSize}\n badge={<BadgeAssets {...(selected ? { status: 'positive' } : badge)} size={badgeSize} />}\n style={{\n // @ts-expect-error CSS custom props allowed\n '--badge-content-position': `${MAP_BADGE_POSITION[size] ?? 0}px`,\n }}\n >\n {children}\n </Badge>\n );\n }\n if (notification) {\n return <NotificationDot avatarSize={size}>{children}</NotificationDot>;\n }\n return children;\n}\n\n/**\n * Common logic for entities (personal & business profiles or recipients)\n */\nfunction Profile({ imgSrc, name, type }: Pick<Props, 'imgSrc' | 'name' | 'type'>) {\n const [tryLoadImage, setTryLoadImage] = useState(true);\n if (imgSrc && tryLoadImage) {\n return <Image src={imgSrc} alt=\"\" onError={() => setTryLoadImage(false)} />;\n }\n if (type) {\n return type.toLowerCase() === 'business' ? <BusinessProfileIcon /> : <PersonalProfileIcon />;\n }\n if (name) {\n return getInitials(name);\n }\n return <PersonalProfileIcon />;\n}\n\nexport default AvatarView;\n"],"names":["AvatarView","children","undefined","size","selected","notification","badge","interactive","className","style","imgSrc","type","name","restProps","_jsx","Circle","fixedSize","clsx","Badges","avatar","enableBorder","Profile","MAP_BADGE_ASSET_SIZE","MAP_BADGE_POSITION","anyCustomBadge","Object","keys","length","badgeSize","Size","SMALL","Badge","BadgeAssets","status","NotificationDot","avatarSize","tryLoadImage","setTryLoadImage","useState","Image","src","alt","onError","toLowerCase","BusinessProfileIcon","PersonalProfileIcon","getInitials"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAASA,UAAUA,CAAC;AAClBC,EAAAA,QAAQ,GAAGC,SAAS;AACpBC,EAAAA,IAAI,GAAG,EAAE;EACTC,QAAQ;EACRC,YAAY;EACZC,KAAK;AACLC,EAAAA,WAAW,GAAG,KAAK;EACnBC,SAAS;EACTC,KAAK;EACLC,MAAM;EACNC,IAAI;EACJC,IAAI;EACJ,GAAGC,SAAAA;AACG,CAAA,EAAA;EACN,oBACEC,cAAA,CAACC,MAAM,EAAA;AACLZ,IAAAA,IAAI,EAAEA,IAAK;IACXa,SAAS,EAAA,IAAA;IACTR,SAAS,EAAES,SAAI,CACb,gBAAgB,EAChBV,WAAW,GAAG,4BAA4B,GAAG,gCAAgC,EAC7E;AAAE,MAAA,yBAAyB,EAAEH,QAAAA;KAAU,EACvCI,SAAS,CACT;AAAA,IAAA,GACEK,SAAS;IAAAZ,QAAA,eAEba,cAAA,CAACI,MAAM,EAAA;AAACC,MAAAA,MAAM,EAAE;QAAEhB,IAAI;QAAEE,YAAY;AAAED,QAAAA,QAAAA;OAAW;AAAA,MAAA,GAAKE,KAAK;MAAAL,QAAA,eACzDa,cAAA,CAACC,MAAM,EAAA;AACLZ,QAAAA,IAAI,EAAEA,IAAK;QACXa,SAAS,EAAA,IAAA;AACTR,QAAAA,SAAS,EAA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