cometchat-react-ui-kit2
Version:
CometChat UI Kit for React App
151 lines (141 loc) • 8.77 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CometChatConversations = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var styles = _interopRequireWildcard(require("./style"));
var _ = require("../");
var _2 = require("../../../");
var _Chats = require("../../Chats");
var _ListBaseStyles = require("../../Shared/PrimaryComponents/CometChatListBase/ListBaseStyles");
var _back = _interopRequireDefault(require("./resources/back.svg"));
var _new = _interopRequireDefault(require("./resources/new.svg"));
var _search = _interopRequireDefault(require("./resources/search.svg"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/**
*
* @version 1.0.0
* @author CometChatTeam
* @description CometChatConversations is a container component that wraps and
* formats CometChatListBase and CometChatConversationList component, with no behavior of its own.
*
*/
var CometChatConversations = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
/**
* Props destructuring
*/
var activeConversation = props.activeConversation,
title = props.title,
searchPlaceholder = props.searchPlaceholder,
backButtonIconURL = props.backButtonIconURL,
startConversationIconURL = props.startConversationIconURL,
searchIconURL = props.searchIconURL,
showBackButton = props.showBackButton,
hideStartConversation = props.hideStartConversation,
hideSearch = props.hideSearch,
style = props.style,
conversationListConfiguration = props.conversationListConfiguration,
theme = props.theme;
/**
* Component internal state
*/
var conversationListRef = _react["default"].useRef(null);
/**
* Component private scoping
*/
var _conversationListConfiguration = new _2.ConversationListConfiguration(conversationListConfiguration !== null && conversationListConfiguration !== void 0 ? conversationListConfiguration : {});
var _theme = new _2.CometChatTheme(theme !== null && theme !== void 0 ? theme : {});
;
_react["default"].useImperativeHandle(ref, function () {
return {
conversationListRef: conversationListRef.current
};
});
/**
* Component internal handlers/methods
*/
var searchHandler = function searchHandler(searchText) {
//TODO: search is not implemented
return false;
};
/**
* Component template scoping
*/
var getStartConversationButtonElem = function getStartConversationButtonElem() {
if (hideStartConversation) {
return /*#__PURE__*/_react["default"].createElement("div", {
style: styles.startConversationBtnStyle(style, _theme, startConversationIconURL)
});
}
return null;
};
/**
* Component template
*/
return /*#__PURE__*/_react["default"].createElement("div", {
style: styles.containerStyle(style, _theme),
className: "cometchat__conversations"
}, /*#__PURE__*/_react["default"].createElement(_2.CometChatListBase, {
style: new _ListBaseStyles.ListBaseStyles(_objectSpread({}, styles.getListBaseStyle(style, _theme))),
title: title,
searchPlaceholder: searchPlaceholder,
hideSearch: hideSearch,
showBackButton: showBackButton,
backButtonIconURL: backButtonIconURL,
onSearch: searchHandler,
searchIconURL: searchIconURL,
searchText: "",
theme: _theme
}, /*#__PURE__*/_react["default"].createElement(_.CometChatConversationList, {
ref: conversationListRef,
style: new _Chats.ConversationListStyles(_objectSpread(_objectSpread({}, styles.getConversationListStyle(style, _theme)), _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.style)),
limit: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.limit,
userAndGroupTags: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.userAndGroupTags,
tags: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.tags,
loadingIconURL: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.loadingIconURL,
customView: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.customView,
hideError: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.hideError,
emptyText: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.emptyText,
errorText: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.errorText,
activeConversation: activeConversation,
enableSoundForMessages: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.enableSoundForMessages,
conversationListItemConfiguration: _conversationListConfiguration === null || _conversationListConfiguration === void 0 ? void 0 : _conversationListConfiguration.conversationListItemConfiguration,
theme: _theme
})));
});
/**
* Component default props
*/
exports.CometChatConversations = CometChatConversations;
CometChatConversations.defaultProps = {
backButtonIconURL: _back["default"],
//TODO: This default props will be moved to configuration class when we move configurations in component folder only.
startConversationIconURL: _new["default"],
searchIconURL: _search["default"]
};
/**
* Component default props types
*/
CometChatConversations.propTypes = {
title: _propTypes["default"].string,
searchPlaceholder: _propTypes["default"].string,
style: _propTypes["default"].object,
backButtonIconURL: _propTypes["default"].string,
searchIconURL: _propTypes["default"].string,
showBackButton: _propTypes["default"].bool,
hideSearch: _propTypes["default"].bool,
startConversationIconURL: _propTypes["default"].string,
hideStartConversation: _propTypes["default"].bool,
activeConversation: _propTypes["default"].object,
//TODO: Figure out way to use PropTypes.objectOf(CometChat.Conversation)
conversationListConfiguration: _propTypes["default"].object,
theme: _propTypes["default"].object
};