Skip to main content
Version: v5

Message Header

Overview

MessageHeader is a Component that showcases the User or Group details in the toolbar. Furthermore, it also presents a typing indicator and a back navigation button for ease of use.

Image

The MessageHeader is comprised of the following components:

ComponentDescription
CometChatListItemThis component’s view consists of avatar, status indicator , title, and subtitle. The fields are then mapped with the SDK’s user, group class.
Back ButtonBackButton that allows users to navigate back from the current activity or screen to the previous one.

Usage

Integration

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export function MessageHeaderDemo() {
const [chatUser, setChatUser] = React.useState<CometChat.User>();
React.useEffect(() => {
CometChat.getUser("uid").then((user) => {
setChatUser(user);
});
}, []);

return chatUser ? (
<div>{chatUser && <CometChatMessageHeader user={chatUser} />}</div>
) : null;
}

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

1. OnBack

OnBack is triggered when you click on the back button of the Message Header component. You can override this action using the following code snippet.

Example

In this example, we are employing the onBack action.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export function MessageHeaderDemo() {
const [chatUser, setChatUser] = React.useState<CometChat.User>();
React.useEffect(() => {
CometChat.getUser("uid").then((user) => {
setChatUser(user);
});
}, []);

function handleOnBack() {
console.log("your custom on back action");
}

return chatUser ? (
<div>
{chatUser && (
<CometChatMessageHeader user={chatUser} onBack={handleOnBack} />
)}
</div>
) : null;
}

2. OnError

This action doesn't change the behavior of the component but rather listens for any errors that occur in the Message Header component.

Example

In this example, we are employing the onError action.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export function MessageHeaderDemo() {
const [chatUser, setChatUser] = React.useState<CometChat.User>();
React.useEffect(() => {
CometChat.getUser("uid").then((user) => {
setChatUser(user);
});
}, []);

function handleError(error: CometChat.CometChatException) {
throw new Error("your custom error action");
}
return chatUser ? (
<div>
{chatUser && (
<CometChatMessageHeader user={chatUser} onError={handleError} />
)}
</div>
) : null;
}

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.

The MessageHeader component does not have any exposed filters.

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.

The MessageHeader component does not produce any events.

Customization

To fit your app's design requirements, you can customize the appearance of the Message Header component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

To customize the appearance, you can customise css of CometChatMessageHeader

Example

Image
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

// Assuming groupObj is defined elsewhere in your code
<CometChatMessageHeader group={groupObj} />;

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

Here is a code snippet demonstrating how you can customize the functionality of the Message Header component.

import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

<CometChatMessageHeader user={chatUser} hideBackButton={true} />;

Following is a list of customizations along with their corresponding code snippets:

PropertyDescriptionCode
Summary Generation Message CountNumber of messages for which the summary should be shown.summaryGenerationMessageCount={1000}
Hide Conversation Summary ButtonHides the conversation summary button.hideConversationSummaryButton={true}
Disable Auto Summary GenerationDisables the auto generation of conversation summary.disableAutoSummaryGeneration={true}
Hide Back ButtonHides the back button in the header in mobile view.hideBackButton={true}
Hide Video Call ButtonHides the video call button.hideVideoCallButton={true}
Hide Voice Call ButtonHides the voice call button.hideVoiceCallButton={true}
Hide User StatusHides the user's online/offline status indicator.hideUserStatus={true}
UserA CometChat.User object representing the user whose information (e.g., status) is displayed.user={chatUser}
GroupA CometChat.Group object representing the group whose details (e.g., member count) are displayed.group={chatGroup}

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.

ItemView

The customized chat interface is displayed below.

Image

Use the following code to achieve the customization shown above.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatMessageHeader,
CometChatListItem,
} from "@cometchat/chat-uikit-react";

// Custom list item view definition
const CustomItemView = (
<>
<CometChatListItem
avatarName={chatUser?.getName()}
avatarURL={chatUser?.getAvatar()}
title={chatUser?.getName()}
subtitleView={chatUser?.getStatus()}
/>
</>
);

<CometChatMessageHeader
user={chatUser}
itemView={CustomItemView}
hideBackButton={false}
/>;

TitleView

The customized chat interface is displayed below.

Image

Use the following code to achieve the customization shown above.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

// Custom title view component
function CustomTitleView() {
return <div className="message-header__title-view">
<span className="message-header__title-view-name">{userObj.getName() + " • "}</span>
<span className="message-header__title-view-status">{userObj.getStatusMessage()}</span>
</div>;
}

<CometChatMessageHeader user={userObj} titleView={CustomTitleView()} />;

SubtitleView

The customized chat interface is displayed below.

Image

Use the following code to achieve the customization shown above.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

// Custom subtitle view component
function CustomSubtitleView() {
return <>{group?.getMembersCount() + " • " + group?.getDescription()}</>;
}

<CometChatMessageHeader group={groupObj} subtitleView={CustomSubtitleView()} />;

LeadingView

The customized chat interface is displayed below.

Image

Use the following code to achieve the customization shown above.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader,CometChatAvatar } from "@cometchat/chat-uikit-react";

// Custom title view component
function CustomLeadingView() {
return <div className="message-header__leading-view">
<CometChatAvatar
image={userObj?.getAvatar()}
name={userObj?.getName()}
/>
<span className="message-header__leading-view-role">{userObj?.getRole()}</span>


</div>;
}

<CometChatMessageHeader user={userObj} leadingView={CustomLeadingView()} />;

TrailingView

The customized chat interface is displayed below.

Image

Use the following code to achieve the customization shown above.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatMessageHeader,
CometChatButton,
} from "@cometchat/chat-uikit-react";

// Custom trailing view component
function CustomTrailingButtonView() {
return (
<>
<CometChatButton
onClick={() => {
// Your logic here
}}
iconURL={icon} // Ensure `icon` is defined or passed as a prop
/>
</>
);
}

<CometChatMessageHeader user={userObj} trailingView={CustomTrailingButtonView()} />;

AuxiliaryButtonView

The customized chat interface is displayed below.

Image

Use the following code to achieve the customization shown above.

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatMessageHeader,
CometChatButton,
} from "@cometchat/chat-uikit-react";

// Custom auxiliary view component
function CustomAuxiliaryButtonView() {
return (
<>
<CometChatButton
onClick={() => {
// Your logic here
}}
iconURL={icon} // Ensure `icon` is defined or passed as a prop
/>
</>
);
}

<CometChatMessageHeader group={groupObj} auxiliaryButtonView={CustomAuxiliaryButtonView()} />;