-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathChatComposite.tsx
More file actions
138 lines (130 loc) · 4.36 KB
/
ChatComposite.tsx
File metadata and controls
138 lines (130 loc) · 4.36 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CommunicationParticipant, MessageRenderer, MessageProps } from '@internal/react-components';
import React from 'react';
import { BaseProvider, BaseCompositeProps } from '../common/BaseComposite';
import { ChatCompositeIcons } from '../common/icons';
import { ChatAdapter } from './adapter/ChatAdapter';
import { ChatAdapterProvider } from './adapter/ChatAdapterProvider';
import { chatScreenContainerStyle } from './styles/Chat.styles';
import { ChatScreen } from './ChatScreen';
/* @conditional-compile-remove(file-sharing) */
import { FileSharingOptions } from './ChatScreen';
/**
* Props for {@link ChatComposite}.
*
* @public
*/
export interface ChatCompositeProps extends BaseCompositeProps<ChatCompositeIcons> {
/**
* An adapter provides logic and data to the composite.
* Composite can also be controlled using the adapter.
*/
adapter: ChatAdapter;
/**
* `(messageProps: MessageProps, defaultOnRender?: MessageRenderer) => JSX.Element`
* A callback for customizing the message renderer.
*/
onRenderMessage?: (messageProps: MessageProps, defaultOnRender?: MessageRenderer) => JSX.Element;
/**
* `(typingUsers: CommunicationParticipant[]) => JSX.Element`
* A callback for customizing the typing indicator renderer.
*/
onRenderTypingIndicator?: (typingUsers: CommunicationParticipant[]) => JSX.Element;
/**
* Flags to enable/disable visual elements of the {@link ChatComposite}.
*/
options?: ChatCompositeOptions;
/* @conditional-compile-remove(file-sharing) */
/**
* Optimizes the composite form factor for either desktop or mobile.
* @remarks `mobile` is currently only optimized for Portrait mode on mobile devices and does not support landscape.
* @defaultValue 'desktop'
*/
formFactor?: 'desktop' | 'mobile';
}
/**
* Optional features of the {@link ChatComposite}.
*
* @public
*/
export type ChatCompositeOptions = {
/**
* Surface Azure Communication Services backend errors in the UI with {@link @azure/communication-react#ErrorBar}.
* Hide or show the error bar.
* @defaultValue true
*/
errorBar?: boolean;
/* @conditional-compile-remove(chat-composite-participant-pane) */
/**
* Show or hide the participant pane. This feature is in beta and not supported on mobile or narrow screen views.
* @defaultValue false
*
* @beta
*/
participantPane?: boolean;
/**
* Show or hide the topic at the top of the chat. Hidden if set to `false`
* @defaultValue true
*/
topic?: boolean;
/**
* enumerable to determine if the input box has focus on render or not.
* When undefined nothing has focus on render
*/
autoFocus?: 'sendBoxTextField';
/* @conditional-compile-remove(file-sharing) */
/**
* Properties for configuring the File Sharing feature.
* If undefined, file sharing feature will be disabled.
* @beta
*/
fileSharing?: FileSharingOptions;
};
/**
* A customizable UI composite for the chat experience.
*
* @remarks Chat composite min width and height are respectively 17.5rem and 20rem (280px and 320px, with default rem at 16px)
*
* @public
*/
export const ChatComposite = (props: ChatCompositeProps): JSX.Element => {
const {
adapter,
options,
onFetchAvatarPersonaData,
onRenderTypingIndicator,
onRenderMessage,
onFetchParticipantMenuItems
} = props;
const formFactor = props['formFactor'] || 'desktop';
/**
* @TODO Remove this function and pass the props directly when file-sharing is promoted to stable.
* @private
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const fileSharingOptions = () => {
/* @conditional-compile-remove(file-sharing) */
return {
fileSharing: options?.fileSharing
};
return {};
};
return (
<div className={chatScreenContainerStyle}>
<BaseProvider {...props}>
<ChatAdapterProvider adapter={adapter}>
<ChatScreen
formFactor={formFactor}
options={options}
onFetchAvatarPersonaData={onFetchAvatarPersonaData}
onRenderTypingIndicator={onRenderTypingIndicator}
onRenderMessage={onRenderMessage}
onFetchParticipantMenuItems={onFetchParticipantMenuItems}
{...fileSharingOptions()}
/>
</ChatAdapterProvider>
</BaseProvider>
</div>
);
};