@transferwise/components 46.74.1 → 46.75.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.
- package/build/alert/Alert.js +3 -1
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +3 -1
- package/build/alert/Alert.mjs.map +1 -1
- package/build/field/Field.js +2 -0
- package/build/field/Field.js.map +1 -1
- package/build/field/Field.mjs +2 -0
- package/build/field/Field.mjs.map +1 -1
- package/build/i18n/en.json +5 -0
- package/build/i18n/en.json.js +5 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +5 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/inlineAlert/InlineAlert.js +3 -1
- package/build/inlineAlert/InlineAlert.js.map +1 -1
- package/build/inlineAlert/InlineAlert.mjs +3 -1
- package/build/inlineAlert/InlineAlert.mjs.map +1 -1
- package/build/statusIcon/StatusIcon.js +50 -16
- package/build/statusIcon/StatusIcon.js.map +1 -1
- package/build/statusIcon/StatusIcon.messages.js +24 -0
- package/build/statusIcon/StatusIcon.messages.js.map +1 -0
- package/build/statusIcon/StatusIcon.messages.mjs +22 -0
- package/build/statusIcon/StatusIcon.messages.mjs.map +1 -0
- package/build/statusIcon/StatusIcon.mjs +48 -14
- package/build/statusIcon/StatusIcon.mjs.map +1 -1
- package/build/types/alert/Alert.d.ts +6 -1
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/field/Field.d.ts +6 -1
- package/build/types/field/Field.d.ts.map +1 -1
- package/build/types/inlineAlert/InlineAlert.d.ts +2 -1
- package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts +7 -1
- package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.messages.d.ts +29 -0
- package/build/types/statusIcon/StatusIcon.messages.d.ts.map +1 -0
- package/build/types/upload/Upload.d.ts +5 -0
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +1 -0
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
- package/build/upload/Upload.js +4 -2
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.mjs +4 -2
- package/build/upload/Upload.mjs.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.js +6 -3
- package/build/upload/steps/uploadImageStep/uploadImageStep.js.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs +6 -3
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs.map +1 -1
- package/package.json +2 -2
- package/src/alert/Alert.spec.tsx +10 -0
- package/src/alert/Alert.tsx +7 -1
- package/src/field/Field.spec.tsx +19 -0
- package/src/field/Field.story.tsx +20 -4
- package/src/field/Field.tsx +7 -1
- package/src/i18n/en.json +5 -0
- package/src/inlineAlert/InlineAlert.spec.tsx +12 -1
- package/src/inlineAlert/InlineAlert.tsx +5 -1
- package/src/statusIcon/StatusIcon.docs.mdx +28 -0
- package/src/statusIcon/StatusIcon.messages.ts +34 -0
- package/src/statusIcon/StatusIcon.spec.tsx +39 -4
- package/src/statusIcon/StatusIcon.story.tsx +15 -6
- package/src/statusIcon/StatusIcon.tsx +63 -14
- package/src/upload/Upload.spec.js +19 -0
- package/src/upload/Upload.tsx +7 -0
- package/src/upload/steps/uploadImageStep/uploadImageStep.spec.js +13 -0
- package/src/upload/steps/uploadImageStep/uploadImageStep.tsx +15 -4
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { Sentiment, Size
|
|
1
|
+
import { Sentiment, Size } from '../common';
|
|
2
2
|
import { render, cleanup, screen, mockMatchMedia } from '../test-utils';
|
|
3
3
|
|
|
4
|
-
import StatusIcon from '.';
|
|
4
|
+
import StatusIcon, { StatusIconProps } from '.';
|
|
5
5
|
|
|
6
6
|
mockMatchMedia();
|
|
7
7
|
|
|
8
8
|
describe('StatusIcon', () => {
|
|
9
9
|
const renderStatusIcon = (props?: {
|
|
10
|
-
sentiment?:
|
|
11
|
-
size?:
|
|
10
|
+
sentiment?: StatusIconProps['sentiment'];
|
|
11
|
+
size?: StatusIconProps['size'];
|
|
12
|
+
iconLabel?: StatusIconProps['iconLabel'];
|
|
12
13
|
}) => {
|
|
13
14
|
return render(
|
|
14
15
|
<StatusIcon
|
|
15
16
|
sentiment={props?.sentiment || Sentiment.NEUTRAL}
|
|
16
17
|
size={props?.size || Size.MEDIUM}
|
|
18
|
+
iconLabel={props?.iconLabel}
|
|
17
19
|
/>,
|
|
18
20
|
);
|
|
19
21
|
};
|
|
@@ -79,4 +81,37 @@ describe('StatusIcon', () => {
|
|
|
79
81
|
renderStatusIcon();
|
|
80
82
|
expect(screen.getByTestId('info-icon')).toHaveClass('light');
|
|
81
83
|
});
|
|
84
|
+
|
|
85
|
+
describe('accessible name', () => {
|
|
86
|
+
it.each([
|
|
87
|
+
['Error', Sentiment.NEGATIVE],
|
|
88
|
+
['Success', Sentiment.POSITIVE],
|
|
89
|
+
['Warning', Sentiment.WARNING],
|
|
90
|
+
['Pending', Sentiment.PENDING],
|
|
91
|
+
['Information', Sentiment.NEUTRAL],
|
|
92
|
+
['Error', Sentiment.ERROR],
|
|
93
|
+
['Information', Sentiment.INFO],
|
|
94
|
+
['Success', Sentiment.SUCCESS],
|
|
95
|
+
])("should set '%s' as an accessible name for the '%s' sentiment", (label, sentiment) => {
|
|
96
|
+
renderStatusIcon({ sentiment });
|
|
97
|
+
|
|
98
|
+
expect(screen.getByLabelText(`${label}:`)).toBeInTheDocument();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should allow for `iconLabel` overrides', () => {
|
|
102
|
+
const iconLabel = 'Custom label';
|
|
103
|
+
renderStatusIcon({ sentiment: Sentiment.NEGATIVE, iconLabel });
|
|
104
|
+
|
|
105
|
+
expect(screen.getByLabelText(iconLabel)).toBeInTheDocument();
|
|
106
|
+
expect(screen.queryByLabelText(`Error:`)).not.toBeInTheDocument();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should allow for `iconLabel` to be `null` to keep the icon presentational', () => {
|
|
110
|
+
const iconLabel = null;
|
|
111
|
+
renderStatusIcon({ sentiment: Sentiment.NEGATIVE, iconLabel });
|
|
112
|
+
|
|
113
|
+
expect(screen.queryByRole(`graphics-symbol`)).not.toBeInTheDocument();
|
|
114
|
+
expect(screen.queryByLabelText(`Error:`)).not.toBeInTheDocument();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
82
117
|
});
|
|
@@ -7,16 +7,25 @@ import StatusIcon from './StatusIcon';
|
|
|
7
7
|
export default {
|
|
8
8
|
component: StatusIcon,
|
|
9
9
|
title: 'Other/StatusIcon',
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
argTypes: {
|
|
12
|
+
iconLabel: {
|
|
13
|
+
control: 'text',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
10
16
|
} satisfies Meta<typeof StatusIcon>;
|
|
11
17
|
|
|
12
18
|
type Story = StoryObj<typeof StatusIcon>;
|
|
13
19
|
|
|
14
|
-
export const Basic: Story = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
export const Basic: Story = {};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Ignored by the screen readers. Use with care.
|
|
24
|
+
*/
|
|
25
|
+
export const Presentational: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
iconLabel: null,
|
|
28
|
+
},
|
|
20
29
|
};
|
|
21
30
|
|
|
22
31
|
export const Variants: Story = {
|
|
@@ -1,34 +1,80 @@
|
|
|
1
1
|
import { Info, Alert, Cross, Check, ClockBorderless } from '@transferwise/icons';
|
|
2
2
|
import { clsx } from 'clsx';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
3
4
|
|
|
4
5
|
import { SizeSmall, SizeMedium, SizeLarge, Sentiment, Size, Breakpoint } from '../common';
|
|
5
6
|
import Circle, { CircleProps } from '../common/circle';
|
|
6
7
|
import { useMedia } from '../common/hooks/useMedia';
|
|
7
8
|
|
|
9
|
+
import messages from './StatusIcon.messages';
|
|
10
|
+
|
|
8
11
|
export type StatusIconProps = {
|
|
9
12
|
sentiment: `${Sentiment}`;
|
|
10
13
|
size: SizeSmall | SizeMedium | SizeLarge;
|
|
14
|
+
/**
|
|
15
|
+
* Override for the sentiment's-derived, default, accessible
|
|
16
|
+
* name announced by the screen readers. <br />
|
|
17
|
+
* Using `null` will render the icon purely presentational.
|
|
18
|
+
* */
|
|
19
|
+
iconLabel?: string | null;
|
|
11
20
|
};
|
|
12
21
|
|
|
13
|
-
const iconTypeMap = {
|
|
14
|
-
positive: Check,
|
|
15
|
-
neutral: Info,
|
|
16
|
-
warning: Alert,
|
|
17
|
-
negative: Cross,
|
|
18
|
-
pending: ClockBorderless,
|
|
19
|
-
info: Info,
|
|
20
|
-
error: Cross,
|
|
21
|
-
success: Check,
|
|
22
|
-
} satisfies Record<`${Sentiment}`, React.ElementType>;
|
|
23
|
-
|
|
24
22
|
const mapLegacySize = {
|
|
25
23
|
[String(Size.SMALL)]: 16,
|
|
26
24
|
[String(Size.MEDIUM)]: 40,
|
|
27
25
|
[String(Size.LARGE)]: 48,
|
|
28
26
|
} satisfies Record<string, CircleProps['size']>;
|
|
29
27
|
|
|
30
|
-
const StatusIcon = ({
|
|
31
|
-
|
|
28
|
+
const StatusIcon = ({
|
|
29
|
+
sentiment = 'neutral',
|
|
30
|
+
size: sizeProp = 'md',
|
|
31
|
+
iconLabel,
|
|
32
|
+
}: StatusIconProps) => {
|
|
33
|
+
const intl = useIntl();
|
|
34
|
+
|
|
35
|
+
const iconMetaBySentiment: Record<
|
|
36
|
+
`${Sentiment}`,
|
|
37
|
+
{
|
|
38
|
+
Icon: React.ElementType;
|
|
39
|
+
defaultIconLabel: string;
|
|
40
|
+
}
|
|
41
|
+
> = {
|
|
42
|
+
[Sentiment.NEGATIVE]: {
|
|
43
|
+
Icon: Cross,
|
|
44
|
+
defaultIconLabel: intl.formatMessage(messages.errorLabel),
|
|
45
|
+
},
|
|
46
|
+
[Sentiment.POSITIVE]: {
|
|
47
|
+
Icon: Check,
|
|
48
|
+
defaultIconLabel: intl.formatMessage(messages.successLabel),
|
|
49
|
+
},
|
|
50
|
+
[Sentiment.WARNING]: {
|
|
51
|
+
Icon: Alert,
|
|
52
|
+
defaultIconLabel: intl.formatMessage(messages.warningLabel),
|
|
53
|
+
},
|
|
54
|
+
[Sentiment.PENDING]: {
|
|
55
|
+
Icon: ClockBorderless,
|
|
56
|
+
defaultIconLabel: intl.formatMessage(messages.pendingLabel),
|
|
57
|
+
},
|
|
58
|
+
[Sentiment.NEUTRAL]: {
|
|
59
|
+
Icon: Info,
|
|
60
|
+
defaultIconLabel: intl.formatMessage(messages.informationLabel),
|
|
61
|
+
},
|
|
62
|
+
// deprecated
|
|
63
|
+
[Sentiment.ERROR]: {
|
|
64
|
+
Icon: Cross,
|
|
65
|
+
defaultIconLabel: intl.formatMessage(messages.errorLabel),
|
|
66
|
+
},
|
|
67
|
+
[Sentiment.INFO]: {
|
|
68
|
+
Icon: Info,
|
|
69
|
+
defaultIconLabel: intl.formatMessage(messages.informationLabel),
|
|
70
|
+
},
|
|
71
|
+
[Sentiment.SUCCESS]: {
|
|
72
|
+
Icon: Check,
|
|
73
|
+
defaultIconLabel: intl.formatMessage(messages.successLabel),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const { Icon, defaultIconLabel } = iconMetaBySentiment[sentiment];
|
|
77
|
+
|
|
32
78
|
const iconColor = sentiment === 'warning' || sentiment === 'pending' ? 'dark' : 'light';
|
|
33
79
|
const isTinyViewport = useMedia(`(max-width: ${Breakpoint.ZOOM_400}px)`);
|
|
34
80
|
const size = sizeProp === Size.SMALL && isTinyViewport ? 32 : mapLegacySize[sizeProp];
|
|
@@ -39,7 +85,10 @@ const StatusIcon = ({ sentiment = 'neutral', size: sizeProp = 'md' }: StatusIcon
|
|
|
39
85
|
data-testid="status-icon"
|
|
40
86
|
className={clsx('status-circle', `status-circle-${sizeProp}`, sentiment)}
|
|
41
87
|
>
|
|
42
|
-
<Icon
|
|
88
|
+
<Icon
|
|
89
|
+
className={clsx('status-icon', iconColor)}
|
|
90
|
+
title={iconLabel === null ? undefined : iconLabel || defaultIconLabel}
|
|
91
|
+
/>
|
|
43
92
|
</Circle>
|
|
44
93
|
);
|
|
45
94
|
};
|
|
@@ -7,6 +7,7 @@ import { ANIMATION_DURATION_IN_MS } from '../processIndicator';
|
|
|
7
7
|
import { CompleteStep, UploadImageStep, ProcessingStep } from './steps';
|
|
8
8
|
|
|
9
9
|
import Upload from '.';
|
|
10
|
+
import { Cross } from '@transferwise/icons';
|
|
10
11
|
|
|
11
12
|
mockMatchMedia();
|
|
12
13
|
|
|
@@ -252,6 +253,7 @@ describe('Upload', () => {
|
|
|
252
253
|
...UPLOADIMAGE_STEP_PROPS,
|
|
253
254
|
isComplete: false,
|
|
254
255
|
errorMessage: 'csFailureText',
|
|
256
|
+
errorIconLabel: undefined,
|
|
255
257
|
usButtonText: 'Try again',
|
|
256
258
|
usHelpImage: null,
|
|
257
259
|
});
|
|
@@ -282,5 +284,22 @@ describe('Upload', () => {
|
|
|
282
284
|
|
|
283
285
|
expect(props.onSuccess).toHaveBeenCalledTimes(1);
|
|
284
286
|
});
|
|
287
|
+
|
|
288
|
+
it('should respect `errorIconLabel` override', async () => {
|
|
289
|
+
const errorIconLabel = 'Custom error icon label';
|
|
290
|
+
component = mount(<Upload {...props} errorIconLabel={errorIconLabel} />);
|
|
291
|
+
const upload = component.children();
|
|
292
|
+
asyncFileRead.mockImplementation(async () => {
|
|
293
|
+
throw 'An error';
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await act(async () => {
|
|
297
|
+
await upload.instance().fileDropped(TEST_FILE);
|
|
298
|
+
});
|
|
299
|
+
await waitForUpload();
|
|
300
|
+
component.update();
|
|
301
|
+
|
|
302
|
+
expect(component.find(Cross).at(1).prop('title')).toBe(errorIconLabel);
|
|
303
|
+
});
|
|
285
304
|
});
|
|
286
305
|
});
|
package/src/upload/Upload.tsx
CHANGED
|
@@ -56,6 +56,11 @@ export interface UploadProps extends WrappedComponentProps {
|
|
|
56
56
|
usHelpImage?: React.ReactNode;
|
|
57
57
|
usLabel?: string;
|
|
58
58
|
usPlaceholder?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Override for the [InlineAlert icon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)
|
|
61
|
+
* announced by the screen readers
|
|
62
|
+
* */
|
|
63
|
+
errorIconLabel?: string;
|
|
59
64
|
/** @deprecated Only a single variant exists, please remove this prop. */
|
|
60
65
|
uploadStep?: `${UploadStep}`;
|
|
61
66
|
onCancel?: () => void;
|
|
@@ -338,6 +343,7 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
338
343
|
csSuccessText,
|
|
339
344
|
size,
|
|
340
345
|
intl,
|
|
346
|
+
errorIconLabel,
|
|
341
347
|
} = this.props;
|
|
342
348
|
|
|
343
349
|
const {
|
|
@@ -422,6 +428,7 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
422
428
|
? response.status
|
|
423
429
|
: undefined,
|
|
424
430
|
)}
|
|
431
|
+
errorIconLabel={errorIconLabel}
|
|
425
432
|
/>
|
|
426
433
|
)}
|
|
427
434
|
{isProcessing && (
|
|
@@ -3,6 +3,7 @@ import { shallow } from 'enzyme';
|
|
|
3
3
|
import StatusIcon from '../../../statusIcon/StatusIcon';
|
|
4
4
|
|
|
5
5
|
import UploadImageStep from '.';
|
|
6
|
+
import { InlineAlert } from '../../../index';
|
|
6
7
|
|
|
7
8
|
describe('uploadImageStep', () => {
|
|
8
9
|
const UPLOADIMAGE_STEP_PROPS = {
|
|
@@ -66,6 +67,18 @@ describe('uploadImageStep', () => {
|
|
|
66
67
|
expect(component.find('.test-image')).toHaveLength(1);
|
|
67
68
|
});
|
|
68
69
|
|
|
70
|
+
it('should respect `errorIconLabel` override', () => {
|
|
71
|
+
const errorIconLabel = 'Error icon label';
|
|
72
|
+
component = shallow(
|
|
73
|
+
<UploadImageStep
|
|
74
|
+
{...UPLOADIMAGE_STEP_PROPS}
|
|
75
|
+
errorMessage="Maximum filesize is 2MB."
|
|
76
|
+
errorIconLabel={errorIconLabel}
|
|
77
|
+
/>,
|
|
78
|
+
);
|
|
79
|
+
expect(component.find(InlineAlert).prop('iconLabel')).toBe(errorIconLabel);
|
|
80
|
+
});
|
|
81
|
+
|
|
69
82
|
describe('when errorMessage is not empty', () => {
|
|
70
83
|
it('renders errorMessage and icon when error is true', () => {
|
|
71
84
|
component = shallow(
|
|
@@ -14,6 +14,7 @@ export interface UploadImageStepProps {
|
|
|
14
14
|
usLabel: string;
|
|
15
15
|
usPlaceholder: string;
|
|
16
16
|
errorMessage?: string | string[];
|
|
17
|
+
errorIconLabel?: string;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export default class UploadImageStep extends PureComponent<UploadImageStepProps> {
|
|
@@ -34,7 +35,7 @@ export default class UploadImageStep extends PureComponent<UploadImageStepProps>
|
|
|
34
35
|
if (errorMessage) {
|
|
35
36
|
return (
|
|
36
37
|
<div className="d-flex flex-column align-items-center">
|
|
37
|
-
<StatusIcon size={Size.LARGE} sentiment={Sentiment.NEGATIVE} />
|
|
38
|
+
<StatusIcon size={Size.LARGE} sentiment={Sentiment.NEGATIVE} iconLabel={null} />
|
|
38
39
|
</div>
|
|
39
40
|
);
|
|
40
41
|
}
|
|
@@ -55,8 +56,16 @@ export default class UploadImageStep extends PureComponent<UploadImageStepProps>
|
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
render() {
|
|
58
|
-
const {
|
|
59
|
-
|
|
59
|
+
const {
|
|
60
|
+
errorMessage,
|
|
61
|
+
isComplete,
|
|
62
|
+
errorIconLabel,
|
|
63
|
+
usAccept,
|
|
64
|
+
usButtonText,
|
|
65
|
+
usDisabled,
|
|
66
|
+
usLabel,
|
|
67
|
+
usPlaceholder,
|
|
68
|
+
} = this.props;
|
|
60
69
|
|
|
61
70
|
return (
|
|
62
71
|
<div className="droppable-default-card" aria-hidden={isComplete}>
|
|
@@ -88,7 +97,9 @@ export default class UploadImageStep extends PureComponent<UploadImageStepProps>
|
|
|
88
97
|
{errorMessage && (
|
|
89
98
|
<div className="upload-error-message">
|
|
90
99
|
<div className="m-t-3 has-error">
|
|
91
|
-
<InlineAlert type={Sentiment.NEGATIVE}
|
|
100
|
+
<InlineAlert type={Sentiment.NEGATIVE} iconLabel={errorIconLabel}>
|
|
101
|
+
{errorMessage}
|
|
102
|
+
</InlineAlert>
|
|
92
103
|
</div>
|
|
93
104
|
</div>
|
|
94
105
|
)}
|