@transferwise/components 0.0.0-experimental-be73f56 → 0.0.0-experimental-2fa5e3f
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.
- package/build/card/Card.js +20 -13
- package/build/card/Card.js.map +1 -1
- package/build/card/Card.mjs +21 -14
- package/build/card/Card.mjs.map +1 -1
- package/build/common/Option/Option.js.map +1 -1
- package/build/common/Option/Option.mjs.map +1 -1
- package/build/i18n/en.json +0 -1
- package/build/i18n/en.json.js +0 -1
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +0 -1
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/main.css +0 -6
- package/build/styles/main.css +0 -6
- package/build/styles/upload/Upload.css +0 -6
- package/build/types/card/Card.d.ts.map +1 -1
- package/build/types/common/Option/Option.d.ts +2 -0
- package/build/types/common/Option/Option.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts +0 -1
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/types/upload/Upload.messages.d.ts +0 -4
- package/build/types/upload/Upload.messages.d.ts.map +1 -1
- package/build/types/upload/steps/completeStep/completeStep.d.ts +3 -1
- package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +0 -1
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
- package/build/upload/Upload.js +12 -26
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.messages.js +0 -3
- package/build/upload/Upload.messages.js.map +1 -1
- package/build/upload/Upload.messages.mjs +0 -3
- package/build/upload/Upload.messages.mjs.map +1 -1
- package/build/upload/Upload.mjs +12 -26
- package/build/upload/Upload.mjs.map +1 -1
- package/build/upload/steps/completeStep/completeStep.js +30 -15
- package/build/upload/steps/completeStep/completeStep.js.map +1 -1
- package/build/upload/steps/completeStep/completeStep.mjs +31 -16
- package/build/upload/steps/completeStep/completeStep.mjs.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.js +32 -56
- package/build/upload/steps/uploadImageStep/uploadImageStep.js.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs +32 -56
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs.map +1 -1
- package/package.json +3 -3
- package/src/card/Card.spec.tsx +35 -3
- package/src/card/Card.story.tsx +56 -40
- package/src/card/Card.tsx +32 -14
- package/src/common/Option/Option.tsx +2 -0
- package/src/i18n/en.json +0 -1
- package/src/main.css +0 -6
- package/src/upload/Upload.css +0 -6
- package/src/upload/Upload.less +0 -5
- package/src/upload/Upload.messages.ts +0 -4
- package/src/upload/Upload.spec.js +7 -8
- package/src/upload/Upload.story.tsx +0 -18
- package/src/upload/Upload.tsx +20 -39
- package/src/upload/steps/completeStep/completeStep.spec.js +9 -0
- package/src/upload/steps/completeStep/completeStep.tsx +29 -14
- package/src/upload/steps/uploadImageStep/uploadImageStep.spec.js +0 -12
- package/src/upload/steps/uploadImageStep/uploadImageStep.tsx +24 -43
|
@@ -46,7 +46,6 @@ const props = {
|
|
|
46
46
|
psProcessingText: 'psProcessingText',
|
|
47
47
|
usAccept: 'image/*',
|
|
48
48
|
usButtonText: 'Or Select File',
|
|
49
|
-
usButtonRetryText: 'Try again',
|
|
50
49
|
usDropMessage: 'Drop file to start upload',
|
|
51
50
|
usPlaceholder: 'Drag and drop a file less than 5MB',
|
|
52
51
|
};
|
|
@@ -232,7 +231,7 @@ describe('Upload', () => {
|
|
|
232
231
|
expect(component.find(CompleteStep)).toHaveLength(1);
|
|
233
232
|
});
|
|
234
233
|
|
|
235
|
-
it('step
|
|
234
|
+
it('step CompleteStep is called with error props', async () => {
|
|
236
235
|
component = mount(<Upload {...props} />);
|
|
237
236
|
const upload = component.children();
|
|
238
237
|
asyncFileRead.mockImplementation(async () => {
|
|
@@ -245,12 +244,12 @@ describe('Upload', () => {
|
|
|
245
244
|
await waitForUpload();
|
|
246
245
|
component.update();
|
|
247
246
|
|
|
248
|
-
expect(component.find(
|
|
249
|
-
...
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
247
|
+
expect(component.find(CompleteStep).props()).toStrictEqual({
|
|
248
|
+
...COMPLETED_STEP_PROPS,
|
|
249
|
+
isImage: false,
|
|
250
|
+
isComplete: true,
|
|
251
|
+
isError: true,
|
|
252
|
+
uploadedImage: undefined,
|
|
254
253
|
});
|
|
255
254
|
});
|
|
256
255
|
|
|
@@ -6,7 +6,6 @@ import { MAX_SIZE_DEFAULT } from './Upload';
|
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
component: Upload,
|
|
9
|
-
title: 'Forms/Upload',
|
|
10
9
|
tags: ['autodocs'],
|
|
11
10
|
argTypes: {
|
|
12
11
|
maxSize: {
|
|
@@ -36,20 +35,3 @@ export const Basic = {
|
|
|
36
35
|
onCancel: fn(),
|
|
37
36
|
},
|
|
38
37
|
} satisfies Story;
|
|
39
|
-
|
|
40
|
-
export const Loading = {
|
|
41
|
-
args: {
|
|
42
|
-
animationDelay: 10000000000,
|
|
43
|
-
maxSize: MAX_SIZE_DEFAULT,
|
|
44
|
-
usAccept: 'image/*',
|
|
45
|
-
usLabel: 'Front of your ID document',
|
|
46
|
-
httpOptions: {
|
|
47
|
-
url: 'https://httpbin.org/post',
|
|
48
|
-
method: 'POST',
|
|
49
|
-
},
|
|
50
|
-
onStart: fn(),
|
|
51
|
-
onSuccess: fn(),
|
|
52
|
-
onFailure: fn(),
|
|
53
|
-
onCancel: fn(),
|
|
54
|
-
},
|
|
55
|
-
} satisfies Story;
|
package/src/upload/Upload.tsx
CHANGED
|
@@ -50,7 +50,6 @@ export interface UploadProps extends WrappedComponentProps {
|
|
|
50
50
|
*/
|
|
51
51
|
usAccept?: string;
|
|
52
52
|
usButtonText?: string;
|
|
53
|
-
usButtonRetryText?: string;
|
|
54
53
|
usDisabled?: boolean;
|
|
55
54
|
usDropMessage?: string;
|
|
56
55
|
usHelpImage?: React.ReactNode;
|
|
@@ -326,7 +325,6 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
326
325
|
usDropMessage,
|
|
327
326
|
usAccept,
|
|
328
327
|
usButtonText,
|
|
329
|
-
usButtonRetryText,
|
|
330
328
|
usDisabled,
|
|
331
329
|
usHelpImage,
|
|
332
330
|
usLabel,
|
|
@@ -361,8 +359,8 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
361
359
|
'tw-droppable-lg droppable-lg': size === 'lg',
|
|
362
360
|
'droppable-dropping': isDroppable,
|
|
363
361
|
'droppable-processing': isProcessing,
|
|
364
|
-
'droppable-complete': isComplete
|
|
365
|
-
'droppable-negative': isError
|
|
362
|
+
'droppable-complete': isComplete,
|
|
363
|
+
'droppable-negative': isError,
|
|
366
364
|
})}
|
|
367
365
|
onDragEnter={(event) => this.onDragEnter(event)}
|
|
368
366
|
onDragLeave={(event) => this.onDragLeave(event)}
|
|
@@ -385,36 +383,28 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
385
383
|
/>
|
|
386
384
|
)}
|
|
387
385
|
|
|
388
|
-
{
|
|
386
|
+
{isProcessing && (
|
|
387
|
+
<ProcessingStep
|
|
388
|
+
isComplete={isComplete}
|
|
389
|
+
isError={isError}
|
|
390
|
+
isSuccess={isSuccess}
|
|
391
|
+
psButtonText={psButtonText || intl.formatMessage(messages.psButtonText)}
|
|
392
|
+
psProcessingText={psProcessingText || intl.formatMessage(messages.psProcessingText)}
|
|
393
|
+
psButtonDisabled={psButtonDisabled}
|
|
394
|
+
onAnimationCompleted={async (status) => this.onAnimationCompleted(status)}
|
|
395
|
+
onClear={(event) => this.handleOnClear(event)}
|
|
396
|
+
/>
|
|
397
|
+
)}
|
|
398
|
+
{/* Starts render the step when isSuccess or isError are true so markup is there when css transition kicks in
|
|
389
399
|
css transition to work properly */}
|
|
390
|
-
{(isSuccess || isComplete) &&
|
|
400
|
+
{(isSuccess || isError || isComplete) && (
|
|
391
401
|
<CompleteStep
|
|
392
402
|
fileName={fileName}
|
|
393
403
|
isComplete={isComplete}
|
|
404
|
+
isError={isError}
|
|
394
405
|
isImage={isImage}
|
|
395
406
|
csButtonText={csButtonText || intl.formatMessage(messages.csButtonText)}
|
|
396
|
-
|
|
397
|
-
uploadedImage={uploadedImage}
|
|
398
|
-
onClear={(event) => this.handleOnClear(event)}
|
|
399
|
-
/>
|
|
400
|
-
)}
|
|
401
|
-
{isError && !isProcessing && (
|
|
402
|
-
<UploadImageStep
|
|
403
|
-
fileDropped={async (file) => {
|
|
404
|
-
this.reset();
|
|
405
|
-
await this.fileDropped(file);
|
|
406
|
-
}}
|
|
407
|
-
isComplete={!isError}
|
|
408
|
-
usAccept={usAccept}
|
|
409
|
-
usButtonText={usButtonRetryText || intl.formatMessage(messages.retry)}
|
|
410
|
-
usDisabled={usDisabled}
|
|
411
|
-
usHelpImage={null}
|
|
412
|
-
usLabel={usLabel}
|
|
413
|
-
usPlaceholder={
|
|
414
|
-
usPlaceholder ||
|
|
415
|
-
intl.formatMessage(messages.usPlaceholder, { maxSize: maxSize / 1000000 })
|
|
416
|
-
}
|
|
417
|
-
errorMessage={this.getErrorMessage(
|
|
407
|
+
csFailureText={this.getErrorMessage(
|
|
418
408
|
response != null &&
|
|
419
409
|
typeof response === 'object' &&
|
|
420
410
|
'status' in response &&
|
|
@@ -422,17 +412,8 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
422
412
|
? response.status
|
|
423
413
|
: undefined,
|
|
424
414
|
)}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
{isProcessing && (
|
|
428
|
-
<ProcessingStep
|
|
429
|
-
isComplete={isComplete}
|
|
430
|
-
isError={isError}
|
|
431
|
-
isSuccess={isSuccess}
|
|
432
|
-
psButtonText={psButtonText || intl.formatMessage(messages.psButtonText)}
|
|
433
|
-
psProcessingText={psProcessingText || intl.formatMessage(messages.psProcessingText)}
|
|
434
|
-
psButtonDisabled={psButtonDisabled}
|
|
435
|
-
onAnimationCompleted={async (status) => this.onAnimationCompleted(status)}
|
|
415
|
+
csSuccessText={csSuccessText || intl.formatMessage(messages.csSuccessText)}
|
|
416
|
+
uploadedImage={uploadedImage}
|
|
436
417
|
onClear={(event) => this.handleOnClear(event)}
|
|
437
418
|
/>
|
|
438
419
|
)}
|
|
@@ -3,6 +3,7 @@ import { shallow } from 'enzyme';
|
|
|
3
3
|
|
|
4
4
|
import Body from '../../../body';
|
|
5
5
|
import Button from '../../../button';
|
|
6
|
+
import StatusIcon from '../../../statusIcon/StatusIcon';
|
|
6
7
|
|
|
7
8
|
import CompleteStep from '.';
|
|
8
9
|
|
|
@@ -40,6 +41,14 @@ describe('CompleteStep', () => {
|
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
|
|
44
|
+
describe('when error is true', () => {
|
|
45
|
+
it('renders errorMessage and icon when error is true', () => {
|
|
46
|
+
component = shallow(<CompleteStep {...COMPLETED_STEP_PROPS} isError />);
|
|
47
|
+
expect(component.find('p').text()).toBe(COMPLETED_STEP_PROPS.csFailureText);
|
|
48
|
+
expect(component.find(StatusIcon)).toHaveLength(1);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
43
52
|
it('renders button when csButtonText is set up', () => {
|
|
44
53
|
expect(component.find(Button)).toHaveLength(1);
|
|
45
54
|
});
|
|
@@ -3,13 +3,17 @@ import { Document as DocumentIcon } from '@transferwise/icons';
|
|
|
3
3
|
import { Typography } from '../../..';
|
|
4
4
|
import Body from '../../../body';
|
|
5
5
|
import Button from '../../../button';
|
|
6
|
+
import { Sentiment, Size } from '../../../common';
|
|
7
|
+
import StatusIcon from '../../../statusIcon';
|
|
6
8
|
import Title from '../../../title';
|
|
7
9
|
|
|
8
10
|
export interface CompleteStepProps {
|
|
9
11
|
csButtonText: string;
|
|
10
12
|
csSuccessText: string;
|
|
13
|
+
csFailureText: string;
|
|
11
14
|
fileName: string;
|
|
12
15
|
isComplete: boolean;
|
|
16
|
+
isError: boolean;
|
|
13
17
|
isImage: boolean;
|
|
14
18
|
uploadedImage?: string;
|
|
15
19
|
onClear: React.MouseEventHandler<HTMLButtonElement>;
|
|
@@ -17,9 +21,11 @@ export interface CompleteStepProps {
|
|
|
17
21
|
|
|
18
22
|
export default function CompleteStep({
|
|
19
23
|
csButtonText,
|
|
24
|
+
csFailureText,
|
|
20
25
|
csSuccessText,
|
|
21
26
|
fileName,
|
|
22
27
|
isComplete,
|
|
28
|
+
isError,
|
|
23
29
|
isImage,
|
|
24
30
|
onClear,
|
|
25
31
|
uploadedImage,
|
|
@@ -31,25 +37,34 @@ export default function CompleteStep({
|
|
|
31
37
|
className="droppable-card-content d-flex flex-column align-items-center"
|
|
32
38
|
aria-live="polite"
|
|
33
39
|
>
|
|
34
|
-
{
|
|
35
|
-
|
|
40
|
+
{isError ? (
|
|
41
|
+
<>
|
|
42
|
+
<StatusIcon size={Size.LARGE} sentiment={Sentiment.NEGATIVE} />
|
|
43
|
+
{csFailureText && <p className="m-t-2 m-b-0">{csFailureText}</p>}
|
|
44
|
+
</>
|
|
36
45
|
) : (
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
<>
|
|
47
|
+
{isImage && uploadedImage ? (
|
|
48
|
+
<img src={uploadedImage} alt="OK" className="thumbnail " />
|
|
49
|
+
) : (
|
|
50
|
+
<DocumentIcon />
|
|
51
|
+
)}
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
{fileName && (
|
|
54
|
+
<Body as="p" className="m-b-0">
|
|
55
|
+
{fileName}
|
|
56
|
+
</Body>
|
|
57
|
+
)}
|
|
58
|
+
{csSuccessText && (
|
|
59
|
+
<Title className="caption m-t-1" type={Typography.TITLE_BODY}>
|
|
60
|
+
{csSuccessText}
|
|
61
|
+
</Title>
|
|
62
|
+
)}
|
|
63
|
+
</>
|
|
49
64
|
)}
|
|
50
65
|
</div>
|
|
51
66
|
{csButtonText && (
|
|
52
|
-
<Button className=
|
|
67
|
+
<Button className={isError ? 'm-t-2' : 'm-t-1'} onClick={onClear}>
|
|
53
68
|
{csButtonText}
|
|
54
69
|
</Button>
|
|
55
70
|
)}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Upload as UploadIcon } from '@transferwise/icons';
|
|
2
2
|
import { shallow } from 'enzyme';
|
|
3
|
-
import StatusIcon from '../../../statusIcon/StatusIcon';
|
|
4
3
|
|
|
5
4
|
import UploadImageStep from '.';
|
|
6
5
|
|
|
@@ -14,7 +13,6 @@ describe('uploadImageStep', () => {
|
|
|
14
13
|
usLabel: '',
|
|
15
14
|
usHelpImage: '',
|
|
16
15
|
usPlaceholder: '',
|
|
17
|
-
errorMessage: '',
|
|
18
16
|
};
|
|
19
17
|
let component;
|
|
20
18
|
beforeEach(() => {
|
|
@@ -65,14 +63,4 @@ describe('uploadImageStep', () => {
|
|
|
65
63
|
|
|
66
64
|
expect(component.find('.test-image')).toHaveLength(1);
|
|
67
65
|
});
|
|
68
|
-
|
|
69
|
-
describe('when errorMessage is not empty', () => {
|
|
70
|
-
it('renders errorMessage and icon when error is true', () => {
|
|
71
|
-
component = shallow(
|
|
72
|
-
<UploadImageStep {...UPLOADIMAGE_STEP_PROPS} errorMessage="error message" />,
|
|
73
|
-
);
|
|
74
|
-
expect(component.find('.upload-error-message').text()).toBe('<InlineAlert />');
|
|
75
|
-
expect(component.find(StatusIcon)).toHaveLength(1);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
66
|
});
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Upload as UploadIcon } from '@transferwise/icons';
|
|
2
2
|
import { createRef, PureComponent } from 'react';
|
|
3
|
-
import StatusIcon from '../../../statusIcon';
|
|
4
|
-
import { Sentiment, Size } from '../../../common';
|
|
5
|
-
import InlineAlert from '../../../inlineAlert';
|
|
6
3
|
|
|
7
4
|
export interface UploadImageStepProps {
|
|
8
5
|
fileDropped: (file: File) => void;
|
|
@@ -13,7 +10,6 @@ export interface UploadImageStepProps {
|
|
|
13
10
|
usHelpImage: React.ReactNode;
|
|
14
11
|
usLabel: string;
|
|
15
12
|
usPlaceholder: string;
|
|
16
|
-
errorMessage?: string | string[];
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
export default class UploadImageStep extends PureComponent<UploadImageStepProps> {
|
|
@@ -29,15 +25,6 @@ export default class UploadImageStep extends PureComponent<UploadImageStepProps>
|
|
|
29
25
|
|
|
30
26
|
getImage = () => {
|
|
31
27
|
const { usHelpImage, usLabel } = this.props;
|
|
32
|
-
const { errorMessage } = this.props;
|
|
33
|
-
|
|
34
|
-
if (errorMessage) {
|
|
35
|
-
return (
|
|
36
|
-
<div className="d-flex flex-column align-items-center">
|
|
37
|
-
<StatusIcon size={Size.LARGE} sentiment={Sentiment.NEGATIVE} />
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
28
|
|
|
42
29
|
if (!usHelpImage) {
|
|
43
30
|
return (
|
|
@@ -55,38 +42,32 @@ export default class UploadImageStep extends PureComponent<UploadImageStepProps>
|
|
|
55
42
|
};
|
|
56
43
|
|
|
57
44
|
render() {
|
|
58
|
-
const { isComplete, usAccept, usButtonText, usDisabled, usLabel, usPlaceholder
|
|
59
|
-
this.props;
|
|
45
|
+
const { isComplete, usAccept, usButtonText, usDisabled, usLabel, usPlaceholder } = this.props;
|
|
60
46
|
|
|
61
47
|
return (
|
|
62
|
-
<div
|
|
63
|
-
<div className="droppable-card-
|
|
64
|
-
<div className="
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
<div className="m-t-3 has-error">
|
|
86
|
-
<InlineAlert type={Sentiment.NEGATIVE}>{errorMessage}</InlineAlert>
|
|
87
|
-
</div>
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
48
|
+
<div>
|
|
49
|
+
<div className="droppable-default-card" aria-hidden={isComplete}>
|
|
50
|
+
<div className="droppable-card-content">
|
|
51
|
+
<div className="m-b-3">{this.getImage()}</div>
|
|
52
|
+
{usLabel && <h4 className="np-text-title-body m-b-1">{usLabel}</h4>}
|
|
53
|
+
{usPlaceholder && <p className="np-text-body-large m-b-3">{String(usPlaceholder)}</p>}
|
|
54
|
+
<label className={`btn btn-primary btn-md ${usDisabled ? 'disabled' : ''}`}>
|
|
55
|
+
{usButtonText ? (
|
|
56
|
+
<span>{usButtonText}</span>
|
|
57
|
+
) : (
|
|
58
|
+
<UploadIcon size={24} className="m-r-0" />
|
|
59
|
+
)}
|
|
60
|
+
<input
|
|
61
|
+
ref={this.uploadInputRef}
|
|
62
|
+
type="file"
|
|
63
|
+
accept={usAccept === '*' ? undefined : usAccept}
|
|
64
|
+
className="tw-droppable-input hidden"
|
|
65
|
+
disabled={usDisabled}
|
|
66
|
+
name="file-upload"
|
|
67
|
+
onChange={() => this.onManualUpload()}
|
|
68
|
+
/>
|
|
69
|
+
</label>
|
|
70
|
+
</div>
|
|
90
71
|
</div>
|
|
91
72
|
</div>
|
|
92
73
|
);
|