-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathChannelHeader.tsx
93 lines (83 loc) · 3.38 KB
/
ChannelHeader.tsx
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
import React from 'react';
import { MenuIcon as DefaultMenuIcon } from './icons';
import { AvatarProps, Avatar as DefaultAvatar } from '../Avatar';
import { useChannelPreviewInfo } from '../ChannelPreview/hooks/useChannelPreviewInfo';
import { useChannelStateContext } from '../../context/ChannelStateContext';
import { useChatContext } from '../../context/ChatContext';
import { useTranslationContext } from '../../context/TranslationContext';
import type { DefaultStreamChatGenerics } from '../../types/types';
export type ChannelHeaderProps = {
/** UI component to display a user's avatar, defaults to and accepts same props as: [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx) */
Avatar?: React.ComponentType<AvatarProps>;
/** Manually set the image to render, defaults to the Channel image */
image?: string;
/** Show a little indicator that the Channel is live right now */
live?: boolean;
/** UI component to display menu icon, defaults to [MenuIcon](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelHeader/ChannelHeader.tsx)*/
MenuIcon?: React.ComponentType;
/** Set title manually */
title?: string;
};
const UnMemoizedChannelHeader = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
>(
props: ChannelHeaderProps,
) => {
const {
Avatar = DefaultAvatar,
MenuIcon = DefaultMenuIcon,
image: overrideImage,
live,
title: overrideTitle,
} = props;
const { channel, watcher_count } = useChannelStateContext<StreamChatGenerics>('ChannelHeader');
const { openMobileNav } = useChatContext<StreamChatGenerics>('ChannelHeader');
const { t } = useTranslationContext('ChannelHeader');
const { displayImage, displayTitle } = useChannelPreviewInfo({
channel,
overrideImage,
overrideTitle,
});
const { member_count, subtitle } = channel?.data || {};
return (
<div className='str-chat__header-livestream str-chat__channel-header'>
<button
aria-label={t('aria/Menu')}
className='str-chat__header-hamburger'
onClick={openMobileNav}
>
<MenuIcon />
</button>
<Avatar
image={displayImage}
name={displayTitle}
shape='rounded'
size={channel?.type === 'commerce' ? 60 : 40}
/>
<div className='str-chat__header-livestream-left str-chat__channel-header-end'>
<p className='str-chat__header-livestream-left--title str-chat__channel-header-title'>
{displayTitle}{' '}
{live && (
<span className='str-chat__header-livestream-left--livelabel'>{t<string>('live')}</span>
)}
</p>
{subtitle && <p className='str-chat__header-livestream-left--subtitle'>{subtitle}</p>}
<p className='str-chat__header-livestream-left--members str-chat__channel-header-info'>
{!live && !!member_count && member_count > 0 && (
<>
{t('{{ memberCount }} members', {
memberCount: member_count,
})}
,{' '}
</>
)}
{t<string>('{{ watcherCount }} online', { watcherCount: watcher_count })}
</p>
</div>
</div>
);
};
/**
* The ChannelHeader component renders some basic information about a Channel.
*/
export const ChannelHeader = React.memo(UnMemoizedChannelHeader) as typeof UnMemoizedChannelHeader;