diff --git a/src/components/General/CreateAvatar/CreateAvatar.tsx b/src/components/General/CreateAvatar/CreateAvatar.tsx index 0d5fba4c..8db43985 100644 --- a/src/components/General/CreateAvatar/CreateAvatar.tsx +++ b/src/components/General/CreateAvatar/CreateAvatar.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { XStack, YStack } from 'tamagui' import { Avatar, Text } from '@status-im/components' import { ReactionIcon } from '@status-im/icons' @@ -6,15 +6,30 @@ import './CreateAvatar.css' import LabelInputField from '../LabelInputField' import ColorPicker from '../ColorPicker/ColorPicker' import EmojiPickerDialog from '../EmojiPickerDialog' -import { Emoji, EmojiClickData } from 'emoji-picker-react' +import { Emoji, EmojiClickData, EmojiStyle } from 'emoji-picker-react' const CreateAvatar = () => { const [chosenColor, setChosenColor] = useState('#2A4AF5') const [isEmojiDialogOpen, setIsEmojiDialogOpen] = useState(false) const [selectedEmoji, setSelectedEmoji] = useState('1f600') + const emojiRef = useRef(null) + function changeEmoji(emojiData: EmojiClickData) { setSelectedEmoji(emojiData.unified) } + + useEffect(() => { + function handleClickOutside(event: any) { + if (emojiRef.current && !emojiRef.current.contains(event.target)) { + setIsEmojiDialogOpen(false) + } + } + document.addEventListener('mousedown', handleClickOutside) + return () => { + document.removeEventListener('mousedown', handleClickOutside) + } + }, [emojiRef]) + return ( @@ -27,7 +42,9 @@ const CreateAvatar = () => {
- {selectedEmoji ? : null} + {selectedEmoji ? ( + + ) : null}
{ /> } /> - {isEmojiDialogOpen && ( - - )} +
+ {isEmojiDialogOpen && ( + + )} +
diff --git a/src/components/General/EmojiPickerDialog.tsx b/src/components/General/EmojiPickerDialog.tsx index e1f39649..4babda00 100644 --- a/src/components/General/EmojiPickerDialog.tsx +++ b/src/components/General/EmojiPickerDialog.tsx @@ -16,13 +16,13 @@ type EmojiPickerProps = { function EmojiPickerDialog({ emojiStyle, changeEmoji }: EmojiPickerProps) { return ( - +