-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathAttachmentUploadCards.tsx
More file actions
99 lines (92 loc) · 3.2 KB
/
AttachmentUploadCards.tsx
File metadata and controls
99 lines (92 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { Icon, mergeStyles } from '@fluentui/react';
import React, { useMemo } from 'react';
import { _AttachmentCard } from './AttachmentCard';
import { _AttachmentCardGroup, _AttachmentCardGroupLayout } from './AttachmentCardGroup';
import { AttachmentMetadataInProgress } from '@internal/acs-ui-common';
import { useLocaleAttachmentCardStringsTrampoline } from '../utils/common';
/**
* Strings of _AttachmentUploadCards that can be overridden.
*
* @internal
*/
export interface _AttachmentUploadCardsStrings {
/** Aria label to notify user when focus is on cancel attachment upload button. */
removeAttachment: string;
/** Aria label to notify user attachment uploading starts. */
uploading: string;
/** Aria label to notify user attachment is uploaded. */
uploadCompleted: string;
/** Aria label to notify user more attachment action menu. */
attachmentMoreMenu: string;
}
/**
* @internal
*/
export interface AttachmentUploadCardsProps {
/**
* Optional array of {@link AttachmentMetadataInProgress}
*/
attachments?: AttachmentMetadataInProgress[];
/**
* Optional callback to remove the attachment upload before sending by clicking on
* cancel icon.
*/
onCancelAttachmentUpload?: (attachmentId: string) => void;
/**
* Optional arialabel strings for attachment upload cards
*/
strings?: _AttachmentUploadCardsStrings;
}
const actionIconStyle = { height: '1rem' };
/**
* @internal
*/
export const _AttachmentUploadCards = (props: AttachmentUploadCardsProps): JSX.Element => {
const attachments = props.attachments;
const localeStrings = useLocaleAttachmentCardStringsTrampoline();
const removeAttachmentButtonString = useMemo(
() => () => {
return props.strings?.removeAttachment ?? localeStrings.removeAttachment;
},
[props.strings?.removeAttachment, localeStrings.removeAttachment]
);
if (!attachments || attachments.length === 0) {
return <></>;
}
return (
<_AttachmentCardGroup attachmentGroupLayout={_AttachmentCardGroupLayout.Flex}>
{attachments &&
attachments
.filter((attachment) => !attachment.error)
.map((attachment) => (
<_AttachmentCard
attachment={attachment}
key={attachment.id}
menuActions={[
{
name: removeAttachmentButtonString(),
icon: (
<div data-testid="attachment-upload-card-remove">
<Icon iconName="CancelAttachmentUpload" className={mergeStyles(actionIconStyle)} />
</div>
),
onClick: (attachment) => {
return new Promise((resolve, reject) => {
try {
props.onCancelAttachmentUpload && props.onCancelAttachmentUpload(attachment.id);
resolve();
} catch (e) {
reject((e as Error).message);
}
});
}
}
]}
strings={props.strings}
/>
))}
</_AttachmentCardGroup>
);
};