import { Input, InputRef, Modal } from 'antd'; import { auto } from 'manate/react'; import React, { useRef, useState } from 'react'; import { Store } from '../../store'; const PromptModals = (props: { store: Store }) => { const { store } = props; const { modals } = store; const emojiInput = useRef(null); const faInput = useRef(null); const [emojiValue, setEmojiValue] = useState(''); const [faValue, setFaValue] = useState(''); const handleEmojiOK = () => { modals.emoji.close(); const value = emojiValue.trim(); if (value.length > 0) { const editor = store.editor; const mainSelection = editor.state.selection.main; editor.dispatch({ changes: { from: mainSelection.from, to: mainSelection.to, insert: `:${value}:`, }, selection: { anchor: mainSelection.head + value.length + 2 }, }); } setEmojiValue(''); }; const handleFaOK = () => { modals.fontAwesome.close(); const value = faValue.trim(); if (value.length > 0) { const editor = store.editor; const mainSelection = editor.state.selection.main; editor.dispatch({ changes: { from: mainSelection.from, to: mainSelection.to, insert: `:fa-${value}:`, }, selection: { anchor: mainSelection.head + value.length + 5 }, }); } setFaValue(''); }; return ( <> {/* emoji modal */} modals.emoji.close()} onOk={() => handleEmojiOK()} maskClosable={true} centered={true} afterOpenChange={(open) => { if (open) { emojiInput.current?.focus(); } }} >

Please enter an emoji code:

{`Examples: "smile", "whale", "santa", "panda_face", "dog", "truck" ...`}

For a complete list, please check{' '} Emoji Cheat Sheet .

setEmojiValue(e.target.value)} placeholder="smile" onKeyUp={(e) => { if (e.key === 'Enter') { handleEmojiOK(); } }} />
{/* font awesome modal */} modals.fontAwesome.close()} onOk={() => handleFaOK()} maskClosable={true} centered={true} afterOpenChange={(open) => { if (open) { faInput.current?.focus(); } }} >

Please enter a Font Awesome code:

{`Examples: "cloud", "flag", "car", "truck", "heart", "dollar" ...`}

For a complete list, please check{' '} Font Awesome Icons .

setFaValue(e.target.value)} onKeyUp={(e) => { if (e.key === 'Enter') { handleFaOK(); } }} />
); }; export default auto(PromptModals);