Skip to content

Commit 4e0ae36

Browse files
authored
Merge pull request #697 from GetStream/channel-header-image
Add image prop to customize header
2 parents 83fdd06 + 4e10c58 commit 4e0ae36

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/components/ChannelHeader/ChannelHeader.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
// @ts-check
21
import React, { useContext } from 'react';
32
import PropTypes from 'prop-types';
43
import { Avatar as DefaultAvatar } from '../Avatar';
5-
import { ChannelContext, TranslationContext, ChatContext } from '../../context';
4+
import { ChannelContext, ChatContext, TranslationContext } from '../../context';
65

76
/**
87
* ChannelHeader - Render some basic information about this channel
98
* @example ../../docs/ChannelHeader.md
109
* @type {React.FC<import('types').ChannelHeaderProps>}
1110
*/
12-
const ChannelHeader = ({ Avatar = DefaultAvatar, title, live }) => {
13-
/** @type {import("types").TranslationContextValue} */
14-
const { t } = useContext(TranslationContext);
15-
/** @type {import("types").ChannelContextValue} */
11+
const ChannelHeader = (props) => {
12+
const { Avatar = DefaultAvatar, image: propImage, live, title } = props;
13+
1614
const { channel, watcher_count } = useContext(ChannelContext);
1715
const { openMobileNav } = useContext(ChatContext);
18-
const { image, member_count, name, subtitle } = channel?.data || {};
16+
const { t } = useContext(TranslationContext);
17+
18+
const { image: channelImage, member_count, name, subtitle } =
19+
channel?.data || {};
20+
21+
const image = propImage || channelImage;
1922

2023
return (
2124
<div className="str-chat__header-livestream">
@@ -68,10 +71,12 @@ ChannelHeader.propTypes = {
6871
* Defaults to and accepts same props as: [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.js)
6972
* */
7073
Avatar: /** @type {PropTypes.Validator<React.ElementType<import('types').AvatarProps>>} */ (PropTypes.elementType),
71-
/** Set title manually */
72-
title: PropTypes.string,
74+
/** Manually set the image to render, defaults to the channel image */
75+
image: PropTypes.string,
7376
/** Show a little indicator that the channel is live right now */
7477
live: PropTypes.bool,
78+
/** Set title manually */
79+
title: PropTypes.string,
7580
};
7681

7782
export default React.memo(ChannelHeader);

types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,11 @@ export interface MessageListProps {
668668

669669
export interface ChannelHeaderProps {
670670
Avatar?: React.ElementType<AvatarProps>;
671-
/** Set title manually */
672-
title?: string;
671+
image?: string;
673672
/** Show a little indicator that the channel is live right now */
674673
live?: boolean;
674+
/** Set title manually */
675+
title?: string;
675676
}
676677

677678
export interface MessageInputProps {

0 commit comments

Comments
 (0)