import { React, useEffect, useState } from "react";import { TabAlignment, CometChatTabItem } from "@cometchat/uikit-resources";import { CometChatUsersWithMessages, CometChatGroupsWithMessages, CometChatConversationsWithMessages, CometChatTabs,} from "@cometchat/chat-uikit-react";import usersTabIcon from "./assets/users.svg";import groupsTabIcon from "./assets/groups.svg";import chatsTabIcon from "./assets/chats.svg";export function CometChatUI() { const chatsTab = new CometChatTabItem({ id: "chats", iconURL: chatsTabIcon, title: "Chats", childView: <CometChatConversationsWithMessages />, }); const usersTab = new CometChatTabItem({ id: "users", iconURL: usersTabIcon, title: "Users", childView: <CometChatUsersWithMessages />, }); const groupsTab = new CometChatTabItem({ id: "groups", title: "Groups", iconURL: groupsTabIcon, childView: <CometChatGroupsWithMessages />, }); const tabs = [chatsTab, usersTab, groupsTab]; return ( <div style={{ width: "100%", height: "100%" }}> <CometChatTabs tabAlignment={TabAlignment.bottom} tabs={tabs} tabsStyle={tStyle} /> </div> );}
Step 4: We make the Chats tab the active tab by default. Apply styles to all the tab items, as well as the entire tabs component, and align them to the bottom of the container. The tab items are draggable so that the user is able to drag and drop them within the container.
Step 5: Import the CometChatUI component into your App component.
Copy
Ask AI
import logo from "./logo.svg";import "./App.css";import { CometChatUI } from "./CometChatUI";function App(props) { return ( <div className="App"> <CometChatUI /> </div> );}export default App;
You can now see chats, users and group components each as tab items. This is how you can launch CometChat UIKit’s individual component in a tabbed layout. 🎉