@@ -7,11 +7,13 @@ import * as storage from "../helpers/storage";
77import Icon from "./Icon" ;
88import toastHelper from "./Toast" ;
99import Editor , { EditorRefActions } from "./Editor/Editor" ;
10+ import EmojiPicker from "./Editor/EmojiPicker" ;
1011import "../less/memo-editor.less" ;
1112
1213interface State {
1314 isUploadingResource : boolean ;
1415 fullscreen : boolean ;
16+ isShowEmojiPicker : boolean ;
1517}
1618
1719const MemoEditor = ( ) => {
@@ -22,6 +24,7 @@ const MemoEditor = () => {
2224 const [ state , setState ] = useState < State > ( {
2325 isUploadingResource : false ,
2426 fullscreen : false ,
27+ isShowEmojiPicker : false ,
2528 } ) ;
2629 const editorRef = useRef < EditorRefActions > ( null ) ;
2730 const prevGlobalStateRef = useRef ( editorState ) ;
@@ -244,6 +247,21 @@ const MemoEditor = () => {
244247 }
245248 } , [ ] ) ;
246249
250+ const handleChangeIsShowEmojiPicker = ( status : boolean ) => {
251+ setState ( {
252+ ...state ,
253+ isShowEmojiPicker : status ,
254+ } ) ;
255+ } ;
256+
257+ const handleEmojiClick = ( event : any , emojiObject : any ) => {
258+ if ( ! editorRef . current ) {
259+ return ;
260+ }
261+ editorRef . current ?. insertText ( `${ emojiObject . emoji } ` ) ;
262+ handleChangeIsShowEmojiPicker ( false ) ;
263+ } ;
264+
247265 const isEditing = Boolean ( editorState . editMemoId && editorState . editMemoId !== UNKNOWN_ID ) ;
248266
249267 const editorConfig = useMemo (
@@ -296,6 +314,9 @@ const MemoEditor = () => {
296314 < button className = "action-btn" >
297315 < Icon . Code className = "icon-img" onClick = { handleCodeBlockBtnClick } />
298316 </ button >
317+ < button className = "action-btn" >
318+ < Icon . Smile className = "icon-img" onClick = { ( ) => handleChangeIsShowEmojiPicker ( ! state . isShowEmojiPicker ) } />
319+ </ button >
299320 < button className = "action-btn" >
300321 < Icon . Image className = "icon-img" onClick = { handleUploadFileBtnClick } />
301322 < span className = { `tip-text ${ state . isUploadingResource ? "!block" : "" } ` } > Uploading</ span >
@@ -306,6 +327,13 @@ const MemoEditor = () => {
306327 </ >
307328 }
308329 />
330+ { state . isShowEmojiPicker && (
331+ < EmojiPicker
332+ onEmojiClick = { handleEmojiClick }
333+ isShowEmojiPicker = { state . isShowEmojiPicker }
334+ handleChangeIsShowEmojiPicker = { handleChangeIsShowEmojiPicker }
335+ />
336+ ) }
309337 </ div >
310338 ) ;
311339} ;
0 commit comments