@transferwise/components 0.0.0-experimental-693e956 → 0.0.0-experimental-d729abf

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 (46) hide show
  1. package/build/i18n/en.json +1 -0
  2. package/build/index.js +2320 -2234
  3. package/build/index.js.map +1 -1
  4. package/build/index.mjs +2322 -2237
  5. package/build/index.mjs.map +1 -1
  6. package/build/main.css +31 -10
  7. package/build/styles/main.css +31 -10
  8. package/build/styles/selectOption/SelectOption.css +31 -0
  9. package/build/styles/uploadInput/UploadInput.css +0 -10
  10. package/build/types/index.d.ts +2 -0
  11. package/build/types/index.d.ts.map +1 -1
  12. package/build/types/selectOption/SelectOption.d.ts +20 -0
  13. package/build/types/selectOption/SelectOption.d.ts.map +1 -0
  14. package/build/types/selectOption/SelectOption.messages.d.ts +8 -0
  15. package/build/types/selectOption/SelectOption.messages.d.ts.map +1 -0
  16. package/build/types/selectOption/index.d.ts +3 -0
  17. package/build/types/selectOption/index.d.ts.map +1 -0
  18. package/build/types/slidingPanel/SlidingPanel.d.ts +1 -0
  19. package/build/types/slidingPanel/SlidingPanel.d.ts.map +1 -1
  20. package/build/types/sticky/Sticky.d.ts +31 -3
  21. package/build/types/sticky/Sticky.d.ts.map +1 -1
  22. package/build/types/uploadInput/types.d.ts +1 -9
  23. package/build/types/uploadInput/types.d.ts.map +1 -1
  24. package/build/types/uploadInput/uploadItem/UploadItem.d.ts.map +1 -1
  25. package/package.json +2 -2
  26. package/src/i18n/en.json +1 -0
  27. package/src/index.ts +2 -0
  28. package/src/main.css +31 -10
  29. package/src/main.less +1 -0
  30. package/src/selectOption/SelectOption.css +31 -0
  31. package/src/selectOption/SelectOption.less +27 -0
  32. package/src/selectOption/SelectOption.messages.ts +8 -0
  33. package/src/selectOption/SelectOption.story.tsx +167 -0
  34. package/src/selectOption/SelectOption.tsx +134 -0
  35. package/src/selectOption/index.ts +2 -0
  36. package/src/slidingPanel/SlidingPanel.spec.js +2 -1
  37. package/src/slidingPanel/SlidingPanel.tsx +3 -0
  38. package/src/sticky/Sticky.spec.tsx +71 -0
  39. package/src/sticky/Sticky.story.tsx +46 -13
  40. package/src/sticky/Sticky.tsx +48 -4
  41. package/src/uploadInput/UploadInput.css +0 -10
  42. package/src/uploadInput/UploadInput.less +0 -11
  43. package/src/uploadInput/UploadInput.story.tsx +7 -50
  44. package/src/uploadInput/types.ts +1 -11
  45. package/src/uploadInput/uploadItem/UploadItem.tsx +6 -25
  46. package/src/sticky/Sticky.spec.js +0 -34
@@ -4,7 +4,7 @@ import { Story, Meta } from '@storybook/react';
4
4
  import { Status } from '../common';
5
5
 
6
6
  import UploadInput, { UploadInputProps } from './UploadInput';
7
- import { UploadedFile, UploadResponse } from './types';
7
+ import { UploadResponse } from './types';
8
8
 
9
9
  const meta: Meta<typeof UploadInput> = {
10
10
  title: 'Forms/UploadInput',
@@ -35,9 +35,9 @@ const files = [
35
35
  filename: 'receipt failed with error object.png',
36
36
  status: Status.SUCCEEDED,
37
37
  },
38
- ] satisfies UploadedFile[];
38
+ ];
39
39
 
40
- const createDelayedPromise = async ({
40
+ const createDelayedPromise = ({
41
41
  successful = true,
42
42
  delaySeconds = 3,
43
43
  response = { id: Math.round(Math.random() * 10000), url: '#' },
@@ -54,10 +54,10 @@ const createDelayedPromise = async ({
54
54
  });
55
55
 
56
56
  const props = {
57
- onUploadFile: async (formData: FormData) => {
57
+ onUploadFile: (formData: FormData) => {
58
58
  return createDelayedPromise();
59
59
  },
60
- onDeleteFile: async (id: string | number) => {
60
+ onDeleteFile: (id: string | number) => {
61
61
  return createDelayedPromise();
62
62
  },
63
63
  };
@@ -93,49 +93,6 @@ WithMultipleExistingFiles.args = {
93
93
  multiple: true,
94
94
  };
95
95
 
96
- export const WithFileErrors: Story<UploadInputProps> = Template.bind({});
97
- WithFileErrors.args = {
98
- ...props,
99
- files: [
100
- {
101
- id: 1,
102
- filename: 'Error with default message.png',
103
- status: Status.FAILED,
104
- },
105
- {
106
- id: 2,
107
- filename: 'Error with `string` error.png',
108
- status: Status.FAILED,
109
- error: 'Single string error',
110
- },
111
- {
112
- id: 3,
113
- filename: 'Error with `obj` error ({ message : `string` }).png',
114
- status: Status.FAILED,
115
- error: { message: 'Single obj error' },
116
- },
117
- {
118
- id: 4,
119
- filename: 'Error with single error passed in `array`.png',
120
- status: Status.FAILED,
121
- errors: ['Single error in array'],
122
- },
123
- {
124
- id: 5,
125
- filename: 'Error with multiple `string` errors passed in `array`.png',
126
- status: Status.FAILED,
127
- errors: ['Error 1', 'Error 2', 'Error 3'],
128
- },
129
- {
130
- id: 6,
131
- filename: 'Error with multiple `obj` errors passed in `array`.png',
132
- status: Status.FAILED,
133
- errors: [{ message: 'Error 1' }, { message: 'Error 2' }, { message: 'Error 3' }],
134
- },
135
- ],
136
- multiple: true,
137
- };
138
-
139
96
  export const WithoutDelete: Story<UploadInputProps> = Template.bind({});
140
97
  WithoutDelete.args = {
141
98
  ...props,
@@ -148,7 +105,7 @@ export const WithUploadFailed: Story<UploadInputProps> = Template.bind({});
148
105
  WithUploadFailed.args = {
149
106
  ...props,
150
107
  files: files.slice(0),
151
- onUploadFile: async () => createDelayedPromise({ successful: false }),
108
+ onUploadFile: () => createDelayedPromise({ successful: false }),
152
109
  multiple: true,
153
110
  };
154
111
 
@@ -156,7 +113,7 @@ export const WithDeleteFailed: Story<UploadInputProps> = Template.bind({});
156
113
  WithDeleteFailed.args = {
157
114
  ...props,
158
115
  files: files.slice(0),
159
- onDeleteFile: async () => createDelayedPromise({ successful: false }),
116
+ onDeleteFile: () => createDelayedPromise({ successful: false }),
160
117
  multiple: true,
161
118
  };
162
119
 
@@ -19,14 +19,9 @@ export type UploadResponse = {
19
19
  url?: string;
20
20
 
21
21
  /**
22
- * Optionally sets a translated error message when file was rejected
22
+ * Optionally set a translated error message when file was rejected
23
23
  */
24
24
  error?: UploadError;
25
-
26
- /**
27
- * Optionally sets a translated errors messages when file was rejected
28
- */
29
- errors?: UploadError[];
30
25
  [key: string]: any;
31
26
  };
32
27
 
@@ -51,11 +46,6 @@ export type UploadedFile = {
51
46
  */
52
47
  error?: UploadError;
53
48
 
54
- /**
55
- * Any API errors array. The messages should be localized.
56
- */
57
- errors?: UploadError[];
58
-
59
49
  /**
60
50
  * Optional. An external URL where the file can be opened from.
61
51
  */
@@ -7,7 +7,7 @@ import Body from '../../body';
7
7
  import { Size, Status, Typography, Sentiment } from '../../common';
8
8
  import ProcessIndicator from '../../processIndicator/ProcessIndicator';
9
9
  import StatusIcon from '../../statusIcon/StatusIcon';
10
- import { UploadedFile, UploadError } from '../types';
10
+ import { UploadedFile } from '../types';
11
11
 
12
12
  import MESSAGES from './UploadItem.messages';
13
13
  import { UploadItemBody } from './UploadItemBody';
@@ -43,13 +43,13 @@ const UploadItem = ({
43
43
  singleFileUpload,
44
44
  }: UploadItemProps) => {
45
45
  const { formatMessage } = useIntl();
46
- const { status, filename, error, errors, url } = file;
46
+ const { status, filename, error, url } = file;
47
47
  const { isModern } = useTheme();
48
48
 
49
49
  const isSucceeded = [Status.SUCCEEDED, undefined].includes(status) && !!url;
50
50
 
51
51
  const getIcon = () => {
52
- if (error || errors?.length || status === Status.FAILED) {
52
+ if (error || status === Status.FAILED) {
53
53
  return isModern ? (
54
54
  <StatusIcon size={Size.SMALL} sentiment={Sentiment.NEGATIVE} />
55
55
  ) : (
@@ -81,33 +81,14 @@ const UploadItem = ({
81
81
  return <span style={{ transform: 'scale(0.8335)' }}>{processIndicator}</span>; // Scale down ProcessIndicator to be 20px*20px to match `icons`
82
82
  };
83
83
 
84
- const getErrorMessage = (error?: UploadError) =>
84
+ const getErrorMessage = () =>
85
85
  typeof error === 'object' ? error.message : error || formatMessage(MESSAGES.uploadingFailed);
86
86
 
87
- const getMultipleErrors = (errors?: UploadError[]) => {
88
- if (!errors?.length) {
89
- return null;
90
- }
91
-
92
- if (errors?.length === 1) {
93
- return getErrorMessage(errors[0]);
94
- }
95
-
96
- return (
97
- <ul className="np-upload-input-errors m-b-0">
98
- {errors.map((error, index) => {
99
- // eslint-disable-next-line react/no-array-index-key
100
- return <li key={index}>{getErrorMessage(error)}</li>;
101
- })}
102
- </ul>
103
- );
104
- };
105
-
106
87
  const getDescription = () => {
107
- if (error || errors?.length || status === Status.FAILED) {
88
+ if (error || status === Status.FAILED) {
108
89
  return (
109
90
  <Body type={Typography.BODY_DEFAULT_BOLD} className="text-negative">
110
- {errors?.length ? getMultipleErrors(errors) : getErrorMessage(error)}
91
+ {getErrorMessage()}
111
92
  </Body>
112
93
  );
113
94
  }
@@ -1,34 +0,0 @@
1
- import { shallow, mount } from 'enzyme';
2
-
3
- import Sticky from './Sticky';
4
-
5
- describe('Sticky', () => {
6
- let component;
7
- const props = {
8
- open: true,
9
- children: null,
10
- stickyPositionFixed: true,
11
- position: 'bottom',
12
- };
13
-
14
- it('renders with right props', () => {
15
- component = mount(<Sticky {...props} />);
16
- expect(component.find(Sticky)).toHaveLength(1);
17
- expect(component.find(Sticky).props()).toStrictEqual({ ...props });
18
- });
19
-
20
- it('renders SlidingPanel with right props', () => {
21
- component = shallow(<Sticky {...props} />);
22
-
23
- const slidingPanel = component.find('ForwardRef');
24
- expect(slidingPanel).toHaveLength(1);
25
-
26
- expect(slidingPanel.props()).toStrictEqual({
27
- children: null,
28
- open: true,
29
- position: 'bottom',
30
- showSlidingPanelBorder: true,
31
- slidingPanelPositionFixed: true,
32
- });
33
- });
34
- });