-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathChatButtonWithUnreadMessagesBadge.tsx
More file actions
77 lines (68 loc) · 2.75 KB
/
ChatButtonWithUnreadMessagesBadge.tsx
File metadata and controls
77 lines (68 loc) · 2.75 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { IStackStyles, Stack } from '@fluentui/react';
import { _formatString } from '@internal/acs-ui-common';
import { ControlBarButtonProps } from '@internal/react-components';
import React, { useCallback, useMemo } from 'react';
import { CallWithChatCompositeIcon } from '../../common/icons';
import { ChatButton } from './ChatButton';
import { useCallWithChatCompositeStrings } from '../hooks/useCallWithChatCompositeStrings';
import { NotificationIcon } from './NotificationIcon';
/**
* @private
*/
export interface ChatButtonWithUnreadMessagesBadgeProps extends ControlBarButtonProps {
unreadChatMessagesCount: number;
hideUnreadChatMessagesBadge?: boolean;
newMessageLabel: string;
}
const filledIcon = <CallWithChatCompositeIcon iconName={'ControlBarChatButtonActive'} />;
const regularIcon = <CallWithChatCompositeIcon iconName={'ControlBarChatButtonInactive'} />;
/**
* @private
*/
export const ChatButtonWithUnreadMessagesBadge = (props: ChatButtonWithUnreadMessagesBadgeProps): JSX.Element => {
const { newMessageLabel, unreadChatMessagesCount, hideUnreadChatMessagesBadge } = props;
const baseIcon = props.showLabel ? regularIcon : filledIcon;
const callWithChatStrings = useCallWithChatCompositeStrings();
const numberOfMsgToolTip =
props.strings?.tooltipOffContent && unreadChatMessagesCount > 0
? _formatString(callWithChatStrings.chatButtonTooltipClosedWithMessageCount, {
unreadMessagesCount: `${unreadChatMessagesCount}`
})
: undefined;
const chatStrings = useMemo(
() => ({
label: props.strings?.label,
tooltipOffContent: numberOfMsgToolTip ? numberOfMsgToolTip : props.strings?.tooltipOffContent,
tooltipOnContent: props.strings?.tooltipOnContent
}),
[numberOfMsgToolTip, props.strings?.label, props.strings?.tooltipOffContent, props.strings?.tooltipOnContent]
);
const onRenderOnIcon = useCallback(() => baseIcon, [baseIcon]);
const notificationOnIcon = useCallback((): JSX.Element => {
return (
<Stack styles={chatNotificationContainerStyles}>
{unreadChatMessagesCount > 0 && !hideUnreadChatMessagesBadge && (
<NotificationIcon chatMessagesCount={unreadChatMessagesCount} label={newMessageLabel} />
)}
{baseIcon}
</Stack>
);
}, [unreadChatMessagesCount, newMessageLabel, baseIcon, hideUnreadChatMessagesBadge]);
return (
<ChatButton
{...props}
data-ui-id="call-with-chat-composite-chat-button"
onRenderOffIcon={notificationOnIcon}
onRenderOnIcon={onRenderOnIcon}
strings={chatStrings}
/>
);
};
const chatNotificationContainerStyles: IStackStyles = {
root: {
display: 'inline',
position: 'relative'
}
};