-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathCaption.tsx
More file actions
65 lines (59 loc) · 1.85 KB
/
Caption.tsx
File metadata and controls
65 lines (59 loc) · 1.85 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { IPersona, Persona, Stack, PersonaSize, Text } from '@fluentui/react';
import React from 'react';
import { _FileUploadCardsStrings } from './FileUploadCards';
import { OnRenderAvatarCallback } from '../types';
import {
captionClassName,
captionsContentContainerClassName,
displayNameClassName,
displayNameContainerClassName,
iconClassName
} from './styles/Captions.style';
import { _CaptionsInfo } from './CaptionsBanner';
/**
* @internal
* Props for a single line of caption.
*/
export interface _CaptionProps extends _CaptionsInfo {
/**
* Optional callback to override render of the avatar.
*
* @param userId - user Id
*/
onRenderAvatar?: OnRenderAvatarCallback;
}
/**
* @internal
* A component for displaying a single line of caption
*/
export const _Caption = (props: _CaptionProps): JSX.Element => {
const { displayName, userId, captionText, onRenderAvatar } = props;
const personaOptions: IPersona = {
hidePersonaDetails: true,
size: PersonaSize.size32,
text: displayName,
showOverflowTooltip: false,
initialsTextColor: 'white',
styles: {
root: {
margin: '0.25rem'
}
}
};
const userIcon = onRenderAvatar ? onRenderAvatar(userId ?? '', personaOptions) : <Persona {...personaOptions} />;
return (
<Stack horizontal verticalAlign="start" horizontalAlign="start">
<Stack.Item className={iconClassName}>{userIcon}</Stack.Item>
<Stack verticalAlign="start" className={captionsContentContainerClassName}>
<Stack.Item className={displayNameContainerClassName}>
<Text className={displayNameClassName}>{displayName}</Text>
</Stack.Item>
<Stack.Item className={captionClassName} dir="auto">
{captionText}
</Stack.Item>
</Stack>
</Stack>
);
};