UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

52 lines (51 loc) 2.45 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React, { useContext } from 'react'; //@ts-expect-error import DefaultEmojiIndex from 'emoji-mart/dist/utils/emoji-index/nimble-emoji-index.js'; var DefaultEmoji = React.lazy(function () { return import('./DefaultEmoji'); }); var DefaultEmojiPicker = React.lazy(function () { return import('./DefaultEmojiPicker'); }); export var EmojiContext = React.createContext(undefined); export var EmojiProvider = function (_a) { var children = _a.children, value = _a.value; var _b = value.Emoji, Emoji = _b === void 0 ? DefaultEmoji : _b, emojiConfig = value.emojiConfig, _c = value.EmojiIndex, EmojiIndex = _c === void 0 ? DefaultEmojiIndex : _c, _d = value.EmojiPicker, EmojiPicker = _d === void 0 ? DefaultEmojiPicker : _d; var emojiContextValue = { Emoji: Emoji, emojiConfig: emojiConfig, EmojiIndex: EmojiIndex, EmojiPicker: EmojiPicker, }; return React.createElement(EmojiContext.Provider, { value: emojiContextValue }, children); }; export var useEmojiContext = function (componentName) { var contextValue = useContext(EmojiContext); if (!contextValue) { console.warn("The useEmojiContext hook was called outside of the EmojiContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the ".concat(componentName, " component.")); return {}; } return contextValue; }; /** * Typescript currently does not support partial inference, so if EmojiContext * typing is desired while using the HOC withEmojiContext, the Props for the * wrapped component must be provided as the first generic. */ export var withEmojiContext = function (Component) { var WithEmojiContextComponent = function (props) { var componentContext = useEmojiContext(); return React.createElement(Component, __assign({}, props, componentContext)); }; WithEmojiContextComponent.displayName = (Component.displayName || Component.name || 'Component').replace('Base', ''); return WithEmojiContextComponent; };