Skip to main content
Version: v4

Groups

Overview

The Groups is a Component, showcasing an accessible list of all available groups. It provides an integral search functionality, allowing you to locate any specific groups swiftly and easily. For each group listed, the group name is displayed by default, in conjunction with the group icon when available. Additionally, it provides a useful feature by displaying the number of members in each group as a subtitle, offering valuable context about group size and activity level.

Image

The Groups component is composed of the following BaseComponents:

ComponentsDescription
CometChatLista reusable container component having title, search box, customisable background and a List View
CometChatListItema component that renders data obtained from a Group object on a Tile having a title, subtitle, leading and trailing view

Usage

Integration

The following code snippet illustrates how you can directly incorporate the Groups component into your Application.

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

const GroupsDemo = () => {
return <CometChatGroups />;
};

export default GroupsDemo;

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. onSelect

The onSelect action is activated when you select the done icon while in selection mode. This returns the group object along with the boolean flag selected to indicate if the group was selected or unselected.

This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.

GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups, SelectionMode } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
function handleOnSelect(group: CometChat.Group, selected: boolean): void {
console.log(group);
//your custom onSelect actions
}
return (
<CometChatGroups
selectionMode={SelectionMode.multiple}
onSelect={handleOnSelect}
/>
);
};

export default GroupsDemo;
2. onItemClick

The onItemClick event is activated when you click on the Group List item. This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.

GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
function handleOnItemClick(group: CometChat.Group): void {
console.log(group, "your custom on item click action");
}
return <CometChatGroups onItemClick={handleOnItemClick} />;
};

export default GroupsDemo;
3. onError

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

GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const handleOnError = (error: CometChat.CometChatException) => {
console.log("Your custom on error actions");
};
return <CometChatGroups onError={handleOnError} />;
};

export default GroupsDemo;

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 ChatSDK.

1. GroupsRequestBuilder

The GroupsRequestBuilder enables you to filter and customize the group list based on available parameters in GroupsRequestBuilder. This feature allows you to create more specific and targeted queries when fetching groups. The following are the parameters available in GroupsRequestBuilder

MethodsTypeDescription
setLimitnumbersets the number groups that can be fetched in a single request, suitable for pagination
setSearchKeywordStringused for fetching groups matching the passed string
joinedOnlybooleanto fetch only joined groups.
setTagsArray<String>used for fetching groups containing the passed tags
withTagsbooleanused to fetch tags data along with the list of groups

Example

In the example below, we are applying a filter to the Group List based on only joined groups and setting the limit to two.

GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
return (
<CometChatGroups
groupsRequestBuilder={new CometChat.GroupsRequestBuilder()
.setLimit(2)
.joinedOnly(true)}
/>
);
};

export default GroupsDemo;
2. SearchRequestBuilder

The SearchRequestBuilder uses GroupsRequestBuilder enables you to filter and customize the search list based on available parameters in GroupsRequestBuilder. This feature allows you to keep uniformity between the displayed Groups List and searched Group List.

Example

GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
return (
<CometChatGroups
searchRequestBuilder={new CometChat.GroupsRequestBuilder()
.setLimit(2)
.setSearchKeyword("your keyword")}
/>
);
};

export default GroupsDemo;

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.

To handle events supported by Groups you have to add corresponding listeners by using CometChatGroupEvents

The Groups component does not produce any events directly.


Customization

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

Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

1. Groups Style

You can set the GroupsStyle to the Groups Component to customize the styling.

Image
GroupsDemo.tsx
import { CometChatGroups, GroupsStyle } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const groupsStyle = new GroupsStyle({
background: "#f7f2ff",
titleTextColor: "#6414fa",
searchTextColor: "#940be3",
separatorColor: "#ffffff",
});
return <CometChatGroups groupsStyle={groupsStyle} />;
};

export default GroupsDemo;

List of properties exposed by GroupsStyle

PropertyDescriptionCode
borderUsed to set borderborder?: string,
borderRadiusUsed to set border radiusborderRadius?: string;
backgroundUsed to set background colourbackground?: string;
heightUsed to set heightheight?: string;
widthUsed to set widthwidth?: string;
titleTextFontUsed to customise the font of the title in the app bartitleTextFont?: string;
titleTextColorUsed to customise the color of the title in the app bartitleTextColor?: string;
emptyStateTextFontUsed to set the font style of the response text shown when fetchig the list of groups has returned an empty listemptyStateTextFont?: string;
emptyStateTextColorUsed to set the color of the response text shown when fetchig the list of groups has returned an empty listemptyStateTextColor?: string;
errorStateTextFontUsed to set the font style of the response text shown in case some error occurs while fetching the list of groupserrorStateTextFont?: string;
errorStateTextColorUsed to set the font style of the response text shown in case some error occurs while fetching the list of groupserrorStateTextColor?: string;
loadingIconTintUsed to set the color of the icon shown while the list of groups is being fetchedloadingIconTint?: string;
separatorColorUsed to set the color of the divider separating the group member itemsseparatorColor?: string;
boxShadowSets shadow effects around the elementboxShadow?: string;
privateGroupIconBackgroundSets background color of private group IconprivateGroupIconBackground?: string;
passwordGroupIconBackgroundSets background color of protected group IconpasswordGroupIconBackground?: string;
searchIconTintUsed to set the color of the search icon in the search boxsearchIconTint?: string;
searchBorderUsed to set the border of the search boxsearchBorder?: string;
searchBorderRadiusUsed to set the border radius of the search boxsearchBorderRadius?: string;
searchBackgroundUsed to set the background color of the search boxsearchBackground?: string;
searchPlaceholderTextFontUsed to set the font of the placeholder text in the search boxsearchPlaceholderTextFont?: string;
searchPlaceholderTextColorUsed to set the color of the placeholder text in the search boxsearchPlaceholderTextColor?: string;
searchTextFontUsed to set the font of the text in the search boxsearchTextFont?: string;
searchTextColorUsed to set the color of the text in the search boxsearchTextColor?: string;
subTitleTextFontUsed to customise the font of the subtitle text.subTitleTextFont?: string;
subTitleTextColorUsed to customise the color of the subtitle text.subTitleTextColor?: string;
2. Avatar Style

To apply customized styles to the Avatar component in the Groups Component, you can use the following code snippet. For further insights on Avatar Styles refer

GroupsDemo.tsx
import { CometChatGroups, AvatarStyle } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const avatarStyle = new AvatarStyle({
backgroundColor: "#cdc2ff",
border: "2px solid #6745ff",
borderRadius: "10px",
outerViewBorderColor: "#ca45ff",
outerViewBorderRadius: "5px",
nameTextColor: "#4554ff",
});
return <CometChatGroups avatarStyle={avatarStyle} />;
};

export default GroupsDemo;
3. StatusIndicator Style

To apply customized styles to the Status Indicator component in the Groups Component, You can use the following code snippet. For further insights on Status Indicator Styles refer

GroupsDemo.tsx
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const statusIndicatorStyle = {
background: "#db35de",
height: "10px",
width: "10px",
};
return <CometChatGroups statusIndicatorStyle={statusIndicatorStyle} />;
};

export default GroupsDemo;
4. ListItem Style

To apply customized styles to the ListItemStyle component in the Groups Component, you can use the following code snippet. For further insights on ListItemStyle Styles refer

GroupsDemo.tsx
import { CometChatGroups, ListItemStyle } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const listItemStyle = new ListItemStyle({
width: "100%",
height: "100%",
border: "2px solid red",
});
return <CometChatGroups listItemStyle={listItemStyle} />;
};

export default GroupsDemo;

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.

GroupsDemo.tsx
import { CometChatGroups, TitleAlignment } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
return (
<CometChatGroups
title="Your Custom Title"
titleAlignment={TitleAlignment.center}
hideSearch={true}
/>
);
};

export default GroupsDemo;

Default:

Image

Custom:

Image

Below is a list of customizations along with corresponding code snippets:

PropertyDescriptionCode
title report Used to set title in the app headingtitle="Your Custom Title"
searchPlaceholderText report Used to set search placeholder textsearchPlaceholderText="Your Custom search placeholder text"
errorStateText report Used to set a custom text response when some error occurs on fetching the list of groupserrorStateText="your custom error state text"
emptyStateText report Used to set a custom text response when fetching the groups has returned an empty listemptyStateText="your custom empty state text"
searchIconURLUsed to set search Icon in the search fieldsearchIconURL="Your Custom search icon"
loadingIconURLUsed to set loading IconloadingIconURL="your custom loading icon url"
privateGroupIconUsed to set the private group IconprivateGroupIcon='Custom Private Group Icon'
passwordGroupIconUsed to set the protected group IconpasswordGroupIcon='Custom protected Group Icon'
hideSearchUsed to toggle visibility for search boxhideSearch={true}"
hideErrorUsed to hide error on fetching groupshideError={true}
hideSeparatorUsed to hide the divider separating the group itemshideSeparator={true}
activeGroup report Used to set the active groupactiveGroup={chatGroup}
titleAlignmentAlignment of the heading text for the componenttitleAlignment={TitleAlignment.center}
selectionModeset the number of groups that can be selected, SelectionMode can be single, multiple or none.selectionMode={SelectionMode.multiple}

Advance

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.


ListItemView

With this property, you can assign a custom ListItem to the Groups Component.

listItemView = { getListItemView };

Example

Default:

Image

Custom:

Image
GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const getListItemView = (group: CometChat.Group) => {
return (
<div
style={{
display: "flex",
alignItems: "left",
padding: "10px",
border: "2px solid #e9baff",
borderRadius: "20px",
background: "#6e2bd9",
}}
>
<cometchat-avatar image={group.getIcon()} name={group.getName()} />

<div style={{ display: "flex", paddingLeft: "10px" }}>
<div
style={{ fontWeight: "bold", color: "#ffffff", fontSize: "14px" }}
>
{group.getName()}
<div
style={{ color: "#ffffff", fontSize: "10px", textAlign: "left" }}
>
{group.getMembersCount()} members
</div>
</div>
</div>
</div>
);
};
return <CometChatGroups listItemView={getListItemView} />;
};

export default GroupsDemo;

SubtitleView

You can customize the subtitle view for each group item to meet your requirements

subtitleView = { getSubtitleView };

Default:

Image

Custom:

Image
GroupsDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const getSubtitleView = (group: CometChat.Group): JSX.Element => {
if (group instanceof CometChat.Group) {
return (
<div
style={{
display: "flex",
alignItems: "left",
padding: "2px",
fontSize: "10px",
}}
>
<div style={{ color: "gray" }}>{group.getMembersCount()} members</div>
</div>
);
} else {
return <></>;
}
};
return <CometChatGroups subtitleView={getSubtitleView} />;
};

export default GroupsDemo;

LoadingStateView

You can set a custom loader view using loadingStateView to match the loading view of your app.

loadingStateView={getLoadingStateView()}

Default:

Image

Custom:

Image
GroupsDemo.tsx
import { CometChatGroups, LoaderStyle } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const getLoadingStateView = () => {
const getLoaderStyle = new LoaderStyle({
iconTint: "#890aff",
height: "100vh",
width: "100vw",
});

return (
<cometchat-loader
iconURL="icon"
loaderStyle={JSON.stringify(getLoaderStyle)}
></cometchat-loader>
);
};
return <CometChatGroups loadingStateView={getLoadingStateView()} />;
};

export default GroupsDemo;

EmptyStateView

You can set a custom EmptyStateView using emptyStateView to match the empty view of your app.

emptyStateView={getEmptyStateView()}

Default:

Image

Custom:

Image
GroupsDemo.tsx

import { CometChatGroups } from '@cometchat/chat-uikit-react'
import React from 'react'

const GroupsDemo = () => {

cconst getEmptyStateView = () => {
return(
<div style={{color:'#d6cfff', fontSize:'30px', font:'bold'}}>
Your Custom Empty State
</div>
);
};
return (
<CometChatGroups
emptyStateView={getEmptyStateView()}
/>
)
}

export default GroupsDemo;


ErrorStateView

You can set a custom ErrorStateView using errorStateView to match the error view of your app.

errorStateView={getErrorStateView()}

Default:

Image

Custom:

Image
GroupsDemo.tsx
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const getErrorStateView = () => {
return (
<div style={{ height: "100vh", width: "100vw" }}>
<img
src=" custom image "
alt="error icon"
style={{
height: "100px",
width: "100px",
marginTop: "250px",
justifyContent: "center",
}}
></img>
</div>
);
};
return <CometChatGroups errorStateView={getErrorStateView()} />;
};

export default GroupsDemo;

You can set the Custom Menu view to add more options to the Groups component.

menus={getMenus()}
Image
GroupsDemo.tsx
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
const getMenus = () => {
const handleReload = () => {
window.location.reload();
};
const getButtonStyle = () => {
return {
height: "20px",
width: "20px",
border: "none",
borderRadius: "0",
background: "transparent",
buttonIconTint: "#7E57C2",
};
};
return (
<div style={{ marginRight: "20px" }}>
<cometchat-button
iconURL="icon"
buttonStyle={JSON.stringify(getButtonStyle())}
onClick={handleReload}
>
{" "}
</cometchat-button>
</div>
);
};
return <CometChatGroups menus={getMenus()} />;
};

export default GroupsDemo;

Options

You can set the Custom options to the Groups component.

Image
GroupsDemo.tsx
import { CometChatGroups, CometChatOption } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
return (
<CometChatGroups
options={(group: any) => {
const customOptions = [
new CometChatOption({
id: "1",
title: "Title",
iconURL: "icon",
backgroundColor: "transparent",
onClick: () => {
console.log("Custom option clicked for group:", group);
},
iconTint: "#890aff",
titleColor: "blue",
}),
];
return customOptions;
}}
/>
);
};

export default GroupsDemo;