@megha-ui/react 1.2.177 → 1.2.179

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { User } from "./ChatList";
3
+ export interface ChatDetailsProps {
4
+ selectedUser: User | null;
5
+ currentUserId: string;
6
+ }
7
+ declare const ChatDetails: React.FC<ChatDetailsProps>;
8
+ export default ChatDetails;
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useRef } from "react";
3
+ import { VscSend } from "react-icons/vsc";
4
+ import { FaUsers } from "react-icons/fa";
5
+ const ChatDetails = ({ selectedUser, currentUserId }) => {
6
+ const [messages, setMessages] = useState([]);
7
+ const [newMessage, setNewMessage] = useState("");
8
+ const endRef = useRef(null);
9
+ useEffect(() => {
10
+ var _a;
11
+ (_a = endRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
12
+ }, [messages]);
13
+ useEffect(() => {
14
+ setMessages([]);
15
+ setNewMessage("");
16
+ }, [selectedUser]);
17
+ const handleSend = () => {
18
+ if (!newMessage.trim() || !selectedUser)
19
+ return;
20
+ const msg = {
21
+ id: Date.now().toString(),
22
+ senderId: currentUserId,
23
+ text: newMessage,
24
+ timestamp: new Date(),
25
+ };
26
+ setMessages((prev) => [...prev, msg]);
27
+ setNewMessage("");
28
+ };
29
+ if (!selectedUser) {
30
+ return _jsx("div", { className: "wk-chat-placeholder", style: { flex: 1, padding: 16 }, children: "Select a chat" });
31
+ }
32
+ return (_jsxs("div", { className: "wk-chat-details", style: { flex: 1, display: "flex", flexDirection: "column" }, children: [_jsxs("div", { className: "wk-chat-header", style: { display: "flex", alignItems: "center", padding: "8px", borderBottom: "1px solid #f5f5f5" }, children: [_jsx("div", { className: "wk-chat-user-icon", style: {
33
+ width: 32,
34
+ height: 32,
35
+ borderRadius: "50%",
36
+ backgroundColor: selectedUser.isGroup ? "#34a853" : "#0096c7",
37
+ color: "#fff",
38
+ display: "flex",
39
+ alignItems: "center",
40
+ justifyContent: "center",
41
+ marginRight: 8,
42
+ textTransform: "uppercase",
43
+ }, children: selectedUser.isGroup ? (_jsx(FaUsers, {})) : (`${selectedUser.firstName[0]}${selectedUser.lastName[0]}`) }), _jsx("div", { style: { fontWeight: "bold" }, children: selectedUser.isGroup
44
+ ? selectedUser.firstName
45
+ : `${selectedUser.firstName} ${selectedUser.lastName}` })] }), _jsxs("div", { className: "wk-chat-messages", style: { flex: 1, overflowY: "auto", padding: "8px" }, children: [messages.map((m) => (_jsx("div", { className: `wk-chat-message${m.senderId === currentUserId ? " wk-sent" : " wk-received"}`, style: {
46
+ marginBottom: 8,
47
+ display: "flex",
48
+ justifyContent: m.senderId === currentUserId ? "flex-end" : "flex-start",
49
+ }, children: _jsx("div", { style: {
50
+ background: m.senderId === currentUserId ? "#F9F9F9" : "#EAF2FA",
51
+ padding: "6px 8px",
52
+ borderRadius: 4,
53
+ maxWidth: "70%",
54
+ }, children: m.text }) }, m.id))), _jsx("div", { ref: endRef })] }), _jsxs("div", { className: "wk-chat-input", style: { display: "flex", padding: 8, borderTop: "1px solid #f5f5f5" }, children: [_jsx("input", { type: "text", value: newMessage, onChange: (e) => setNewMessage(e.target.value), onKeyDown: (e) => {
55
+ if (e.key === "Enter") {
56
+ e.preventDefault();
57
+ handleSend();
58
+ }
59
+ }, style: { flex: 1, border: "1px solid #dbdfe9", borderRadius: 4, padding: "6px" } }), _jsx("button", { onClick: handleSend, style: { marginLeft: 8, background: "transparent", border: "none", cursor: "pointer" }, children: _jsx(VscSend, { size: 20 }) })] })] }));
60
+ };
61
+ export default ChatDetails;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ export interface User {
3
+ id: string;
4
+ firstName: string;
5
+ lastName: string;
6
+ roleType?: string;
7
+ latestMessageTimestamp?: number;
8
+ latestMessageText?: string;
9
+ isGroup?: boolean;
10
+ }
11
+ export interface ChatListProps {
12
+ users: User[];
13
+ onSelectUser: (user: User) => void;
14
+ selectedUserId?: string;
15
+ unreadCounts?: Record<string, number>;
16
+ }
17
+ declare const ChatList: React.FC<ChatListProps>;
18
+ export default ChatList;
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { FaUsers } from "react-icons/fa";
3
+ import Loader from "../../loader";
4
+ const formatTimestamp = (timestamp) => {
5
+ if (!timestamp)
6
+ return "";
7
+ const date = new Date(timestamp);
8
+ const now = new Date();
9
+ const diffInDays = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
10
+ if (diffInDays === 0) {
11
+ return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
12
+ }
13
+ else if (diffInDays === 1) {
14
+ return "Yesterday";
15
+ }
16
+ else if (diffInDays < 7) {
17
+ return date.toLocaleDateString([], { weekday: "long" });
18
+ }
19
+ else {
20
+ return date.toLocaleDateString();
21
+ }
22
+ };
23
+ const ChatList = ({ users, onSelectUser, selectedUserId, unreadCounts = {}, }) => {
24
+ return (_jsx("div", { className: "wk-chat-list", style: { width: "30%", overflowY: "auto" }, children: users.length > 0 ? (users.map((user) => {
25
+ var _a, _b;
26
+ return (_jsxs("div", { onClick: () => onSelectUser(user), className: `wk-chat-user-item${selectedUserId === user.id ? " wk-selected" : ""}`, style: {
27
+ padding: "8px",
28
+ cursor: "pointer",
29
+ display: "flex",
30
+ borderBottom: "1px solid #f5f5f5",
31
+ }, children: [_jsx("div", { className: "wk-chat-user-icon", style: {
32
+ width: 32,
33
+ height: 32,
34
+ borderRadius: "50%",
35
+ backgroundColor: user.isGroup ? "#34a853" : "#0096c7",
36
+ color: "#fff",
37
+ display: "flex",
38
+ alignItems: "center",
39
+ justifyContent: "center",
40
+ marginRight: 8,
41
+ textTransform: "uppercase",
42
+ }, children: user.isGroup ? (_jsx(FaUsers, {})) : (`${(_a = user.firstName) === null || _a === void 0 ? void 0 : _a[0]}${(_b = user.lastName) === null || _b === void 0 ? void 0 : _b[0]}`) }), _jsxs("div", { style: { flex: 1 }, children: [_jsx("div", { style: { fontWeight: "bold" }, children: user.isGroup
43
+ ? user.firstName
44
+ : `${user.firstName} ${user.lastName}` }), _jsx("div", { style: { fontSize: "0.8rem", color: "#555" }, children: user.latestMessageText || "No messages yet" })] }), unreadCounts[user.id] > 0 && (_jsx("span", { style: {
45
+ marginLeft: "auto",
46
+ background: "#0096c7",
47
+ color: "#fff",
48
+ borderRadius: "50%",
49
+ width: 20,
50
+ height: 20,
51
+ display: "flex",
52
+ alignItems: "center",
53
+ justifyContent: "center",
54
+ fontSize: "0.75rem",
55
+ }, children: unreadCounts[user.id] })), _jsx("div", { style: { marginLeft: 8, fontSize: "0.75rem", color: "#888" }, children: formatTimestamp(user.latestMessageTimestamp) })] }, user.id));
56
+ })) : (_jsx("div", { style: { padding: 16, textAlign: "center" }, children: _jsx(Loader, { size: 24 }) })) }));
57
+ };
58
+ export default ChatList;
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { User } from "./components/ChatList";
3
+ export interface ChatProps {
4
+ users: User[];
5
+ currentUserId: string;
6
+ }
7
+ declare const Chat: React.FC<ChatProps>;
8
+ export default Chat;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import ChatList from "./components/ChatList";
4
+ import ChatDetails from "./components/ChatDetails";
5
+ const Chat = ({ users, currentUserId }) => {
6
+ const [selectedUser, setSelectedUser] = useState(null);
7
+ return (_jsxs("div", { className: "wk-chat-container", style: { display: "flex", border: "1px solid #dbdfe9", height: "400px" }, children: [_jsx(ChatList, { users: users, onSelectUser: setSelectedUser, selectedUserId: selectedUser === null || selectedUser === void 0 ? void 0 : selectedUser.id }), _jsx(ChatDetails, { selectedUser: selectedUser, currentUserId: currentUserId })] }));
8
+ };
9
+ export default Chat;
@@ -53,7 +53,7 @@ const GridFilterDropdown = ({ headerDropdownIndex, searchOptions, position, colu
53
53
  }
54
54
  onFilter(_uniqueSeach, columnKey);
55
55
  };
56
- return (_jsxs("div", { style: Object.assign(Object.assign({ position: "absolute", top: "calc(100% + 5px)" }, (columnIndex > 1 ? { right: 0 } : { left: 0 })), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "white", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", listStyleType: "none", padding: "0.35rem 0", width: "max-content", maxWidth: "500px", borderRadius: "0.5rem", margin: 0 }), ref: headerDropdown, onClick: (e) => e.stopPropagation(), children: [searchInput && searchInput, sortingOps, _jsxs("div", { style: {
56
+ return (_jsxs("div", { style: Object.assign(Object.assign({ position: "absolute", top: "calc(100% + 5px)" }, (columnIndex > 1 ? { right: 0 } : { left: 0 })), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "var(--background)", color: "var(--foreground)", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", listStyleType: "none", padding: "0.35rem 0", width: "max-content", maxWidth: "500px", borderRadius: "0.5rem", margin: 0 }), ref: headerDropdown, onClick: (e) => e.stopPropagation(), children: [searchInput && searchInput, sortingOps, _jsxs("div", { style: {
57
57
  padding: "0.5rem 0.75rem",
58
58
  cursor: "pointer",
59
59
  display: "flex",
@@ -64,7 +64,7 @@ const GridFilterDropdown = ({ headerDropdownIndex, searchOptions, position, colu
64
64
  maxHeight: 300,
65
65
  overflow: "auto",
66
66
  padding: "0.5rem 0.75rem",
67
- }, children: [_jsx("div", { className: "mb-2", children: _jsx(TextInput, { placeholder: `filter`, onChange: (e) => setFilterSearch(e.target.value), value: filterSearch, height: 32, width: "100%", className: "w-full", backgroundColor: "#fff" }) }), filterColumnData.length > 0 && (_jsxs(_Fragment, { children: [_jsxs("div", { style: {
67
+ }, children: [_jsx("div", { className: "mb-2", children: _jsx(TextInput, { placeholder: `filter`, onChange: (e) => setFilterSearch(e.target.value), value: filterSearch, height: 32, width: "100%", className: "w-full", backgroundColor: "var(--background)" }) }), filterColumnData.length > 0 && (_jsxs(_Fragment, { children: [_jsxs("div", { style: {
68
68
  cursor: "pointer",
69
69
  display: "flex",
70
70
  alignItems: "center",
@@ -289,7 +289,7 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
289
289
  } })), _jsx(MdFilterList, { size: 18, style: {
290
290
  color: activeFilters[((_q = headerColumns.find((column) => column.key === _groupBy)) === null || _q === void 0 ? void 0 : _q.key) || ""]
291
291
  ? "#2377ba"
292
- : "#000",
292
+ : "var(--row-header-text)",
293
293
  } }), dropdownVisible ===
294
294
  ((_r = headerColumns.find((column) => column.key === _groupBy)) === null || _r === void 0 ? void 0 : _r.key) &&
295
295
  (((_s = headerColumns.find((column) => column.key === _groupBy)) === null || _s === void 0 ? void 0 : _s.uniqueDrop) ? (_jsx(GridFilterDropdown, { locale: locale, formatOptions: formatOptions, columnType: (_u = (_t = headerColumns.find((column) => column.key === _groupBy)) === null || _t === void 0 ? void 0 : _t.dataType) !== null && _u !== void 0 ? _u : "string", columnIndex: -1, searchable: ((_v = headerColumns.find((column) => column.key === _groupBy)) === null || _v === void 0 ? void 0 : _v.search) || false, headerDropdownIndex: headerDropdownIndex, searchInput: (search &&
@@ -321,7 +321,7 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
321
321
  background: ((_z = headerColumns.find((column) => column.key === _groupBy)) === null || _z === void 0 ? void 0 : _z.search)
322
322
  ? "var(--background)"
323
323
  : "var(--disabled-bg)",
324
- }, value: ((_1 = searchQueries[((_0 = headerColumns.find((column) => column.key === _groupBy)) === null || _0 === void 0 ? void 0 : _0.key) || ""]) === null || _1 === void 0 ? void 0 : _1.text) || "", disabled: !((_2 = headerColumns.find((column) => column.key === _groupBy)) === null || _2 === void 0 ? void 0 : _2.search), height: 32, extraInputStyle: { minWidth: 10 }, className: "w-full", backgroundColor: "#fff" }) }))) ||
324
+ }, value: ((_1 = searchQueries[((_0 = headerColumns.find((column) => column.key === _groupBy)) === null || _0 === void 0 ? void 0 : _0.key) || ""]) === null || _1 === void 0 ? void 0 : _1.text) || "", disabled: !((_2 = headerColumns.find((column) => column.key === _groupBy)) === null || _2 === void 0 ? void 0 : _2.search), height: 32, extraInputStyle: { minWidth: 10 }, className: "w-full", backgroundColor: "var(--background)" }) }))) ||
325
325
  null, sortingOps: _jsx(GridHeaderDropdown, { options: menuOptions.filter((item) => item.label !== "Group by"), onClose: () => setDropdownVisible(null), column: headerColumns.find((column) => column.key === _groupBy) }), searchOptions: searchOptions.filter((item) => {
326
326
  var _a, _b;
327
327
  return ((_a = headerColumns.find((column) => column.key === _groupBy)) === null || _a === void 0 ? void 0 : _a.dataType) === "number"
@@ -562,7 +562,7 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
562
562
  } })), _jsx(MdFilterList, { size: 18, style: {
563
563
  color: activeFilters[column.key]
564
564
  ? "#2377ba"
565
- : "#000",
565
+ : "var(--row-header-text)",
566
566
  } }), dropdownVisible === column.key &&
567
567
  (column.uniqueDrop ? (_jsx(GridFilterDropdown, { locale: locale, formatOptions: formatOptions, columnType: (_b = column.dataType) !== null && _b !== void 0 ? _b : "string", columnIndex: colIndex, searchable: (column === null || column === void 0 ? void 0 : column.search) || false, headerDropdownIndex: headerDropdownIndex, searchOptions: searchOptions.filter((item) => column.dataType === "number" ||
568
568
  column.dataType === "currency"
@@ -22,7 +22,7 @@ const TextFilterDropdown = ({ headerDropdownIndex, searchOptions, combined, posi
22
22
  }
23
23
  : columnIndex > 1
24
24
  ? { right: 0 }
25
- : { left: 0 })), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "white", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", listStyleType: "none", padding: "0.25rem 0", width: 230, borderRadius: "0.5rem", margin: 0 }), id: "grid-dropdown", onClick: (e) => e.stopPropagation(), children: [searchInput && searchInput, sortingOps && sortingOps, _jsx("div", { style: {
25
+ : { left: 0 })), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "var(--background)", color: "var(--foreground)", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", listStyleType: "none", padding: "0.25rem 0", width: 230, borderRadius: "0.5rem", margin: 0 }), id: "grid-dropdown", onClick: (e) => e.stopPropagation(), children: [searchInput && searchInput, sortingOps && sortingOps, _jsx("div", { style: {
26
26
  padding: "0.5rem 0.75rem",
27
27
  }, children: _jsx(Dropdown, { options: searchOptions, selectedValues: [activeSearchType], onChange: (selected) => { var _a; return handleDropdownChange((_a = selected[0].toString()) !== null && _a !== void 0 ? _a : "", columnKey); }, searchEnabled: false, maxDropdownHeight: 350 }) }), !["blank", "notblank"].includes(activeSearchType.toLowerCase()) && (_jsx("div", { style: {
28
28
  padding: "0.5rem 0.75rem",
package/dist/index.d.ts CHANGED
@@ -14,3 +14,4 @@ export { default as TextEditor } from "./components/texteditor";
14
14
  export { default as Toggle } from "./components/toggle";
15
15
  export { Tabs, Tab, TabList, TabPanel } from "./components/tabs";
16
16
  export { formatValue } from "./services/commonService";
17
+ export { default as Chat } from "./components/chat";
package/dist/index.js CHANGED
@@ -14,3 +14,4 @@ export { default as TextEditor } from "./components/texteditor";
14
14
  export { default as Toggle } from "./components/toggle";
15
15
  export { Tabs, Tab, TabList, TabPanel } from "./components/tabs";
16
16
  export { formatValue } from "./services/commonService";
17
+ export { default as Chat } from "./components/chat";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.177",
3
+ "version": "1.2.179",
4
4
  "description": "A collection of reusable UI components for React applications, built with TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "@types/react": "^19.1.8",
31
31
  "@types/react-dom": "^19.1.6",
32
32
  "jest": "^27.5.1",
33
- "ts-jest": "^27.1.5",
33
+ "ts-jest": "^29.4.0",
34
34
  "typescript": "^5.8.3"
35
35
  },
36
36
  "peerDependencies": {