@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
43 lines (42 loc) • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const lexical_1 = require("lexical");
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
const material_1 = require("@mui/material");
const EmojiPicker_1 = tslib_1.__importDefault(require("../../../shared/EmojiPicker"));
const constants_1 = require("../constants");
function Emoji({ editor, className = '', isLessonCommentEditor = false }) {
// STATE
const theme = (0, material_1.useTheme)();
const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
const [emojiAnchorEl, setEmojiAnchorEl] = (0, react_1.useState)(false);
// HANDLERS
const handleOpen = (event) => {
setEmojiAnchorEl(event.currentTarget);
};
const handleEmojiClick = (emojiData, event) => {
editor.focus();
editor.dispatchCommand(lexical_1.CONTROLLED_TEXT_INSERTION_COMMAND, emojiData.emoji);
};
if (isMobile) {
return null;
}
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ className: className, onClick: handleOpen }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "sentiment_satisfied_alt" }) })), (0, jsx_runtime_1.jsx)(material_1.Popover, Object.assign({ open: Boolean(emojiAnchorEl), anchorEl: emojiAnchorEl, onClose: () => setEmojiAnchorEl(null), TransitionComponent: material_1.Fade, anchorOrigin: isLessonCommentEditor ? { vertical: 'bottom', horizontal: 'left' } : { vertical: 'top', horizontal: 'right' }, transformOrigin: isLessonCommentEditor ? { vertical: 'top', horizontal: 'right' } : { vertical: 'bottom', horizontal: 'left' }, sx: (theme) => {
return { zIndex: theme.zIndex.tooltip };
} }, { children: (0, jsx_runtime_1.jsx)(EmojiPicker_1.default, { onEmojiClick: handleEmojiClick }) }))] }));
}
const classes = {
root: `${constants_1.PREFIX}-emoji-plugin-root`
};
const Root = (0, material_1.styled)(Emoji, {
name: constants_1.PREFIX,
slot: 'EmojiPluginRoot'
})(() => ({}));
function EmojiPlugin({ isLessonCommentEditor = false }) {
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
return (0, jsx_runtime_1.jsx)(Root, { editor: editor, className: classes.root, isLessonCommentEditor: isLessonCommentEditor });
}
exports.default = EmojiPlugin;